| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::Modules::Alerts; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
818
|
use DateTime; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
24
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
40
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use XAS::Factory; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XAS::Class |
|
10
|
1
|
|
|
|
|
4
|
debug => 0, |
|
11
|
|
|
|
|
|
|
version => $VERSION, |
|
12
|
|
|
|
|
|
|
base => 'XAS::Singleton', |
|
13
|
|
|
|
|
|
|
accessors => 'spooler', |
|
14
|
|
|
|
|
|
|
codec => 'JSON', |
|
15
|
|
|
|
|
|
|
utils => ':validation', |
|
16
|
|
|
|
|
|
|
filesystem => 'Dir' |
|
17
|
1
|
|
|
1
|
|
67
|
; |
|
|
1
|
|
|
|
|
1
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
20
|
|
|
|
|
|
|
# Public Methods |
|
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub send { |
|
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
25
|
0
|
|
|
|
|
|
my ($message) = validate_params(\@_, [1]); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $dt = DateTime->now(time_zone => 'local'); |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $data = { |
|
30
|
|
|
|
|
|
|
hostname => $self->env->host, |
|
31
|
|
|
|
|
|
|
datetime => $dt->strftime('%Y-%m-%dT%H:%M:%S.%3N%z'), |
|
32
|
|
|
|
|
|
|
process => $self->env->script, |
|
33
|
|
|
|
|
|
|
pid => $$, |
|
34
|
|
|
|
|
|
|
tid => 0, |
|
35
|
|
|
|
|
|
|
msgnum => 0, |
|
36
|
|
|
|
|
|
|
priority => $self->env->priority, |
|
37
|
|
|
|
|
|
|
facility => $self->env->facility, |
|
38
|
|
|
|
|
|
|
message => $message, |
|
39
|
|
|
|
|
|
|
}; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $json = encode($data); |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->spooler->write($json); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
48
|
|
|
|
|
|
|
# Private Methods |
|
49
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub init { |
|
52
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{'spooler'} = XAS::Factory->module('spooler', { |
|
57
|
|
|
|
|
|
|
-directory => Dir($self->env->spool, 'alerts'), |
|
58
|
|
|
|
|
|
|
-lock => Dir($self->env->spool, 'alerts', 'locked')->path, |
|
59
|
|
|
|
|
|
|
-mask => 0777, |
|
60
|
|
|
|
|
|
|
}); |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |