root/lib/Resmon/Module.pm

Revision d710bcb9b19ab354fa6cbab08cbe91dcee175e86, 0.8 kB (checked in by Mark Harrison <mark@omniti.com>, 8 years ago)

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

  • Property mode set to 100644
Line 
1 package Resmon::Module;
2 use strict;
3 use warnings;
4
5 sub new {
6     my ($class, $check_name, $config) = @_;
7     my $self = {};
8     $self->{config} = $config;
9     $self->{check_name} = $check_name;
10     bless ($self, $class);
11     return $self;
12 }
13
14 sub handler {
15     die "Monitor not implemented.\n";
16 }
17
18 sub wildcard_handler {
19     die "Monitor not implemented.\n";
20 }
21
22 sub cache_metrics {
23     # Simple method to cache the results of a check
24     my $self = shift;
25     $self->{lastmetrics} = shift;
26     $self->{lastupdate} = time;
27 }
28
29 sub get_cached_metrics {
30     my $self = shift;
31     return undef unless $self->{check_interval};
32     my $now = time;
33     if(($self->{lastupdate} + $self->{check_interval}) >= $now) {
34         return $self->{lastmetrics};
35     }
36     return undef;
37 }
38
39 1;
Note: See TracBrowser for help on using the browser.