/[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 136 - (show annotations) (download)
Thu May 27 13:50:26 2010 UTC (10 years, 7 months ago) by racvision
File MIME type: text/plain
File size: 3132 byte(s)
add contrib from Herve Donati
1 #!/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
31 my ( $vsnmp, $timeout ) = ( 1, 2 );
32 my $base_oid = '.1.3.6.1.2.1.25.3.8.1';
33 my $mesg_reponse = 'Invalid status';
34 my $version = '1.0.1';
35 my $liste_fs_ro;
36
37 my $np = Nagios::Plugin->new(
38 version => $version,
39 blurb => 'Plugin de test d\'acces en lecture-ecriture des filesystems',
40 usage => "Usage: %s -H|--host <host> [-p|--port=<portSNMP>] [-c|--communaute=<communaute_snmp>]",
41 timeout => 10
42 );
43
44 $np->add_arg (
45 spec => 'host|H=s',
46 help => 'name of the host to test',
47 default => 'localhost',
48 );
49
50 $np->add_arg (
51 spec => 'port|p=i',
52 help => 'SNMP port',
53 default => 161,
54 );
55
56 $np->add_arg (
57 spec => 'communaute|c=s',
58 help => 'SNMP community',
59 default => 'public',
60 );
61
62 $np->getopts;
63 my $host = $np->opts->get('host');
64 my $port = $np->opts->get('port');
65 my $comm = $np->opts->get('communaute');
66
67 my ( $session, $error ) = Net::SNMP->session(
68 -hostname => $host,
69 -community => $comm,
70 -timeout => $timeout,
71 -version => $vsnmp,
72 -port => $port,
73 );
74
75 if ( !defined $session ) {
76 $np->nagios_exit( UNKNOWN, "ERROR: %s." );
77 }
78
79 my $oid = $base_oid . '.1';
80 my $reponse = $session->get_table( $oid );
81 if ( !defined $reponse ) {
82 $np->nagios_exit( UNKNOWN, "Unable to get SNMP values" );
83 }
84 my @tab_ix = values( %$reponse );
85 my $status = 0;
86 $mesg_reponse = 'All filesystems RW';
87 map {
88 my $indice = $_;
89 my $oid = $base_oid . '.2.' . $indice;
90 my $rep = $session->get_next_request( $oid );
91 my @tab_res = values( %$rep );
92 my $nom_fs = $tab_res[ 0 ];
93 $oid = $base_oid . '.5.' . $indice;
94 $rep = $session->get_next_request( $oid );
95 @tab_res = values( %$rep );
96 my $st_fs = $tab_res[ 0 ];
97 if ( ( $st_fs == 2 ) && ( $nom_fs !~ /cdrom/ ) ) {
98 $liste_fs_ro .= $nom_fs . ' ';
99 if ( ( $nom_fs eq '/' ) || ( $nom_fs eq '/var' ) ) {
100 $status = 2;
101 } else {
102 $status = 1 unless ( $status eq 2 );
103 }
104 }
105 } @tab_ix;
106 $session->close();
107 $mesg_reponse = "Filesystem(s) $liste_fs_ro: readonly" if $status;
108 $np->nagios_exit( $status, $mesg_reponse );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8