~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to server/munin-limits.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
Import upstream version 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# Nagios
 
3
#
 
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)
 
7
#
 
8
# Revision 1.3  2004/01/29 17:34:06  jimmyo
 
9
# Updated copyright information
 
10
#
 
11
# Revision 1.2  2004/01/15 15:20:01  jimmyo
 
12
# Making things workable after name change. Upping for test verwion.
 
13
#
 
14
# Revision 1.1  2004/01/02 18:50:01  jimmyo
 
15
# Renamed occurrances of lrrd -> munin
 
16
#
 
17
# Revision 1.1.1.1  2004/01/02 15:18:08  jimmyo
 
18
# Import of LRRD CVS tree after renaming to Munin
 
19
#
 
20
# Revision 1.4  2003/11/07 20:46:12  jimmyo
 
21
# Only require Config::General if using old config format.
 
22
#
 
23
# Revision 1.3  2003/11/07 17:43:16  jimmyo
 
24
# Cleanups and log entries
 
25
#
 
26
 
 
27
use strict;
 
28
 
 
29
use Munin;
 
30
use POSIX qw(strftime);
 
31
use Getopt::Long;
 
32
my $DEBUG=0;
 
33
my $conffile = "@@CONFDIR@@/munin.conf";
 
34
my $do_usage = 0;
 
35
my @limit_hosts = ();
 
36
my @limit_services = ();
 
37
my $force_root = 0;
 
38
my %notes = ();
 
39
 
 
40
# Get options
 
41
$do_usage=1  unless 
 
42
GetOptions ( "force-root!"  => \$force_root,
 
43
             "host=s"       => \@limit_hosts,
 
44
             "service=s"    => \@limit_services,
 
45
             "config=s"     => \$conffile,
 
46
             "debug!"       => \$DEBUG,
 
47
             "help"         => \$do_usage );
 
48
 
 
49
if ($do_usage)
 
50
{
 
51
    print "Usage: $0 [options]
 
52
 
 
53
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]
 
63
 
 
64
";
 
65
    exit 0;
 
66
}
 
67
 
 
68
if ($> == 0 and !$force_root)
 
69
{
 
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";
 
73
    exit (1);
 
74
}
 
75
 
 
76
my $config = &munin_config ($conffile);
 
77
my $modified=0;
 
78
 
 
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");
 
83
 
 
84
        
 
85
 
 
86
 
 
87
for my $domain ( keys %{$config->{domain}}) {
 
88
    logger ("processing domain: $domain");
 
89
    process_domain($domain);
 
90
}
 
91
&munin_writeconfig ("$config->{dbdir}/limits", \%notes);
 
92
logger("munin-limits finished.");
 
93
 
 
94
 
 
95
sub process_domain {
 
96
    my ($domain) = @_;
 
97
    for my $node ( keys %{$config->{domain}->{$domain}->{node}}) {
 
98
        if (@limit_hosts and !grep (/^$node$/, @limit_hosts))
 
99
        {
 
100
                logger ("skipping node: $node");
 
101
                next;
 
102
        }
 
103
        logger ("processing node: $node");
 
104
        process_node($domain,$node ,$config->{domain}->{$domain}->{node}->{$node} );
 
105
    }
 
106
}
 
107
 
 
108
sub process_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});
 
113
  }
 
114
}
 
115
 
 
116
sub process_service {
 
117
  my $critical= undef;
 
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/) {
 
123
        my $key = $1;
 
124
        next unless ((exists $client->{"$key.warning"}) || ($client->{"$key.critical"}));
 
125
        if (@limit_services and !grep (/^$service$/, @limit_services))
 
126
        {
 
127
                next;
 
128
        }
 
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*$/)
 
133
        {
 
134
                $critical[0] = $1 if defined $1;
 
135
                $critical[1] = $2 if defined $2;
 
136
        }
 
137
        elsif (defined $client->{"$key.critical"} and
 
138
            $client->{"$key.critical"} =~ /^\s*([-\d]+)\s*$/)
 
139
        {
 
140
                $critical[1] = $1 if defined $1;
 
141
        }
 
142
        elsif (defined $client->{"$key.critical"})
 
143
        {
 
144
            @critical = (0, 0);
 
145
        }
 
146
        if (defined $client->{"$key.warning"} and 
 
147
            $client->{"$key.warning"} =~ /^\s*([-\d]*):([-\d]*)\s*$/)
 
148
        {
 
149
                $warning[0] = $1 if defined $1;
 
150
                $warning[1] = $2 if defined $2;
 
151
        }
 
152
        elsif (defined $client->{"$key.warning"} and
 
153
            $client->{"$key.warning"} =~ /^\s*([-\d]+)\s*$/)
 
154
        {
 
155
                $warning[1] = $1 if defined $1;
 
156
        }
 
157
        elsif (defined $client->{"$key.warning"})
 
158
        {
 
159
            @warning = (0, 0);
 
160
        }
 
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");
 
164
        
 
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");
 
172
        }
 
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");
 
180
        }
 
181
      }
 
182
  }
 
183
}
 
184
 
 
185
sub logger {
 
186
  my ($comment) = @_;
 
187
  my $now = strftime "%b %d %H:%M:%S", localtime;
 
188
  print LOG "$now - $comment\n";
 
189
}
 
190
 
 
191
close LOG;
 
192
 
 
193
=head1 NAME
 
194
 
 
195
munin-nagios - A program to warn nagios of any off-limit values
 
196
 
 
197
=head1 SYNOPSIS
 
198
 
 
199
munin-nagios [options]
 
200
 
 
201
=head1 OPTIONS
 
202
 
 
203
=over 5
 
204
 
 
205
=item B<< --service <service> >>
 
206
 
 
207
Limit services to those of E<lt>serviceE<gt>. Multiple --service options may be supplied. [unset]
 
208
 
 
209
=item B<< --host <host> >>
 
210
 
 
211
Limit hosts to those of E<lt>host<gt>. Multiple --host options may be supplied. [unset]
 
212
 
 
213
=item B<< --config <file> >>
 
214
 
 
215
Use E<lt>fileE<gt> as configuration file. [/etc/munin/munin.conf]
 
216
 
 
217
=item B<< --[no]force >>
 
218
 
 
219
Force sending of messages ieven if you normally wouldn't. [--noforce]
 
220
 
 
221
=item B<< --[no]force-root >>
 
222
 
 
223
Force running as root (stupid and unnecessary). [--noforce-root]
 
224
 
 
225
=item B<< --removeok >>
 
226
 
 
227
Reset warning status (remove .ok-files).
 
228
 
 
229
=item B<< --help >>
 
230
 
 
231
View help message.
 
232
 
 
233
=item B<< --[no]debug >>
 
234
 
 
235
If set, view debug messages. [--nodebug]
 
236
 
 
237
=back
 
238
 
 
239
=head1 DESCRIPTION
 
240
 
 
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.
 
245
 
 
246
Munin-nagios can warn any nagios-servers about off-limit values.
 
247
 
 
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.
 
250
 
 
251
=head1 CONFIGURATION
 
252
 
 
253
The configuration file "munin.conf" must have the following optinons set correctly for munin-nagios to work:
 
254
 
 
255
        nsca         /usr/bin/send_nsca
 
256
        nsca_server  nagios-server.your.dom
 
257
        nsca_config  /etc/nagios/send_nsca.cfg
 
258
        
 
259
In addition NSCA must be installed and configured correctly.
 
260
 
 
261
=head1 FILES
 
262
 
 
263
        @@CONFDIR@@/munin.conf
 
264
        @@DBDIR@@/*
 
265
        @@LOGDIR@@/munin-nagios
 
266
        @@STATEDIR@@/*
 
267
 
 
268
=head1 VERSION
 
269
 
 
270
This is munin-nagios version @@VERSION@@
 
271
 
 
272
=head1 AUTHORS
 
273
 
 
274
Audun Ytterdal and Jimmy Olsen.
 
275
 
 
276
=head1 BUGS
 
277
 
 
278
munin-nagios does, as of now, not check the syntax of the configuration file.
 
279
 
 
280
Please report other bugs in the bug tracker at L<http://munin.sf.net/>.
 
281
 
 
282
=head1 COPYRIGHT
 
283
 
 
284
Copyright � 2002-2004 Knut Haugen, Audun Ytterdal, and Jimmy Olsen / Linpro AS.
 
285
 
 
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
 
288
PURPOSE.
 
289
 
 
290
This program is released under the GNU General Public License
 
291
 
 
292
=cut
 
293