@@ -685,7 +685,8 @@ 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 | elkmanager | trafficmanagers | trafficmanager | kafkamanager" )
688
+ "| snortmanager | elkmanager | trafficmanagers | trafficmanager | kafkamanager "
689
+ "| ossecmanagers | ossecmanager | ryumanager" )
689
690
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
690
691
"""
691
692
Stops an entity
@@ -747,6 +748,12 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
747
748
stop_traffic_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
748
749
elif entity == "kafkamanager" :
749
750
stop_kafka_manager (ip = ip , emulation = name , ip_first_octet = id )
751
+ elif entity == "ossecmanagers" :
752
+ stop_ossec_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
753
+ elif entity == "ossecmanager" :
754
+ stop_ossec_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
755
+ elif entity == "ryumanager" :
756
+ stop_ryu_manager (ip = ip , emulation = name , ip_first_octet = id )
750
757
else :
751
758
container_stopped = False
752
759
for node in config .cluster_config .cluster_nodes :
@@ -941,6 +948,54 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
941
948
bold = False )
942
949
943
950
951
+ def stop_ryu_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
952
+ """
953
+ Utility function for stopping the ryu manager
954
+
955
+ :param ip: the ip of the node to stop the ryu manger
956
+ :param emulation: the emulation of the execution
957
+ :param ip_first_octet: the ID of the execution
958
+ :return: None
959
+ """
960
+ import csle_common .constants .constants as constants
961
+ from csle_common .metastore .metastore_facade import MetastoreFacade
962
+ config = MetastoreFacade .get_config (id = 1 )
963
+ for node in config .cluster_config .cluster_nodes :
964
+ if node .ip == ip or ip == "" :
965
+ stopped = ClusterController .stop_ryu_manager (
966
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
967
+ ip_first_octet = ip_first_octet )
968
+ if stopped .outcome :
969
+ click .secho (f"Stopping host managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
970
+ else :
971
+ click .secho (f"Host managers are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
972
+ bold = False )
973
+
974
+
975
+ def stop_ossec_ids_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
976
+ """
977
+ Utility function for stopping the ossec managers
978
+
979
+ :param ip: the ip of the node to stop the ossec mangers
980
+ :param emulation: the emulation of the execution
981
+ :param ip_first_octet: the ID of the execution
982
+ :return: None
983
+ """
984
+ import csle_common .constants .constants as constants
985
+ from csle_common .metastore .metastore_facade import MetastoreFacade
986
+ config = MetastoreFacade .get_config (id = 1 )
987
+ for node in config .cluster_config .cluster_nodes :
988
+ if node .ip == ip or ip == "" :
989
+ stopped = ClusterController .stop_ossec_ids_managers (
990
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
991
+ ip_first_octet = ip_first_octet )
992
+ if stopped .outcome :
993
+ click .secho (f"Stopping ossec managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
994
+ else :
995
+ click .secho (f"Ossec managers are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
996
+ bold = False )
997
+
998
+
944
999
def stop_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
945
1000
"""
946
1001
Utility function for stopping the host manager
@@ -968,6 +1023,34 @@ def stop_host_manager(ip: str, container_ip: str, emulation: str, ip_first_octet
968
1023
bold = False )
969
1024
970
1025
1026
+ def stop_ossec_ids_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
1027
+ """
1028
+ Utility function for stopping the ossec manager
1029
+
1030
+ :param ip: the ip of the node to stop the ossec manager
1031
+ :param container_ip: the ip of the host to be stopped
1032
+ :param emulation: the emulation of the execution
1033
+ :param ip_first_octet: the ID of the execution
1034
+ :return: None
1035
+ """
1036
+ import csle_common .constants .constants as constants
1037
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1038
+ config = MetastoreFacade .get_config (id = 1 )
1039
+ for node in config .cluster_config .cluster_nodes :
1040
+ if node .ip == ip or ip == "" :
1041
+ stopped = ClusterController .stop_ossec_ids_manager (
1042
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1043
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1044
+ if stopped .outcome :
1045
+ click .secho (
1046
+ f"Stopping ossec manager with ip { container_ip } on port:"
1047
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1048
+ else :
1049
+ click .secho (f"Ossec manager with ip { container_ip } is not "
1050
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1051
+ bold = False )
1052
+
1053
+
971
1054
def stop_client_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
972
1055
"""
973
1056
Utility function for stopping the client manager
@@ -1333,7 +1416,8 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1333
1416
"container-name | emulation-name | all | statsmanager | training_job "
1334
1417
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1335
1418
"| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager "
1336
- "| trafficmanagers | trafficmanager | kafkamanager" )
1419
+ "| trafficmanagers | trafficmanager | kafkamanager | ossecmanagers | ossecmanager "
1420
+ "| ryumanager" )
1337
1421
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1338
1422
container_ip : str , no_beats : bool ) -> None :
1339
1423
"""
@@ -1406,6 +1490,12 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1406
1490
start_traffic_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1407
1491
elif entity == "kafkamanager" :
1408
1492
start_kafka_manager (ip = ip , emulation = name , ip_first_octet = id )
1493
+ elif entity == "ossecmanagers" :
1494
+ start_ossec_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
1495
+ elif entity == "ossecmanager" :
1496
+ start_ossec_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1497
+ elif entity == "ryumanager" :
1498
+ start_ryu_manager (ip = ip , emulation = name , ip_first_octet = id )
1409
1499
else :
1410
1500
container_started = False
1411
1501
for node in config .cluster_config .cluster_nodes :
@@ -1604,6 +1694,30 @@ def start_host_managers(ip: str, emulation: str, ip_first_octet: int):
1604
1694
bold = False )
1605
1695
1606
1696
1697
+ def start_ryu_manager (ip : str , emulation : str , ip_first_octet : int ):
1698
+ """
1699
+ Utility function for starting ryu manager
1700
+
1701
+ :param ip: the ip of the node to start ryu manager
1702
+ :param emulation: the emulation of the execution
1703
+ :param ip_first_octet: the ID of the execution
1704
+ :return: None
1705
+ """
1706
+ import csle_common .constants .constants as constants
1707
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1708
+ config = MetastoreFacade .get_config (id = 1 )
1709
+ for node in config .cluster_config .cluster_nodes :
1710
+ if node .ip == ip or ip == "" :
1711
+ operation_outcome = ClusterController .start_ryu_manager (
1712
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1713
+ ip_first_octet = ip_first_octet )
1714
+ if operation_outcome .outcome :
1715
+ click .secho (f"Starting ryu managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1716
+ else :
1717
+ click .secho (f"Ryu managers are not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1718
+ bold = False )
1719
+
1720
+
1607
1721
def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1608
1722
"""
1609
1723
Utility function for starting host manager
@@ -1726,6 +1840,57 @@ def start_snort_ids_manager(ip: str, container_ip: str, emulation: str, ip_first
1726
1840
bold = False )
1727
1841
1728
1842
1843
+ def start_ossec_ids_managers (ip : str , emulation : str , ip_first_octet : int ):
1844
+ """
1845
+ Utility function for starting ossec managers
1846
+
1847
+ :param ip: the ip of the node to start ossec managers
1848
+ :param emulation: the emulation of the execution
1849
+ :param ip_first_octet: the ID of the execution
1850
+ :return: None
1851
+ """
1852
+ import csle_common .constants .constants as constants
1853
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1854
+ config = MetastoreFacade .get_config (id = 1 )
1855
+ for node in config .cluster_config .cluster_nodes :
1856
+ if node .ip == ip or ip == "" :
1857
+ operation_outcome = ClusterController .start_ossec_ids_managers (
1858
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1859
+ ip_first_octet = ip_first_octet )
1860
+ if operation_outcome .outcome :
1861
+ click .secho (f"Starting ossec ids managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1862
+ else :
1863
+ click .secho (f"Ossec ids managers are not started:"
1864
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " , bold = False )
1865
+
1866
+
1867
+ def start_ossec_ids_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1868
+ """
1869
+ Utility function for starting ossec ids manager
1870
+
1871
+ :param ip: the ip of the node to start ossec ids manager
1872
+ :param container_ip: the ip of the host to start
1873
+ :param emulation: the emulation of the execution
1874
+ :param ip_first_octet: the ID of the execution
1875
+ :return: None
1876
+ """
1877
+ import csle_common .constants .constants as constants
1878
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1879
+ config = MetastoreFacade .get_config (id = 1 )
1880
+ for node in config .cluster_config .cluster_nodes :
1881
+ if node .ip == ip or ip == "" :
1882
+ operation_outcome = ClusterController .start_ossec_ids_manager (
1883
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1884
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1885
+ if operation_outcome .outcome :
1886
+ click .secho (f"Started ossec ids manager with ip { container_ip } on "
1887
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1888
+ else :
1889
+ click .secho (f"Ossec ids manager with ip { container_ip } is not "
1890
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1891
+ bold = False )
1892
+
1893
+
1729
1894
def start_elk_manager (ip : str , emulation : str , ip_first_octet : int ):
1730
1895
"""
1731
1896
Utility function for starting elk manager
@@ -2112,7 +2277,8 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
2112
2277
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
2113
2278
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
2114
2279
"simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
2115
- "clientmanager | snortmanagers | elkmanager | trafficmanagers | kafkamanager" )
2280
+ "clientmanager | snortmanagers | elkmanager | trafficmanagers | kafkamanager | "
2281
+ "ossecmanagers | ryumanager" )
2116
2282
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
2117
2283
@click .option ('--all' , is_flag = True , help = 'list all' )
2118
2284
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -2189,6 +2355,10 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
2189
2355
list_traffic_managers (ip = ip , emulation = name , ip_first_octet = id )
2190
2356
elif entity == "kafkamanager" :
2191
2357
list_kafka_managers (ip = ip , emulation = name , ip_first_octet = id )
2358
+ elif entity == "ossecmanagers" :
2359
+ list_ossec_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
2360
+ elif entity == "ryumanager" :
2361
+ list_ryu_manager (ip = ip , emulation = name , ip_first_octet = id )
2192
2362
else :
2193
2363
container = get_running_container (name = entity )
2194
2364
if container is not None :
@@ -2223,6 +2393,32 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
2223
2393
click .secho (f"entity: { entity } is not recognized" , fg = "red" , bold = True )
2224
2394
2225
2395
2396
+ def list_ryu_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
2397
+ """
2398
+ Utility function for listing ryu manager
2399
+
2400
+ :param ip: the ip of the node to list ryu manager
2401
+ :param emulation: the emulation of the execution
2402
+ :param ip_first_octet: the ID of the execution
2403
+
2404
+ :return: None
2405
+ """
2406
+ import csle_common .constants .constants as constants
2407
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2408
+ emulation_config = MetastoreFacade .get_emulation_by_name (name = emulation )
2409
+ has_sdn = emulation_config .sdn_controller_config is not None
2410
+ config = MetastoreFacade .get_config (id = 1 )
2411
+ for node in config .cluster_config .cluster_nodes :
2412
+ if node .ip == ip or ip == "" :
2413
+ if has_sdn :
2414
+ ryu_manager_info = ClusterController .get_ryu_managers_info (
2415
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2416
+ ip_first_octet = ip_first_octet )
2417
+ click .secho (ryu_manager_info )
2418
+ else :
2419
+ click .secho (f"Emulation with name: { emulation } does not have SDN." , fg = "red" , bold = True )
2420
+
2421
+
2226
2422
def list_host_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
2227
2423
"""
2228
2424
Utility function for listing host managers
@@ -2430,6 +2626,43 @@ def list_snort_ids_managers(ip: str, emulation: str, ip_first_octet: int) -> Non
2430
2626
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2431
2627
2432
2628
2629
+ def list_ossec_ids_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
2630
+ """
2631
+ Utility function for listing ossec ids managers
2632
+
2633
+ :param ip: the ip of the node to list ossec ids managers
2634
+ :param emulation: the emulation of the execution
2635
+ :param ip_first_octet: the ID of the execution
2636
+
2637
+ :return: None
2638
+ """
2639
+ import csle_common .constants .constants as constants
2640
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2641
+ config = MetastoreFacade .get_config (id = 1 )
2642
+ for node in config .cluster_config .cluster_nodes :
2643
+ if node .ip == ip or ip == "" :
2644
+ ossec_manager_info = ClusterController .get_ossec_ids_managers_info (
2645
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2646
+ ip_first_octet = ip_first_octet )
2647
+
2648
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2649
+ click .secho (f'|{ "Ossec ids manager IP" :^30} ' , nl = False , fg = 'white' )
2650
+ click .secho ('|' , nl = False , fg = 'white' )
2651
+ click .secho (f'{ "Ossec ids status" :^29} ' , nl = False , fg = 'white' )
2652
+ click .secho ('|' , fg = 'white' )
2653
+
2654
+ for i in range (len (ossec_manager_info .ips )):
2655
+ status = "Running" if ossec_manager_info .ossecIdsManagersRunning [i ] else "Stopped"
2656
+ status_color = 'green' if ossec_manager_info .ossecIdsManagersRunning [i ] else 'red'
2657
+
2658
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2659
+ click .secho (f'|{ ossec_manager_info .ips [i ]:^30} ' , nl = False , fg = 'white' )
2660
+ click .secho ('|' , nl = False , fg = 'white' )
2661
+ click .secho (f'{ status :^29} ' , nl = False , fg = status_color )
2662
+ click .secho ('|' , fg = 'white' )
2663
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2664
+
2665
+
2433
2666
def list_client_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
2434
2667
"""
2435
2668
Utility function for listing client managers
0 commit comments