Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSierra committed Jun 17, 2024
1 parent 412bba1 commit bc11beb
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
init()

# Constants
CONFIG_FILE = 'config.yaml'
CONFIG_FILE = '../FalconTests/config.yaml'

# Function to load configuration
def load_config(file_path):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 63 additions & 11 deletions FalconTests/GetMembersTest.py
Original file line number Diff line number Diff line change
@@ -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 = "<group_id>" # Replace <group_id> 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 = "<group_id>" # Replace <group_id> 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)
File renamed without changes.
5 changes: 3 additions & 2 deletions FalconTests/config.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bc11beb

Please sign in to comment.