Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / nagios / nagiosstatus @ 444c7939

Historique | Voir | Annoter | Télécharger (3,93 ko)

1 4b1c7d14 Rune Nordb?e Skillingstad
#!/usr/bin/perl -w
2
#
3
# Copyright (C) 2008 Rune Nordb?e Skillingstad
4
#
5
# Plugin to monitor status in Nagios
6
#
7
# Usage: copy or link into /etc/munin/plugins
8
#
9
# Parameters:
10
#
11
#       config   (required)
12
#       autoconf (optional - used by munin-config)
13
#
14
# Config variables:
15
#
16
#       statuslog       - Which logfile to use
17
#                         Might be /var/log/nagios2/nagios.log if 
18
#                         /var/log/nagios/status.log is missing
19
#
20
# This program is free software; you can redistribute it and/or
21
# modify it under the terms of the GNU General Public License
22
# as published by the Free Software Foundation; version 2 dated June,
23
# 1991.
24
#
25
# This program is distributed in the hope that it will be useful,
26
# but WITHOUT ANY WARRANTY; without even the implied warranty of
27
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
# GNU General Public License for more details.
29
#
30
# You should have received a copy of the GNU General Public License
31
# along with this program; if not, write to the Free Software
32
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33
#
34
#
35
# $Log$
36
#%# family=auto
37
#%# capabilities=autoconf
38
39
use strict;
40
use warnings;
41
42
# File location may be defined with environment variable
43
my $NAGIOSSTAT=($ENV{'statuslog'} || '/var/log/nagios/status.log');
44
45
if ($ARGV[0]) {
46
  if ($ARGV[0] eq 'autoconf') {
47
    if (-r $NAGIOSSTAT) {
48
      print "yes";
49
      exit 0;
50
    } else {
51
      print "no (Nagios status file not found)";
52
      exit 1;
53
    }
54
  } elsif ($ARGV[0] eq "config") {
55
    print "graph_args --base 1000 -l 0 --vertical-label Checks\n";
56
    print "graph_title Nagios status\n";
57 444c7939 dipohl
    print "graph_category munin\n";
58 4b1c7d14 Rune Nordb?e Skillingstad
    print "graph_info This graph shows how many Nagios checks are in warning or critical state.\n";
59
    print "graph_order hdown hunknown swarning scritical sunknown\n";
60
    print "hdown.label Hosts down\n";
61
    print "hdown.info Number of Nagios hosts in DOWN state\n";
62
    print "hdown.type GAUGE\n";
63
    print "hdown.draw AREA\n";
64
    print "hdown.warning 20\n";
65
    print "hdown.critical 25\n";
66
    print "hunknown.label Hosts unknown\n";
67
    print "hunknown.info Number of Nagios hosts in UNKNOWN state\n";
68
    print "hunknown.type GAUGE\n";
69
    print "hunknown.draw STACK\n";
70
    print "hunknown.warning 15\n";
71
    print "hunknown.critical 20\n";
72
    print "swarning.label Services warning\n";
73
    print "swarning.info Number of Nagios services in WARNING state\n";
74
    print "swarning.type GAUGE\n";
75
    print "swarning.draw LINE2\n";
76
    print "swarning.warning 20\n";
77
    print "swarning.critical 25\n";
78
    print "scritical.label Services critical\n";
79
    print "scritical.info Number of Nagios services in CRITICAL state\n";
80
    print "scritical.type GAUGE\n";
81
    print "scritical.draw LINE2\n";
82
    print "scritical.warning 15\n";
83
    print "scritical.critical 20\n";
84
    print "sunknown.label Services unknown\n";
85
    print "sunknown.info Number of Nagios services in UNKNOWN state\n";
86
    print "sunknown.type GAUGE\n";
87
    print "sunknown.draw LINE2\n";
88
    print "sunknown.warning 15\n";
89
    print "sunknown.critical 20\n";
90
  }
91
  exit 0;
92
}
93
94
95
96
97
my $HDOWN     =0;
98
my $HUNKNOWN  =0;
99
my $SWARNING  =0;
100
my $SCRITICAL =0;
101
my $SUNKNOWN  =0;
102
103
my $type = "";
104
my %values;
105
106
open (STATUS, $NAGIOSSTAT) or die;
107
while(<STATUS>) {
108
    chomp();
109
    if(/^\s+\}\s*$/) {
110
	$type = "";
111
    }
112
    
113
    if($type) {
114
	push(@{$values{$type}}, $_);
115
    }
116
    if(/^host \{/) {
117
	$type = "host";
118
    }
119
    if(/^service \{/) {
120
	$type = "service";
121
    }
122
}
123
close (STATUS);
124
125
$HDOWN     = grep(/current_state=1/, @{$values{'host'}});
126
$HUNKNOWN  = grep(/current_state=2/, @{$values{'host'}});
127
$SWARNING  = grep(/current_state=1/, @{$values{'service'}});
128
$SCRITICAL = grep(/current_state=2/, @{$values{'service'}});
129
$SUNKNOWN  = grep(/current_state=3/, @{$values{'service'}});
130
131
print "hdown.value $HDOWN\n";
132
print "hunknown.value $HUNKNOWN\n";
133
print "swarning.value $SWARNING\n";
134
print "scritical.value $SCRITICAL\n";
135
print "sunknown.value $SUNKNOWN\n";
136