Netapp Inode Check

Wir brauchten unbedingt einen Check, der überprüfen kann wieviele Inodes eigentlich bei diversen definierten Volumes belegt sind. Da ich nichts passendes gefunden habe, hier ein eigenes Script:

#!/usr/bin/env perl

##############
## 2015-10-12
## Script by Clemens Steinkogler (clemens[at]steinkogler.org) for monitoring disk-inode usage
## Copyright (C) 2015 Clemens Steinkogler
##
## 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;
## if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
## MA 02111-1307 USA

##############
## This script relies on NETWORK-APPLIANCE_MIB by Netapp - netapp.netapp1.filesys.dfTable

## You may have to install Scalar::MoreUtils via cpan. If you want to do this on Debian in a clean way,
## use cpan2deb* for example https://github.com/sharl/cpan2deb - just follow the installation readme
## 
## * You will need following Debian packages:
##   + libmodule-depends-perl
##   + dh-make-perl
##   + devscripts
## 
## 
use strict;
use warnings;

use Data::Dump qw(dump);
use Scalar::MoreUtils qw(empty);
use Net::SNMP;
use Getopt::Long qw(:config no_ignore_case); # set no_ignore_case so options are case sensitive
use Pod::Usage;

#messy hardcoding or so called default values :o)
my $host = '127.0.0.1';
my $port = 161;
my $community = "icinga";
my $snmp_version = '2c';
my $oid_dfEntry = '1.3.6.1.4.1.789.1.5.4.1';
my $oid_dfMountedOn = '1.3.6.1.4.1.789.1.5.4.1.10';
my $oid_dfPerCentInodeCapacity = '1.3.6.1.4.1.789.1.5.4.1.9';
my $dskPath = '/';
my $warning = 80;
my $critical = 90;
my $debug = 0;
my $help = 0;

GetOptions(
            "host|H=s" => \$host,
            "port|P=i" => \$port,
            "community|C=s" => \$community,
            "snmp-version|v=s" => \$snmp_version,
            "dskPath|d=s" => \$dskPath,
            "warning|w=i" => \$warning,
            "critical|c=i" => \$critical,
            "debug" => \$debug,
            "help|?" => \$help,
           ) or pod2usage(2);
pod2usage(1) if $help;

my ($sess, $err) = Net::SNMP->session(
    -hostname  => $host,
    -port      => $port,
    -community => $community,
    -version   => $snmp_version,
);

if (!defined $sess) {
    print "UNKONWN: Error connecting to target ". $host . ": ". $err;
    next;
}

# WARNING: Results from this method can become very large if the base OBJECT IDENTIFIER is close to the root of the SNMP MIB tree.
my $result = $sess->get_table(
    -baseoid => $oid_dfEntry,
);

$sess->close(); # close the session because we do not need it anymore

if (! $result) {
    print "UNKONWN: An error occurred requesting the OID: " . $sess->error() . "\n";
    exit 3; # exit code of script indicates error
} else {
    my %hash_result = %$result; # dereference $result hash-reference for easier usage
    
    # we need to find the key/OID for the corresponding partition
    my %search_result = reverse %$result;
    my $key = $search_result{$dskPath};
    
    my $id;
    if ( not empty($key) ) {
        $key =~ m/\.(\d+)$/;
        $id = $1;
    }
    
    my $full_oid;
    my $percentInode;
    if ( not empty($id) ) {
        $full_oid = $oid_dfPerCentInodeCapacity.".$id";
        $percentInode = $hash_result{$full_oid};
        
        if ( $debug == 1) { # only show if debugging is enabled
            print "############### DEBUGGING ###############";
            print "received requested OID data\n";
            print "RESULT TYPE: $result \n";
            print dump($result)."\n";
            print "Hash-Key requested: ".$key."\n";
            print "ID of partition: ".$id."\n";
            print "Full inode OID: ".$full_oid."\n";
        }
        
        if ( $percentInode < $warning ) {
            print "Inode usage of $dskPath: ".$percentInode."% (<$warning) : OK | inode_usage=$percentInode%;$warning;$critical\n";
            exit 0;
        } elsif ( $percentInode >= $warning && $percentInode < $critical ) {
            print "Inode usage of $dskPath: ".$percentInode."% (>=$warning and <$critical) : WARNING | inode_usage=$percentInode%;$warning;$critical\n";
            exit 1;
        } elsif ( $percentInode >= $critical ) {
            print "Inode usage of $dskPath: ".$percentInode."% (>=$critical) : CRITICAL | inode_usage=$percentInode%;$warning;$critical\n";
            exit 2;
        } else {
            print "UNKONWN Inode usage of $dskPath: \n";
            exit 3;
        }
    } else { # we didn't find any partition named like that
        print "UNKONWN: no corresponding partition $dskPath found \n";
        exit 3;
    }

}
    
__END__

=head1 NAME

check_snmp_inodes.pl - a check script for monitoring inode usage of a defined partition

=head1 SYNOPSIS

check_snmp_inodes.pl [options]

 Options:
   --help, -?                           this help message
   --host=[host], -H                    define host IP or FQDN (default: localhost)
   --port=[port], -P                    define listening SNMP-server port (default: 161)
   --community=[community], -C         define SNMP community (default: icinga)
   --snmp-version=[snmp-version], -v    define SNMP version (default: 2c)
   --dskpath=[dskpath], -d              define partition (default: /)
   --warning=[warning], -w              define warning limit in percent (default: 80)
   --critical=[crictical], -c           define critical limit in percent (default:90)
   --debug                              activates debugging messages
   
=cut

 

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.