#!/usr/bin/perl
# upswhyatt, Boone, 05/27/99
# Why is the UPS on battery?
#
# Modifications:
# 05/27/99 Boone      Initial coding
# 11/29/04 Boone      Newer versions (5.? and later) of the Perl SNMP
#                     module default to SNMPv3, but our UPS doesn't
#                     speak anything later than SNMPv1; specify the SNMP
#                     version in the session setup
# 04/30/08 Boone      Community string from command line
# 12/02/09 Boone      Default MIB dir seems to have changed at some version
#                     of the underlying SNMP kit; explicitly add both known
#                     options to the search list
# End Modifications

# Libraries

	use SNMP 1.8;

# Initialize

	$host = shift(@ARGV);
	$comm = shift(@ARGV);
	$var = "upsAdvInputLineFailCause.0";

# Set up connection

	$SNMP::debugging = 0;
	$SNMP::use_enums = 1;
	&SNMP::addMibDirs("/usr/share/snmp/mibs", "/usr/share/mibs");
	&SNMP::initMib();
	&SNMP::loadModules("PowerNet-MIB");
	$sess = new SNMP::Session(DestHost => $host, Community => $comm,
		Version => 1) ||
		die "new session failed: " . $sess -> {ErrorStr};

# Extract items

	$value = $sess -> get($var);
	if ($sess -> {ErrorStr})
	{
		die "get failed: " . $sess->{ErrorStr};
	}

	print $value, "\n";
	exit(0);
