-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_ns_auth_vserver.py
62 lines (54 loc) · 2.64 KB
/
check_ns_auth_vserver.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
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
from nssrc.com.citrix.netscaler.nitro.resource.config.authentication.authenticationvserver import authenticationvserver
from nssrc.com.citrix.netscaler.nitro.service.nitro_service import nitro_service
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check Netscaler authentication vserver status')
parser.add_argument('--host', metavar='HOSTNAME', required=True, help='Netscaler hostname')
parser.add_argument('--user', metavar='USERNAME', default='nagios', help='Netscaler username')
parser.add_argument('--password', metavar='PASSWORD', default='api_user', help='Netscaler password')
parser.add_argument('--ssl', action="store_true", help='turn ssl on')
parser.add_argument('--nosslverify', action="store_true", help='turn ssl verify off')
parser.add_argument('--vservername', metavar='LBVSERVERNAME', required=True, help='name of vserver; Use ALL to get a list of all vservers')
parser.add_argument('--dargs', action='store_true', help='show service')
args = parser.parse_args()
if args.dargs:
print(args)
sys.exit(3)
# nitro = NSNitro(args.host, args.user, args.password, args.ssl)
if args.ssl:
nitro_session = nitro_service(args.host, "HTTPS")
if args.nosslverify:
nitro_session.certvalidation = False
nitro_session.hostnameverification = False
else:
nitro_session = nitro_service(args.host, "HTTP")
nitro_session.set_credential(args.user, args.password)
nitro_session.timeout = 310
try:
nitro_session.login()
try :
obj = authenticationvserver.get(nitro_session, name=args.vservername)
if (obj.curstate != "UP"):
print "CRITICAL: " + obj.name + " state: " + obj.curstate
nitro_session.logout()
sys.exit(2)
elif (obj.curstate == "UP"):
print "OK: " + obj.name + " state: " + obj.curstate + " | curusers=" + obj.curaaausers + ";;;;"
nitro_session.logout()
sys.exit(0)
except nitro_exception as e :
print("Exception::statsystem::errorcode="+str(e.errorcode)+",message="+ e.message)
sys.exit(4)
except Exception as e :
print("Exception::statsystem::message="+str(e.args))
sys.exit(4)
except nitro_exception as e :
print("Exception::statsystem::errorcode="+str(e.errorcode)+",message="+ e.message)
sys.exit(4)
except Exception as e :
print("Exception::statsystem::message="+str(e.args))
sys.exit(4)