Skip to content

Instantly share code, notes, and snippets.

View kuharan's full-sized avatar
🏠
Working from home

KUHARAN BHOWMIK kuharan

🏠
Working from home
View GitHub Profile
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"
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": {
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']
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
@kuharan
kuharan / lambda_function.py
Last active February 25, 2021 17:04
AWS Lambda Function to automate DP APIs
import json
import requests
import time
from pytz import timezone
import datetime
status_dict = {'0':'Running','1':'Running with Errors','12':'Running with Failures','15':'Queueing with Failures'}
session_type_dict = {'0':'Backup'}
@kuharan
kuharan / json2csv.py
Last active February 15, 2021 18:03
JSON to CSV
def json_to_csv(path, fileInput, fileOutput):
inputFile = open(path + fileInput)
data = json.load(inputFile)
inputFile.close()
with open(os.path.join(path,fileOutput), 'w') as fp:
output = csv.writer(fp)
output.writerow(data[0].keys())
for row in data:
output.writerow(row.values())
@kuharan
kuharan / send_email_with_attachments.py
Created February 14, 2021 05:37
Send email with attachments in AWS lambda
def send_email(sender, recipient, aws_region, subject, file_name):
# The email body for recipients with non-HTML email clients.
BODY_TEXT = "Hello,\r\nPlease find the attached file."
# The HTML body of the email.
BODY_HTML = """\
<html>
<head></head>
<body>
<h1>Hello!</h1>
<p>Please find the attached file.</p>
@kuharan
kuharan / send_email.py
Created February 14, 2021 05:35
Send emails in AWSlambda
from botocore.exceptions import ClientError
from botocore.vendored import requests
def send_email(sender, recipient, aws_region, subject):
# This address must be verified with Amazon SES.
SENDER = sender
# If your account is still in the sandbox, this address must be verified.
RECIPIENT = recipient
# Specify a configuration set. If you do not want to use a configuration
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.