How to use Python with json to get job started

ADDM, Client Management, Spread sheet loads by ITSM, etc..
Post Reply
hudatolah
Site Admin
Posts: 42
Joined: Thu Apr 04, 2013 8:10 pm
Are You a Headhunter?: Affirmative
Surfer?: Yes

How to use Python with json to get job started

Post by hudatolah » Mon Oct 07, 2019 11:22 am

Code: Select all

import csv
import json
import requests

url = "https://ADDMApplianceHost/api/v1.1/discovery/runs"
targetRanges = []
with open("/usr/tideway/job_queue/tmssubnet.csv") as csvFile:
        foundRanges = []
          next(rows)
             for row in rows:
                 range2 = ''
                     if row[1] == '32':
                          range = row[0]
                     elif row[1] == '31': 
                         ipParts = row[0].split('.')
                            range = row[0]
                            range2 = ipParts[0]+'.'+ipParts[1]+'.'+ipParts[2]+'.'+str(int(ipParts[3])+1)
                     else:
                            range = row[0]+"/"+row[1]
                     if range not in foundRanges:
                                    foundRanges.append(range2)
                     if range2 != '':
                                 if range2 not in foundRanges:
                                    foundRanges.append(range2)
                targetRanges = foundRanges
jsondata = {}
jsondata['scan_kind'] = 'IP'
jsondata['ranges'] = targetRanges
jsondata['label'] = "TMS network Full list'
jsondata['scan_level'] = 'Full Discovery'
jsonbody = json.dumps(jsondata)
print(jsonbody)
payload = jsonbody
headers = {
     'Content-Type': "application/json",
     'Accept': "application/json",
     'Authorization': "Bearer ..........",
     'Verify': "False"
    }
response = requests.request("POST", url, data=payload, headers=headers, verify=False)

#print(response.text)
The Blackholesurfer. My surfboard has teeth.