#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - custom.pl
#
# Webmin Sysstats Module
# Copyright (C) 2002 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;
use RRDs;
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 $module_name;
###############################################################################
my %config;
read_file_cached( 'config', \%config );
$module_name = $config{'name'};
debug( "run $module_name version " . $config{'version'} );
my %codes = action_load( \%config );
my $pre = $config{'pre'};
my $custom_num = 1;
while ( exists $config{ $pre . $custom_num } ) {
my @tab = split /,/, $config{ $pre . $custom_num };
my $real_custom_num = $tab[0];
my $custom_name = $tab[1];
my $custom_cmd = $tab[2];
my $runstop = $tab[4];
my $total = 'U';
if ( is_param_runstop($runstop) ) {
# see also test_command
# test if command exists (be carefull for args)
my ( $cmd, undef ) = split_awk($custom_cmd);
if ( !-x $cmd ) {
warning(
"($custom_name) command $cmd does not exists or can not be executed"
);
}
else {
# we assume the commands output is a number
## no critic (ProhibitBacktickOperators)
$total = `$custom_cmd`;
## use critic
chomp $total;
}
debug(
"$module_name $custom_name ($real_custom_num $custom_cmd): total=$total"
);
action_param( $custom_name, $total, \%codes );
}
else {
debug("aquisition for $custom_name stopped");
}
my $rrdbase = $real_custom_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase database : $ERR") if $ERR;
$custom_num++;
}