pyTenable
pyTenable copied to clipboard
Create scans in Tenable.io for specific agent groups
Hi,
In the documentation I dont see a way to create an agent scan and add agent groups to be scanned to the new scan. Is there any way we can do that similar to adding target groups?
Thanks
if you see response of tio.scans.details(scan['id'])
for a agent scan -> it format the targeted agent groups as a list to a key "agent_group_id" and I tested by creating scan using tio.scans.create
and passing agent_group_id on place of target as a list of agent group uuids.
scan = tio.scans.create(name = name, template = 'basic', agent_group_id = agent_group)
scan_id = scan['id']
response = tio.scans.launch(scan_id)
Complete flow I am using until now: Iterate through list of agent group, check if they are still active by comparing the list of agent groups from Tenable and then create the list and launch scan
def fetch_ag_dict(tio):
ag_list = tio.agent_groups.list()
ag_dict = {}
for ag in ag_list:
ag_dict[ag['uuid']] = ag['id']
return ag_dict
agent_group = [a,b,x,d,e,f,g,h] # List of Agent Group UUIDs. Either offline copy or online fetched
# ignore the below check if agent_Group list fetched in real time from Tenable.IO else if fetching from scan history makes sense to see do verification else launch can fail
agent_dict = fetch_ag_dict(tio)
agent_group = [x for x in agent_group if x in agent_dict.keys()]
response = tio.scans.configure(scan_id, agent_group_id = agent_group)
response = tio.scans.launch(scan_id)
or
scan = tio.scans.create(name = name, template = 'basic', agent_group_id = agent_group)
scan_id = scan['id']
response = tio.scans.launch(scan_id)
Closing (as-designed).