-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
412bba1
commit bc11beb
Showing
16 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |