Skip to content

Instantly share code, notes, and snippets.

View kuharan's full-sized avatar
🎯
Focusing

KUHARAN BHOWMIK kuharan

🎯
Focusing
View GitHub Profile
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
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']
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": {
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"
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",
@kuharan
kuharan / rest_example.ps1
Created May 22, 2021 19:33
This powershell snippet makes a api call to url with a json body converted from csv.
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;
}
}
@kuharan
kuharan / data_protector_login.py
Created July 11, 2021 12:07
login to data protector
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
@kuharan
kuharan / get_all_specifications.py
Created July 11, 2021 12:11
get all specification configured in data protector
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']
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)
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 = []