summaryrefslogtreecommitdiffstats
path: root/contrib/check_pcpmetric.py
diff options
context:
space:
mode:
authorStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2005-01-27 04:46:08 (GMT)
committerStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2005-01-27 04:46:08 (GMT)
commitfce1f09f770fc5bbc6d323865af709ff515c803c (patch)
tree1e997a0bc1ace6217cc0dab87b65de52bca8be20 /contrib/check_pcpmetric.py
parentccf789e017547e1f71b5945b2e1d85ce5b9cb8e4 (diff)
downloadmonitoring-plugins-fce1f09f770fc5bbc6d323865af709ff515c803c.tar.gz
New /contrib plugin
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1112 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_pcpmetric.py')
-rw-r--r--contrib/check_pcpmetric.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/contrib/check_pcpmetric.py b/contrib/check_pcpmetric.py
new file mode 100644
index 0000000..71d816d
--- /dev/null
+++ b/contrib/check_pcpmetric.py
@@ -0,0 +1,106 @@
1#! /usr/bin/env python
2#
3# Nagios client for checking Performance Co-Pilot metrics
4#
5#
6
7from sys import argv,exit
8import popen2, getopt, string, types
9
10DEBUG=0
11
12nagios_pcpclient_version = 0.01
13PMVAL='/usr/bin/pmval'
14COMMANDLINE=PMVAL + " -s 1"
15METRIC='undefined'
16CRITICAL=0
17WARNING=0
18
19def usage():
20 print "Usage:", argv[0], "[options]"
21 print "Options:"
22 print "\t[-H host]\tHostname to contact"
23 print "\t[-m metric]\tPCP metric to check"
24 print "\t[-i instance]\tPCP metric instance"
25 print "\t[-w warn]\tIssue warning alert if value is larger than this"
26 print "\t[-c critical]\tIssue critical alert value is larger than this"
27 print "\t[-V]\t\tProgram version"
28 print "\t[-h]\t\tThis helptext"
29 print ""
30 print "F.ex. to check 5 minute loadaverage, warn if the load is above 2,"
31 print "and give critical warning if it's above 10:"
32 print "\n\t%", argv[0], " -i 5 -m kernel.all.load -w 2 -c 10"
33 print ""
34 print "A list of all PCP metrics can be found with the command 'pminfo'."
35 print "A list of all instances within a metric can be found with 'pminfo -f metric'."
36 print "F.ex. to see all available instances of 'filesys.full' execute:"
37 print "\n\t% pminfo -f filesys.full"
38 print "\tfilesys.full"
39 print """\t\tinst [0 or "/dev/root"] value 45.35514044640914"""
40 print """\t\tinst [1 or "/dev/sda1"] value 46.74285959344712"""
41 print """\t\tinst [2 or "/dev/sdb1"] value 0.807766570678168"""
42 print ""
43 print "And the command to have nagios monitor the /dev/sda1 filesystem would be:"
44 print "\n\t", argv[0], " -i /dev/sda1 -m filesys.full -w 70 -c 90"
45
46
47opts, args = getopt.getopt(argv[1:],'hH:c:w:m:i:V')
48for opt in opts:
49 key,value = opt
50 if key == '-H':
51 COMMANDLINE = COMMANDLINE + " -h " + value
52 elif key == '-m':
53 METRIC=value
54 elif key == '-i':
55 COMMANDLINE = COMMANDLINE + " -i " + value
56 elif key == '-c':
57 CRITICAL = value
58 elif key == '-w':
59 WARNING = value
60 elif key == '-h':
61 usage()
62 exit(0)
63 elif key == '-V':
64 print "Nagios Performance CoPilot client v%.2f" % nagios_pcpclient_version
65 print "Written by Jan-Frode Myklebust <janfrode@parallab.uib.no>"
66 exit(0)
67
68if METRIC == 'undefined':
69 usage()
70 exit(3)
71
72COMMANDLINE = COMMANDLINE + " " + METRIC
73if DEBUG: print COMMANDLINE
74p=popen2.Popen4(COMMANDLINE)
75exitcode=p.wait()
76
77# Get the last line of output from 'pmval':
78buffer = p.fromchild.readline()
79while (buffer != ''):
80 output=buffer
81 buffer = p.fromchild.readline()
82
83returndata = string.split(output)[0]
84
85
86# Confirm that we have gotten a float, and not
87# some errormessage in the returndata. If not,
88# print the error, and give the UNKNOWN exit code:
89
90try:
91 retval = string.atof(returndata)
92except ValueError, e:
93 print e
94 exit(3)
95
96if (retval < WARNING):
97 EXITCODE=0
98elif (retval > CRITICAL):
99 EXITCODE=2
100elif (retval > WARNING):
101 EXITCODE=1
102else:
103 EXITCODE=3
104
105print retval
106exit(EXITCODE)