中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nagios磁盤利用率監控

發布時間:2020-06-25 22:08:35 來源:網絡 閱讀:2437 作者:hahazhu0634 欄目:移動開發

#!/usr/bin/env perl
###################################
#Version 1.1
#Auth Badboy
#FileName Check_disk_utilization.pl
#LastModify 20120722
###################################
use strict;
use Net::SNMP;
use Nagios::Plugin;

(my $snmpVersion = Net::SNMP->VERSION) =~ s/\D//g;
my $TIMEOUT=15;

my $np=Nagios::Plugin->new(
       shortname=>'CheckDiskUtilization',
       usage=>'Usage: %s -H <host> -C <community> -c <threshold> -w <threshold>',
       version =>'Version 1.1'
);

sub isnotnum { # Return true if arg is not a number
  my $num = shift;
  if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0; }
  return 1;
}

$SIG{'ALRM'} = sub {
   $np->nagios_exit(UNKNOWN, "ERROR: Alarm signal (Nagios time-out)");
};

sub verbose {
   my $t = shift;
   print $t, "\n" if $np->opts->verbose > 0;
}

sub check_options{
   $np->add_arg(spec => 'hostname|H=s',   help => 'Hostname or IP address to poll', required => 1, label => [ 'HOSTNAME' ]);
   $np->add_arg(spec => 'community|C=s',  help => 'SNMP community to use when connecting', required => 1, default => 'public', label
 => [ 'COMMUNITY' ]);
  $np->add_arg(spec => 'critical|c=i',   help => 'Return critical status if larger than critical threshold', label => [ 'threshold n
um' ]);
   $np->add_arg(spec => 'warning|w=i',    help => 'Return warning status if larger than warning threshold', label => [ 'threshold nu
m' ]);
   $np->add_arg(spec => 'port|p=i',       help => 'Changes the SNMP port, defaults to 161', default => 161, label => [ 'PORT' ]);
   $np->add_arg(spec => 'snmpv1|1',       help => 'Use SNMP v1 instead of the default version 2c');
   $np->add_arg(spec => 'perfdata',       help => 'Write out performance data (number of disk used size)');

   $np->getopts();

   if (defined($np->opts->timeout) && (isnotnum($np->opts->timeout) || ($np->opts->timeout < 2) || ($np->opts->timeout > 60))) {
      $np->nagios_exit(UNKNOWN, 'Timeout must be between 1 and 60');
   }
   if (!defined($np->opts->critical) || !defined($np->opts->warning) || isnotnum($np->opts->critical) || isnotnum($np->opts->warning
)) {
         $np->nagios_exit(UNKNOWN, 'The values for critical and warning threshold must be integers');
      }
}

check_options();

my $disk_warning=$np->opts->warning;
my $disk_critical=$np->opts->critical;

if (defined($TIMEOUT)) {
   verbose("Alarm at $TIMEOUT");
   alarm($TIMEOUT);
} else {
   verbose("No timeout defined : " . $np->opts->timeout . " + 10");
   alarm ($np->opts->timeout + 10);
}

#snmp data
my $disk_index_table = ".1.3.6.1.2.1.25.2.3.1.1";
my $disk_index_result=get_snmp_data($disk_index_table);
my $disk_desrc_table = ".1.3.6.1.2.1.25.2.3.1.3";
my $disk_desrc_result=get_snmp_data($disk_desrc_table);
my $disk_units_table = ".1.3.6.1.2.1.25.2.3.1.4";
my $disk_units_result=get_snmp_data($disk_units_table);
my $disk_size_table = ".1.3.6.1.2.1.25.2.3.1.5";
my $disk_size_result=get_snmp_data($disk_size_table);
my $disk_used_table = ".1.3.6.1.2.1.25.2.3.1.6";
my $disk_used_result=get_snmp_data($disk_used_table);

my $status=undef;
my $critical_count=0;

foreach my $oid (keys(%$disk_index_result)) {
    my $disk_desrc=${$disk_desrc_result}{$disk_desrc_table.".".${$disk_index_result}{$oid}};
    my $disk_total_size=${$disk_size_result}{$disk_size_table.".".${$disk_index_result}{$oid}};
    my $disk_used_size=${$disk_used_result}{$disk_used_table.".".${$disk_index_result}{$oid}};
    if($disk_desrc!~/Virtual Memory|R:/  and $disk_desrc !~/Physical Memory|R:/ and $disk_total_size !=0 ){
        my $disk_used_utilization=$disk_used_size/$disk_total_size*100;
        if($disk_used_utilization > $disk_critical){
              printf "%.2s Critical %2.2f%%; ",$disk_desrc,$disk_used_utilization;
              $status=2;
              ++$critical_count;
              next;
        }
        elsif($disk_used_utilization >$disk_warning){
             printf "%.2s Warning %2.2f%%; ",$disk_desrc,$disk_used_utilization;
              $status=1;
              next;
        }
        elsif( $status!=1 and $status!=2  ){
                        printf "%.2s OK;",$disk_desrc;
                        $status=0;
                }
    }           
}
if($critical_count != 0){
    $status=2;
    verbose("\nPlugin Exit Code=$status");
}
verbose("Plugin Exit Code=$status");
exit $status;

sub get_snmp_data(){
my $oid=shift;
my ($session, $error) = (undef, undef);
if (defined($np->opts->snmpv1)) {
   # SNMPv1 login
   ($session, $error) = Net::SNMP->session(
      -hostname  => $np->opts->hostname,
      -community => $np->opts->community,
      -port      => $np->opts->port,
      -timeout   => $np->opts->timeout
   );
} else {
   # SNMPv2 login
   ($session, $error) = Net::SNMP->session(
      -hostname  => $np->opts->hostname,
      -version   => 2,
      -community => $np->opts->community,
      -port      => $np->opts->port,
      -timeout   => $np->opts->timeout
   );
}

if (!defined($session)) {
   $np->nagios_exit(UNKNOWN, 'SNMP Error: ' . $error);
}

#get snmp data
   my $result = undef;
   $result = ($snmpVersion < 4) ? $session->get_table($oid) : $session->get_table(Baseoid => $oid);

if (!defined($result)) {
   $session->close;
   $np->nagios_exit(UNKNOWN, "ERROR: get snmp data table: " . $session->error);
}
        return $result;
        $session->close();
}

 

今天將使用的腳本做了大大調整,供大家參考!


如果想了解更多,請關注我們的公眾號
公眾號ID:opdevos
掃碼關注

nagios磁盤利用率監控

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

贡山| 昭觉县| 芒康县| 调兵山市| 斗六市| 灵武市| 菏泽市| 明溪县| 贵南县| 英德市| 奈曼旗| 泰和县| 措美县| 漾濞| 滨海县| 资中县| 镇原县| 龙州县| 大宁县| 凌海市| 如东县| 根河市| 巨鹿县| 正定县| 平安县| 天柱县| 恩施市| 枝江市| 广德县| 馆陶县| 罗平县| 于都县| 嘉定区| 西乌珠穆沁旗| 岳普湖县| 祁连县| 绍兴县| 新闻| 依安县| 石河子市| 铁岭县|