summaryrefslogtreecommitdiffstats
path: root/contrib/check_nwstat.pl
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_nwstat.pl
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_nwstat.pl')
-rw-r--r--contrib/check_nwstat.pl188
1 files changed, 188 insertions, 0 deletions
diff --git a/contrib/check_nwstat.pl b/contrib/check_nwstat.pl
new file mode 100644
index 0000000..2194640
--- /dev/null
+++ b/contrib/check_nwstat.pl
@@ -0,0 +1,188 @@
1#!/usr/bin/perl
2#
3# check_nwstat.pl: Nagios plugin that uses Jim Drews' nwstat.pl for
4# MRTG instead of emulating it. For use particularly with Cliff
5# Woolley's mrtgext.pl Unix companion to Drews' MRTGEXT.NLM, where
6# mrtgext.pl can contain custom commands that check_nwstat won't recognize,
7# though this also does its best to perfectly emulate the C version
8# of check_nwstat.
9#
10
11
12######################################################################
13# Configuration
14######################################################################
15
16$nwstatcmd = "/apps/mrtg/helpers/nwstat.pl";
17
18use Getopt::Long;
19
20$::host = shift || &usage(%ERROR);
21$::opt_v = undef;
22$::opt_wv = undef;
23$::opt_cv = undef;
24$::opt_to = 10;
25$::opt_url = undef;
26
27GetOptions (qw(v=s wv=i cv=i to=i url=s)) || &usage(%ERROR);
28
29my $cmd1 = "";
30my $cmd2 = "ZERO";
31my $backward = 0;
32my $desc = "";
33my $okstr = "OK";
34my $probstr = "Problem";
35my $result = "";
36my @CMD;
37my %ERROR = ("UNKNOWN" => -1,
38 "OK" => 0,
39 "WARNING" => 1,
40 "CRITICAL" => 2);
41my $status = $ERROR{"OK"};
42
43
44######################################################################
45# Main program
46######################################################################
47
48$SIG{'ALRM'} = sub {
49 print "Connection timed out\n";
50 exit $ERROR{"CRITICAL"};
51};
52
53# translate table for compatability with
54# check_nwstat (C version)
55SWITCH: for ($::opt_v) {
56 /^LOAD(1|5|15)$/
57 && do { $desc = "Load <status> - Up <cmd2>, ".
58 "$1-min load average = <cmd0>%";
59 $cmd1 = "UTIL$1"; last; };
60 /^CONNS$/ && do { $desc = "Conns <status>: ".
61 "<cmd0> current connections";
62 $cmd1 = "CONNECT"; last; };
63 /^CDBUFF$/ && do { $desc = "Dirty cache buffers = <cmd0>";
64 $cmd1 = "S3"; last; };
65 /^LTCH$/ && do { $desc = "Long term cache hits = <cmd0>%";
66 $cmd1 = "S1";
67 $backward = 1; last; };
68 /^CBUFF$/ && do { $desc = "Total cache buffers = <cmd0>";
69 $cmd1 = "S2";
70 $backward = 1; last; };
71 /^LRUM$/ && do { $desc = "LRU sitting time = <cmd0> minutes";
72 $cmd1 = "S5";
73 $backward = 1; last; };
74 /^VPF(.*)$/ && do { $desc = "<status><int(cmd0/1024)> MB ".
75 "(<result>%) free on volume $1";
76 $okstr = ""; $probstr = "Only ";
77 $cmd1 = "VKF$1";
78 $cmd2 = "VKS$1";
79 $backward = 1; last; };
80 /^VKF/ && do { $desc = "<status><cmd0> KB free on volume $1";
81 $okstr = ""; $probstr = "Only ";
82 $cmd1 = "$::opt_v";
83 $backward = 1; last; };
84 /^$/ && die "Nothing to check!";
85 $desc = "<status>: <cmd0>";
86 $cmd1 = "$::opt_v";
87 }
88
89
90# begin timeout period, run the check
91alarm($::opt_to);
92open ( CMD, "$nwstatcmd $host $cmd1 $cmd2|" ) || die "Couldn't execute nwstat";
93@CMD = <CMD>;
94close ( CMD );
95alarm(0);
96
97for (@CMD) { chomp; }
98
99# for any variables that manipulate the results instead of
100# just using <cmd0> directly, do that manipulation here into <result>
101SWITCH: for ($::opt_v) {
102 /^VPF/ && do { $result=int(("$CMD[0]"/"$CMD[1]")*100); last; };
103 $result = "$CMD[0]";
104 }
105
106if ("$result" == -1) {
107 $status = $ERROR{"UNKNOWN"};
108 $desc = "Server returned \"variable unknown\"";
109} elsif ("$result" == -2) {
110 $status = $ERROR{"CRITICAL"};
111 $desc = "Connection failed";
112}
113
114if (defined($::opt_cv) && $status == $ERROR{"OK"}) {
115 if ($backward) {
116 ("$result" <= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} );
117 } else {
118 ("$result" >= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} );
119 }
120}
121if (defined($::opt_wv) && $status == $ERROR{"OK"}) {
122 if ($backward) {
123 ("$result" <= "$::opt_wv") && ( $status = $ERROR{"WARNING"} );
124 } else {
125 ("$result" >= "$::opt_wv") && ( $status = $ERROR{"WARNING"} );
126 }
127}
128
129$desc =~ s/<status>/($status == $ERROR{"OK"})?"$okstr":"$probstr"/eg;
130$desc =~ s/<([^>]*)cmd([0-3])([^>]*)>/eval("$1\"$CMD[$2]\"$3")/eg;
131$desc =~ s/<result>/"$result"/eg;
132
133if (defined($::opt_url)) {
134 print "<A HREF=\"$::opt_url\">$desc</A>\n";
135} else {
136 print "$desc\n";
137}
138exit $status;
139
140
141######################################################################
142# Subroutines
143######################################################################
144
145sub usage {
146
147 %ERROR = shift;
148
149 print <<EOF
150check_nwstat.pl plugin for Nagios
151by Cliff Woolley, (c) 2000
152
153Usage: ./check_nwstat.pl <host_address> [-v variable] [-wv warn_value] [-cv crit_value] [-to to_sec] [-url url_value]
154
155Options:
156 [variable] = Variable to check. Valid variables include:
157 LOAD1 = 1 minute average CPU load
158 LOAD5 = 5 minute average CPU load
159 LOAD15 = 15 minute average CPU load
160 CONNS = number of currently licensed connections
161 VPF<vol> = percent free space on volume <vol>
162 VKF<vol> = KB of free space on volume <vol>
163 LTCH = percent long term cache hits
164 CBUFF = current number of cache buffers
165 CDBUFF = current number of dirty cache buffers
166 LRUM = LRU sitting time in minutes
167 [warn_value] = Threshold for value necessary to result in a warning status
168 [crit_value] = Threshold for value necessary to result in a critical status
169 [to_sec] = Number of secs before connection times out - default is 10 sec
170 [url_value] = URL to use in output as a hyperlink. Useful to link to a page
171 with more details or history for this variable (ie an MRTG page)
172
173This plugin attempts to contact the MRTGEXT NLM running on a Novell server
174to gather the requested system information.
175
176Notes:
177 - This plugin requres that the MRTGEXT.NLM file distributed with
178 James Drews' MRTG extension for NetWare (available from
179 http://www.engr.wisc.edu/~drews/mrtg/) be loaded on the Novell
180 servers you wish to check.
181 - Critical thresholds should be lower than warning thresholds when
182 the following variables are checked: VPF, VKF, LTCH, CBUFF, and LRUM.
183EOF
184;
185
186 exit $ERROR{"UNKNOWN"};
187}
188