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. Perhaps this is a wilcard only module?\n"; |
---|
16 |
} |
---|
17 |
|
---|
18 |
sub wildcard_handler { |
---|
19 |
die "Monitor not implemented. Perhaps this is a non-wildcard module?\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; |
---|