Simple script to check upscheck and shut down server if necessary.
This commit is contained in:
parent
27babc338d
commit
61124dd1c6
|
@ -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");
|
||||||
|
}
|
Loading…
Reference in New Issue