HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/lib/nagios/plugins/check_nfsmounts
#!/usr/bin/perl
# vim: ts=2 sts=2 sw=2:et ai:
#
# Usage: check_nfsmounts [ -t nfs timeout ] [ -w ]
# Description: determines whether there are stale NFS mounts on the host.
# Author: Clint Byrum <clint@adicio.com>
#
#    Copyright 2007 Adicio, Inc.
#
#    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 3 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, see <http://www.gnu.org/licenses/>. 
#

sub load_module {
    my @names = @_;
    my $module;
    for my $name (@names) {
        my $file = $name;
        # requires need either a bare word or a file name
        $file =~ s{::}{/}gsxm;
        $file .= '.pm';
        eval {
            require $file;
            $name->import(qw(%ERRORS));
            $module = $name;
		};
		last if $module;
    }
    return $module;
}

my $plugin_module;
BEGIN {
	$plugin_module = load_module( 'Monitoring::Plugin', 'Nagios::Plugin' );
}

use Time::HiRes qw{time alarm};
use Sys::Hostname;
use Getopt::Long;
use strict;

my $version="1.0";

my $nfs_timeout=15;
my $nfs_warn=-1;
my $writemode=0;
my $help=0;

sub usage {
  print STDERR "NFS UNKNOWN: version $version, check_nfs_client [ --nfs-critical|-c seconds ]\n";
  print STDERR "             [ --nfs-warning seconds ][ --writemode|-w ]\n";
  exit $ERRORS{'UNKNOWN'};
}

if(!GetOptions('nfs-timeout|nfstimeout|critical|c|t=f' => \$nfs_timeout,
               'nfs-warning=f' => \$nfs_warn,
               'writemode|write|w' => \$writemode,
               'help' => \$help,
          )) {
  &usage;
}

if($help) {
  &usage;
}

if($nfs_timeout <= 0) {
  print STDERR "timeout must be greater than 0\n";
  &usage;
}

our $dir; # Because its a signal handler, we have to 
sub alarm_handler {
  print "NFS CRITICAL:  Stale NFS mount point - $dir.\n";
  exit $ERRORS{'CRITICAL'};
}

sub bad_mount {
  my $mountpoint=shift();
  my $emsg=shift();
  print "NFS CRITICAL: cannot operate on mount point $mountpoint. [$emsg]\n";
  exit $ERRORS{'CRITICAL'};
}

#my @dirs = `mount | grep " type nfs " | awk '{print \$3}'`;
if(!open MTAB,"< /etc/mtab") {
  print "NFS UNKNOWN: could not open mtab.\n";
  exit $ERRORS{'UNKNOWN'};
}

my @dirs=();
my %mountmodes=();
while(my $line=<MTAB>) {
  if($line =~ /^[^ ]+ [^ ]+ nfs4? /) {
    my @fields=split(/\s+/,$line);
    my $mountpoint=$fields[1];
    push(@dirs,$mountpoint);
    #my %modes=split(/,/,$fields[3]);
    my $modes = {};
    foreach my $mode (split(/,/,$fields[3])) {
      $modes->{$mode}=1;
    }
    $mountmodes{$mountpoint}=$modes;
  }
}
close MTAB;

if(@dirs < 1) {
  print "NFS OK: no NFS mounts found.\n";
  exit $ERRORS{'OK'};
}

my @ages=();
my @warnings=();
foreach $dir (@dirs) {
  chomp $dir;
  $SIG{ALRM} = \&alarm_handler;
  my $start=time;
  my $pid=fork;
  if($pid==0) {
    chdir $dir or &bad_mount($dir,$!);
    if($writemode and exists($mountmodes{$dir}->{"rw"})) {
      my $check_filename="$dir/.nfscheck_" . hostname;
      open X,"> $check_filename" or exit $?;
      print X $ENV{HOSTNAME}."\n".localtime()."\n"; # XXX Full disk may fail..
      close X or exit $?;
    }
    exit 0;
  } else {
    alarm $nfs_timeout;
    waitpid $pid,0;
    if($?) {
      &bad_mount($dir,$?);
    };
    alarm 0;
  }
  my $age=time()-$start;
  if($nfs_warn > 0 and $age > $nfs_warn) {
    push(@warnings,sprintf("$dir took %7.5f to complete all operations ",$age));
  }
  push(@ages,$age);
}

my $x=0;
my $agetot=0;
my $maxage=0;
foreach my $age (@ages) {
  $agetot+=$age;
  if($age > $maxage) {
    $maxage=$age;
  }
  $x++;
}
my $avgage=$agetot/$x;

my $perfdata=sprintf("maxtime=%9.7f;avgtime=%9.7f;mountpoints=$x",$maxage,$avgage);

if(@warnings) {
  print "NFS WARNING: @warnings|$perfdata\n";
  exit $ERRORS{'WARNING'};
}
  
printf "NFS OK: $x mount points avg of %7.5f secs, max %7.5f secs.|$perfdata\n",$avgage,$maxage,$maxage,$avgage;
exit $ERRORS{'OK'};