Added Device List Query

This commit is contained in:
2025-09-25 12:30:32 -04:00
parent 5c11629f64
commit f8bcb826e7
3 changed files with 80 additions and 19 deletions
+11 -7
View File
@@ -125,12 +125,13 @@ def deduplicate_list(lst):
def menu_main():
while True:
ct.displayIntro();
print(ct.colorText("1. Get All Events for Single Device", "yellow"))
print(ct.colorText("2. OTP", "yellow"))
print(ct.colorText("3. Find Unexcluded from 24hr Execution", "yellow"))
print(ct.colorText("4. Prepare Policy For Enforcement", "yellow"))
print(ct.colorText("5. Update Audit Policies from Enforcement Policies", "yellow"))
print(ct.colorText("Q. Quit", "yellow"))
print(ct.colorText("1. 🖥️ - Get All Events for Single Device", "yellow"))
print(ct.colorText("2. 🎫 - OTP", "yellow"))
print(ct.colorText("3. ⏱️ - Find Unexcluded from 24hr Execution", "yellow"))
print(ct.colorText("4. 🔒 - Prepare Policy For Enforcement", "yellow"))
print(ct.colorText("5. 🔄 - Update Audit Policies from Enforcement Policies", "yellow"))
print(ct.colorText("6 🔍 - Device Search", "yellow"))
print(ct.colorText("Q. 🔚 - Quit", "yellow"))
choice = input(ct.colorText("\nEnter Menu Item: ", "white"))
if choice == '1':
@@ -143,6 +144,9 @@ def menu_main():
menu_prepare_to_enforce()
elif choice == "5":
utils.policyfunctions.updateAuditPoliciesFromEnforcementPolices(url, policy_relationship_map)
elif choice == "6":
device_input_str = utils.clientfunctions.promptForDevices()
utils.clientfunctions.findAgents(url, device_input_str)
elif choice == "Q":
break
else:
@@ -150,7 +154,7 @@ def menu_main():
def menu_otp():
while True:
print(ct.colorText("\n--- OTP Submenu ---","cyan"))
print(ct.colorText("\n--- 🎫 OTP Submenu 🎫 ---","cyan"))
print(ct.colorText("1. Generate OTP","cyan"))
#print(ct.colorText("2. Sub-option B","cyan"))
print(ct.colorText("Q. Return to Main Menu","cyan"))
+61 -1
View File
@@ -17,9 +17,10 @@
import utils.pretty as ct
#Standard Libary Imports:
import datetime
from datetime import datetime
import json
import os
import re
#3rd Party Imports:
import pandas as pd
@@ -184,3 +185,62 @@ def devicehistory(url, outputjson: bool):
else:
print(ct.colorText("No execution history found or data is not in expected format.", "red"))
def findAllAgents(url):
endpoint = url + '/v1/agent/find'
payload = {}
headers = {"X-APIKey": os.getenv('APIKEY')}
payload = json.dumps(payload)
response = requests.post(endpoint, headers=headers, data=payload, verify=False)
result = json.loads(response.text)
data = pd.DataFrame(result["response"]["agents"])
return(data)
def findAgents(url, device_input_str):
os.makedirs("device_search", exist_ok=True)
# Step 1: Get the DataFrame from your function
df = findAllAgents(url)
# Step 2: Parse the input string into device names (newline-separated only)
device_names = device_input_str.strip().split('\n')
device_names = [name.strip() for name in device_names if name.strip()]
# Step 3: Build a regex pattern for case-insensitive matching
pattern = '|'.join([re.escape(name) for name in device_names])
regex = re.compile(pattern, re.IGNORECASE)
# Step 4: Filter the DataFrame using regex
matched_df = df[df['hostname'].apply(lambda x: bool(regex.search(str(x))))]
# Step 5: Export to CSV with timestamp
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"agentsearch_{timestamp}.csv"
matched_df.to_csv(f"device_search\\{filename}", index=False)
print(ct.colorText(f"\n✅ Matched devices exported to: device_search\\{filename}","green"))
def promptForDevices():
print(ct.colorText("🔍 Device Search", "cyan"))
print(ct.colorText("Enter the device hostnames you'd like to search for, one per line.", "cyan"))
print(ct.colorText("When you're done, press Enter twice.\n", "cyan"))
print(ct.colorText("Example:", "cyan"))
print(ct.colorText("H00000", "cyan"))
print(ct.colorText("UTN00000", "cyan"))
print(ct.colorText("i-hSuperSecretServer", "cyan"))
print(ct.colorText("u-hVenderBroke\n", "cyan"))
# Collect multiline input from user
print(ct.colorText("Paste or type your device names below:", "white"))
device_input_lines = []
while True:
line = input()
if line == "":
break
device_input_lines.append(line)
device_input_str = "\n".join(device_input_lines)
return device_input_str
+8 -11
View File
@@ -196,7 +196,7 @@ def displayIntro():
def printEnforceChecklist(first_policy, second_policy, allowlist_child_name, allowlist_parent_name, destination_name):
print(colorText("\n --------------------------------------------------------------------", "cyan"))
print(colorText(" -------------------- Prepare to Enforce Policy ---------------------", "cyan"))
print(colorText(" ------------- 🛠️ 🔒 Prepare to Enforce Policy 🛠️ 🔒 ------------------", "cyan"))
print(colorText(" --------------------------------------------------------------------", "cyan"))
print(colorText("\nSequentually follow these steps to prepare a policy for enforcement:", "white"))
@@ -308,17 +308,14 @@ def printEnforceChecklist(first_policy, second_policy, allowlist_child_name, all
print(colorText("Q. Quit", "cyan"))
def areYouSure():
print(colorText(f"*******************************************************************************************************************************************","red"))
print(colorText(f"*=========================================================================================================================================*","yellow"))
print(colorText(f"*=========================================================================================================================================*","red"))
print(colorText(f"*-------------This program will now begin to make changes to the Airlock Console. Do you understand and agree to proceed? ----------------*", "yellow"))
print(colorText(f"*=========================================================================================================================================*","red"))
print(colorText(f"*=========================================================================================================================================*","yellow"))
print(colorText(f"*******************************************************************************************************************************************","red"))
print(colorText(f"🛑*****************************************************************************************************************************************🛑","red"))
print(colorText(f"⚠️=========================================================================================================================================⚠️","yellow"))
print(colorText(f"🛑========================================================================================================================================🛑","red"))
print(colorText(f"⚠️-------------This program will now begin to make changes to the Airlock Console. Do you understand and agree to proceed? ----------------⚠️", "yellow"))
print(colorText(f"🛑=========================================================================================================================================🛑","red"))
print(colorText(f"⚠️=========================================================================================================================================⚠️","yellow"))
print(colorText(f"🛑******************************************************************************************************************************************🛑","red"))
def locked():