@@ -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 | heartbeats | heartbeat" )
690
+ "| metricbeats | heartbeats | heartbeat | packetbeat | packetbeats " )
691
691
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
692
692
"""
693
693
Stops an entity
@@ -767,6 +767,10 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
767
767
stop_heartbeats (ip = ip , emulation = name , ip_first_octet = id )
768
768
elif entity == "heartbeat" :
769
769
stop_heartbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
770
+ elif entity == "packetbeats" :
771
+ stop_packetbeats (ip = ip , emulation = name , ip_first_octet = id )
772
+ elif entity == "packetbeat" :
773
+ stop_packetbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
770
774
else :
771
775
container_stopped = False
772
776
for node in config .cluster_config .cluster_nodes :
@@ -1393,6 +1397,58 @@ def stop_heartbeat(ip: str, container_ip: str, emulation: str, ip_first_octet: i
1393
1397
bold = False )
1394
1398
1395
1399
1400
+ def stop_packetbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
1401
+ """
1402
+ Utility function for stopping the packetbeats
1403
+
1404
+ :param ip: the ip of the node to stop the packetbeats
1405
+ :param emulation: the emulation of the execution
1406
+ :param ip_first_octet: the ID of the execution
1407
+ :return: None
1408
+ """
1409
+ import csle_common .constants .constants as constants
1410
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1411
+ config = MetastoreFacade .get_config (id = 1 )
1412
+ for node in config .cluster_config .cluster_nodes :
1413
+ if node .ip == ip or ip == "" :
1414
+ stopped = ClusterController .stop_packetbeats (
1415
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1416
+ ip_first_octet = ip_first_octet )
1417
+ if stopped .outcome :
1418
+ click .secho (f"Stopping packetbeats on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1419
+ else :
1420
+ click .secho (f"Packetbeats are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1421
+ bold = False )
1422
+
1423
+
1424
+ def stop_packetbeat (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
1425
+ """
1426
+ Utility function for stopping the packetbeat
1427
+
1428
+ :param ip: the ip of the node to stop the packetbeat
1429
+ :param container_ip: the ip of the host that traffic is running on
1430
+ :param emulation: the emulation of the execution
1431
+ :param ip_first_octet: the ID of the execution
1432
+ :return: None
1433
+ """
1434
+ import csle_common .constants .constants as constants
1435
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1436
+ config = MetastoreFacade .get_config (id = 1 )
1437
+ for node in config .cluster_config .cluster_nodes :
1438
+ if node .ip == ip or ip == "" :
1439
+ stopped = ClusterController .stop_packetbeat (
1440
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1441
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1442
+ if stopped .outcome :
1443
+ click .secho (
1444
+ f"Stopping packetbeat with ip { container_ip } on port:"
1445
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1446
+ else :
1447
+ click .secho (f"Packetbeat with ip { container_ip } is not "
1448
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1449
+ bold = False )
1450
+
1451
+
1396
1452
@click .argument ('max_workers' , default = 10 , type = int )
1397
1453
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
1398
1454
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1587,7 +1643,8 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1587
1643
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1588
1644
"| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager "
1589
1645
"| trafficmanagers | trafficmanager | kafkamanager | ossecmanagers | ossecmanager "
1590
- "| ryumanager | filebeats | filebeat | metricbeats | metricbeat | heartbeat | heartbeats" )
1646
+ "| ryumanager | filebeats | filebeat | metricbeats | metricbeat | heartbeat | heartbeats"
1647
+ "| packetbeat | packetbeats" )
1591
1648
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1592
1649
container_ip : str , no_beats : bool , initial_start : bool ) -> None :
1593
1650
"""
@@ -1681,6 +1738,11 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1681
1738
elif entity == "heartbeat" :
1682
1739
start_heartbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id ,
1683
1740
initial_start = initial_start )
1741
+ elif entity == "packetbeats" :
1742
+ start_packetbeats (ip = ip , emulation = name , ip_first_octet = id , initial_start = initial_start )
1743
+ elif entity == "packetbeat" :
1744
+ start_packetbeat (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id ,
1745
+ initial_start = initial_start )
1684
1746
else :
1685
1747
container_started = False
1686
1748
for node in config .cluster_config .cluster_nodes :
@@ -2029,6 +2091,30 @@ def start_heartbeats(ip: str, emulation: str, ip_first_octet: int, initial_start
2029
2091
bold = False )
2030
2092
2031
2093
2094
+ def start_packetbeats (ip : str , emulation : str , ip_first_octet : int , initial_start : bool ):
2095
+ """
2096
+ Utility function for starting packetbeats
2097
+
2098
+ :param ip: the ip of the node to start packetbeats
2099
+ :param emulation: the emulation of the execution
2100
+ :param ip_first_octet: the ID of the execution
2101
+ :return: None
2102
+ """
2103
+ import csle_common .constants .constants as constants
2104
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2105
+ config = MetastoreFacade .get_config (id = 1 )
2106
+ for node in config .cluster_config .cluster_nodes :
2107
+ if node .ip == ip or ip == "" :
2108
+ operation_outcome = ClusterController .start_packetbeats (
2109
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2110
+ ip_first_octet = ip_first_octet , initial_start = initial_start )
2111
+ if operation_outcome .outcome :
2112
+ click .secho (f"Starting packetbeats on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
2113
+ else :
2114
+ click .secho (f"Packetbeats are not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
2115
+ bold = False )
2116
+
2117
+
2032
2118
def start_heartbeat (ip : str , container_ip : str , emulation : str , ip_first_octet : int , initial_start : bool ):
2033
2119
"""
2034
2120
Utility function for starting heartbeat
@@ -2056,6 +2142,33 @@ def start_heartbeat(ip: str, container_ip: str, emulation: str, ip_first_octet:
2056
2142
bold = False )
2057
2143
2058
2144
2145
+ def start_packetbeat (ip : str , container_ip : str , emulation : str , ip_first_octet : int , initial_start : bool ):
2146
+ """
2147
+ Utility function for starting packetbeat
2148
+
2149
+ :param ip: the ip of the node to start packetbeat
2150
+ :param container_ip: the ip of the host to start
2151
+ :param emulation: the emulation of the execution
2152
+ :param ip_first_octet: the ID of the execution
2153
+ :return: None
2154
+ """
2155
+ import csle_common .constants .constants as constants
2156
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2157
+ config = MetastoreFacade .get_config (id = 1 )
2158
+ for node in config .cluster_config .cluster_nodes :
2159
+ if node .ip == ip or ip == "" :
2160
+ operation_outcome = ClusterController .start_packetbeat (
2161
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2162
+ ip_first_octet = ip_first_octet , container_ip = container_ip , initial_start = initial_start )
2163
+ if operation_outcome .outcome :
2164
+ click .secho (f"Started packetbeat with ip { container_ip } on "
2165
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
2166
+ else :
2167
+ click .secho (f"Packetbeat with ip { container_ip } is not "
2168
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
2169
+ bold = False )
2170
+
2171
+
2059
2172
def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
2060
2173
"""
2061
2174
Utility function for starting host manager
@@ -2703,6 +2816,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
2703
2816
list_metricbeats (ip = ip , emulation = name , ip_first_octet = id )
2704
2817
elif entity == "heartbeats" :
2705
2818
list_heartbeats (ip = ip , emulation = name , ip_first_octet = id )
2819
+ elif entity == "packetbeats" :
2820
+ list_packetbeats (ip = ip , emulation = name , ip_first_octet = id )
2706
2821
else :
2707
2822
container = get_running_container (name = entity )
2708
2823
if container is not None :
@@ -2801,6 +2916,38 @@ def list_heartbeats(ip: str, emulation: str, ip_first_octet: int) -> None:
2801
2916
click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2802
2917
2803
2918
2919
+ def list_packetbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
2920
+ """
2921
+ Utility function for listing packetbeats
2922
+
2923
+ :param ip: the ip of the node to list packetbeats
2924
+ :param emulation: the emulation of the execution
2925
+ :param ip_first_octet: the ID of the execution
2926
+
2927
+ :return: None
2928
+ """
2929
+ import csle_common .constants .constants as constants
2930
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2931
+ config = MetastoreFacade .get_config (id = 1 )
2932
+ for node in config .cluster_config .cluster_nodes :
2933
+ if node .ip == ip or ip == "" :
2934
+ packetbeats_info = ClusterController .get_host_managers_info (
2935
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2936
+ ip_first_octet = ip_first_octet )
2937
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2938
+ click .secho (f'|{ "Host IP" :^30} |{ "Packetbeats running Status" :^29} |' , fg = 'white' )
2939
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2940
+ for i in range (len (packetbeats_info .hostManagersStatuses )):
2941
+ status = "Running" if packetbeats_info .hostManagersStatuses [i ].packetbeat_running else "Stopped"
2942
+ status_color = 'green' if packetbeats_info .hostManagersStatuses [i ].packetbeat_running else 'red'
2943
+ click .secho ('|' , nl = False , fg = 'white' )
2944
+ click .secho (f'{ packetbeats_info .ips [i ]:<30} ' , nl = False , fg = 'white' )
2945
+ click .secho ('|' , nl = False , fg = 'white' )
2946
+ click .secho (f'{ status :^29} ' , nl = False , fg = status_color )
2947
+ click .secho ('|' , fg = 'white' )
2948
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2949
+
2950
+
2804
2951
def list_metricbeats (ip : str , emulation : str , ip_first_octet : int ) -> None :
2805
2952
"""
2806
2953
Utility function for listing filebeats
0 commit comments