#!/usr/bin/perl -w # # Copyright (c) 2010 Hervé Donati # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA # # $Id: $ # # RVD 27/05/2010 - Ajout utilisation Nagios::Plugin # use strict; use warnings; use Net::SNMP; use Getopt::Long; use Nagios::Plugin; use Locale::gettext; use POSIX qw(setlocale); my $DEBUG = 0; my ( $vsnmp, $timeout ) = ( 1, 2 ); my $base_oid = '.1.3.6.1.2.1.25.3.8.1'; my $mesg_reponse = 'Invalid status'; my $version = '1.0.1'; my $liste_fs_ro; my $np = Nagios::Plugin->new( version => $version, blurb => 'Plugin de test d\'acces en lecture-ecriture des filesystems', usage => "Usage: %s -H|--host [-p|--port=] [-c|--communaute=]", timeout => 10 ); $np->add_arg ( spec => 'host|H=s', help => 'Name of the host to test', required => 1, ); $np->add_arg ( spec => 'port|p=i', help => 'SNMP port', default => 161, ); $np->add_arg ( spec => 'community|c=s', help => 'SNMP community', default => 'public', ); $np->add_arg ( spec => 'debug|d', help => _gt('Debug level'), ); $np->getopts; my $host = $np->opts->get('host'); my $port = $np->opts->get('port'); my $comm = $np->opts->get('community'); $DEBUG = $np->opts->get('debug'); my ( $session, $error ) = Net::SNMP->session( -hostname => $host, -community => $comm, -timeout => $timeout, -version => $vsnmp, -port => $port, ); if ( !defined $session ) { $np->nagios_exit( UNKNOWN, "ERROR: %s." ); } my $oid = $base_oid . '.1'; my $reponse = $session->get_table( $oid ); if ( !defined $reponse ) { $np->nagios_exit( UNKNOWN, "Unable to get SNMP values" ); } my @tab_ix = values( %$reponse ); my $status = OK; my $count = 0; map { my $indice = $_; my $oid = $base_oid . '.2.' . $indice; my $rep = $session->get_next_request( $oid ); my @tab_res = values( %$rep ); my $nom_fs = $tab_res[ 0 ]; $oid = $base_oid . '.5.' . $indice; $rep = $session->get_next_request( $oid ); @tab_res = values( %$rep ); my $st_fs = $tab_res[ 0 ]; &logD("$indice: $nom_fs => $st_fs"); if ( ( $st_fs == 2 ) && ( $nom_fs !~ /cdrom/ ) ) { $liste_fs_ro .= $nom_fs . ' '; if ( ( $nom_fs eq '/' ) || ( $nom_fs eq '/var' ) ) { $status = CRITICAL; } else { $status = WARNING unless ( $status eq CRITICAL ); } } $count++; } @tab_ix; $session->close(); if ($status) { $mesg_reponse = sprintf("Filesystem(s) %s: readonly" , $liste_fs_ro) } else { $mesg_reponse = sprintf("All filesystems (%d) RW", $count); } $np->nagios_exit( $status, $mesg_reponse ); sub logD { print STDERR 'DEBUG: '.$_[0]."\n" if ($DEBUG); } sub logW { print STDERR 'WARNING: '.$_[0]."\n" if ($DEBUG); } # Gettext wrapper sub _gt { return gettext($_[0]); }