4
# $Log: munin-limits.in,v $
5
# Revision 1.4 2004/01/29 17:40:10 jimmyo
6
# Fixed pod typos patched by Lupe Christoph (SF#884092)
8
# Revision 1.3 2004/01/29 17:34:06 jimmyo
9
# Updated copyright information
11
# Revision 1.2 2004/01/15 15:20:01 jimmyo
12
# Making things workable after name change. Upping for test verwion.
14
# Revision 1.1 2004/01/02 18:50:01 jimmyo
15
# Renamed occurrances of lrrd -> munin
17
# Revision 1.1.1.1 2004/01/02 15:18:08 jimmyo
18
# Import of LRRD CVS tree after renaming to Munin
20
# Revision 1.4 2003/11/07 20:46:12 jimmyo
21
# Only require Config::General if using old config format.
23
# Revision 1.3 2003/11/07 17:43:16 jimmyo
24
# Cleanups and log entries
30
use POSIX qw(strftime);
33
my $conffile = "@@CONFDIR@@/munin.conf";
36
my @limit_services = ();
42
GetOptions ( "force-root!" => \$force_root,
43
"host=s" => \@limit_hosts,
44
"service=s" => \@limit_services,
45
"config=s" => \$conffile,
47
"help" => \$do_usage );
51
print "Usage: $0 [options]
54
--[no]force-root Force running, even as root. [--noforce-root]
55
--help View this message.
56
--debug View debug messages.
57
--service <service> Limit notified services to <service>. Multiple
58
--service options may be supplied.
59
--host <host> Limit notified hosts to <host>. Multiple --host
60
options may be supplied.
61
--config <file> Use <file> as configuration file.
62
[/etc/munin/munin.conf]
68
if ($> == 0 and !$force_root)
70
print "You are running this program as root, which is neither smart nor necessary.
71
If you really want to run it as root, use the --force-root option. Else, run
72
it as the user \"munin\". Aborting.\n\n";
76
my $config = &munin_config ($conffile);
79
open LOG,">>$config->{logdir}/munin-limits.log" or die "Unable to create/access $config->{logdir}/munin-limits.log\n";
80
logger("Starting munin-limits, checking lock");
81
munin_runlock("$config->{dbdir}/munin-limits.lock");
82
logger("Created lock: $config->{dbdir}/munin-limits.lock");
87
for my $domain ( keys %{$config->{domain}}) {
88
logger ("processing domain: $domain");
89
process_domain($domain);
91
&munin_writeconfig ("$config->{dbdir}/limits", \%notes);
92
logger("munin-limits finished.");
97
for my $node ( keys %{$config->{domain}->{$domain}->{node}}) {
98
if (@limit_hosts and !grep (/^$node$/, @limit_hosts))
100
logger ("skipping node: $node");
103
logger ("processing node: $node");
104
process_node($domain,$node ,$config->{domain}->{$domain}->{node}->{$node} );
109
my ($domain,$name,$node) = @_;
110
for my $client (keys %{$node->{client}}) {
111
logger ("processing node: $client") if $DEBUG;
112
process_service($domain,$name,$client,$node->{client}->{$client});
116
sub process_service {
118
my ($domain, $name,$clientname,$client) = @_;
119
return unless $client;
120
for my $service (keys %$client) {
121
logger ("processing service: $service") if $DEBUG;
122
if ($service =~ /(^.*)\.label/) {
124
next unless ((exists $client->{"$key.warning"}) || ($client->{"$key.critical"}));
125
if (@limit_services and !grep (/^$service$/, @limit_services))
129
my @critical = (undef, undef);
130
my @warning = (undef, undef);
131
if (defined $client->{"$key.critical"} and
132
$client->{"$key.critical"} =~ /^\s*([-\d]*):([-\d]*)\s*$/)
134
$critical[0] = $1 if defined $1;
135
$critical[1] = $2 if defined $2;
137
elsif (defined $client->{"$key.critical"} and
138
$client->{"$key.critical"} =~ /^\s*([-\d]+)\s*$/)
140
$critical[1] = $1 if defined $1;
142
elsif (defined $client->{"$key.critical"})
146
if (defined $client->{"$key.warning"} and
147
$client->{"$key.warning"} =~ /^\s*([-\d]*):([-\d]*)\s*$/)
149
$warning[0] = $1 if defined $1;
150
$warning[1] = $2 if defined $2;
152
elsif (defined $client->{"$key.warning"} and
153
$client->{"$key.warning"} =~ /^\s*([-\d]+)\s*$/)
155
$warning[1] = $1 if defined $1;
157
elsif (defined $client->{"$key.warning"})
161
my $filename = "$config->{dbdir}/$domain/$name-$clientname-$key-".
162
lc substr (($client->{"$key.type"}||"GAUGE"),0,1) . ".rrd";
163
my $value = sprintf "%.2f",munin_fetch("$filename");
165
if ((defined ($critical[0]) and $value < $critical[0]) or
166
(defined ($critical[1]) and $value > $critical[1])) {
167
$notes{$name}{$clientname}{'critical'} =
168
(defined $client->{"$key.extinfo"}?
169
"$value (not in $critical[0]:$critical[1]): ".
170
$client->{"$key.extinfo"}:
171
"Value is $value. Critical range ($critical[0]:$critical[1]) exceeded");
173
elsif ((defined ($warning[0]) and $value < $warning[0]) or
174
(defined ($warning[1]) and $value > $warning[1])) {
175
$notes{$name}{$clientname}{'warning'} =
176
(defined $client->{"$key.extinfo"}?
177
"$value (not in $warning[0]:$warning[1]): ".
178
$client->{"$key.extinfo"}:
179
"Value is $value. Warning range ($warning[0]:$warning[1]) exceeded");
187
my $now = strftime "%b %d %H:%M:%S", localtime;
188
print LOG "$now - $comment\n";
195
munin-nagios - A program to warn nagios of any off-limit values
199
munin-nagios [options]
205
=item B<< --service <service> >>
207
Limit services to those of E<lt>serviceE<gt>. Multiple --service options may be supplied. [unset]
209
=item B<< --host <host> >>
211
Limit hosts to those of E<lt>host<gt>. Multiple --host options may be supplied. [unset]
213
=item B<< --config <file> >>
215
Use E<lt>fileE<gt> as configuration file. [/etc/munin/munin.conf]
217
=item B<< --[no]force >>
219
Force sending of messages ieven if you normally wouldn't. [--noforce]
221
=item B<< --[no]force-root >>
223
Force running as root (stupid and unnecessary). [--noforce-root]
225
=item B<< --removeok >>
227
Reset warning status (remove .ok-files).
233
=item B<< --[no]debug >>
235
If set, view debug messages. [--nodebug]
241
Munin-nagios is a part of the package Munin, which is used in combination
242
with Munin's node. Munin is a group of programs to gather data from
243
Munin's nodes, graph them, create html-pages, and optionally warn Nagios
244
about any off-limit values.
246
Munin-nagios can warn any nagios-servers about off-limit values.
248
If a service has fields with "warning" or "critical"-options (e.g. "load.warning 10"), and the munin-server
249
configuration file contains the necessary configuration options, munin-nagios will warn the nagios-server.
253
The configuration file "munin.conf" must have the following optinons set correctly for munin-nagios to work:
255
nsca /usr/bin/send_nsca
256
nsca_server nagios-server.your.dom
257
nsca_config /etc/nagios/send_nsca.cfg
259
In addition NSCA must be installed and configured correctly.
263
@@CONFDIR@@/munin.conf
265
@@LOGDIR@@/munin-nagios
270
This is munin-nagios version @@VERSION@@
274
Audun Ytterdal and Jimmy Olsen.
278
munin-nagios does, as of now, not check the syntax of the configuration file.
280
Please report other bugs in the bug tracker at L<http://munin.sf.net/>.
284
Copyright � 2002-2004 Knut Haugen, Audun Ytterdal, and Jimmy Olsen / Linpro AS.
286
This is free software; see the source for copying conditions. There is
287
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
290
This program is released under the GNU General Public License