-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_epic_api.py
executable file
·116 lines (86 loc) · 3.71 KB
/
check_epic_api.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
import argparse
import sys
import epicclient
import signal
from time import strftime,gmtime
TEST_SUFFIX='NAGIOS-' + strftime("%Y%m%d-%H%M%S",gmtime())
VALUE_ORIG='http://www.' + TEST_SUFFIX + '.com/1'
VALUE_AFTER='http://www.' + TEST_SUFFIX + '.com/2'
def handler(signum, stack):
print "UNKNOWN: Timeout reached, exiting."
sys.exit(3)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='EPIC API create, read, update, delete probe')
req = parser.add_argument_group('required arguments')
req.add_argument('-u', '--url', action='store', dest='url', required=True,
help='baseuri of EPIC API to test')
req.add_argument('-U', '--username', action='store', dest='username', required=True,
help='EPIC API user')
req.add_argument('-P', '--pass', action='store', dest='password', required=True,
help='EPIC API key')
req.add_argument('-p', '--prefix', action='store', dest='prefix', required=True,
help='prefix to test')
req.add_argument('-t', '--timeout', action='store', dest='timeout',
help='timeout')
parser.add_argument('-d', '--debug', action='store_true', dest='debug',
help='debug mode')
param = parser.parse_args()
if param.timeout and int(param.timeout) > 0 :
signal.signal(signal.SIGALRM, handler)
signal.alarm(int(param.timeout))
try:
url = param.url
if (url[-1] != '/'):
url = url + '/'
# Credentials __init__ has been modified to accept url,username,password,prefix and dbg as arguments
cred = epicclient.Credentials(uri=url, username=param.username, password=param.password,
prefix=param.prefix, dbg=param.debug)
client = epicclient.EpicClient(cred)
# Create test
create_result = client.createHandle(
cred.prefix, VALUE_ORIG, None, None,
None, TEST_SUFFIX)
if create_result == str(cred.prefix + '/' + TEST_SUFFIX):
print "OK: Create handle successful."
else:
print "CRITICAL: Create handle returned unexpected response."
sys.exit(2)
# Read test
read_value = client.getValueFromHandle(
cred.prefix, 'URL', TEST_SUFFIX)
if read_value == VALUE_ORIG:
print "OK: Read handle successful."
else:
print "CRITICAL: Read handle returned unexpected response."
client.deleteHandle(cred.prefix, '', TEST_SUFFIX)
sys.exit(2)
# Modify test
key = 'URL'
modify_result = client.modifyHandle(
cred.prefix, key, VALUE_AFTER, TEST_SUFFIX)
if not modify_result:
print "CRITICAL: Modify handle value returned unexpected response."
client.deleteHandle(cred.prefix, '', TEST_SUFFIX)
sys.exit(2)
get_value_result = client.getValueFromHandle(
cred.prefix, key, TEST_SUFFIX)
if get_value_result == VALUE_AFTER:
print "OK: Modify handle successful."
else:
print "CRITICAL: Modify handle value returned unexpected value."
print "Expected : " + VALUE_AFTER
print "Returned : " + get_value_result
client.deleteHandle(cred.prefix, '', TEST_SUFFIX)
sys.exit(2)
# Delete test
delete_result = client.deleteHandle(cred.prefix, '', TEST_SUFFIX)
if delete_result:
print "OK: Delete handle successful."
sys.exit(0)
else:
print "CRITICAL: Delete existing handle returned unexpected response."
sys.exit(2)
except Exception as e:
print "UNKNOWN: " + e
sys.exit(3)