root / utils / nagios_check_node @ ffccf6eccda1f0cad803664a7148fe3f0810dcd0

View | Annotate | Download (2.1 KB)

1
#!/usr/bin/env python
2
import sys, os
3
import socket
4
import getopt
5
import ConfigParser
6
7
sys.path.append('/home/dev/nfs/jul/sinn/lib')
8
9
import pysinn.xmlrpcliblocal as xmlrpclib
10
from optparse import OptionParser
11
import sys
12
13
14
# Standard Nagios return codes
15
OK       = 0
16
WARNING  = 1
17
CRITICAL = 2
18
UNKNOWN  = 3
19
20
21
parser = OptionParser()
22
parser.add_option("-H", "--hostname", help="hostname checked",
23
        default='localhost', metavar="HOST", dest="hostname")
24
parser.add_option("-P", "--port", default='8080', help="xmlrpc listening port",
25
        metavar="PORT", dest="port")
26
parser.add_option( "--stornode", default=False, action="store_true",
27
dest="stornode",
28
        help="host check is a storage node")
29
parser.add_option( "--hostnode", default=False, action="store_true",
30
dest="hostnode",
31
        help="host check is host node")
32
parser.add_option( "--netnode", default=False, action="store_true",
33
dest="netnode",
34
        help="host check is net node")
35
(options, args) = parser.parse_args()
36
37
if not options.hostnode and not options.stornode and not options.netnode:
38
    parser.print_help()
39
    sys.exit()
40
41
xmlrpcServer = "http://%s:%s" % (options.hostname, options.port)
42
43
xml = xmlrpclib.ServerProxy(xmlrpcServer, timeout=4)
44
45
46
try:
47
    res = xml.usage()
48
    if options.hostnode:
49
        print 'OK - xmlrpc srv Fine - Hostnode usage : memory used = %dMo/%dMo - cpu used = %s/%s' % (
50
                res['memory_used'], res['memory_total'], res['cpu_used'],
51
res['cpu_total'])
52
        sys.exit(OK)
53
    elif options.stornode:
54
        if type(res) is str and res == "Standby mode":
55
            print 'OK - xmlrpc srv Fine - Stornode status is : %s' % res
56
            sys.exit(OK)
57
        else:
58
            print 'OK - xmlrpc srv Fine - Stornode usage : space used : %dGo/%dGo' % (
59
                    res['space_used'], res['space_total'])
60
            sys.exit(OK)
61
    elif options.netnode:
62
        print 'OK - xmlrpc srv Fine - Netnode usage :  %s' % res
63
        sys.exit(OK)
64
except Exception, e:
65
    print 'CRITICAL - xmlrpc srv DOWN : %s' % e
66
    sys.exit(CRITICAL)
67
68
# vim: tabstop=4 expandtab shiftwidth=4 textwidth=79
69