[go: up one dir, main page]

Menu

[e245b0]: / ups.pl  Maximize  Restore  History

Download this file

111 lines (91 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - ups.pl
#
# Webmin Sysstats Module
# Copyright (C) 2003 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###############################################################################
use strict;
use warnings;
# to be used alone or from sysstat.pl without warning
# because require verify the path
require '../../gen-lib.pl' if ( !exists $ENV{WEBMINSTAT_TEMP} );
use RRDs;
###############################################################################
sub getUpsStatus($$) {
my $server = shift(@_);
my $ups_cmd = shift(@_);
my $fh_ups;
my $cmd = "$ups_cmd $server" . stderr_debug() . '|';
if ( open( $fh_ups, $cmd ) ) {
my %result;
while (<$fh_ups>) {
if (m/^(.*):\s+([+-]?\d+\.?\d*)/) {
$result{$1} = $2;
}
}
close($fh_ups);
return \%result;
}
else {
warning("can not open $ups_cmd : $!");
return;
}
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
my $param = 'vol';
my $vol_num = 1;
my $server = $config{'server'};
my $ups_cmd = $config{'upsc'};
if ($server) {
my $result = getUpsStatus( $server, $ups_cmd );
if ( !defined $result ) {
# to avoid many messages stop module acquisition
$config{'runstop'} = 1;
write_file( 'config', \%config );
debug('stop acquisition');
goto END;
}
while ( exists( $config{ $param . $vol_num } ) ) {
my @tab = split( /,/, $config{ $param . $vol_num } );
my $real_vol_num = $tab[0];
my $vol = $tab[1];
my $runstop = $tab[3];
#debug( "volume = $vol");
my $total = 'U';
if ( is_param_runstop($runstop) ) {
$total = $result->{$vol};
}
else {
debug("aquisition for $vol stopped");
}
debug("ups $vol ($real_vol_num) : val=$total");
my $rrdbase = $real_vol_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ups : ERROR while updating $rrdbase: $ERR") if $ERR;
$vol_num++;
}
}
else {
debug("ups : no server defined");
}
# a label to quit
#I can not use return when executing this script standalone,
# so I had to use goto
END: