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
    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 
    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" ?>
<SCAN active="yes" ref="532305">
    <DAILY frequency_days=""/>
  <OPTION>Rolling Scan Option with Host Discovery</OPTION>
    <OPTION_PROFILE_TITLE option_profile_default="1"><![CDATA[Rolling Scan Option with Host Discovery]]></OPTION_PROFILE_TITLE>