Exemplo n.º 1
0
#!/usr/bin/python3
import argparse
import mod_getsndata

parser = argparse.ArgumentParser(description="Gets a ServiceNow table and returns the JSON")
parser.add_argument("--instance","-i", help="ServiceNow Instance name to access", required=True)
parser.add_argument("--user","-u", help="ServiceNow User", required=True)
parser.add_argument("--password","-p", help="Password for ServiceNow User", required=True)
parser.add_argument("--table","-t",help="ServiceNow Table to retrieve", required=True, choices=['incident','u_request','change_request'])
parser.add_argument("--format","-f",help="Export format - Defaults to JSON",default="JSONv2", choices=['JSONv2','XML'])
parser.add_argument("--query","-q",help="URL Query to run against the table - Default is updated",default="updated",choices=['updated','created','closed','resolved','completed','startdate'])
parser.add_argument("--time","-d",help="Time period for Query to be run against - Default is ThisMonth",default="ThisMonth",choices=['ThisMonth','LastMonth','Last6Months','Last12Months'])

args = parser.parse_args()

data = mod_getsndata.get_sn_table_data(args.instance, args.user, args.password, args.table, args.query, args.time, args.format)

print(data)

Exemplo n.º 2
0
#!/usr/bin/python3
import argparse
import mod_trimsndata
import mod_getsndata
import mod_loadsndata

parser = argparse.ArgumentParser(description="Gets a ServiceNow table and returns the JSON")
parser.add_argument("--instance","-i", help="ServiceNow Instance name to access", required=True)
parser.add_argument("--user","-u", help="ServiceNow User", required=True)
parser.add_argument("--password","-p", help="Password for ServiceNow User", required=True)
parser.add_argument("--table","-t",help="ServiceNow Table to retrieve", required=True, choices=['incident','u_request','change_request'])
parser.add_argument("--format","-f",help="Export format - Defaults to JSON",default="JSONv2", choices=['JSONv2','XML'])
parser.add_argument("--query","-q",help="URL Query to run against the table - Default is updated",default="updated",choices=['updated','created','closed','resolved','completed','startdate'])
parser.add_argument("--time","-d",help="Time period for Query to be run against - Default is ThisMonth",default="LastHour",choices=['LastHour','ThisMonth','LastMonth','Last6Months','Last12Months'])
parser.add_argument("--database","-db", help="DB to update in Mongo", default="KDash")

args = parser.parse_args()

fields = ["assigned_to","assignment_group","category","contact_type","description","number","opened_at","opened_by","priority","short_description","state","sys_class_name","sys_created_on","sys_id","sys_updated_on","u_req_priority","u_requestor","u_affected_contact","u_business_service","u_resolution_code","u_resolution_reason","u_sla_progress","u_resolved","u_completed"]

data = mod_getsndata.get_sn_table_data(args.instance, args.user, args.password, args.table, args.query, args.time, args.format)

records = mod_trimsndata.trim_sn_data(data,fields)

for record in records:
    mongoid = mod_loadsndata.update_mongo_collection(args.database,args.table,records[record])
    print("Upserted "+str(mongoid))
Exemplo n.º 3
0
mongorunning = 0

while mongorunning == 0:
    print("Checking for mongo connection")
    mongorunning = mod_loadsndata.check_connection()
    if mongorunning == 0:
        print("Mongo not running. Trying again in 120 seconds")
        time.sleep(120)
    else:
        conn = mod_loadsndata.get_connection()
        print("Mongo is running. Continuing")

for table in tables:
    print("Getting data for "+table+" for "+timeframe)
    data = mod_getsndata.get_sn_table_data(instance, username, password, table, query, timeframe)
    records = mod_trimsndata.trim_sn_data(data,fields)

    for record in records:
        mongoid = mod_loadsndata.update_mongo_collection(conn,database,"tickets",records[record])
        print("Table:"+table+":Upserted "+str(mongoid))


while True:
    print("Waiting 10 minutes to get next update")
    time.sleep(600)
    for table in tables:
        data = mod_getsndata.get_sn_table_data(instance, username, password, table)
        records = mod_trimsndata.trim_sn_data(data,fields)
        for record in records:
            mongoid = mod_loadsndata.update_mongo_collection(conn,database,"tickets",records[record])