simple/upscheck/upscheck

30 lines
716 B
Perl

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
my %ups;
my $content = get("http://intra.wsr.ac.at/informationssysteme/ups/");
for my $line (split(/\n/, $content)) {
my ($oid, $value) = split(/\t/, $line);
$ups{$oid} = $value;
}
if (!defined $ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} ||
!defined $ups{'UPS-MIB::upsEstimatedChargeRemaining.0'}
) {
die "can't get current charge";
}
my $min_minutes = rand(10) + 5;
my $min_charge = rand(10) + 5;
if ($ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} < $min_minutes ||
$ups{'UPS-MIB::upsEstimatedChargeRemaining.0'} < $min_charge
) {
print STDERR "charge low: shutting down\n";
system("/sbin/shutdown", "-h", "+1");
}