source: monitoring/plugins/mpi/check_lat_lexus.py @ 1737

Last change on this file since 1737 was 1737, checked in by dietuyt, 12 years ago

Initial checkin of some example nagios plugins (for the MPI services)

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/python
2
3import sys, getopt, httplib
4
5nagios_codes = {'OK': 0,
6'WARNING': 1,
7'CRITICAL': 2,
8'UNKNOWN': 3,
9'DEPENDENT': 4}
10
11def usage():
12    """ returns nagios status UNKNOWN with
13        a one line usage description
14        usage() calls nagios_return()
15    """
16    nagios_return('UNKNOWN',
17            "usage: {0} -h host".format(sys.argv[0]))
18
19def nagios_return(code, response):
20    """ prints the response message
21        and exits the script with one
22        of the defined exit codes
23        DOES NOT RETURN
24    """
25    print code + ": " + response
26    sys.exit(nagios_codes[code])
27
28def check_condition(host):
29    conn = httplib.HTTPConnection(host)
30    conn.request("GET","/mpi/lexusDojo/")
31    r1 = conn.getresponse()
32    conn.close()
33    if r1.status == 200:
34        return {"code": "OK", "message": host + " ok"}
35    else:
36        return {"code": "CRITICAL", "message": host + " has a problem with lexus"}
37
38
39def main():
40    """ example options processing
41        here we're expecting 1 option "-h"
42        with a parameter
43    """
44
45    if len(sys.argv) < 2:
46        usage()
47
48    try:
49        opts, args = getopt.getopt(sys.argv[1:], "h:")
50    except getopt.GetoptError, err:
51        usage()
52
53    for o, value in opts:
54        if o == "-h":
55            host = value
56        else:
57            usage()
58
59    result = check_condition(host)
60    nagios_return(result['code'], result['message'])
61
62if __name__ == "__main__":
63    main()
64
Note: See TracBrowser for help on using the repository browser.