AnsweredAssumed Answered

Schedule Scan Qualys API v1 Python

Question asked by Alex waitkus on Jul 23, 2014
Latest reply on Jul 23, 2014 by Jonas Kelley

I have created a python script for asset import. I have tried to use that script to take my asset import csv and use it for creating scheduled scans. I am having trouble creating the scans. The schedule part of the scan is not setting from the script. Has anyone else accomplished this? Can anyone see any errors with my code?

 

import csv
import qualysapi  
f = open('tenant_out.csv', 'rU') #open file
try:
    r = csv.reader(f) #init csv reader
    for row in r:
        #defining variables
        tenant_title = row[0]
        subnet = row[1]
        location = row[2]
        appliance = row[3]
        scan_type = row[4]
        #concatinate the title to the acceptable format
        asset_title = tenant_title.replace(",","-") + '-' + subnet.replace(",","-") + '-' + location
        title = subnet.replace(",","-") + '-' + location +'-'+ 'ScheduledScan'
        #print title
        # Setup connection to QualysGuard API
        qgc = qualysapi.connect('config.txt') 
        # The call is our request's first parameter. 
        call = 'scheduled_scans.php' 
        # The parameters to append to the url is our request's second parameter. 
        parameters = {'add_task': 'yes', 
        'scan_title': title,
        'active': 'yes',
        'type': 'scan',
        'asset_groups': asset_title,
        'scanners_in_ag': '1',
        'option': 'Rolling Scan Option with Host Discovery',
        'occurrence': 'weekly',
        'frequency_weeks': '1',
        'weekdays': 'Tuesday',
        'time_zone_code': 'US-GA',
        'observe_dst': 'yes',
        'start_hour': '11',
        'start_minute': '15'}
        xml_output = qgc.request(call, parameters)  
        print xml_output 
finally:
    f.close() #cleanup

 

 

The output is similar to below, some items have been changed to protect IP space

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE SCHEDULEDSCANS SYSTEM "https://qualysapi.qualys.com/scheduled_scans.dtd">
<SCHEDULEDSCANS>
<SCAN active="yes" ref="532305">
  <TITLE><![CDATA[10.10.10.0/24-EDUCATION8-9-ScheduledScan]]></TITLE>
  <TARGETS><![CDATA[10.10.10.0-10.10.10.255]]></TARGETS>
  <SCHEDULE>
    <DAILY frequency_days=""/>
    <START_DATE_UTC>1970-01-01T00:00:00</START_DATE_UTC>
  <START_HOUR></START_HOUR>
  <START_MINUTE></START_MINUTE>
  <TIME_ZONE>
    <TIME_ZONE_CODE></TIME_ZONE_CODE>
    <TIME_ZONE_DETAILS><![CDATA[]]></TIME_ZONE_DETAILS>
  </TIME_ZONE>
  <DST_SELECTED></DST_SELECTED>
  </SCHEDULE>
  <DEFAULT_SCANNER>0</DEFAULT_SCANNER>
  <ISCANNER_NAME>All Scanners in AG</ISCANNER_NAME>
  <OPTION>Rolling Scan Option with Host Discovery</OPTION>
  <TYPE>SCAN</TYPE>
  <ASSET_GROUPS>
    <ASSET_GROUP>
      <ASSET_GROUP_TITLE><![CDATA[10.10.10.0/24-EDUCATION8-9]]></ASSET_GROUP_TITLE>
    </ASSET_GROUP>
  </ASSET_GROUPS>
  <OPTION_PROFILE>
    <OPTION_PROFILE_TITLE option_profile_default="1"><![CDATA[Rolling Scan Option with Host Discovery]]></OPTION_PROFILE_TITLE>
  </OPTION_PROFILE>
</SCAN>
</SCHEDULEDSCANS>

Outcomes