Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
APC SmartUPS check if UPS is on batteries or cable
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!
This script will check if the UPS is on batteries (and display the percent of battery which is left) or on cable power.
#!/usr/local/bin/php
/*
*
* Can check if your APC Smart UPS is on batteries or on power.
* Made by Soeren, sa@billetkontoret.dk 29-06-2010
*
*/
if(!isset($argv[1]))
{
echo "Usage: ./check_apc ";
exit(2);
}
$host = $argv[1];
$query = @snmpget("$host", "public", ".1.3.6.1.4.1.318.1.1.1.4.1.1.0", 1000000);
$snmp = str_replace(array("INTEGER: ", """),"",$query);
if ($query)
{
if ($snmp == 1)
{
$output = "State unknown";
echo $output;
exit(1);
}
if ($snmp == 2)
{
$output = "Power connected";
echo $output;
exit(0);
}
if ($snmp == 3)
{
$query3 = @snmpget("$host", "public", ".1.3.6.1.4.1.318.1.1.1.2.2.1.0", 1000000);
$charge = str_replace(array("Gauge32: ", """),"",$query3);
$output = "Power lost. Running on batteries. $charge% left.";
echo $output;
exit(1);
}
if ($snmp == 7)
{
$output = "UPS turned off";
echo $output;
exit(1);
}
if ($snmp == 8)
{
$output = "UPS is rebooting";
echo $output;
exit(1);
}
if ($snmp == 11)
{
$output = "UPS is sleeping until power returns";
echo $output;
exit(1);
}
}
else
{
echo "Cannot read data from host.";
exit(2);
}
?>
Remember to change /usr/local/bin/php to whereever your php-binary is located. Also chmod +x check_apc
commands.cfg:
define command{
command_name check_apc
command_line $USER1$/check_apc_on_battery $HOSTADDRESS$
}
services.cfg:
define service{
use default-critical
host_name apc
service_description UPS Status
check_command check_apc! $HOSTADDRESS$
max_check_attempts 1
notification_interval 5
}
#!/usr/local/bin/php
/*
*
* Can check if your APC Smart UPS is on batteries or on power.
* Made by Soeren, sa@billetkontoret.dk 29-06-2010
*
*/
if(!isset($argv[1]))
{
echo "Usage: ./check_apc
exit(2);
}
$host = $argv[1];
$query = @snmpget("$host", "public", ".1.3.6.1.4.1.318.1.1.1.4.1.1.0", 1000000);
$snmp = str_replace(array("INTEGER: ", """),"",$query);
if ($query)
{
if ($snmp == 1)
{
$output = "State unknown";
echo $output;
exit(1);
}
if ($snmp == 2)
{
$output = "Power connected";
echo $output;
exit(0);
}
if ($snmp == 3)
{
$query3 = @snmpget("$host", "public", ".1.3.6.1.4.1.318.1.1.1.2.2.1.0", 1000000);
$charge = str_replace(array("Gauge32: ", """),"",$query3);
$output = "Power lost. Running on batteries. $charge% left.";
echo $output;
exit(1);
}
if ($snmp == 7)
{
$output = "UPS turned off";
echo $output;
exit(1);
}
if ($snmp == 8)
{
$output = "UPS is rebooting";
echo $output;
exit(1);
}
if ($snmp == 11)
{
$output = "UPS is sleeping until power returns";
echo $output;
exit(1);
}
}
else
{
echo "Cannot read data from host.";
exit(2);
}
?>
Remember to change /usr/local/bin/php to whereever your php-binary is located. Also chmod +x check_apc
commands.cfg:
define command{
command_name check_apc
command_line $USER1$/check_apc_on_battery $HOSTADDRESS$
}
services.cfg:
define service{
use default-critical
host_name apc
service_description UPS Status
check_command check_apc! $HOSTADDRESS$
max_check_attempts 1
notification_interval 5
}
Reviews (1)
./check_apc.php 10.0.64.191 public
No Result
php check_apc.php 10.0.64.191 public
No Result
php check_apc.php 10.0.64.191
No Result
No Result
php check_apc.php 10.0.64.191 public
No Result
php check_apc.php 10.0.64.191
No Result