check_apc: added high precision (double) value in input voltage, iutput...

check_apc: added high precision (double) value in input voltage, iutput voltage and output current checks Fix #1 as proposed by @fbarton
parent de1e7a80
#!/usr/bin/perl -w
#
# check_apc.pl v2.1.1
# check_apc.pl v2.2
#
# version history
#
# 2.2 added High Precision value for InputVoltage/OutputVoltage/OutputCurrent (thanks to @fbarton)
# 2.1 added power modules check
# 2.0 first release after fork
#
# Nagios plugin script for checking APC UPS.
# Nagios plugin script for checking APC Symmetra UPS.
#
# License: GPL v2
# Copyright (c) 2017 Davide "Argaar" Foschi
......@@ -24,15 +25,15 @@ use Time::Local;
# Command arguments
my %options=();
getopts("H:C:l:p:t:w:c:u", \%options);
getopts("H:C:l:p:t:w:c:hu", \%options);
# Help message etc
(my $script_name = $0) =~ s/.\///;
my $help_info = <<END;
\n$script_name - v2.0
\n$script_name - v2.2
Nagios script to check status of an APC Uninteruptable Power Supply.
Nagios script to check status of an APC Symmetra Uninteruptable Power Supply.
Usage:
-H Address of hostname of UPS (required)
......@@ -42,6 +43,7 @@ Usage:
-t Connection timeout (optional, default 10s)
-w Warning threshold (optional, see commands)
-c Critical threshold (optional, see commands)
-h Use High Precision values for InputVoltage/OutputVoltage/OutputCurrent
-u Script / connection errors will return unknown rather than critical
Commands (supplied with -l argument):
......@@ -135,14 +137,17 @@ my $oid_upsAdvBatteryNominalVoltage = ".1.3.6.1.4.1.318.1.1.1.2.2.7.0";
my $oid_upsAdvBatteryActualVoltage = ".1.3.6.1.4.1.318.1.1.1.2.2.8.0"; # INTEGER
my $oid_upsBasicInputPhase = ".1.3.6.1.4.1.318.1.1.1.3.1.1.0"; # INTEGER
my $oid_upsAdvInputLineVoltage = ".1.3.6.1.4.1.318.1.1.1.3.2.1.0"; # GAUGE
my $oid_upsAdvInputHPLineVoltage = ".1.3.6.1.4.1.318.1.1.1.3.3.1.0"; # GAUGE32
my $oid_upsAdvInputFrequency = ".1.3.6.1.4.1.318.1.1.1.3.2.4.0"; # GAUGE
my $oid_upsBasicOutputStatus = ".1.3.6.1.4.1.318.1.1.1.4.1.1.0"; # INTEGER {unknown(1),onLine(2),onBattery(3),onSmartBoost(4),timedSleeping(5),softwareBypass(6),
# off(7),rebooting(8),switchedBypass(9),hardwareFailureBypass(10),sleepingUntilPowerReturn(11),onSmartTrim(12)}
my $oid_upsBasicOutputPhase = ".1.3.6.1.4.1.318.1.1.1.4.1.2.0"; # INTEGER
my $oid_upsAdvOutputVoltage = ".1.3.6.1.4.1.318.1.1.1.4.2.1.0"; # GAUGE
my $oid_upsAdvOutputHPVoltage = ".1.3.6.1.4.1.318.1.1.1.4.3.1.0"; # GAUGE32
my $oid_upsAdvOutputFrequency = ".1.3.6.1.4.1.318.1.1.1.4.2.2.0"; # GAUGE
my $oid_upsAdvOutputLoad = ".1.3.6.1.4.1.318.1.1.1.4.2.3.0"; # GAUGE
my $oid_upsAdvOutputCurrent = ".1.3.6.1.4.1.318.1.1.1.4.2.4.0"; # GAUGE
my $oid_upsAdvOutputHPCurrent = ".1.3.6.1.4.1.318.1.1.1.4.3.4.0"; # GAUGE32
my $oid_upsDiagPMTableSize = ".1.3.6.1.4.1.318.1.1.1.13.2.1.0"; # INTEGER
my $oid_upsDiagPMSerialNumPrefix = ".1.3.6.1.4.1.318.1.1.1.13.2.2.1.5."; # DISPLAYSTRING (DISTINCT POWER MODULE SERIAL NUMBER)
my $oid_upsDiagPMStatusPrefix = ".1.3.6.1.4.1.318.1.1.1.13.2.2.1.2."; # INTEGER {unknown (1),notInstalled (2),offOk (3),onOk (4),offFail (5),onFail (6),lostComm (7)} (DISTINCT POWER MODULE STATUS)
......@@ -160,6 +165,7 @@ my $snmp_community = $options{C};
my $snmp_port = $options{p} || 161; # SNMP port default is 161
my $connection_timeout = $options{t} || 10; # Connection timeout default 10s
my $default_error = (!defined $options{u}) ? $CRITICAL : $UNKNOWN;
my $high_precision = (defined $options{h}) ? 1 : 0;
my $check_command = $options{l};
my $critical_threshold = $options{c};
my $warning_threshold = $options{w};
......@@ -172,7 +178,7 @@ if(defined $snmp_community) {$snmp_community = substr($snmp_community,0,15);}
# If we don't have the needed command line arguments exit with UNKNOWN.
if(!defined $options{H} || !defined $options{C}){
print "$help_info\n\n--> ERROR <--\n--> Not all required options were specified. <--\n\n";
print "$help_info\n --> Not all required options were specified. <--\n\n";
exit $UNKNOWN;
}
......@@ -452,7 +458,12 @@ if (!defined $options{l}) { # If no command was given, just output the UPS mode
exit $exitCode;
}
case "in_volt" {
my $in_volt = query_oid($oid_upsAdvInputLineVoltage);
my $in_volt;
if ($high_precision) {
$in_volt = query_oid($oid_upsAdvInputHPLineVoltage)/10;
} else {
$in_volt = query_oid($oid_upsAdvInputLineVoltage);
}
$session->close();
my @crit_values = split(/:/, $critical_threshold);
my @warn_values = split(/:/, $warning_threshold);
......@@ -550,7 +561,12 @@ if (!defined $options{l}) { # If no command was given, just output the UPS mode
exit $exitCode;
}
case "out_volt" {
my $out_volt = query_oid($oid_upsAdvOutputVoltage);
my $out_volt;
if ($high_precision) {
$out_volt = query_oid($oid_upsAdvOutputHPVoltage)/10;
} else {
$out_volt = query_oid($oid_upsAdvOutputVoltage);
}
$session->close();
my @crit_values = split(/:/, $critical_threshold);
my @warn_values = split(/:/, $warning_threshold);
......@@ -617,7 +633,12 @@ if (!defined $options{l}) { # If no command was given, just output the UPS mode
exit $exitCode;
}
case "out_current" {
my $out_current = query_oid($oid_upsAdvOutputCurrent);
my $out_current;
if ($high_precision) {
$out_current = query_oid($oid_upsAdvOutputHPCurrent)/10;
} else {
$out_current = query_oid($oid_upsAdvOutputCurrent);
}
$session->close();
if (defined $critical_threshold && defined $warning_threshold && $critical_threshold<$warning_threshold) {
print "ERROR: Critical Threshold should be GREATER than Warning Threshold!\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment