#!/usr/bin/perl -w
###############################################################################
#
# Webmin Sysstats Module
# Copyright (C) 2007 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id: hplog.pl 4033 2011-05-25 11:30:38Z gerbier $
#
# 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;
use RRDs;
use English qw(-no_match_vars);
use FindBin;
# to be used alone or from sysstat.pl without warning
# because require verify the path
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use lib "$FindBin::Bin/../..";
## no critic (RequireBarewordIncludes)
require 'sysstats-aquisition-lib.pl';
## use critic
}
my $EMPTY = EMPTY();
my $SPACE = SPACE();
###############################################################################
#ID TYPE LOCATION STATUS CURRENT THRESHOLD
# 1 ADM1022 Processor Zone Nominal 86F/ 30C 156F/ 69C
# 2 ADM1022 I/O Zone Nominal 96F/ 36C 167F/ 75C
# 3 ADM1022 CPU (1) Nominal 87F/ 31C 161F/ 72C
# 4 ADM1022 CPU (2) Nominal 87F/ 31C 161F/ 72C
sub get_temp_data($$) {
my $cmd = shift @_; # hplog with path
my $r_data = shift @_;
# temp
my $fullcmd = "$cmd -t";
my $r_tab = read_pipe($fullcmd);
# get parameters values
my $first_line = 1;
foreach my $line ( @{$r_tab} ) {
chomp $line;
# skip blank lines
next if ( $line eq $EMPTY );
if ($first_line) {
$first_line = 0;
next;
}
# parameter name
my $location = substr $line, 17, 13;
$location =~ s/\s*$//;
my $name = encode_param( 'temp', $location );
# values
my $val = substr $line, 43, 9;
# get celsius value
if ( $val =~ m{/\s*(\d+)C} ) {
$r_data->{$name} = $1;
}
else {
warning("data parsing error on $val for $name");
}
} # foreach
return;
}
###############################################################################
#ID TYPE LOCATION STATUS REDUNDANT FAN SPEED
# 1 Var. Speed Processor Zone Normal Yes Low ( 11)
# 2 Var. Speed Processor Zone Normal Yes Low ( 11)
# 3 Var. Speed I/O Zone Normal Yes Low ( 11)
# 4 Var. Speed I/O Zone Normal Yes Low ( 11)
# 5 Var. Speed Processor Zone Normal Yes Low ( 11)
# 6 Var. Speed Processor Zone Normal Yes Low ( 11)
# 7 Var. Speed Pwr. Supply Bay Normal Yes Low ( 11)
# 8 Var. Speed Pwr. Supply Bay Normal Yes Low ( 11)
sub get_fan_data($$) {
my $cmd = shift @_; # hplog with path
my $r_data = shift @_;
# temp
my $fullcmd = "$cmd -f";
my $r_tab = read_pipe($fullcmd);
# get parameters values
my $first_line = 1;
foreach my $line ( @{$r_tab} ) {
chomp $line;
# skip blank lines
next if ( $line eq $EMPTY );
if ($first_line) {
$first_line = 0;
next;
}
# parameter name
my $location = substr $line, 17, 13;
$location =~ s/\s*$//;
my $name = encode_param( 'fan', $location );
# values
my $val = substr $line, 52, 13;
# get celsius value
if ( $val =~ m/(\d+)/ ) {
$r_data->{$name} = $1;
}
else {
debug("data parsing error on $val for $name");
}
} # foreach
return;
}
###############################################################################
# get data parameters
sub get_data($) {
my $cmd = shift @_; # hplog with path
my %data;
get_temp_data( $cmd, \%data );
get_fan_data( $cmd, \%data );
return %data;
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
my %codes = action_load( \%config );
my $hplog_bin = $config{'hplog'};
if ( !$hplog_bin ) {
warning('hplog not configured');
goto FIN;
}
elsif ( !-x $hplog_bin ) {
warning("hplog command $hplog_bin not found");
goto FIN;
}
my $pre = $config{'pre'};
my %data = get_data($hplog_bin); # data cache
my $vol_num = 1;
while ( exists $config{ $pre . $vol_num } ) {
my @tab = split /,/, $config{ $pre . $vol_num };
my $real_vol_num = $tab[0];
my $vol = $tab[1];
my $type = $tab[2];
my $runstop = $tab[4];
#debug( "volume = $vol");
my $value = 'U';
if ( is_param_runstop($runstop) ) {
if ( exists $data{$vol} ) {
$value = $data{$vol};
}
else {
warning("can not find $vol");
}
debug("hplog $vol ($real_vol_num) : value=$value");
action_param( $vol, $value, \%codes );
}
else {
debug("aquisition for $vol stopped");
}
my $rrdbase = $real_vol_num . '.rrd';
RRDs::update( $rrdbase, "N:$value" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase: $ERR") if $ERR;
$vol_num++;
} # while
# a label to quit
#I can not use return when executing this script standalone,
# so I had to use goto
FIN: