This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SNOW_BASE_URL = 'https://xxxx.service-now.com/api/' | |
| def snow_login(states): | |
| user = 'XXXX' | |
| pwd = 'XXXX' | |
| headers = {"Content-Type":"application/json","Accept":"application/json"} | |
| snow_data=[] | |
| for state in states: | |
| url = SNOW_BASE_URL + 'now/table/incident?sysparm_display_value=all&sysparm_fields=number%2Cassigned_to%2Csys_id%2Cstate%2Ccomments%2Cwork_notes%2Ccmdb_ci&cmdb_ci=xxxx&state='+state | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DP_BASE_URL = 'https://xxxx.com:xxxx/' | |
| def dp_login(): | |
| session = requests.session() | |
| url = DP_BASE_URL + 'auth/realms/DataProtector/protocol/openid-connect/token' | |
| payload = {'username':'xxxx|*|xxxx', 'password':'xxxx.', 'client_id':'dp-gui', 'grant_type':'password'} | |
| response = json.loads(session.post(url,data=payload,verify='xxxx_cacert.pem').text) | |
| access_token = response['access_token'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_dp_info(session, access_token, incident): | |
| url = DP_BASE_URL + 'idb/sessions/filter/' | |
| # transform session name format | |
| zeros_to_prefix = 4 - len(incident['session_name'].split('-')[-1]) | |
| session_name = incident['session_name'].replace('-', ' ' + zeros_to_prefix * '0') | |
| payload = json.dumps({ | |
| "filter": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import json | |
| def open_incidents_test(incident): | |
| url = "https:/xxxx/api/koi/servicenow_incident_api/update" | |
| payload = json.dumps({ | |
| "Incident_Update": { | |
| "number": incident, | |
| "state": "New", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add-type @" | |
| using System.Net; | |
| using System.Security.Cryptography.X509Certificates; | |
| public class TrustAllCertsPolicy : ICertificatePolicy { | |
| public bool CheckValidationResult( | |
| ServicePoint srvPoint, X509Certificate certificate, | |
| WebRequest request, int certificateProblem) { | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def login(): | |
| session = requests.session() | |
| url = 'https://xxxx.com:7116/auth/realms/DataProtector/protocol/openid-connect/token' | |
| payload = {'username':'username|*|xxxx.com', 'password':'password.', 'client_id':'dp-gui', 'grant_type':'password'} | |
| response = json.loads(session.post(url, data=payload,verify='xxxx.com_cacert.pem').text) | |
| access_token = response['access_token'] | |
| return access_token, session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_all_specifications(access_token, session): | |
| url = 'https://xxxx.com:7116/dp-gui/dp-scheduler-gui/restws/specification' | |
| headers = { | |
| 'Authorization': 'Bearer {}'.format(access_token), | |
| 'Content-Type': 'application/json' | |
| } | |
| response = json.loads(session.get(url, headers=headers).text) | |
| return response['specifications'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def filter_specification(all_specifications): | |
| filtered = [item for item in all_specifications if item['jobType'].lower()=='backup'] | |
| return filtered | |
| all_backup_specification = filter_specification(all_specifications) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_last_success_run(access_token, session, all_backup_specification): | |
| url = "https://xxxx.com:7116/idb/sessions/filter/" | |
| headers = { | |
| 'Authorization': 'Bearer {}'.format(access_token), | |
| 'Content-Type': 'application/json' | |
| } | |
| all_completed_runs = [] | |
| sessions_not_found = [] |