Skip to content

Instantly share code, notes, and snippets.

@kuharan
Created May 1, 2021 19:17
Show Gist options
  • Select an option

  • Save kuharan/5fc95ed94f61ca1d5de36bd547681750 to your computer and use it in GitHub Desktop.

Select an option

Save kuharan/5fc95ed94f61ca1d5de36bd547681750 to your computer and use it in GitHub Desktop.
def close_incident(incident):
url = SNOW_BASE_URL + "koi/servicenow_incident_api/update"
payload = json.dumps({
"Incident_Update": {
"number": incident['number']['value'],
"state": "Closed",
"work_notes": "xxxx",
"additional_comments": "xxxx"
}
})
headers = {
'Authorization': 'Basic xxxx',
'Content-Type': 'application/json'
}
response = requests.patch(url, headers=headers, data=payload)
return response.text
def check_success_status(session, access_token, incident):
url = DP_BASE_URL + 'idb/sessions/filter/'
headers = {
'Authorization': 'Bearer {}'.format(access_token),
'Content-Type': 'application/json'
}
if incident['backupType']==0:
# filter with session type and datalist when backuptype is 0, since dp apis dont accept a value 0. No idea why.
payload = json.dumps({
"filter": {
"sessionType": [0],
"datalist": incident['specification']
}
}
)
response = session.post(url, headers=headers, data=payload)
response_data = json.loads(response.text)
dp_items = response_data['items']
for item in dp_items:
if item['backupType']==0 and item['status']==2 and item['startTime'] > incident['endTime']:
status = close_incident(incident)
return status
else:
# filter with session type, datalist and backupType when backuptype is 10.
payload = json.dumps({
"filter": {
"sessionType": [0],
"datalist": incident['specification'],
"backupType":incident['backupType']
}
}
)
response = session.post(url, headers=headers, data=payload)
response_data = json.loads(response.text)
dp_items = response_data['items']
for item in dp_items:
if item['status']==2 and item['startTime'] > incident['endTime']:
status = close_incident(incident)
return status
#call this using
for incident in final_list:
closure_status = check_success_status(session, access_token, incident)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment