Simple script to check upscheck and shut down server if necessary.

This commit is contained in:
hjp 2011-09-26 10:09:03 +00:00
parent 27babc338d
commit 61124dd1c6
1 changed files with 29 additions and 0 deletions

29
upscheck/upscheck Normal file
View File

@ -0,0 +1,29 @@
#!/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");
}