Quiet Hosts Calculator Added

This commit is contained in:
2025-09-26 16:18:53 -04:00
parent b82b4a0f1b
commit 8462e3adf5
3 changed files with 109 additions and 23 deletions
+77 -1
View File
@@ -349,4 +349,80 @@ def returnToEnforcement(url, device_df, policy_relationship_map, bad_publisher_l
break
else:
print(ct.colorText("Invalid choice. Please try again.", "red"))
"""
"""
def findQuietAgents(url):
choice, policynames, policyid = policyf.listPolicies(url)
policy = policynames[choice]
groupid = policyid[choice]
agents = findGroupAgents(url,groupid)
while True:
try:
history_days = int(input("Enter the how many days in of history do you want to pull - select a number between 1 and 150: "))
if 1 <= history_days <= 150:
break
else:
print("Invalid input. Please enter a number between 1 and 150.")
except ValueError:
print("Invalid input. Please enter a valid integer.")
policy_exec_history = policyf.getPolicyInfo(url, policy, [1, 2, 6, 7], history_days)
# Count occurrences of each hostname in the executions dataframe
hostname_counts = policy_exec_history['hostname'].value_counts()
# Map those counts to the hostnames in the first dataframe
agents['execution_count'] = agents['hostname'].map(hostname_counts).fillna(0).astype(int)
agents = agents.sort_values(by=['execution_count', 'hostname'], ascending=[True, True])
print(ct.colorText(f"Saving CSV to {policy}_agents_last_{history_days}_days.csv","green"))
agents.to_csv(f"{policy}_agents_last_{history_days}_days.csv", index=False)
# Count hosts with execution_count == 0
zero_count = (agents['execution_count'] == 0).sum()
# Total number of hosts
total_hosts = len(agents)
# Calculate percentage
zero_percentage = (zero_count / total_hosts) * 100
# Print results
print(f"Number of hosts with execution_count = 0: {zero_count}")
print(f"Percentage of hosts with execution_count = 0: {zero_percentage:.2f}%")
def findGroupAgents(url, groupid):
endpoint = url + '/v1/agent/find'
payload = {
"groupid" : f"{groupid}"
}
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"])
group_ids = sorted(data['groupid'].unique().tolist())
group_policy_map = {}
for groupid in group_ids:
policy_name = getPolicyName(url, groupid)
group_policy_map[groupid] = policy_name
data['policy_name'] = data['groupid'].map(group_policy_map)
status_map = {
0: 'Offline',
1: 'Online',
2: 'Hidden',
3: 'Safemode'
}
data['status'] = data['status'].map(status_map)
return(data)
return(data)