I am trying to create a report for each IP in a site. However, when getting Asset ID from 2 different IPs in 1 site, it only returns the same Asset ID, leading to reports only returning information of the first IP in the site.
def get_asset_id_from_ip(ip):
response = requests.get(f"{base_url}/api/3/assets?filter=ip-address:{ip}", headers=headers, verify=False)
if response.status_code == 200:
assets = response.json().get('resources', [])
if assets:
return assets[0]['id']
else:
print(f"No asset found for IP: {ip}")
return None
else:
print(f"Failed to fetch asset for IP {ip}: {response.status_code} - {response.text}")
return None
def configure_report_for_ip(ip):
asset_id = get_asset_id_from_ip(ip)
if not asset_id:
print(f"No asset found for IP: {ip}")
return None
report_data = {
"name": f"Report_{ip}_{datetime.now().strftime('%d%m%Y')}",
"template": "audit-report",
"format": "pdf",
"scope": {
"assets": [asset_id]
},
"timezone": "America/New_York",
"language": "en-US"
}
response = requests.post(f"{base_url}/api/3/reports", headers=headers, data=json.dumps(report_data), verify=False)
if response.status_code == 201:
report_id = response.json()['id']
print(f"Report configured successfully with ID: {report_id}")
return report_id
else:
print(f"Failed to configure report: {response.status_code} - {response.text}")
return None
Has anyone had a similar problem that can help me?