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

Contents of /trunk/plugins/check_snmp_fsrw.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (hide annotations) (download)
Tue Jan 7 10:21:09 2014 UTC (7 years ago) by racvision
File MIME type: text/plain
File size: 3464 byte(s)
mise à jour fr_FR
1 racvision 136 #!/usr/bin/perl -w
2     #
3     # Copyright (c) 2010 Herv√© Donati <herve.donati@ac-caen.fr>
4     #
5     # This program is free software; you can redistribute it and/or
6     # modify it under the terms of the GNU General Public License
7     # as published by the Free Software Foundation; either version 2
8     # of the License, or (at your option) any later version.
9     #
10     # This program is distributed in the hope that it will be useful,
11     # but WITHOUT ANY WARRANTY; without even the implied warranty
12     # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     # GNU General Public License for more details.
14     #
15     # you should have received a copy of the GNU General Public License
16     # along with this program (or with Nagios); if not, write to the
17     # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18     # Boston, MA 02111-1307, USA
19     #
20     # $Id: $
21     #
22     # RVD 27/05/2010 - Ajout utilisation Nagios::Plugin
23     #
24    
25     use strict;
26     use warnings;
27     use Net::SNMP;
28     use Getopt::Long;
29     use Nagios::Plugin;
30 racvision 137 use Locale::gettext;
31     use POSIX qw(setlocale);
32 racvision 136
33 racvision 137 my $DEBUG = 0;
34 racvision 136 my ( $vsnmp, $timeout ) = ( 1, 2 );
35     my $base_oid = '.1.3.6.1.2.1.25.3.8.1';
36     my $mesg_reponse = 'Invalid status';
37     my $version = '1.0.1';
38     my $liste_fs_ro;
39    
40     my $np = Nagios::Plugin->new(
41 racvision 137 version => $version,
42     blurb => 'Plugin de test d\'acces en lecture-ecriture des filesystems',
43     usage => "Usage: %s -H|--host <host> [-p|--port=<portSNMP>] [-c|--communaute=<communaute_snmp>]",
44     timeout => 10
45 racvision 136 );
46    
47     $np->add_arg (
48 racvision 137 spec => 'host|H=s',
49     help => 'Name of the host to test',
50     required => 1,
51 racvision 136 );
52    
53     $np->add_arg (
54 racvision 137 spec => 'port|p=i',
55     help => 'SNMP port',
56     default => 161,
57 racvision 136 );
58    
59     $np->add_arg (
60 racvision 137 spec => 'community|c=s',
61     help => 'SNMP community',
62     default => 'public',
63 racvision 136 );
64    
65 racvision 137 $np->add_arg (
66     spec => 'debug|d',
67     help => _gt('Debug level'),
68     );
69    
70 racvision 136 $np->getopts;
71     my $host = $np->opts->get('host');
72     my $port = $np->opts->get('port');
73 racvision 137 my $comm = $np->opts->get('community');
74     $DEBUG = $np->opts->get('debug');
75 racvision 136
76     my ( $session, $error ) = Net::SNMP->session(
77 racvision 137 -hostname => $host,
78     -community => $comm,
79     -timeout => $timeout,
80     -version => $vsnmp,
81     -port => $port,
82 racvision 136 );
83    
84     if ( !defined $session ) {
85 racvision 137 $np->nagios_exit( UNKNOWN, "ERROR: %s." );
86 racvision 136 }
87    
88     my $oid = $base_oid . '.1';
89     my $reponse = $session->get_table( $oid );
90     if ( !defined $reponse ) {
91 racvision 137 $np->nagios_exit( UNKNOWN, "Unable to get SNMP values" );
92 racvision 136 }
93     my @tab_ix = values( %$reponse );
94 racvision 137 my $status = OK;
95     my $count = 0;
96 racvision 136 map {
97 racvision 137 my $indice = $_;
98     my $oid = $base_oid . '.2.' . $indice;
99 racvision 151 my $rep = $session->get_request( $oid );
100 racvision 137 my @tab_res = values( %$rep );
101     my $nom_fs = $tab_res[ 0 ];
102     $oid = $base_oid . '.5.' . $indice;
103 racvision 151 $rep = $session->get_request( $oid );
104 racvision 137 @tab_res = values( %$rep );
105     my $st_fs = $tab_res[ 0 ];
106     &logD("$indice: $nom_fs => $st_fs");
107     if ( ( $st_fs == 2 ) && ( $nom_fs !~ /cdrom/ ) ) {
108     $liste_fs_ro .= $nom_fs . ' ';
109     if ( ( $nom_fs eq '/' ) || ( $nom_fs eq '/var' ) ) {
110     $status = CRITICAL;
111     } else {
112     $status = WARNING unless ( $status eq CRITICAL );
113     }
114     }
115     $count++;
116 racvision 136 } @tab_ix;
117     $session->close();
118 racvision 137
119     if ($status) {
120     $mesg_reponse = sprintf("Filesystem(s) %s: readonly" , $liste_fs_ro)
121     } else {
122     $mesg_reponse = sprintf("All filesystems (%d) RW", $count);
123     }
124    
125    
126 racvision 136 $np->nagios_exit( $status, $mesg_reponse );
127 racvision 137
128    
129     sub logD {
130     print STDERR 'DEBUG: '.$_[0]."\n" if ($DEBUG);
131     }
132     sub logW {
133     print STDERR 'WARNING: '.$_[0]."\n" if ($DEBUG);
134     }
135     # Gettext wrapper
136     sub _gt {
137     return gettext($_[0]);
138     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8