From bc11beb7fb2ff68fb1b917e8eef2479224908ae9 Mon Sep 17 00:00:00 2001 From: Erik Sierra Date: Mon, 17 Jun 2024 10:05:53 -0400 Subject: [PATCH] Update --- .../GetGroupMembers.py | 0 .../Get_Host_Group.py | 0 .../GroupContainment.py | 2 +- .../config.yaml | 0 .../dummy.txt | 0 .../requirements.txt | Bin .../Containment.py | 0 .../ContainmentStatus.py | 0 {Host_Containment => Contain_Host}/Dummy.txt | 0 .../Lift_containment.py | 0 .../computers.txt | 0 .../config.yaml | 0 .../requirements.txt | Bin FalconTests/GetMembersTest.py | 74 +++++++++++++++--- .../{MockGroup.py => GroupContainSim.py} | 0 FalconTests/config.yaml | 5 +- 16 files changed, 67 insertions(+), 14 deletions(-) rename {Group_Containment => Contain_Group}/GetGroupMembers.py (100%) rename {Group_Containment => Contain_Group}/Get_Host_Group.py (100%) rename FalconTests/GroupContainmentTest1.py => Contain_Group/GroupContainment.py (99%) rename {Group_Containment => Contain_Group}/config.yaml (100%) rename {Group_Containment => Contain_Group}/dummy.txt (100%) rename {Group_Containment => Contain_Group}/requirements.txt (100%) rename {Host_Containment => Contain_Host}/Containment.py (100%) rename {Host_Containment => Contain_Host}/ContainmentStatus.py (100%) rename {Host_Containment => Contain_Host}/Dummy.txt (100%) rename {Host_Containment => Contain_Host}/Lift_containment.py (100%) rename {Host_Containment => Contain_Host}/computers.txt (100%) rename {Host_Containment => Contain_Host}/config.yaml (100%) rename {Host_Containment => Contain_Host}/requirements.txt (100%) rename FalconTests/{MockGroup.py => GroupContainSim.py} (100%) diff --git a/Group_Containment/GetGroupMembers.py b/Contain_Group/GetGroupMembers.py similarity index 100% rename from Group_Containment/GetGroupMembers.py rename to Contain_Group/GetGroupMembers.py diff --git a/Group_Containment/Get_Host_Group.py b/Contain_Group/Get_Host_Group.py similarity index 100% rename from Group_Containment/Get_Host_Group.py rename to Contain_Group/Get_Host_Group.py diff --git a/FalconTests/GroupContainmentTest1.py b/Contain_Group/GroupContainment.py similarity index 99% rename from FalconTests/GroupContainmentTest1.py rename to Contain_Group/GroupContainment.py index b5276c5..37578c5 100644 --- a/FalconTests/GroupContainmentTest1.py +++ b/Contain_Group/GroupContainment.py @@ -8,7 +8,7 @@ init() # Constants -CONFIG_FILE = 'config.yaml' +CONFIG_FILE = '../FalconTests/config.yaml' # Function to load configuration def load_config(file_path): diff --git a/Group_Containment/config.yaml b/Contain_Group/config.yaml similarity index 100% rename from Group_Containment/config.yaml rename to Contain_Group/config.yaml diff --git a/Group_Containment/dummy.txt b/Contain_Group/dummy.txt similarity index 100% rename from Group_Containment/dummy.txt rename to Contain_Group/dummy.txt diff --git a/Group_Containment/requirements.txt b/Contain_Group/requirements.txt similarity index 100% rename from Group_Containment/requirements.txt rename to Contain_Group/requirements.txt diff --git a/Host_Containment/Containment.py b/Contain_Host/Containment.py similarity index 100% rename from Host_Containment/Containment.py rename to Contain_Host/Containment.py diff --git a/Host_Containment/ContainmentStatus.py b/Contain_Host/ContainmentStatus.py similarity index 100% rename from Host_Containment/ContainmentStatus.py rename to Contain_Host/ContainmentStatus.py diff --git a/Host_Containment/Dummy.txt b/Contain_Host/Dummy.txt similarity index 100% rename from Host_Containment/Dummy.txt rename to Contain_Host/Dummy.txt diff --git a/Host_Containment/Lift_containment.py b/Contain_Host/Lift_containment.py similarity index 100% rename from Host_Containment/Lift_containment.py rename to Contain_Host/Lift_containment.py diff --git a/Host_Containment/computers.txt b/Contain_Host/computers.txt similarity index 100% rename from Host_Containment/computers.txt rename to Contain_Host/computers.txt diff --git a/Host_Containment/config.yaml b/Contain_Host/config.yaml similarity index 100% rename from Host_Containment/config.yaml rename to Contain_Host/config.yaml diff --git a/Host_Containment/requirements.txt b/Contain_Host/requirements.txt similarity index 100% rename from Host_Containment/requirements.txt rename to Contain_Host/requirements.txt diff --git a/FalconTests/GetMembersTest.py b/FalconTests/GetMembersTest.py index 9d61a5a..7bc31dd 100644 --- a/FalconTests/GetMembersTest.py +++ b/FalconTests/GetMembersTest.py @@ -1,16 +1,68 @@ -from falconpy.hosts import Hosts +import os +import yaml +import sys + from falconpy import HostGroup -from Group_Containment.GetGroupMembers import falcon -group_id = "" # Replace with the actual group ID you want to filter by -filter_string = f"group_id:'{group_id}'" +# Constants +CONFIG_FILE = 'config.yaml' +GROUP_ID = '123456789' # Replace with your actual group ID + + +# Function to load configuration +def load_config(file_path): + if not os.path.isfile(file_path): + print(f"Error: Configuration file '{file_path}' not found.") + return None + + try: + with open(file_path, 'r') as f: + config = yaml.safe_load(f) + return config + except yaml.YAMLError as e: + print(f"Error reading configuration file: {e}") + return None + + +# Load the configuration +config = load_config(CONFIG_FILE) +if not config: + sys.exit(1) + +CLIENT_ID = config['api']['client_id'] +CLIENT_SECRET = config['api']['client_secret'] + +# Initialize the API harness +falcon = HostGroup(client_id=CLIENT_ID, client_secret=CLIENT_SECRET) + + +# Function to list and print the names and IDs of the members of a host group +def list_host_group_members(group_id): + try: + response = falcon.query_combined_group_members(id=group_id, limit=5000) + if response['status_code'] != 200: + print(f"Error fetching group members: {response.get('errors', 'Unknown error')}") + return + + # Extract and print hostnames and IDs + members = response['body']['resources'] + if not members: + print("No hosts found in the group.") + return + + # Print headers + print(f"{'Hostname':<30} {'Host ID'}") + print(f"{'-' * 30} {'-' * 10}") + + for member in members: + hostname = member.get('hostname', 'Unknown hostname') + host_id = member.get('device_id', 'Unknown ID') + print(f"{hostname:<30} {host_id}") + + except Exception as e: + print(f"An error occurred: {e}") -returned = falcon.query_devices_by_filter( - sort="hostname.asc" -) -print(returned) +# List the members of the specified host group +list_host_group_members(GROUP_ID) -group_id = "" # Replace with the actual group ID you want to filter by -filter_string = f"group_id:'{group_id}'" -results = falcon.query_devices_by_filter(filter=filter_string) diff --git a/FalconTests/MockGroup.py b/FalconTests/GroupContainSim.py similarity index 100% rename from FalconTests/MockGroup.py rename to FalconTests/GroupContainSim.py diff --git a/FalconTests/config.yaml b/FalconTests/config.yaml index 40a6ed6..237a6f8 100644 --- a/FalconTests/config.yaml +++ b/FalconTests/config.yaml @@ -1,3 +1,4 @@ api: - client_id: "REPLACEME_KEEPQUOTES" - client_secret: "REPLACEME_KEEPQUOTES" + client_id: YOUR_CLIENT_ID + client_secret: YOUR_CLIENT_SECRET +file_path: computers.txt \ No newline at end of file