Tenable ‐ update agent profile with list of systems - dishplate/blog GitHub Wiki
#This will update a tenable agent profile with a list of systems by id
#use a file with just the tenable id of the hosts in the file
import csv
import requests
# === Set your credentials and profile UUID ===
ACCESS_KEY = 'your_access_key'
SECRET_KEY = 'your_secret_key'
PROFILE_UUID = 'your_profile_uuid'
CSV_FILE = 'agents.csv'
# === Read agent IDs from CSV ===
agent_ids = []
with open(CSV_FILE, newline='') as file:
reader = csv.DictReader(file)
for row in reader:
if 'id' in row and row['id']:
agent_ids.append(row['id'])
# === Prepare and send the PATCH request ===
url = f'https://cloud.tenable.com/sensors/profiles/agent/{PROFILE_UUID}'
headers = {
'X-ApiKeys': f'accessKey={ACCESS_KEY}; secretKey={SECRET_KEY}',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
data = {
'agents': agent_ids
}
response = requests.patch(url, json=data, headers=headers)
# === Print result ===
if response.status_code == 200:
print("Agent profile updated successfully.")
else:
print("Error:", response.status_code, response.text)