You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to ask that a "GenericProbe" which allows just writing a command into "config" be added to Smokeping.
I have actually written a similar probe for myself, but my Perl skills are sub-standard, so the code quality might not match what is expected of a mature software.
Nevertheless, here is the code:
packageSmokeping::probes::GenericCommand;
=head1301 Moved PermanentlyThis is a Smokeping probe module. Please use the command C<smokeping -man Smokeping::probes::GenericCommand>to view the documentation or the commandC<smokeping -makepod Smokeping::probes::GenericCommand>to generate the POD document.=cutuse strict;
use base qw(Smokeping::probes::basefork);
use IPC::Open3;
use Symbol;
use Carp;
use Time::HiRes qw(gettimeofday tv_interval);
subpod_hash {
return {
name=><<DOC,
Smokeping::probes::GenericCommand - Generic Command Probe for SmokePingDOCdescription=><<DOC,
Runs a command given as a parameter n times, and records stdout (should be a number)If you are using this module to monitor hdd temperature, you might needsetcap 'CAP_SYS_RAWIO+eip CAP_DAC_OVERRIDE+eip CAP_SYS_ADMIN+eip' /usr/sbin/smartctlDOCauthors=><<'DOC',
Anon DOC
}
}
subnew($$$)
{
my$proto = shift;
my$class = ref($proto) || $proto;
my$self = $class->SUPER::new(@_);
# no need for this if we run as a cgireturn$self;
}
subProbeDesc($){
my$self = shift;
return"Generic Command";
}
subpingone ($){
my$self = shift;
my$target = shift;
my$inh = gensym;
my$outh = gensym;
my$errh = gensym;
my$host = $target->{addr};
#my $query = "$self->{properties}{binary} -t $target->{vars}->{keytype} -p $target->{vars}->{port} $host";#my $query = q(timeout 10 /usr/sbin/smartctl -x /dev/nvme0 | grep -F 'Temperature:' | awk '{printf($2);}' || echo 9999);my$query = "$target->{vars}->{command}";
my@times;
my@values;
# get the user and system times before and after the test$self->do_debug("query=$query\n");
for (my$run = 0; $run < $self->pings; $run++) {
my$t0 = [gettimeofday()];
my$pid = open3($inh,$outh,$errh, $query);
while (my$line = <$outh>) {
my$num;
chomp$line;
$num = int($line);
push (@values, $num);
push@times, tv_interval($t0);
}
waitpid$pid,0;
my$rc = $?;
carp "$query returned with exit code $rc. run with debug enabled to get more information"unless$rc == 0;
close$errh;
close$inh;
close$outh;
}
@times = map {sprintf"%.10e", $_ } sort {$a<=>$b} @times;
@values = map {sprintf"%.10e", $_ } sort {$a<=>$b} @values;
$self->do_debug("time=@times\n");
return@values;
return@times;
}
subprobevars {
my$class = shift;
return$class->_makevars($class->SUPER::probevars, {})
}
subtargetvars {
my$class = shift;
return$class->_makevars($class->SUPER::targetvars, {
_mandatory=> [ 'command' ],
command=> {
_doc=>"command to run",
_re=>'.+',
_example=>q(/usr/sbin/smartctl -x /dev/nvme0 | grep -F 'Temperature:' | awk '{printf($2);}'),
},
})
}
1;
The text was updated successfully, but these errors were encountered:
I would like to ask that a "GenericProbe" which allows just writing a command into "config" be added to Smokeping.
I have actually written a similar probe for myself, but my Perl skills are sub-standard, so the code quality might not match what is expected of a mature software.
Nevertheless, here is the code:
The text was updated successfully, but these errors were encountered: