mirror of
https://github.com/webmin/webmin.git
synced 2026-06-20 03:10:30 +01:00
Make monitor details available to commands via environment
This commit is contained in:
@@ -77,3 +77,5 @@ Added a monitor-level option to run a command if the monitor times out.
|
||||
Enhanced the free memory monitor to be able to check virtual memory as well.
|
||||
---- Changes since 1.530 ----
|
||||
Update the SSL certificate monitor to check alternate names as well when looking for hostname mismatches.
|
||||
---- Changes since 1.590 ----
|
||||
Commands run when a monitor goes up or down can now access details of the monitor via environment variables starting with STATUS_
|
||||
|
||||
@@ -385,39 +385,43 @@ print STDERR "No SNMP perl module found\n";
|
||||
# run_on_command(&serv, command)
|
||||
sub run_on_command
|
||||
{
|
||||
return undef if (!$_[1]);
|
||||
local ($serv, $cmd) = @_;
|
||||
return undef if (!$cmd);
|
||||
local $out;
|
||||
if ($_[0]->{'runon'} && $_[0]->{'remote'}) {
|
||||
if ($serv->{'runon'} && $serv->{'remote'}) {
|
||||
# Run on the remote host
|
||||
local $cmd = quotemeta($_[1]);
|
||||
$remote_error_msg = undef;
|
||||
&remote_foreign_call($serv->{'remote'}, "status",
|
||||
"set_monitor_environment", $serv);
|
||||
&remote_error_setup(\&remote_error_callback);
|
||||
if ($config{'output'}) {
|
||||
$out = &remote_eval($_[0]->{'remote'}, "status",
|
||||
"`($cmd) 2>&1 </dev/null`");
|
||||
$out = &remote_foreign_call($serv->{'remote'}, "status",
|
||||
"backquote_command", "($cmd) 2>&1 </dev/null");
|
||||
}
|
||||
else {
|
||||
&remote_eval($_[0]->{'remote'}, "status",
|
||||
"system('($cmd) >/dev/null 2>&1 </dev/null')");
|
||||
&remote_foreign_call($serv->{'remote'}, "status",
|
||||
"execute_command", $cmd);
|
||||
}
|
||||
&remote_error_setup(undef);
|
||||
&remote_foreign_call($serv->{'remote'}, "status",
|
||||
"reset_monitor_environment", $serv);
|
||||
if ($remote_error_msg) {
|
||||
return &text('monitor_runerr', $_[1], $_[0]->{'remote'},
|
||||
return &text('monitor_runerr', $cmd, $serv->{'remote'},
|
||||
$remote_error_msg);
|
||||
}
|
||||
return &text('monitor_run1', $_[1], $_[0]->{'remote'})."\n";
|
||||
return &text('monitor_run1', $cmd, $serv->{'remote'})."\n".$out;
|
||||
}
|
||||
else {
|
||||
# Just run locally
|
||||
&set_monitor_environment($serv);
|
||||
if ($config{'output'}) {
|
||||
$out = `($_[1]) 2>&1 </dev/null`;
|
||||
return &text('monitor_run2', $_[1])."\n".
|
||||
$out;
|
||||
$out = &backquote_command("($cmd) 2>&1 </dev/null");
|
||||
}
|
||||
else {
|
||||
system("($_[1]) >/dev/null 2>&1 </dev/null");
|
||||
return &text('monitor_run2', $_[1])."\n";
|
||||
&execute_command($cmd);
|
||||
}
|
||||
&reset_monitor_environment($serv);
|
||||
return &text('monitor_run2', $cmd)."\n".$out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -509,5 +509,29 @@ local ($tmpl) = @_;
|
||||
&unlink_logged($tmpl->{'file'});
|
||||
}
|
||||
|
||||
# set_monitor_environment(&serv)
|
||||
# Sets environment variables based on some monitor
|
||||
sub set_monitor_environment
|
||||
{
|
||||
local ($serv) = @_;
|
||||
foreach my $k (keys %$serv) {
|
||||
if (!ref($serv->{$k})) {
|
||||
$ENV{'STATUS_'.uc($k)} = $serv->{$k};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# reset_monitor_environment(&serv)
|
||||
# Undoes the call to set_monitor_environment
|
||||
sub reset_monitor_environment
|
||||
{
|
||||
local ($serv) = @_;
|
||||
foreach my $k (keys %$serv) {
|
||||
if (!ref($serv->{$k})) {
|
||||
delete($ENV{'STATUS_'.uc($k)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user