4
# $Id: munin-nagios.in,v 1.4 2004/01/29 17:40:10 jimmyo Exp $
6
# $Log: munin-nagios.in,v $
7
# Revision 1.4 2004/01/29 17:40:10 jimmyo
8
# Fixed pod typos patched by Lupe Christoph (SF#884092)
10
# Revision 1.3 2004/01/29 17:34:06 jimmyo
11
# Updated copyright information
13
# Revision 1.2 2004/01/15 15:20:01 jimmyo
14
# Making things workable after name change. Upping for test verwion.
16
# Revision 1.1 2004/01/02 18:50:01 jimmyo
17
# Renamed occurrances of lrrd -> munin
19
# Revision 1.1.1.1 2004/01/02 15:18:08 jimmyo
20
# Import of LRRD CVS tree after renaming to Munin
22
# Revision 1.14 2003/12/10 11:59:39 jimmyo
23
# Enable/disable notifications at any level
25
# Revision 1.13 2003/11/12 12:28:37 jimmyo
26
# Only send ok-messages if lockfile was created.
28
# Revision 1.12 2003/11/12 12:19:29 jimmyo
31
# Revision 1.11 2003/11/12 12:17:16 jimmyo
34
# Revision 1.10 2003/11/12 12:07:46 jimmyo
35
# Off by one error. Cosmetic only.
37
# Revision 1.9 2003/11/12 12:04:45 jimmyo
38
# Make sure extinfo comes accross
40
# Revision 1.8 2003/11/10 16:09:00 jimmyo
41
# Be nice to Nagios - don't DOS it.
43
# Revision 1.7 2003/11/07 20:46:12 jimmyo
44
# Only require Config::General if using old config format.
46
# Revision 1.6 2003/11/07 19:00:17 jimmyo
47
# Put lockfiles in the right place
49
# Revision 1.5 2003/11/07 17:43:16 jimmyo
50
# Cleanups and log entries
57
use POSIX qw(strftime);
59
my $VERSION="@@VERSION@@";
61
my $conffile = "@@CONFDIR@@/munin.conf";
64
my @limit_services = ();
65
my $force_sendmsg = 0;
72
GetOptions ( "force!" => \$force_sendmsg,
73
"force-root!" => \$force_root,
74
"host=s" => \@limit_hosts,
75
"service=s" => \@limit_services,
76
"config=s" => \$conffile,
78
"version!" => \$do_version,
79
"removeok" => \$removeok,
80
"help" => \$do_usage );
84
print "Usage: $0 [options]
87
--[no]force Force sending of messages even if you normally
89
--[no]force-root Force running, even as root. [--noforce-root]
90
--help View this message.
91
--version View version information.
92
--debug View debug messages.
93
--service <service> Limit notified services to <service>. Multiple
94
--service options may be supplied.
95
--host <host> Limit notified hosts to <host>. Multiple --host
96
options may be supplied.
97
--config <file> Use <file> as configuration file.
98
[/etc/munin/munin.conf]
99
--removeok Reset warning status (remove .ok-files).
107
print "munin-nagios version $VERSION.\n";
108
print "Written by Audun Ytterdal, Jimmy Olsen, Tore Anderson / Linpro AS\n";
110
print "Copyright (C) 2002-2004\n";
111
print "This is free software released under the GNU Public License. There is NO\n";
112
print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
116
if ($> == 0 and !$force_root)
118
print "You are running this program as root, which is neither smart nor necessary.
119
If you really want to run it as root, use the --force-root option. Else, run
120
it as the user \"munin\". Aborting.\n\n";
124
my $config = &munin_config ($conffile);
127
open LOG,">>$config->{logdir}/munin-nagios.log" or die "Unable to create/access $config->{logdir}/munin-nagios.log\n";
128
logger("Starting munin-nagios, checking lock");
129
munin_runlock("$config->{rundir}/munin-nagios.lock");
130
logger("Created lock: $config->{rundir}/munin-nagios.lock");
131
unless ($config->{nsca}) {
132
logger ("No nsca-configuration found, exiting");
139
for my $domain ( keys %{$config->{domain}}) {
141
my $deletepath = "$config->{dbdir}/$domain";
144
foreach my $host (@limit_hosts)
146
my $deleted = unlink <$deletepath/$host-*.ok>;
147
logger("$deleted .ok-files successfully deleted for \"$host\"");
152
logger("Removing nagios .ok-files for $domain");
153
my $deleted = unlink <$deletepath/*.ok>;
154
logger("$deleted .ok-files successfully deleted");
157
logger ("processing domain: $domain");
158
process_domain($domain);
160
logger("munin-nagios finished.");
166
for my $node ( keys %{$config->{domain}->{$domain}->{node}}) {
167
if (@limit_hosts and !grep (/^$node$/, @limit_hosts))
169
logger ("skipping node: $node");
172
logger ("processing node: $node");
173
process_node($domain,$node ,$config->{domain}->{$domain}->{node}->{$node} );
178
my ($domain,$name,$node) = @_;
179
for my $client (keys %{$node->{client}}) {
180
logger ("processing node $client") if $DEBUG;
181
process_service($domain,$name,$client,$node->{client}->{$client});
185
sub process_service {
187
my ($domain, $name,$clientname,$client) = @_;
188
return unless $client;
196
for my $service (keys %$client) {
197
logger ("processing service: $service") if $DEBUG;
198
if ($service =~ /(^.*)\.label/) {
200
next unless ((exists $client->{"$key.warning"}) || ($client->{"$key.critical"}));
201
next unless (munin_get_bool ($config, "nagios", 1, $domain, $name, $clientname, $key));
202
if (@limit_services and !grep (/^$service$/, @limit_services))
207
my @critical = (undef, undef);
208
my @warning = (undef, undef);
210
if (defined $client->{"$key.critical"} and
211
$client->{"$key.critical"} =~ /^\s*([-\d]*):([-\d]*)\s*$/)
213
$critical[0] = $1 if defined $1;
214
$critical[1] = $2 if defined $2;
216
elsif (defined $client->{"$key.critical"} and
217
$client->{"$key.critical"} =~ /^\s*([-\d]+)\s*$/)
219
$critical[1] = $1 if defined $1;
221
elsif (defined $client->{"$key.critical"})
225
if (defined $client->{"$key.warning"} and
226
$client->{"$key.warning"} =~ /^\s*([-\d]*):([-\d]*)\s*$/)
228
$warning[0] = $1 if defined $1;
229
$warning[1] = $2 if defined $2;
231
elsif (defined $client->{"$key.warning"} and
232
$client->{"$key.warning"} =~ /^\s*([-\d]+)\s*$/)
234
$warning[1] = $1 if defined $1;
236
elsif (defined $client->{"$key.warning"})
240
my $filename = "$config->{dbdir}/$domain/$name-$clientname-$key-".
241
lc substr (($client->{"$key.type"}||"GAUGE"),0,1) . ".rrd";
242
my $value = sprintf "%.2f",munin_fetch("$filename");
244
if ((defined ($critical[0]) and $value < $critical[0]) or
245
(defined ($critical[1]) and $value > $critical[1])) {
246
# print "Sending; $name, $clientname ", $client->{"$key.label"}, ",2,Value is $value. Critical range ($critical[0]:$critical[1]) exceeded\n";
247
# munin_nscasend($name,$clientname,$client->{"$key.label"},2,
248
push (@crits, $client->{"$key.label"} .
249
(defined $client->{"$key.extinfo"}?
250
" ($value ($critical[0]:$critical[1]): ".
251
$client->{"$key.extinfo"} . ")":
252
" $value ($critical[0]:$critical[1])"));
253
munin_removelock("$config->{dbdir}/$domain/$name-$clientname-$key.ok");
255
elsif ((defined ($warning[0]) and $value < $warning[0]) or
256
(defined ($warning[1]) and $value > $warning[1])) {
257
# print "Sending; $name, $clientname ", $client->{"$key.label"}, ",2,Value is $value. Warning range ($warning[0]:$warning[1]) exceeded\n";
258
# print "Extinfo; $name, $clientname ", $client->{"$key.extinfo"}, "\n";
259
#munin_nscasend($name,$clientname,$client->{"$key.label"},1,
260
push (@warns, $client->{"$key.label"}.
261
(defined $client->{"$key.extinfo"}?
262
" ($value ($warning[0]:$warning[1]): ".
263
$client->{"$key.extinfo"} . ")":
264
" $value ($warning[0]:$warning[1])"));
265
munin_removelock("$config->{dbdir}/$domain/$name-$clientname-$key.ok");
267
elsif ($value eq "U") {
268
#munin_nscasend($name,$clientname,$client->{"$key.label"},1,
269
push (@unknowns, $client->{"$key.label"});
270
munin_removelock("$config->{dbdir}/$domain/$name-$clientname-$key.ok");
273
push (@oks, $client->{"$key.label"}.
275
if (munin_createlock("$config->{dbdir}/$domain/$name-$clientname-$key.ok"))
284
munin_nscasend ($name, $clientname, "", 2,
285
scalar (@crits) . " CRITICALs: ". join (',', @crits[0 .. (@crits>20?20:@crits)]) .
286
(@warns ? "; " . scalar (@warns) . " WARNINGs: " . join (', ', @warns[0 .. (@warns>20?20:@warns-1)]) : "") .
287
(@unknowns ? "; " . scalar (@unknowns) . " UNKNOWNs: " . join (', ', @unknowns[0 .. (@unknowns>20?20:@unknowns-1)]) : "") .
288
(@oks ? "; " . scalar (@oks) . " OKs: " . join (', ', @oks[0 .. (@oks>20?20:@oks-1)]) : "") .
293
munin_nscasend ($name, $clientname, "", 1,
294
scalar (@warns) . " WARNINGs: " . join (',', @warns[0 .. (@warns>20?20:@warns)]) .
295
(@unknowns ? "; " . scalar (@unknowns) . " UNKNOWNs: " . join (', ', @unknowns[0 .. (@unknowns>20?20:@unknowns-1)]) : "") .
296
(@oks ? "; " . scalar (@oks) . " OKs: " . join (', ', @oks[0 .. (@oks>20?20:@oks-1)]) : "") .
301
munin_nscasend ($name, $clientname, "", 3,
302
scalar (@unknowns) . " UNKNOWNs: " . join (',', @unknowns[0 .. (@unknowns>20?20:@unknowns-1)]) .
303
(@oks ? "; " . scalar (@oks) . " OKs: " . join (', ', @oks[0 .. (@oks>20?20:@oks-1)]) : "") .
306
elsif (@oks and $update)
308
munin_nscasend ($name, $clientname, "", 0,
309
scalar (@oks) . " OKs: " . join (', ', @oks[0 .. (@oks>20?20:@oks-1)]) .
316
my $now = strftime "%b %d %H:%M:%S", localtime;
317
print LOG "$now - $comment\n";
324
munin-nagios - A program to warn nagios of any off-limit values
328
munin-nagios [options]
334
=item B<< --service <service> >>
336
Limit services to those of E<lt>serviceE<gt>. Multiple --service options may be supplied. [unset]
338
=item B<< --host <host> >>
340
Limit hosts to those of E<lt>host<gt>. Multiple --host options may be supplied. [unset]
342
=item B<< --config <file> >>
344
Use E<lt>fileE<gt> as configuration file. [/etc/munin/munin.conf]
346
=item B<< --[no]force >>
348
Force sending of messages ieven if you normally wouldn't. [--noforce]
350
=item B<< --[no]force-root >>
352
Force running as root (stupid and unnecessary). [--noforce-root]
354
=item B<< --removeok >>
356
Reset warning status (remove .ok-files).
362
=item B<< --[no]debug >>
364
If set, view debug messages. [--nodebug]
370
Munin-nagios is a part of the package Munin, which is used in
371
combination with Munin's node. Munin is a group of programs to gather
372
data from Munin's nodes, graph them, create html-pages, and optionally
373
warn Nagios about any off-limit values.
375
Munin-nagios can warn any nagios-servers about off-limit values.
377
If a service has fields with "warning" or "critical"-options (e.g.
378
"load.warning 10"), and the munin configuration file contains the
379
necessary configuration options, munin-nagios will warn the
384
The configuration file "munin.conf" must have the following optinons set correctly for munin-nagios to work:
386
nsca /usr/bin/send_nsca
387
nsca_server nagios-server.your.dom
388
nsca_config /etc/nagios/send_nsca.cfg
390
In addition NSCA must be installed and configured correctly.
394
@@CONFDIR@@/munin.conf
396
@@LOGDIR@@/munin-nagios
401
This is munin-nagios version @@VERSION@@
405
Audun Ytterdal and Jimmy Olsen.
409
munin-nagios does, as of now, not check the syntax of the configuration file.
411
Please report other bugs in the bug tracker at L<http://munin.sf.net/>.
415
Copyright � 2002-2004 Knut Haugen, Audun Ytterdal, and Jimmy Olsen / Linpro AS.
417
This is free software; see the source for copying conditions. There is
418
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
421
This program is released under the GNU General Public License