Skip to content
Snippets Groups Projects
Commit d710bcb9 authored by Mark Harrison's avatar Mark Harrison
Browse files

Support wildcard modules (fixes #7)

This is done using a wildcard_handler method in addition to the normal handler
method. The wildcard_handler method is called if * is in the config file as
the check name, and the handler module is called for normal checks. By
default, both methods will die with "Not implemented", meaning modules can
implement one or both of the methods, depending on whether they support normal
checks, wildcard checks, or some combination of both.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@386 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 24af467c
No related branches found
No related tags found
No related merge requests found
......@@ -12,9 +12,11 @@ sub new {
}
sub handler {
return {
'error_message' => ["Monitor not implemented", "s"]
}
die "Monitor not implemented.\n";
}
sub wildcard_handler {
die "Monitor not implemented.\n";
}
sub cache_metrics {
......
......@@ -90,40 +90,51 @@ $status->serve_http_on($config->{interface}, $config->{port},
while(1) {
while(my($module_name, $mod_configs) = each %{$config->{Module}}) {
while(my($check_name, $monitor_obj) = each %$mod_configs) {
my $check_metric = {};
my $check_metrics = {};
my $starttime = [gettimeofday];
# Get old status if it hasn't expired
$check_metric = $monitor_obj->get_cached_metrics();
$check_metrics = $monitor_obj->get_cached_metrics();
# Otherwise, run the check
if (!$check_metric) {
if (!$check_metrics) {
my $timeout = $monitor_obj->{'check_timeout'} ||
$config->{'timeout'};
alarm($timeout);
my $handler;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
$check_metric = $monitor_obj->handler();
if ($check_name eq "*") {
$check_metrics = $monitor_obj->wildcard_handler;
} else {
$check_metrics = {
$check_name => $monitor_obj->handler
};
}
};
alarm 0;
# Store the last metrics for use by fresh_status_msg later
$monitor_obj->cache_metrics($check_metric);
$monitor_obj->cache_metrics($check_metrics);
};
my $checkproblem = $@;
my $results = {
last_runtime_seconds => sprintf("%.6f",
tv_interval($starttime)),
metric => $check_metric
};
if($checkproblem) {
chomp $checkproblem;
$results->{metric} = { "error" => ["$checkproblem", "s"]};
if ($checkproblem eq "alarm") {
$results->{metric} = { "error" => ["Check timeout", "s"]};
$checkproblem = "Check timeout";
}
$check_metrics = {
$check_name => {"error" => ["$checkproblem", "s"]}
};
Resmon::ExtComm::clean_up;
}
$status->store($module_name,$monitor_obj->{'check_name'}, $results);
$status->write($module_name,$monitor_obj->{'check_name'},
$results->{'metric'}, $debug);
foreach my $name (keys %$check_metrics) {
my $results = {
last_runtime_seconds => sprintf("%.6f",
tv_interval($starttime)),
metric => $check_metrics->{$name}
};
$status->store($module_name,$name, $results);
$status->write($module_name,$name, $results->{'metric'},
$debug);
}
}
}
$status->close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment