/[nagios-plugins-perl]/trunk/plugins/check_nsd_load.pl
ViewVC logotype

Contents of /trunk/plugins/check_nsd_load.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations) (download)
Thu Nov 12 13:29:04 2009 UTC (11 years ago) by racvision
File MIME type: text/plain
File size: 4728 byte(s)
convert source structure from autotools to rpm-build.sh
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) 2001 Eirik Robertstad (erobertstad@users.sourceforge.net) (check_swap.pl)
4 # Code taken from check_mem.pl by Dan Larsson <dl@tyfon.net>
5 #
6 # (c) 2002-2004 St�hane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty
15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # you should have received a copy of the GNU General Public License
19 # along with this program (or with Netsaint); if not, write to the
20 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA
22 #
23 #
24 # $Id: check_nsd_load.pl,v 1.4 2006-12-20 11:00:43 uid5000 Exp $
25
26 use strict; # should never be differently :-)
27 use warnings;
28
29 use File::Basename; # get dirname()
30 use lib dirname($0); # to get local libs
31 use libplugins qw(%EXIT_CODES &showUsage);
32 use NSD;
33
34
35 # Default values ::
36 my %DEFVALUES = (
37 'LOAD_WARNING' => {
38 'v' => 20,
39 'desc' => _("Load warning level"),
40 },
41 'LOAD_CRITICAL' => {
42 'v' => 50,
43 'desc' => _("Load critical level"),
44 },
45 'TIMEOUT' => {
46 'v' => $NSD::NSD_TIMEOUT,
47 'desc' => _("Nagiosstatd connection timeout"),
48 },
49 'VERSION' => {
50 'v' => "1.1",
51 'desc' => _("Plugin Version"),
52 },
53 );
54
55
56 my $DEBUG = 0;
57
58 # Get the options :
59 use vars qw($opt_V $opt_h $opt_m $opt_perf $opt_H $opt_p $opt_w $opt_c);
60
61 Getopt::Long::GetOptions (
62 "V" => \$opt_V, "version" => \$opt_V,
63 "h|?" => \$opt_h, "help" => \$opt_m,
64 "man" => \$opt_m,
65 "perf" => \$opt_perf,
66
67 "d" => \$DEBUG, "debug=i" => \$DEBUG,
68 "H=s" => \$opt_H, "host=s" => \$opt_H,
69 "p=i" => \$opt_p, "port=i" => \$opt_p,
70
71 "w=i" => \$opt_w, "warning=i" => \$opt_w,
72 "c=i" => \$opt_c, "critical=i" => \$opt_c,
73
74 );
75
76
77 my $answer = '';
78
79 if ( defined ($opt_h) || defined ($opt_m) ) {
80 &showUsage($opt_m,\%DEFVALUES);
81 }
82 if ( (!defined ($opt_H)) || ($opt_H eq "")) {
83 print _("Missing remote hostname parameter !");
84 &showUsage();
85 }
86
87 # Set default values :
88 my $warn_level = $opt_w || $DEFVALUES{LOAD_WARNING}{v};
89 my $crit_level = $opt_c || $DEFVALUES{LOAD_CRITICAL}{v};
90
91
92 # Connect to remote Nagiosstatd:
93 my $service = "uptime";
94 my $o_nsd = new NSD ( address => $opt_H , port => $opt_p, debug => $DEBUG);
95
96 if ( $o_nsd->connect() ) {
97 print $o_nsd->getErrorMsg()."\n";
98 exit $EXIT_CODES{'UNKNOWN'};
99 }
100 if ( $o_nsd->ask($service) ) {
101 $o_nsd->close();
102 print $o_nsd->getErrorMsg()."\n";
103 exit $EXIT_CODES{'UNKNOWN'};
104 }
105 $o_nsd->close();
106 my $servanswer = $o_nsd->getResponse();
107
108 my $state = "OK";
109 my $perf="";
110
111 if ($servanswer =~ /^(.*) - ([\d\.]+) /) {
112 my $uptime = $1;
113 my $load = $2;
114 if ($load < $warn_level) {
115 $answer = sprintf(_("5-min load currently %s, up %s"),$load,$uptime);
116 } elsif ($load < $crit_level) {
117 $state = "WARNING";
118 $answer = sprintf(_("5-min load currently %s, up %s"),$load,$uptime);
119 } else {
120 $state = "CRITICAL";
121 $answer = sprintf(_("5-min load currently %s, up %s"),$load,$uptime);
122 }
123 $answer = "Load $state - ".$answer;
124 $perf = "Load=$load;$warn_level;$crit_level";
125
126 if ($opt_perf) {
127 $answer .= "|$perf";
128 }
129
130 } else {
131 $state = "UNKNOWN";
132 $answer = sprintf(_("Invalid data (%s) !"),$servanswer);
133 }
134
135 print $answer."\n";
136 exit $EXIT_CODES{$state};
137
138
139
140 __END__
141
142 =head1 NAME
143
144 check_nsd_load.pl - Nagios plugins.
145
146 =head1 SYNOPSIS
147
148 B<check_nsd_load.pl> S<-H I<remote host>> [S<-p I<nsd port>>] [S<-w I<warn>>] [S<-c I<crit>>]
149
150 =head1 DESCRIPTION
151
152 Nagios plugins to check remote load using Nagiosstatd.
153
154
155 =head1 OPTIONS
156
157 =over 4
158
159 =item B<-H> I<remote host>
160
161 Host running Nagiosstatd to check.
162
163 =item B<-p> I<nsd port>
164
165 Nagiosstatd port.
166
167 =item B<-w> I<warn>
168
169 Load level at which a warning message will be generated.
170
171 =item B<-c> I<crit>
172
173 Load level at which a critical message will be generated.
174
175 =item B<-h>
176
177 A short help. Also give default values.
178
179 =item B<--help> | B<--man>
180
181 The full man page.
182
183 =item B<--perf>
184
185 Add Nagios performances datas.
186 Available : Load
187
188
189 =back
190
191
192
193 =head1 NAGIOS CONGIGURATIONS
194
195 In F<checkcommands.cfg> you have to add :
196
197 # 'check_nsd_load'
198 # Check remote swap.
199 define command {
200 command_name check_nsd_load
201 command_line $USER1$/check_nsd_load.pl -H $HOSTADDRESS$ -w $ARG2$ -c $ARG3$
202 }
203
204 =head1 AUTHOR
205
206 St�hane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
207
208 Thanks to Charlie Cook & Nick Reinking and many others for writing modules that have been used as example for this one.
209
210 =cut

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8