Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_apc.pl
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
status: power status (normal, on battery, bypass etc) and runtime remaining
health: last diagnostics result and battery replacement
load: % load and/or wattage
Requires Net::SNMP for perl as the script is SNMP based.
check_apc.pl - v1.0
Nagios script to check status of an APC Uninteruptable Power Supply.
Usage:
-H Address of hostname of UPS (required)
-C SNMP community string (required)
-l Command (optional, see command list)
-p SNMP port (optional, defaults to port 161)
-t Connection timeout (optional, default 10s)
-w Warning threshold (optional)
-c Critical threshold (optional)
-u Script / connection errors will return unknown rather than critical
Commands (supplied with -l argument):
status
Shows output status of UPS (On battery power, bypass, etc)
health
Shows result of last diagnostic test and date run. Optional warning or critical
values for days since last test was run. Will also warn if battery needs replacing.
load[:###]
Shows output load in percentage of maximum load. Optional warning or critical
values in percentages of total load.
If an integer value of the maximum output wattage capacity of the UPS is included
after a colon (:), then the output in watts will be included in the result.
No command is supplied, the script return OKAY with the UPS model information.
Example:
check_apc.pl -H ups1.domain.local -C public -l health
In order to show output load in watts, the maximum power load wattage must be included in the check. This can be found on your UPS management page under the UPS tab and then About using the real power ratting shown.
check_apc.pl - v1.0
Nagios script to check status of an APC Uninteruptable Power Supply.
Usage:
-H Address of hostname of UPS (required)
-C SNMP community string (required)
-l Command (optional, see command list)
-p SNMP port (optional, defaults to port 161)
-t Connection timeout (optional, default 10s)
-w Warning threshold (optional)
-c Critical threshold (optional)
-u Script / connection errors will return unknown rather than critical
Commands (supplied with -l argument):
status
Shows output status of UPS (On battery power, bypass, etc)
health
Shows result of last diagnostic test and date run. Optional warning or critical
values for days since last test was run. Will also warn if battery needs replacing.
load[:###]
Shows output load in percentage of maximum load. Optional warning or critical
values in percentages of total load.
If an integer value of the maximum output wattage capacity of the UPS is included
after a colon (:), then the output in watts will be included in the result.
No command is supplied, the script return OKAY with the UPS model information.
Example:
check_apc.pl -H ups1.domain.local -C public -l health
In order to show output load in watts, the maximum power load wattage must be included in the check. This can be found on your UPS management page under the UPS tab and then About using the real power ratting shown.
Reviews (8)
bygauravbishtuk, December 18, 2017
HI Nagios,
Thankyou for building this wonderful plugin to monitor my company ups status. It gives us accurate live data. I am very happy to use this plugin.
One last thing i want to know or set warning and critical level in bat_capacity if battery level is less than 80 and 50 percent. I am using command like:-
./check_apc.pl -H 192.X.X.X -C CommunityName -l bat_capacity -c = 80
OK: Battery Capacity is: 100%|'Battery Capacity'=100;;80;0;100.
Thankyou for building this wonderful plugin to monitor my company ups status. It gives us accurate live data. I am very happy to use this plugin.
One last thing i want to know or set warning and critical level in bat_capacity if battery level is less than 80 and 50 percent. I am using command like:-
./check_apc.pl -H 192.X.X.X -C CommunityName -l bat_capacity -c = 80
OK: Battery Capacity is: 100%|'Battery Capacity'=100;;80;0;100.
bydozla, September 3, 2014
Hey,
added a check for Runtime againt Warning / Critical Values. Noticed that one of our UPS had a remaining runtime of 6! Minutes, but the Replacement Flag for the battery was not set.
case "runtime" {
my $ups_runtime_ticks = query_oid($oid_runtimeleft);
my $ups_runtime_mins = int($ups_runtime_ticks / 100 / 60);
my $perf_data = "|'Runtime Remaining'=$ups_runtime_mins,$warning_threshold,$critical_threshold;;";
if ($ups_runtime_mins > $warning_threshold) {
print "OK, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $OKAY;
} elsif ($ups_runtime_mins > $critical_threshold) {
print "Warning, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $WARNING;
} else {
print "Critical, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $CRITICAL;
}
#print "MINUTES: $ups_runtime_minutes\n";
#exit $OKAY;
}
Host File:
define service{
use local-service ; Name of service template to use
host_name
service_description RUNTIME
check_command check_apc!runtime -w 20 -c 10
}
added a check for Runtime againt Warning / Critical Values. Noticed that one of our UPS had a remaining runtime of 6! Minutes, but the Replacement Flag for the battery was not set.
case "runtime" {
my $ups_runtime_ticks = query_oid($oid_runtimeleft);
my $ups_runtime_mins = int($ups_runtime_ticks / 100 / 60);
my $perf_data = "|'Runtime Remaining'=$ups_runtime_mins,$warning_threshold,$critical_threshold;;";
if ($ups_runtime_mins > $warning_threshold) {
print "OK, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $OKAY;
} elsif ($ups_runtime_mins > $critical_threshold) {
print "Warning, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $WARNING;
} else {
print "Critical, (Runtime remaining: $ups_runtime_mins minutes)$perf_data\n";
exit $CRITICAL;
}
#print "MINUTES: $ups_runtime_minutes\n";
#exit $OKAY;
}
Host File:
define service{
use local-service ; Name of service template to use
host_name
service_description RUNTIME
check_command check_apc!runtime -w 20 -c 10
}
bykwoodrg, May 28, 2014
Just had one problem and that was the error mentioned in my review title. To fix it, I deleted the:
|| $diag_result == 3
From line 167 in the Health Check area. Otherwise an awesome check script. Thank you!
|| $diag_result == 3
From line 167 in the Health Check area. Otherwise an awesome check script. Thank you!
bybrandon.pal, March 31, 2014
Hey,
This is my first time working with custom scripts and SNMP. I'm very new to Nagios.
When I Run the script I get the following:
./check_apc.pl -H 10.XX.XX.XXX -C public -l status
CRITICAL: Received noSuchName(2) error-status at error-index 1
This is my first time working with custom scripts and SNMP. I'm very new to Nagios.
When I Run the script I get the following:
./check_apc.pl -H 10.XX.XX.XXX -C public -l status
CRITICAL: Received noSuchName(2) error-status at error-index 1
byoerli, August 1, 2013
Changed the following to get it to work and Date check if it's unknown.
--- /home/rmu/check_apc.pl 2013-07-31 13:29:08.893074154 +0200
+++ check_apc.pl 2013-08-02 10:06:06.328270476 +0200
@@ -1,4 +1,6 @@
#!/usr/bin/perl -w
+# This Script doesn't work with the Embedded Perl from icinga, disable it:
+# icinga: -epn
#
# check_apc.pl v1.0
#
@@ -174,6 +176,10 @@
# If Okay, then check the date of the last self test before returning result of check
# First the returned date is converted to epoch for simplified date math
# UPS returns date as mm/dd/yyyy
+ if (lc($diag_date) eq "unknown"){
+ print "WARNING: Unknown when self test run last time\n";
+ exit $WARNING;
+ }else{
my @diagdate_split = split(/\//,$diag_date);
my $diagdate_epoch = timelocal(0,0,12,$diagdate_split[1],$diagdate_split[0] - 1,$diagdate_split[2]);
my $diag_daysago = int((time - $diagdate_epoch) / 86400 + 0.5); # How many days since last self test
@@ -188,6 +194,7 @@
print "OK: Self test passed on $diag_date ($diag_daysago days ago)\n";
exit $OKAY;
}
+ }
}
}
case m/^load$|^load:\d{2,5}$/{
--- /home/rmu/check_apc.pl 2013-07-31 13:29:08.893074154 +0200
+++ check_apc.pl 2013-08-02 10:06:06.328270476 +0200
@@ -1,4 +1,6 @@
#!/usr/bin/perl -w
+# This Script doesn't work with the Embedded Perl from icinga, disable it:
+# icinga: -epn
#
# check_apc.pl v1.0
#
@@ -174,6 +176,10 @@
# If Okay, then check the date of the last self test before returning result of check
# First the returned date is converted to epoch for simplified date math
# UPS returns date as mm/dd/yyyy
+ if (lc($diag_date) eq "unknown"){
+ print "WARNING: Unknown when self test run last time\n";
+ exit $WARNING;
+ }else{
my @diagdate_split = split(/\//,$diag_date);
my $diagdate_epoch = timelocal(0,0,12,$diagdate_split[1],$diagdate_split[0] - 1,$diagdate_split[2]);
my $diag_daysago = int((time - $diagdate_epoch) / 86400 + 0.5); # How many days since last self test
@@ -188,6 +194,7 @@
print "OK: Self test passed on $diag_date ($diag_daysago days ago)\n";
exit $OKAY;
}
+ }
}
}
case m/^load$|^load:\d{2,5}$/{
bycsdragon, August 1, 2013
When I first integrated the script I always got the error message
>>(Service check did not exit properly) half day I finally found out that the perl-interpreter of Nagios works a little bit different than the manually one...
Well... I inserted to my commandline the path /usr/bin/perl and it worked...
Here's my present command-line:
command_line /usr/bin/perl $USER1$/check_apc.pl -H $HOSTADDRESS$ -C public -l $ARG1$ $ARG2$ $ARG3$
>>(Service check did not exit properly) half day I finally found out that the perl-interpreter of Nagios works a little bit different than the manually one...
Well... I inserted to my commandline the path /usr/bin/perl and it worked...
Here's my present command-line:
command_line /usr/bin/perl $USER1$/check_apc.pl -H $HOSTADDRESS$ -C public -l $ARG1$ $ARG2$ $ARG3$
byjoshmalone, July 25, 2013
Nice plugin. Does what it says. I'm replacing my homemade apc check plugin with this now except for one test.
This plugin, in the 'status' mode will deplay available runtime, but it doesn't display battery charge as a percentage. Would be nice if it could output both charge level and estimated runtime values (and perfdata) as my current plugin does.
This plugin, in the 'status' mode will deplay available runtime, but it doesn't display battery charge as a percentage. Would be nice if it could output both charge level and estimated runtime values (and perfdata) as my current plugin does.
bystaun, June 19, 2013
With the command -l health I get the message:
CRITICAL: Self test failure
Just did a couple of self tests on the APC, but still the same message.
Anyone got a success/ normal status with this command?
CRITICAL: Self test failure
Just did a couple of self tests on the APC, but still the same message.
Anyone got a success/ normal status with this command?