@@ -684,7 +684,8 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
684
684
@click .argument ('entity' , default = "" , shell_complete = stop_shell_complete )
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
- "| docker | clustermanager | hostmanagers | hostmanager | clientmanager" )
687
+ "| docker | clustermanager | hostmanagers | hostmanager | clientmanager | snortmanagers "
688
+ "| snortmanager" )
688
689
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
689
690
"""
690
691
Stops an entity
@@ -734,6 +735,10 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
734
735
stop_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
735
736
elif entity == "clientmanager" :
736
737
stop_client_manager (ip = ip , emulation = name , ip_first_octet = id )
738
+ elif entity == "snortmanagers" :
739
+ stop_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
740
+ elif entity == "snortmanager" :
741
+ stop_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
737
742
else :
738
743
container_stopped = False
739
744
for node in config .cluster_config .cluster_nodes :
@@ -978,6 +983,57 @@ def stop_client_manager(ip: str, emulation: str, ip_first_octet: int) -> None:
978
983
bold = False )
979
984
980
985
986
+ def stop_snort_ids_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
987
+ """
988
+ Utility function for stopping the snort ids managers
989
+
990
+ :param ip: the ip of the node to stop the snort ids mangers
991
+ :param emulation: the emulation of the execution
992
+ :param ip_first_octet: the ID of the execution
993
+ :return: None
994
+ """
995
+ import csle_common .constants .constants as constants
996
+ from csle_common .metastore .metastore_facade import MetastoreFacade
997
+ config = MetastoreFacade .get_config (id = 1 )
998
+ for node in config .cluster_config .cluster_nodes :
999
+ if node .ip == ip or ip == "" :
1000
+ stopped = ClusterController .stop_snort_ids_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1001
+ emulation = emulation , ip_first_octet = ip_first_octet )
1002
+ if stopped :
1003
+ click .secho (f"Stopping snort ids managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1004
+ else :
1005
+ click .secho (f"Snort ids managers are not stopped:"
1006
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " , bold = False )
1007
+
1008
+
1009
+ def stop_snort_ids_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
1010
+ """
1011
+ Utility function for stopping the snort ids manager
1012
+
1013
+ :param ip: the ip of the node to stop the host manager
1014
+ :param container_ip: the ip of the host to be stopped
1015
+ :param emulation: the emulation of the execution
1016
+ :param ip_first_octet: the ID of the execution
1017
+ :return: None
1018
+ """
1019
+ import csle_common .constants .constants as constants
1020
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1021
+ config = MetastoreFacade .get_config (id = 1 )
1022
+ for node in config .cluster_config .cluster_nodes :
1023
+ if node .ip == ip or ip == "" :
1024
+ stopped = ClusterController .stop_snort_ids_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1025
+ emulation = emulation , ip_first_octet = ip_first_octet ,
1026
+ container_ip = container_ip )
1027
+ if stopped :
1028
+ click .secho (
1029
+ f"Stopping snort ids on the host with ip { container_ip } on "
1030
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1031
+ else :
1032
+ click .secho (f"Snort ids on the host with ip { container_ip } is not "
1033
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1034
+ bold = False )
1035
+
1036
+
981
1037
@click .argument ('max_workers' , default = 10 , type = int )
982
1038
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
983
1039
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1169,7 +1225,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1169
1225
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1170
1226
"container-name | emulation-name | all | statsmanager | training_job "
1171
1227
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1172
- "| hostmanager | clientmanager" )
1228
+ "| hostmanager | clientmanager | snortmanagers | snortmanager " )
1173
1229
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1174
1230
container_ip : str , no_beats : bool ) -> None :
1175
1231
"""
@@ -1230,6 +1286,10 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1230
1286
start_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1231
1287
elif entity == "clientmanager" :
1232
1288
start_client_manager (ip = ip , emulation = name , ip_first_octet = id )
1289
+ elif entity == "snortmanagers" :
1290
+ start_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
1291
+ elif entity == "snortmanager" :
1292
+ start_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1233
1293
else :
1234
1294
container_started = False
1235
1295
for node in config .cluster_config .cluster_nodes :
@@ -1499,6 +1559,57 @@ def start_host_manager(ip: str, container_ip: str, emulation: str, ip_first_octe
1499
1559
bold = False )
1500
1560
1501
1561
1562
+ def start_snort_ids_managers (ip : str , emulation : str , ip_first_octet : int ):
1563
+ """
1564
+ Utility function for starting snort managers
1565
+
1566
+ :param ip: the ip of the node to start snort managers
1567
+ :param emulation: the emulation of the execution
1568
+ :param ip_first_octet: the ID of the execution
1569
+ :return: None
1570
+ """
1571
+ import csle_common .constants .constants as constants
1572
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1573
+ config = MetastoreFacade .get_config (id = 1 )
1574
+ for node in config .cluster_config .cluster_nodes :
1575
+ if node .ip == ip or ip == "" :
1576
+ operation_outcome = ClusterController .start_snort_ids_managers (
1577
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1578
+ ip_first_octet = ip_first_octet )
1579
+ if operation_outcome .outcome :
1580
+ click .secho (f"Starting snort ids managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1581
+ else :
1582
+ click .secho (f"Snort ids managers are not started:"
1583
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " , bold = False )
1584
+
1585
+
1586
+ def start_snort_ids_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1587
+ """
1588
+ Utility function for starting snort ids manager
1589
+
1590
+ :param ip: the ip of the node to start snort ids manager
1591
+ :param container_ip: the ip of the host to start
1592
+ :param emulation: the emulation of the execution
1593
+ :param ip_first_octet: the ID of the execution
1594
+ :return: None
1595
+ """
1596
+ import csle_common .constants .constants as constants
1597
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1598
+ config = MetastoreFacade .get_config (id = 1 )
1599
+ for node in config .cluster_config .cluster_nodes :
1600
+ if node .ip == ip or ip == "" :
1601
+ operation_outcome = ClusterController .start_snort_ids_manager (
1602
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1603
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1604
+ if operation_outcome .outcome :
1605
+ click .secho (f"Started snort ids manager with ip { container_ip } on "
1606
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1607
+ else :
1608
+ click .secho (f"Snort ids manager with ip { container_ip } is not "
1609
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1610
+ bold = False )
1611
+
1612
+
1502
1613
def run_image (image : str , name : str , create_network : bool = True , version : str = "0.0.1" ) -> bool :
1503
1614
"""
1504
1615
Runs a container with a given image
@@ -1786,7 +1897,7 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
1786
1897
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
1787
1898
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
1788
1899
"simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
1789
- "clientmanager" )
1900
+ "clientmanager | snortmanagers " )
1790
1901
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
1791
1902
@click .option ('--all' , is_flag = True , help = 'list all' )
1792
1903
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -1855,6 +1966,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
1855
1966
list_host_managers (ip = ip , emulation = name , ip_first_octet = id )
1856
1967
elif entity == "clientmanager" :
1857
1968
list_client_manager (ip = ip , emulation = name , ip_first_octet = id )
1969
+ elif entity == "snortmanagers" :
1970
+ list_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
1858
1971
else :
1859
1972
container = get_running_container (name = entity )
1860
1973
if container is not None :
@@ -1925,6 +2038,43 @@ def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
1925
2038
click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
1926
2039
1927
2040
2041
+ def list_snort_ids_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
2042
+ """
2043
+ Utility function for listing snort ids managers
2044
+
2045
+ :param ip: the ip of the node to start snort ids managers
2046
+ :param emulation: the emulation of the execution
2047
+ :param ip_first_octet: the ID of the execution
2048
+
2049
+ :return: None
2050
+ """
2051
+ import csle_common .constants .constants as constants
2052
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2053
+ config = MetastoreFacade .get_config (id = 1 )
2054
+ for node in config .cluster_config .cluster_nodes :
2055
+ if node .ip == ip or ip == "" :
2056
+ snort_manager_info = ClusterController .get_snort_ids_managers_info (
2057
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2058
+ ip_first_octet = ip_first_octet )
2059
+
2060
+ for i in range (len (snort_manager_info .ips )):
2061
+ status = "Running" if snort_manager_info .snortIdsManagersRunning [i ] else "Stopped"
2062
+ status_color = 'green' if snort_manager_info .snortIdsManagersRunning [i ] else 'red'
2063
+
2064
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2065
+ click .secho (f'|{ "Snort ids manager IP" :^40} ' , nl = False , fg = 'white' )
2066
+ click .secho ('|' , nl = False , fg = 'white' )
2067
+ click .secho (f'{ snort_manager_info .ips [i ]:<19} ' , nl = False , fg = status_color )
2068
+ click .secho ('|' , fg = 'white' )
2069
+
2070
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2071
+ click .secho (f'|{ "Status" :^40} ' , nl = False , fg = 'white' )
2072
+ click .secho ('|' , nl = False , fg = 'white' )
2073
+ click .secho (f'{ status :<19} ' , nl = False , fg = status_color )
2074
+ click .secho ('|' , fg = 'white' )
2075
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2076
+
2077
+
1928
2078
def list_client_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
1929
2079
"""
1930
2080
Utility function for listing client managers
@@ -1940,49 +2090,59 @@ def list_client_manager(ip: str, emulation: str, ip_first_octet: int) -> None:
1940
2090
config = MetastoreFacade .get_config (id = 1 )
1941
2091
for node in config .cluster_config .cluster_nodes :
1942
2092
if node .ip == ip or ip == "" :
1943
- host_manager_info = ClusterController .get_client_managers_info (
2093
+ client_manager_info = ClusterController .get_client_managers_info (
1944
2094
ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1945
2095
ip_first_octet = ip_first_octet )
2096
+ for i in range (len (client_manager_info .ips )):
2097
+ status_color = 'green' if client_manager_info .clientManagersStatuses [i ].num_clients > 0 else 'red'
2098
+ manager_status = 'Running' if client_manager_info .clientManagersStatuses [i ].num_clients > 0 \
2099
+ else 'Stopped'
1946
2100
1947
- click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1948
- click .secho (f'|{ "Host IP" :^40} ' , nl = False , fg = 'white' )
1949
- for i in range (len (host_manager_info .ips )):
2101
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2102
+ click .secho (f'|{ "Host IP" :^40} ' , nl = False , fg = 'white' )
2103
+ click .secho ('|' , nl = False , fg = 'white' )
2104
+ click .secho (f'{ client_manager_info .ips [i ]:<19} ' , nl = False , fg = status_color )
2105
+ click .secho ('|' , fg = 'white' )
2106
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2107
+
2108
+ click .secho (f'|{ "Status" :^40} ' , nl = False , fg = 'white' )
1950
2109
click .secho ('|' , nl = False , fg = 'white' )
1951
- click .secho (f'{ host_manager_info . ips [ i ] :<19} ' , nl = False , fg = "green" )
2110
+ click .secho (f'{ manager_status :<19} ' , nl = False , fg = status_color )
1952
2111
click .secho ('|' , fg = 'white' )
1953
2112
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1954
2113
1955
2114
click .secho (f'|{ "Clients number" :^40} ' , nl = False , fg = 'white' )
1956
2115
click .secho ('|' , nl = False , fg = 'white' )
1957
- click .secho (f'{ host_manager_info .clientManagersStatuses [i ].num_clients :<19} ' , nl = False , fg = "green" )
2116
+ click .secho (f'{ client_manager_info .clientManagersStatuses [i ].num_clients :<19} ' , nl = False ,
2117
+ fg = status_color )
1958
2118
click .secho ('|' , fg = 'white' )
1959
2119
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1960
2120
1961
2121
click .secho (f'|{ "Client process active" :^40} ' , nl = False , fg = 'white' )
1962
2122
click .secho ('|' , nl = False , fg = 'white' )
1963
- click .secho (f'{ bool (host_manager_info .clientManagersStatuses [i ].client_process_active ):<19} ' ,
1964
- nl = False , fg = "green" )
2123
+ click .secho (f'{ bool (client_manager_info .clientManagersStatuses [i ].client_process_active ):<19} ' ,
2124
+ nl = False , fg = status_color )
1965
2125
click .secho ('|' , fg = 'white' )
1966
2126
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1967
2127
1968
2128
click .secho (f'|{ "Procedure active" :^40} ' , nl = False , fg = 'white' )
1969
2129
click .secho ('|' , nl = False , fg = 'white' )
1970
- click .secho (f'{ bool (host_manager_info .clientManagersStatuses [i ].producer_active ):<19} ' ,
1971
- nl = False , fg = "green" )
2130
+ click .secho (f'{ bool (client_manager_info .clientManagersStatuses [i ].producer_active ):<19} ' ,
2131
+ nl = False , fg = status_color )
1972
2132
click .secho ('|' , fg = 'white' )
1973
2133
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1974
2134
1975
2135
click .secho (f'|{ "Client time step length in seconds" :^40} ' , nl = False , fg = 'white' )
1976
2136
click .secho ('|' , nl = False , fg = 'white' )
1977
- click .secho (f'{ host_manager_info .clientManagersStatuses [i ].clients_time_step_len_seconds :<19} ' ,
1978
- nl = False , fg = "green" )
2137
+ click .secho (f'{ client_manager_info .clientManagersStatuses [i ].clients_time_step_len_seconds :<19} ' ,
2138
+ nl = False , fg = status_color )
1979
2139
click .secho ('|' , fg = 'white' )
1980
2140
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1981
2141
1982
2142
click .secho (f'|{ "Producer time step length in seconds" :^40} ' , nl = False , fg = 'white' )
1983
2143
click .secho ('|' , nl = False , fg = 'white' )
1984
- click .secho (f'{ host_manager_info .clientManagersStatuses [i ].producer_time_step_len_seconds :<19} ' ,
1985
- nl = False , fg = "green" )
2144
+ click .secho (f'{ client_manager_info .clientManagersStatuses [i ].producer_time_step_len_seconds :<19} ' ,
2145
+ nl = False , fg = status_color )
1986
2146
click .secho ('|' , fg = 'white' )
1987
2147
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1988
2148
0 commit comments