@@ -685,7 +685,7 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
685
685
@click .command ("stop" , help = "prometheus | node_exporter | cadvisor | grafana | flask | container-name | "
686
686
"emulation-name | statsmanager | emulation_executions | pgadmin | all | nginx | postgresql "
687
687
"| docker | clustermanager | hostmanagers | hostmanager | clientmanager | snortmanagers "
688
- "| snortmanager" )
688
+ "| snortmanager | elkmanager " )
689
689
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
690
690
"""
691
691
Stops an entity
@@ -739,6 +739,8 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
739
739
stop_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
740
740
elif entity == "snortmanager" :
741
741
stop_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
742
+ elif entity == "elkmanager" :
743
+ stop_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
742
744
else :
743
745
container_stopped = False
744
746
for node in config .cluster_config .cluster_nodes :
@@ -926,7 +928,7 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
926
928
if node .ip == ip or ip == "" :
927
929
stopped = ClusterController .stop_host_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
928
930
emulation = emulation , ip_first_octet = ip_first_octet )
929
- if stopped :
931
+ if stopped . outcome :
930
932
click .secho (f"Stopping host managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
931
933
else :
932
934
click .secho (f"Host managers are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
@@ -951,7 +953,7 @@ def stop_host_manager(ip: str, container_ip: str, emulation: str, ip_first_octet
951
953
stopped = ClusterController .stop_host_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
952
954
emulation = emulation , ip_first_octet = ip_first_octet ,
953
955
container_ip = container_ip )
954
- if stopped :
956
+ if stopped . outcome :
955
957
click .secho (
956
958
f"Stopping host with ip { container_ip } on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
957
959
else :
@@ -976,7 +978,7 @@ def stop_client_manager(ip: str, emulation: str, ip_first_octet: int) -> None:
976
978
if node .ip == ip or ip == "" :
977
979
stopped = ClusterController .stop_client_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
978
980
emulation = emulation , ip_first_octet = ip_first_octet )
979
- if stopped :
981
+ if stopped . outcome :
980
982
click .secho (f"Stopping client manager on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
981
983
else :
982
984
click .secho (f"Client manager is not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
@@ -999,7 +1001,7 @@ def stop_snort_ids_managers(ip: str, emulation: str, ip_first_octet: int) -> Non
999
1001
if node .ip == ip or ip == "" :
1000
1002
stopped = ClusterController .stop_snort_ids_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1001
1003
emulation = emulation , ip_first_octet = ip_first_octet )
1002
- if stopped :
1004
+ if stopped . outcome :
1003
1005
click .secho (f"Stopping snort ids managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1004
1006
else :
1005
1007
click .secho (f"Snort ids managers are not stopped:"
@@ -1024,7 +1026,7 @@ def stop_snort_ids_manager(ip: str, container_ip: str, emulation: str, ip_first_
1024
1026
stopped = ClusterController .stop_snort_ids_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1025
1027
emulation = emulation , ip_first_octet = ip_first_octet ,
1026
1028
container_ip = container_ip )
1027
- if stopped :
1029
+ if stopped . outcome :
1028
1030
click .secho (
1029
1031
f"Stopping snort ids on the host with ip { container_ip } on "
1030
1032
f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
@@ -1034,6 +1036,29 @@ def stop_snort_ids_manager(ip: str, container_ip: str, emulation: str, ip_first_
1034
1036
bold = False )
1035
1037
1036
1038
1039
+ def stop_elk_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
1040
+ """
1041
+ Utility function for stopping the elk manage
1042
+
1043
+ :param ip: the ip of the node to stop the elk manger
1044
+ :param emulation: the emulation of the execution
1045
+ :param ip_first_octet: the ID of the execution
1046
+ :return: None
1047
+ """
1048
+ import csle_common .constants .constants as constants
1049
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1050
+ config = MetastoreFacade .get_config (id = 1 )
1051
+ for node in config .cluster_config .cluster_nodes :
1052
+ if node .ip == ip or ip == "" :
1053
+ stopped = ClusterController .stop_elk_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1054
+ emulation = emulation , ip_first_octet = ip_first_octet )
1055
+ if stopped .outcome :
1056
+ click .secho (f"Stopping elk manager on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1057
+ else :
1058
+ click .secho (f"Elk manager is not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1059
+ bold = False )
1060
+
1061
+
1037
1062
@click .argument ('max_workers' , default = 10 , type = int )
1038
1063
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
1039
1064
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1225,7 +1250,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1225
1250
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1226
1251
"container-name | emulation-name | all | statsmanager | training_job "
1227
1252
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1228
- "| hostmanager | clientmanager | snortmanagers | snortmanager" )
1253
+ "| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager " )
1229
1254
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1230
1255
container_ip : str , no_beats : bool ) -> None :
1231
1256
"""
@@ -1290,6 +1315,8 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1290
1315
start_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
1291
1316
elif entity == "snortmanager" :
1292
1317
start_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1318
+ elif entity == "elkmanager" :
1319
+ start_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
1293
1320
else :
1294
1321
container_started = False
1295
1322
for node in config .cluster_config .cluster_nodes :
@@ -1610,6 +1637,30 @@ def start_snort_ids_manager(ip: str, container_ip: str, emulation: str, ip_first
1610
1637
bold = False )
1611
1638
1612
1639
1640
+ def start_elk_manager (ip : str , emulation : str , ip_first_octet : int ):
1641
+ """
1642
+ Utility function for starting elk manager
1643
+
1644
+ :param ip: the ip of the node to start elk manager
1645
+ :param emulation: the emulation of the execution
1646
+ :param ip_first_octet: the ID of the execution
1647
+ :return: None
1648
+ """
1649
+ import csle_common .constants .constants as constants
1650
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1651
+ config = MetastoreFacade .get_config (id = 1 )
1652
+ for node in config .cluster_config .cluster_nodes :
1653
+ if node .ip == ip or ip == "" :
1654
+ operation_outcome = ClusterController .start_elk_manager (
1655
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1656
+ ip_first_octet = ip_first_octet )
1657
+ if operation_outcome .outcome :
1658
+ click .secho (f"Starting elk manager on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1659
+ else :
1660
+ click .secho (f"Elk manager is not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1661
+ bold = False )
1662
+
1663
+
1613
1664
def run_image (image : str , name : str , create_network : bool = True , version : str = "0.0.1" ) -> bool :
1614
1665
"""
1615
1666
Runs a container with a given image
@@ -1897,7 +1948,7 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
1897
1948
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
1898
1949
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
1899
1950
"simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
1900
- "clientmanager | snortmanagers" )
1951
+ "clientmanager | snortmanagers | elkmanager " )
1901
1952
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
1902
1953
@click .option ('--all' , is_flag = True , help = 'list all' )
1903
1954
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -1968,6 +2019,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
1968
2019
list_client_manager (ip = ip , emulation = name , ip_first_octet = id )
1969
2020
elif entity == "snortmanagers" :
1970
2021
list_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
2022
+ elif entity == "elkmanager" :
2023
+ list_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
1971
2024
else :
1972
2025
container = get_running_container (name = entity )
1973
2026
if container is not None :
@@ -2006,7 +2059,7 @@ def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
2006
2059
"""
2007
2060
Utility function for listing host managers
2008
2061
2009
- :param ip: the ip of the node to start host manager
2062
+ :param ip: the ip of the node to list host manager
2010
2063
:param emulation: the emulation of the execution
2011
2064
:param ip_first_octet: the ID of the execution
2012
2065
@@ -2038,11 +2091,69 @@ def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
2038
2091
click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
2039
2092
2040
2093
2094
+ def list_elk_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
2095
+ """
2096
+ Utility function for listing elk manager
2097
+
2098
+ :param ip: the ip of the node to list elk manager
2099
+ :param emulation: the emulation of the execution
2100
+ :param ip_first_octet: the ID of the execution
2101
+
2102
+ :return: None
2103
+ """
2104
+ import csle_common .constants .constants as constants
2105
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2106
+ config = MetastoreFacade .get_config (id = 1 )
2107
+ for node in config .cluster_config .cluster_nodes :
2108
+ if node .ip == ip or ip == "" :
2109
+ elk_manager_info = ClusterController .get_elk_managers_info (
2110
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2111
+ ip_first_octet = ip_first_octet )
2112
+ for i in range (len (elk_manager_info .ips )):
2113
+ status_color = 'green' if elk_manager_info .elkManagersRunning [i ] else 'red'
2114
+ manager_status = 'Running' if elk_manager_info .elkManagersRunning [i ] else 'Stopped'
2115
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2116
+ click .secho (f'|{ "Elk manager IP" :^40} ' , nl = False , fg = 'white' )
2117
+ click .secho ('|' , nl = False , fg = 'white' )
2118
+ click .secho (f'{ elk_manager_info .ips [i ]:<19} ' , nl = False , fg = status_color )
2119
+ click .secho ('|' , fg = 'white' )
2120
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2121
+ click .secho (f'|{ "Elk manager status" :^40} ' , nl = False , fg = 'white' )
2122
+ click .secho ('|' , nl = False , fg = 'white' )
2123
+ click .secho (f'{ manager_status :<19} ' , nl = False , fg = status_color )
2124
+ click .secho ('|' , fg = 'white' )
2125
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2126
+ if manager_status == "Running" :
2127
+ click .secho (f'|{ "Elk manager elasticRunning" :^40} ' , nl = False , fg = 'white' )
2128
+ click .secho ('|' , nl = False , fg = 'white' )
2129
+ elasticRunning = 'True' if elk_manager_info .elkManagersStatuses [0 ].elasticRunning else 'False'
2130
+ click .secho (f'{ elasticRunning :<19} ' ,
2131
+ nl = False , fg = status_color )
2132
+ click .secho ('|' , fg = 'white' )
2133
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2134
+
2135
+ click .secho (f'|{ "Elk manager kibanaRunning" :^40} ' , nl = False , fg = 'white' )
2136
+ click .secho ('|' , nl = False , fg = 'white' )
2137
+ kibanaRunning = 'True' if elk_manager_info .elkManagersStatuses [0 ].kibanaRunning else 'False'
2138
+ click .secho (f'{ kibanaRunning :<19} ' ,
2139
+ nl = False , fg = status_color )
2140
+ click .secho ('|' , fg = 'white' )
2141
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2142
+
2143
+ click .secho (f'|{ "Elk manager logstashRunning" :^40} ' , nl = False , fg = 'white' )
2144
+ click .secho ('|' , nl = False , fg = 'white' )
2145
+ logstashRunning = 'True' if elk_manager_info .elkManagersStatuses [0 ].logstashRunning else 'False'
2146
+ click .secho (f'{ logstashRunning :<19} ' ,
2147
+ nl = False , fg = status_color )
2148
+ click .secho ('|' , fg = 'white' )
2149
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2150
+
2151
+
2041
2152
def list_snort_ids_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
2042
2153
"""
2043
2154
Utility function for listing snort ids managers
2044
2155
2045
- :param ip: the ip of the node to start snort ids managers
2156
+ :param ip: the ip of the node to list snort ids managers
2046
2157
:param emulation: the emulation of the execution
2047
2158
:param ip_first_octet: the ID of the execution
2048
2159
@@ -2079,7 +2190,7 @@ def list_client_manager(ip: str, emulation: str, ip_first_octet: int) -> None:
2079
2190
"""
2080
2191
Utility function for listing client managers
2081
2192
2082
- :param ip: the ip of the node to start host manager
2193
+ :param ip: the ip of the node to list client manager
2083
2194
:param emulation: the emulation of the execution
2084
2195
:param ip_first_octet: the ID of the execution
2085
2196
0 commit comments