-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsNowIncidentGetMultiple.py
executable file
·73 lines (54 loc) · 2.21 KB
/
sNowIncidentGetMultiple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# AUTHOR: Created by John Singer, 4.13.15
# Any usage must include giving credit to the above author,
# but there is no warranty, express or implied for the use of this code.
#
# If problems are encountered, your 'best bet' is to ask for help
# on the bigfix forum (http://forum.bigfix.com).
#
import sys
import requests
from argparse import ArgumentParser
usage = """sNowIncidentGetMultiple.py [options]
Get ServiceNow Incident information, based on commandline
Options:
--user USERNAME IEM console-login USERNAME
(no default)
--password PASSWORD IEM console-login PASSWORD for above user
(no default)
-h, --help Print this help message and exit
Examples:
sNowIncidentGetMultiple -u Admin -p Password
"""
el = ''
if __name__ == '__main__':
try:
parser = ArgumentParser(add_help=False, usage=usage)
parser.add_argument('-u', '--user')
parser.add_argument('-p', '--password')
if '-h' in sys.argv or '--help' in sys.argv:
print(usage)
exit()
args = parser.parse_args()
if args.user: user = args.user
if args.password: password = args.password
# Now, try 'tapping into' the ServiceNow instance
snUrlBase = 'https://mjones1.service-now.com'
headers = {"Accept":"application/json"}
r = requests.get(snUrlBase+'/api/now/table/incident?sysparm_limit=10',auth=(user,password),headers=headers)
if r.status_code != 200:
print('sNowIncidentGetinfo ERROR -- Status: ', r.status_code, 'Headers:', r.headers, 'Error Response:', r.json())
exit()
else:
print('Status:', r.status_code, 'Headers:', r.headers, 'Response:', r.json())
print('Cookies:', r.cookies)
print('\nAnd now; the first 10 ServciceNow records...')
for record in r.json()['result']:
print ('\n', record)
# Handle any exceptions, printing out error code
except SystemExit:
pass
except:
print("Unexpected error:", sys.exc_info()[0])
raise
finally:
print("\n")