Switch to using resource groups with dynamic hosts.

This commit is contained in:
Marsell Kukuljevic 2024-12-06 10:44:34 +01:00
parent 87b27b3b49
commit 1dca9e4a65
6 changed files with 22 additions and 11 deletions

Binary file not shown.

View File

@ -147,6 +147,7 @@ def get_resource_group(obj):
return None return None
resource_groups = {}
command, tenant, username, password, proxy = get_args(sys.argv) command, tenant, username, password, proxy = get_args(sys.argv)
token = get_token(tenant, username, password, proxy) token = get_token(tenant, username, password, proxy)
@ -161,11 +162,13 @@ for subscription in list_subscriptions(token, proxy):
if not status in ['Active', 'InProgress']: if not status in ['Active', 'InProgress']:
continue continue
print_json({ group = get_resource_group(alert)
resource_groups.setdefault(group, []).append({
'type': command, 'type': command,
'name': alert['name'], 'name': alert['name'],
'location': re.search(REGION_RE, alert['id'])[1], 'location': re.search(REGION_RE, alert['id'])[1],
'resource_group': get_resource_group(alert), 'resource_group': group,
'alert': { 'alert': {
'status': status, 'status': status,
'severity': properties['severity'], 'severity': properties['severity'],
@ -178,7 +181,9 @@ for subscription in list_subscriptions(token, proxy):
elif command == 'firewall': elif command == 'firewall':
for firewall in list_firewalls(token, proxy, subscription_id): for firewall in list_firewalls(token, proxy, subscription_id):
metrics = get_recent_metrics(token, proxy, firewall['id'], FIREWALL_METRICS) metrics = get_recent_metrics(token, proxy, firewall['id'], FIREWALL_METRICS)
print_json({ group = get_resource_group(firewall)
resource_groups.setdefault(group, []).append({
'type': command, 'type': command,
'name': firewall['name'], 'name': firewall['name'],
'location': firewall['location'], 'location': firewall['location'],
@ -189,10 +194,22 @@ for subscription in list_subscriptions(token, proxy):
elif command == 'keyvault': elif command == 'keyvault':
for vault in list_vaults(token, proxy, subscription_id): for vault in list_vaults(token, proxy, subscription_id):
metrics = get_recent_metrics(token, proxy, vault['id'], VAULT_METRICS) metrics = get_recent_metrics(token, proxy, vault['id'], VAULT_METRICS)
print_json({ group = get_resource_group(vault)
resource_groups.setdefault(group, []).append({
'type': command, 'type': command,
'name': vault['name'], 'name': vault['name'],
'location': vault['location'], 'location': vault['location'],
'resource_group': get_resource_group(vault), 'resource_group': group,
'metrics': metrics_to_lookup(metrics), 'metrics': metrics_to_lookup(metrics),
}) })
for group, results in resource_groups.items():
if group is None:
print(f"<<<<>>>>")
else:
print(f"<<<<{group}>>>>")
print(f"<<<azure_{command}:sep(0)>>>")
for result in results:
print_json(result)

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
echo '<<<azure_defender:sep(0)>>>'
dir=$(dirname -- "${BASH_SOURCE[0]}") dir=$(dirname -- "${BASH_SOURCE[0]}")
"$dir"/agent_azure_common defender "$1" "$2" "$3" "$4" "$dir"/agent_azure_common defender "$1" "$2" "$3" "$4"

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
echo '<<<azure_firewall:sep(0)>>>'
dir=$(dirname -- "${BASH_SOURCE[0]}") dir=$(dirname -- "${BASH_SOURCE[0]}")
"$dir"/agent_azure_common firewall "$1" "$2" "$3" "$4" "$dir"/agent_azure_common firewall "$1" "$2" "$3" "$4"

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
echo '<<<azure_keyvault:sep(0)>>>'
dir=$(dirname -- "${BASH_SOURCE[0]}") dir=$(dirname -- "${BASH_SOURCE[0]}")
"$dir"/agent_azure_common keyvault "$1" "$2" "$3" "$4" "$dir"/agent_azure_common keyvault "$1" "$2" "$3" "$4"