@@ -687,7 +687,7 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
687
687
"| docker | clustermanager | hostmanagers | hostmanager | clientmanager | snortmanagers "
688
688
"| snortmanager | elkmanager | trafficmanagers | trafficmanager | kafkamanager "
689
689
"| ossecmanagers | ossecmanager | ryumanager | filebeats | filebeat | metricbeat "
690
- "| metricbeats" )
690
+ "| metricbeats | heartbeats | heartbeat " )
691
691
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
692
692
"""
693
693
Stops an entity
@@ -763,6 +763,10 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
763
763
stop_metricbeats (ip = ip , emulation = name , ip_first_octet = id )
764
764
elif entity == "metricbeat" :
765
765
stop_metricbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
766
+ elif entity == "heartbeats" :
767
+ stop_heartbeats (ip = ip , emulation = name , ip_first_octet = id )
768
+ elif entity == "heartbeat" :
769
+ stop_heartbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
766
770
else :
767
771
container_stopped = False
768
772
for node in config .cluster_config .cluster_nodes :
@@ -1337,6 +1341,58 @@ def stop_metricbeat(ip: str, container_ip: str, emulation: str, ip_first_octet:
1337
1341
bold = False )
1338
1342
1339
1343
1344
+ def stop_heartbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
1345
+ """
1346
+ Utility function for stopping the heartbeats
1347
+
1348
+ :param ip: the ip of the node to stop the heartbeats
1349
+ :param emulation: the emulation of the execution
1350
+ :param ip_first_octet: the ID of the execution
1351
+ :return: None
1352
+ """
1353
+ import csle_common .constants .constants as constants
1354
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1355
+ config = MetastoreFacade .get_config (id = 1 )
1356
+ for node in config .cluster_config .cluster_nodes :
1357
+ if node .ip == ip or ip == "" :
1358
+ stopped = ClusterController .stop_heartbeats (
1359
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1360
+ ip_first_octet = ip_first_octet )
1361
+ if stopped .outcome :
1362
+ click .secho (f"Stopping heartbeats on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1363
+ else :
1364
+ click .secho (f"Heartbeats are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1365
+ bold = False )
1366
+
1367
+
1368
+ def stop_heartbeat (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
1369
+ """
1370
+ Utility function for stopping the heartbeat
1371
+
1372
+ :param ip: the ip of the node to stop the heartbeat
1373
+ :param container_ip: the ip of the host that traffic is running on
1374
+ :param emulation: the emulation of the execution
1375
+ :param ip_first_octet: the ID of the execution
1376
+ :return: None
1377
+ """
1378
+ import csle_common .constants .constants as constants
1379
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1380
+ config = MetastoreFacade .get_config (id = 1 )
1381
+ for node in config .cluster_config .cluster_nodes :
1382
+ if node .ip == ip or ip == "" :
1383
+ stopped = ClusterController .stop_heartbeat (
1384
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1385
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1386
+ if stopped .outcome :
1387
+ click .secho (
1388
+ f"Stopping heartbeat with ip { container_ip } on port:"
1389
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1390
+ else :
1391
+ click .secho (f"Heartbeat with ip { container_ip } is not "
1392
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1393
+ bold = False )
1394
+
1395
+
1340
1396
@click .argument ('max_workers' , default = 10 , type = int )
1341
1397
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
1342
1398
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1531,7 +1587,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1531
1587
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1532
1588
"| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager "
1533
1589
"| trafficmanagers | trafficmanager | kafkamanager | ossecmanagers | ossecmanager "
1534
- "| ryumanager | filebeats | filebeat | metricbeats | metricbeat" )
1590
+ "| ryumanager | filebeats | filebeat | metricbeats | metricbeat | heartbeat | heartbeats " )
1535
1591
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1536
1592
container_ip : str , no_beats : bool , initial_start : bool ) -> None :
1537
1593
"""
@@ -1620,6 +1676,11 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1620
1676
elif entity == "metricbeat" :
1621
1677
start_metricbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id ,
1622
1678
initial_start = initial_start )
1679
+ elif entity == "heartbeats" :
1680
+ start_heartbeats (ip = ip , emulation = name , ip_first_octet = id , initial_start = initial_start )
1681
+ elif entity == "heartbeat" :
1682
+ start_heartbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id ,
1683
+ initial_start = initial_start )
1623
1684
else :
1624
1685
container_started = False
1625
1686
for node in config .cluster_config .cluster_nodes :
@@ -1944,6 +2005,57 @@ def start_metricbeat(ip: str, container_ip: str, emulation: str, ip_first_octet:
1944
2005
bold = False )
1945
2006
1946
2007
2008
+ def start_heartbeats (ip : str , emulation : str , ip_first_octet : int , initial_start : bool ):
2009
+ """
2010
+ Utility function for starting heartbeats
2011
+
2012
+ :param ip: the ip of the node to start heartbeats
2013
+ :param emulation: the emulation of the execution
2014
+ :param ip_first_octet: the ID of the execution
2015
+ :return: None
2016
+ """
2017
+ import csle_common .constants .constants as constants
2018
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2019
+ config = MetastoreFacade .get_config (id = 1 )
2020
+ for node in config .cluster_config .cluster_nodes :
2021
+ if node .ip == ip or ip == "" :
2022
+ operation_outcome = ClusterController .start_heartbeats (
2023
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2024
+ ip_first_octet = ip_first_octet , initial_start = initial_start )
2025
+ if operation_outcome .outcome :
2026
+ click .secho (f"Starting heartbeats on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
2027
+ else :
2028
+ click .secho (f"Heartbeats are not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
2029
+ bold = False )
2030
+
2031
+
2032
+ def start_heartbeat (ip : str , container_ip : str , emulation : str , ip_first_octet : int , initial_start : bool ):
2033
+ """
2034
+ Utility function for starting heartbeat
2035
+
2036
+ :param ip: the ip of the node to start heartbeat
2037
+ :param container_ip: the ip of the host to start
2038
+ :param emulation: the emulation of the execution
2039
+ :param ip_first_octet: the ID of the execution
2040
+ :return: None
2041
+ """
2042
+ import csle_common .constants .constants as constants
2043
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2044
+ config = MetastoreFacade .get_config (id = 1 )
2045
+ for node in config .cluster_config .cluster_nodes :
2046
+ if node .ip == ip or ip == "" :
2047
+ operation_outcome = ClusterController .start_heartbeat (
2048
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2049
+ ip_first_octet = ip_first_octet , container_ip = container_ip , initial_start = initial_start )
2050
+ if operation_outcome .outcome :
2051
+ click .secho (f"Started heartbeat with ip { container_ip } on "
2052
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
2053
+ else :
2054
+ click .secho (f"Heartbeat with ip { container_ip } is not "
2055
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
2056
+ bold = False )
2057
+
2058
+
1947
2059
def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1948
2060
"""
1949
2061
Utility function for starting host manager
@@ -2504,7 +2616,7 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
2504
2616
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
2505
2617
"simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
2506
2618
"clientmanager | snortmanagers | elkmanager | trafficmanagers | kafkamanager | "
2507
- "ossecmanagers | ryumanager | filebeats | metricbeats" )
2619
+ "ossecmanagers | ryumanager | filebeats | metricbeats | heartbeats " )
2508
2620
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
2509
2621
@click .option ('--all' , is_flag = True , help = 'list all' )
2510
2622
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -2589,6 +2701,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
2589
2701
list_filebeats (ip = ip , emulation = name , ip_first_octet = id )
2590
2702
elif entity == "metricbeats" :
2591
2703
list_metricbeats (ip = ip , emulation = name , ip_first_octet = id )
2704
+ elif entity == "heartbeats" :
2705
+ list_heartbeats (ip = ip , emulation = name , ip_first_octet = id )
2592
2706
else :
2593
2707
container = get_running_container (name = entity )
2594
2708
if container is not None :
@@ -2655,6 +2769,38 @@ def list_filebeats(ip: str, emulation: str, ip_first_octet: int) -> None:
2655
2769
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2656
2770
2657
2771
2772
+ def list_heartbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
2773
+ """
2774
+ Utility function for listing heartbeats
2775
+
2776
+ :param ip: the ip of the node to list heartbeats
2777
+ :param emulation: the emulation of the execution
2778
+ :param ip_first_octet: the ID of the execution
2779
+
2780
+ :return: None
2781
+ """
2782
+ import csle_common .constants .constants as constants
2783
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2784
+ config = MetastoreFacade .get_config (id = 1 )
2785
+ for node in config .cluster_config .cluster_nodes :
2786
+ if node .ip == ip or ip == "" :
2787
+ heartbeats_info = ClusterController .get_host_managers_info (
2788
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2789
+ ip_first_octet = ip_first_octet )
2790
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2791
+ click .secho (f'|{ "Host IP" :^30} |{ "Heartbeats running Status" :^29} |' , fg = 'white' )
2792
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2793
+ for i in range (len (heartbeats_info .hostManagersStatuses )):
2794
+ status = "Running" if heartbeats_info .hostManagersStatuses [i ].heartbeat_running else "Stopped"
2795
+ status_color = 'green' if heartbeats_info .hostManagersStatuses [i ].heartbeat_running else 'red'
2796
+ click .secho ('|' , nl = False , fg = 'white' )
2797
+ click .secho (f'{ heartbeats_info .ips [i ]:<30} ' , nl = False , fg = 'white' )
2798
+ click .secho ('|' , nl = False , fg = 'white' )
2799
+ click .secho (f'{ status :^29} ' , nl = False , fg = status_color )
2800
+ click .secho ('|' , fg = 'white' )
2801
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2802
+
2803
+
2658
2804
def list_metricbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
2659
2805
"""
2660
2806
Utility function for listing filebeats
0 commit comments