Added Device List Query
This commit is contained in:
+11
-7
@@ -125,12 +125,13 @@ def deduplicate_list(lst):
|
|||||||
def menu_main():
|
def menu_main():
|
||||||
while True:
|
while True:
|
||||||
ct.displayIntro();
|
ct.displayIntro();
|
||||||
print(ct.colorText("1. Get All Events for Single Device", "yellow"))
|
print(ct.colorText("1. 🖥️ - Get All Events for Single Device", "yellow"))
|
||||||
print(ct.colorText("2. OTP", "yellow"))
|
print(ct.colorText("2. 🎫 - OTP", "yellow"))
|
||||||
print(ct.colorText("3. Find Unexcluded from 24hr Execution", "yellow"))
|
print(ct.colorText("3. ⏱️ - Find Unexcluded from 24hr Execution", "yellow"))
|
||||||
print(ct.colorText("4. Prepare Policy For Enforcement", "yellow"))
|
print(ct.colorText("4. 🔒 - Prepare Policy For Enforcement", "yellow"))
|
||||||
print(ct.colorText("5. Update Audit Policies from Enforcement Policies", "yellow"))
|
print(ct.colorText("5. 🔄 - Update Audit Policies from Enforcement Policies", "yellow"))
|
||||||
print(ct.colorText("Q. Quit", "yellow"))
|
print(ct.colorText("6 🔍 - Device Search", "yellow"))
|
||||||
|
print(ct.colorText("Q. 🔚 - Quit", "yellow"))
|
||||||
|
|
||||||
choice = input(ct.colorText("\nEnter Menu Item: ", "white"))
|
choice = input(ct.colorText("\nEnter Menu Item: ", "white"))
|
||||||
if choice == '1':
|
if choice == '1':
|
||||||
@@ -143,6 +144,9 @@ def menu_main():
|
|||||||
menu_prepare_to_enforce()
|
menu_prepare_to_enforce()
|
||||||
elif choice == "5":
|
elif choice == "5":
|
||||||
utils.policyfunctions.updateAuditPoliciesFromEnforcementPolices(url, policy_relationship_map)
|
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":
|
elif choice == "Q":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -150,7 +154,7 @@ def menu_main():
|
|||||||
|
|
||||||
def menu_otp():
|
def menu_otp():
|
||||||
while True:
|
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("1. Generate OTP","cyan"))
|
||||||
#print(ct.colorText("2. Sub-option B","cyan"))
|
#print(ct.colorText("2. Sub-option B","cyan"))
|
||||||
print(ct.colorText("Q. Return to Main Menu","cyan"))
|
print(ct.colorText("Q. Return to Main Menu","cyan"))
|
||||||
|
|||||||
@@ -17,9 +17,10 @@
|
|||||||
import utils.pretty as ct
|
import utils.pretty as ct
|
||||||
|
|
||||||
#Standard Libary Imports:
|
#Standard Libary Imports:
|
||||||
import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
#3rd Party Imports:
|
#3rd Party Imports:
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -184,3 +185,62 @@ def devicehistory(url, outputjson: bool):
|
|||||||
else:
|
else:
|
||||||
print(ct.colorText("No execution history found or data is not in expected format.", "red"))
|
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
@@ -196,7 +196,7 @@ def displayIntro():
|
|||||||
def printEnforceChecklist(first_policy, second_policy, allowlist_child_name, allowlist_parent_name, destination_name):
|
def printEnforceChecklist(first_policy, second_policy, allowlist_child_name, allowlist_parent_name, destination_name):
|
||||||
|
|
||||||
print(colorText("\n --------------------------------------------------------------------", "cyan"))
|
print(colorText("\n --------------------------------------------------------------------", "cyan"))
|
||||||
print(colorText(" -------------------- Prepare to Enforce Policy ---------------------", "cyan"))
|
print(colorText(" ------------- 🛠️ 🔒 Prepare to Enforce Policy 🛠️ 🔒 ------------------", "cyan"))
|
||||||
print(colorText(" --------------------------------------------------------------------", "cyan"))
|
print(colorText(" --------------------------------------------------------------------", "cyan"))
|
||||||
print(colorText("\nSequentually follow these steps to prepare a policy for enforcement:", "white"))
|
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"))
|
print(colorText("Q. Quit", "cyan"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def areYouSure():
|
def areYouSure():
|
||||||
print(colorText(f"*******************************************************************************************************************************************","red"))
|
print(colorText(f"🛑*****************************************************************************************************************************************🛑","red"))
|
||||||
print(colorText(f"*=========================================================================================================================================*","yellow"))
|
print(colorText(f"⚠️=========================================================================================================================================⚠️","yellow"))
|
||||||
print(colorText(f"*=========================================================================================================================================*","red"))
|
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"⚠️-------------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"🛑=========================================================================================================================================🛑","red"))
|
||||||
print(colorText(f"*=========================================================================================================================================*","yellow"))
|
print(colorText(f"⚠️=========================================================================================================================================⚠️","yellow"))
|
||||||
print(colorText(f"*******************************************************************************************************************************************","red"))
|
print(colorText(f"🛑******************************************************************************************************************************************🛑","red"))
|
||||||
|
|
||||||
def locked():
|
def locked():
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user