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

Contents of /trunk/plugins/check_nsd_namedproc.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: 6239 byte(s)
convert source structure from autotools to rpm-build.sh
1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2002-2005 Stéphane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
4 # Copyright (c) 2003 Olivier Brousselle <Olivier.Brousselle@ac-rouen.fr>
5 # Copyright (c) 1999 Charlie Cook & Nick Reinking
6 #
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 # $Id: check_nsd_namedproc.pl,v 1.5 2005-06-16 13:42:57 uid601 Exp $
24
25
26 use strict; # should never be differently :-)
27 use warnings;
28
29 use File::Basename; # get basename()
30 use lib dirname($0); # to get local libs
31 use libplugins qw(%EXIT_CODES &showUsage);
32 use NSD; # used to connect to Nagiosstatd
33
34 use Getopt::Long; # get command line args
35
36 sub usage;
37 sub isnum;
38
39 # default levels :
40 my $DEFAULT_MAX_PROC_WARNING=990;
41 my $DEFAULT_MAX_PROC_CRITICAL=1000;
42 my $DEFAULT_MIN_PROC_WARNING=-1;
43 my $DEFAULT_MIN_PROC_CRITICAL=-1;
44 my $DEBUG = 0;
45
46 # Get the options :
47 use vars qw($opt_V $opt_h $opt_m $opt_perf $opt_r $opt_p );
48 use vars qw($opt_pro $opt_maxw $opt_maxc $opt_minw $opt_minc );
49
50 Getopt::Long::Configure ("no_ignore_case");
51 GetOptions (
52 "V" => \$opt_V, "version" => \$opt_V,
53 "h|?" => \$opt_h, "help" => \$opt_h,
54 "man" => \$opt_m,
55 "perf" => \$opt_perf,
56
57 "d" => \$DEBUG, "debug=i" => \$DEBUG,
58 "H=s" => \$opt_r, "host=s" => \$opt_r,
59 "p=i" => \$opt_p, "port=i" => \$opt_p,
60 "maxw=i" => \$opt_maxw,
61 "maxc=i" => \$opt_maxc,
62 "minw=i" => \$opt_minw,
63 "minc=i" => \$opt_minc,
64
65 "n=s" => \$opt_pro, "namedproc=s" => \$opt_pro,
66 );
67
68
69 my $answer = '';
70 if ( defined ($opt_h) || defined ($opt_m) ) {
71 &usage($opt_m);
72 }
73 if ( (!defined ($opt_r)) || ($opt_r eq "")) {
74 $answer = _("Missing remote hostname parameter !");
75 &usage;
76 }
77 if ( (!defined ($opt_pro)) || ($opt_pro eq "")) {
78 $answer = _("Missing <proc name> parameter !");
79 &usage;
80 }
81
82
83 # set default option :
84 $opt_maxw = defined($opt_maxw) ? $opt_maxw : $DEFAULT_MAX_PROC_WARNING;
85 $opt_maxc = defined($opt_maxc) ? $opt_maxc : $DEFAULT_MAX_PROC_CRITICAL;
86 $opt_minw = defined($opt_minw) ? $opt_minw : $DEFAULT_MIN_PROC_WARNING;
87 $opt_minc = defined($opt_minc) ? $opt_minc : $DEFAULT_MIN_PROC_CRITICAL;
88
89
90 # reorder warn/crit levels:
91 if ( $opt_minc > $opt_minw ) {
92 $opt_minw = $opt_minc;
93 }
94 if ( $opt_maxw > $opt_maxc ) {
95 $opt_maxw = $opt_maxc;
96 }
97
98
99 my $service = "named_proc $opt_pro" ;
100
101
102 # Connect to remote Nagiosstatd:
103 my $o_nsd = new NSD ( address => $opt_r , port => $opt_p, debug => $DEBUG);
104
105 if ( $o_nsd->connect() ) {
106 print $o_nsd->getErrorMsg()."\n";
107 exit $EXIT_CODES{'UNKNOWN'};
108 }
109 if ( $o_nsd->ask($service) ) {
110 $o_nsd->close();
111 print $o_nsd->getErrorMsg()."\n";
112 exit $EXIT_CODES{'UNKNOWN'};
113 }
114 $o_nsd->close();
115 my $servanswer = $o_nsd->getResponse();
116
117
118 my $state = "OK";
119 my $perf="";
120
121 if ( defined($servanswer) && ($servanswer =~ /^\d*$/)) {
122 my $nb_process = ($servanswer eq '') ? 0 : $servanswer;
123 $perf = "procs=$nb_process";
124 if ( ($nb_process > $opt_minw) && ($nb_process < $opt_maxw) ) {
125 $answer = sprintf(_("%i \"%s\" process running."),$nb_process,$opt_pro);
126
127 } elsif ($nb_process <= $opt_minw) {
128 $state = "WARNING";
129 my $limit = $opt_minw;
130 if ($nb_process <= $opt_minc) {
131 $state = "CRITICAL";
132 $limit = $opt_minc;
133 }
134 $answer = sprintf(_("Too few (%i <= %i) \"%s\" process running !"),$nb_process,$limit,$opt_pro);
135
136 } elsif ($nb_process >= $opt_maxw) {
137 my $limit = $opt_maxw;
138 $state = "WARNING";
139 if ($nb_process >= $opt_maxc) {
140 $state = "CRITICAL";
141 $limit = $opt_maxc;
142 }
143 $answer = sprintf(_("Too many (%i <= %i) \"%s\" process running !"),$nb_process,$limit,$opt_pro);
144
145 } else {
146 $state = "UNKNOWN";
147 $answer = _("Bugs ?");
148 }
149
150 if ($DEBUG) {
151 print "levels : $opt_minc < $opt_minw < ($nb_process) < $opt_maxw < $opt_maxc\n";
152 }
153
154 if ($opt_perf) {
155 $answer .= "|$perf";
156 }
157
158 } else {
159 $state = "UNKNOWN";
160 $answer = sprintf(_("Invalid data (%s) !"),$servanswer);
161 }
162
163 $answer = _("Named proc")." $state - ".$answer;
164
165 print $answer."\n";
166 exit $EXIT_CODES{$state};
167
168 sub usage {
169 my ($opt_m)=@_;
170
171 print $answer."\n";
172
173 &showUsage($opt_m);
174
175 exit $EXIT_CODES{"UNKNOWN"};
176 }
177
178 __END__
179
180 =head1 NAME
181
182 check_nsd_namedproc.pl - Nagios plugins.
183
184 =head1 SYNOPSIS
185
186 B<check_nsd_namedproc.pl> S<-H I<remote host>> S<[-p I<nsd port>]> S<-n I<proc name>> S<[-maxw I<max warn>]> S<[-maxc I<max crit>]> S<[-minw I<min warn>]> S<[-minc I<min crit>]> S<[-- perf]>
187
188 =head1 DESCRIPTION
189
190 Nagios plugins to check named process number using Nagiosstatd.
191
192
193 =head1 OPTIONS
194
195 =over 4
196
197 =item B<-H> I<remote host>
198
199 Host running Nagiosstatd to check.
200
201 =item B<-p> I<nsd port>
202
203 Nagiosstatd port.
204
205 =item B<-n> I<proc name>
206
207 The name of the process to monitor.
208
209 =item B<-maxw> I<max warn>
210
211 Maximun number of process at which a warning message will be generated.
212
213 =item B<-maxc> I<max crit>
214
215 Maximun number of process at which a critical message will be generated.
216
217 =item B<-minw> I<min warn>
218
219 Minimun number of process at which a warning message will be generated.
220
221 =item B<-minc> I<min crit>
222
223 Minimun number of process at which a critical message will be generated.
224
225 =item B<--perf>
226
227 Output performance informations (nb procs).
228
229 =back
230
231 =head1 NAGIOS CONGIGURATIONS
232
233 In F<checkcommands.cfg> you have to add :
234
235 # 'check_nsd_namedproc'
236 #
237 define command {
238 command_name check_nsd_namedproc
239 command_line $USER1$/check_nsd_namedproc.pl -H $HOSTADDRESS$ -n $ARG1$ -maxw $ARG2$ -maxc $ARG3$ -minw $ARG4$ -minc $ARG5$
240 }
241
242 =head1 AUTHOR
243
244 Olivier Brousselle <Olivier.Brousselle@ac-rouen.fr>
245 Stéphane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
246
247 Thanks to Charlie Cook & Nick Reinking and many others for writing modules that have been used as example for this one.
248
249 =cut
250
251

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8