FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit bfa66e76 authored by Ben Harris's avatar Ben Harris
Browse files

Tag ucs-infra-bits 1.37.

parent 1776df6b
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,16 @@ sub getstatus {
return $val;
}
sub getvers {
my ($self) = @_;
return $self->snmp->get("sPDUIdentFirmwareRev.0");
}
sub getmodel {
my ($self) = @_;
return $self->snmp->get("sPDUIdentModelNumber.0");
}
sub power_state {
my ($self, $outlet) = @_;
my $val = $self->snmp->get("rPDUOutletStatusOutletState.$outlet");
......
......@@ -40,6 +40,16 @@ sub getstatus {
return sprintf("%s (%.2f A)", $val, $current);
}
sub getvers {
my ($self) = @_;
return $self->{'Ucam::Infra::DominionPX::ver'};
}
sub getmodel {
my ($self) = @_;
return $self->snmp->get("objectName.0");
}
sub power_state {
my ($self, $outlet) = @_;
$outlet = $self->mapoutlet($outlet);
......
#! /usr/bin/perl
use warnings;
use strict;
=head1 NAME
pdu - Control and monitor power distribution units
=cut
use Getopt::Std;
use Getopt::Long 2.33 qw/:config posix_default bundling/;
use Pod::Usage;
use Ucam::Infra::PDU::Outlet;
=head1 SYNOPSIS
pdu [-d|-r|-u] <outlet> ...
pdu [-d|-r|-u] { -a | <outlet> ... }
=cut
$Getopt::Std::STANDARD_HELP_VERSION = 1;
my %opts;
getopts('dru', \%opts);
my $listpdus;
GetOptions("d" => \$opts{d},
"r" => \$opts{r},
"u" => \$opts{u},
"a" => \$opts{a},
"l" => \$listpdus,
"V" => \$opts{V}) or pod2usage(2);
if ($opts{a} && @ARGV || !$opts{a} && !@ARGV) {
pod2usage(2);
}
=head1 DESCRIPTION
The C<pdu> utility provides a means of monitoring and controlling networked
......@@ -33,22 +45,63 @@ particular box can be named by omitting the PSU designation, so C<easton>
names all outlets supplying Easton.
Outlets can also be named by PDU name and outlet number, like
C<pdu-n9-o:14>, or just by PDU name.
C<pdu-n9-o:14>, or just by PDU name. Finally, C<-a> means "all
outlets on all PDUs".
To query the state of an outlet, or set of outlets, use:
pdu [outlet ...]
pdu outlet ...
To power-cycle an outlet, use:
pdu -r [outlet ...]
pdu -r outlet ...
Power can be turned on and off using C<-u> and C<-d>, but for various
reasons these are dangerous and should not be used.
Model and version information for PDUs can be requested using the
C<-V> option:
pdu -V pdu ...
As with outlets, C<-a> works with C<-V> to get version information for
all PDUs.
Similarly, a list of know PDUs can be requested using:
pdu -la
=cut
my @outlets = Ucam::Infra::PDU::Outlet->find(@ARGV);
my @outlets;
if (!!$opts{V} + !!$opts{u} + !!$opts{d} + !!$listpdus > 1) {
pod2usage(2);
}
if ($opts{V} || $listpdus) {
my @pdu;
if ($opts{a}) {
@pdu = Ucam::Infra::PDU::Any->retrieve_all();
} else {
@pdu = map(Ucam::Infra::PDU::Any->search(pduname => $_), @ARGV);
}
for my $pdu (@pdu) {
if ($opts{V}) {
printf("%-11s %-10s %s\n", $pdu->pduname.":",
$pdu->getmodel, $pdu->getvers);
} else {
print($pdu->pduname, "\n");
}
}
exit 0;
}
if ($opts{a}) {
@outlets = Ucam::Infra::PDU::Outlet->retrieve_all();
} else {
@outlets = Ucam::Infra::PDU::Outlet->find(@ARGV);
}
my $status = 0;
......@@ -58,14 +111,16 @@ foreach my $row (@outlets) {
($pduname, $outlet, $box, $psu) =
($row->pdu, $row->outlet, $row->boxname, $row->psuname);
my $pdu = $row->pdu;
$val = $pdu->getstatus($outlet);
unless (defined($val) && $s->{ErrorInd} == 0) {
my $val = $pdu->getstatus($outlet);
unless (defined($val)) {
die "snmp get failed\n";
}
if (defined $psu) {
printf "%30s (%9s:%-2d): %s", "$box:$psu", $pduname, $outlet, $val;
} else {
} elsif (defined $box) {
printf "%30s (%9s:%-2d): %s", $box, $pduname, $outlet, $val;
} else {
printf "%30s (%9s:%-2d): %s", "", $pduname, $outlet, $val;
}
if ($opts{u}) {
$pdu->on($outlet);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment