Commit ac33e3fd authored by Mike Hibler's avatar Mike Hibler

Support 'status' command on APC power controllers

parent c7f8572e
......@@ -360,6 +360,7 @@ sub byname() {
sub dostatus(@) {
my @wanted = @_;
my %ctrls = ();
my %IPs = ();
my $errors = 0;
if ($ELABINELAB) {
......@@ -372,12 +373,14 @@ sub dostatus(@) {
#
# Fetch all possible power controllers
#
my $result = DBQueryFatal("select n.node_id,t.type ".
"from nodes as n " .
"left join node_types as t on n.type=t.type " .
"where n.role='powerctrl'");
while (my ($ctrl, $type) = $result->fetchrow()) {
my $result = DBQueryFatal("select n.node_id,t.type,i.IP ".
"from nodes as n " .
"left join node_types as t on n.type=t.type " .
"left join interfaces as i on n.node_id=i.node_id " .
"where n.role='powerctrl'");
while (my ($ctrl, $type, $IP) = $result->fetchrow()) {
$ctrls{$ctrl} = $type;
$IPs{$ctrl} = $IP;
}
@wanted = sort byname keys(%ctrls)
......@@ -415,7 +418,28 @@ sub dostatus(@) {
for my $ctrl (@nwanted) {
my %status;
if ($ctrls{$ctrl} =~ /^RPC/) {
if ($ctrls{$ctrl} eq "APC") {
my $device = new snmpit_apc($IPs{$ctrl}, $verbose);
if (!defined $device) {
warn "Unable to contact controller $ctrl.\n";
$errors++;
next;
} else {
print "Calling device->status()\n"
if $verbose > 1;
if ($device->status(\%status)) {
print "Could not get status for $ctrl.\n";
$errors++;
next;
}
}
for my $outlet (1..20) {
my $ostr = "outlet$outlet";
print "$ctrl Outlet $outlet: ", $status{$ostr}, "\n"
if (defined($status{$ostr}));
}
print "\n";
} elsif ($ctrls{$ctrl} =~ /^RPC/) {
if (rpc27status($ctrl,\%status)) {
print "Could not get status for $ctrl.\n";
$errors++;
......
......@@ -2,14 +2,14 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group.
# All rights reserved.
#
#
# snmpit module for APC MasterSwitch power controllers
#
# supports new(ip), power(on|off|cyc[le],port)
# supports new(ip), power(on|off|cyc[le],port), status
#
package snmpit_apc;
......@@ -85,6 +85,34 @@ sub power {
return $errors;
}
sub status {
my $self = shift;
my $statusp = shift;
my %status;
my $StatOID = ".1.3.6.1.4.1.318.1.1.4.2.2";
my $Status = 0;
$Status = $self->{SESS}->get([[$StatOID,0]]);
if (!defined $Status) {
print STDERR $self->{DEVICENAME}, ": no answer from device\n";
return 1;
}
print("Status is '$Status'\n") if $self->{DEBUG};
if ($statusp) {
my @stats = split '\s+', $Status;
my $o = 1;
foreach my $ostat (@stats) {
my $outlet = "outlet$o";
$status{$outlet} = $ostat;
$o++;
}
%$statusp = %status;
}
return 0;
}
sub UpdateField {
my ($self,$OID,$port,$val) = @_;
......
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