| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::Modules::Alerts; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2187
|
use DateTime; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
44
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use XAS::Factory; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XAS::Class |
|
10
|
1
|
|
|
|
|
5
|
debug => 0, |
|
11
|
|
|
|
|
|
|
version => $VERSION, |
|
12
|
|
|
|
|
|
|
base => 'XAS::Singleton', |
|
13
|
|
|
|
|
|
|
accessors => 'spooler', |
|
14
|
|
|
|
|
|
|
codec => 'JSON', |
|
15
|
|
|
|
|
|
|
utils => ':validation', |
|
16
|
|
|
|
|
|
|
filesystem => 'Dir' |
|
17
|
1
|
|
|
1
|
|
74
|
; |
|
|
1
|
|
|
|
|
2
|
|
|
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__ |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
XAS::Lib::Modules::Alerts - The alert module for the XAS environment |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Your program can use this module in the following fashion: |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use XAS::Lib::Modules::Alerts; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $alert = XAS::Lib::Modules::Alerts->new(); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$alert->send('There is a problem'); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This is the module for sending alerts within the XAS environment. It will write |
|
87
|
|
|
|
|
|
|
an "alert" to the alerts spool directory. It is implemented as a singleton |
|
88
|
|
|
|
|
|
|
and will auto-load when invoked. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 new |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This method initializes the module. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 send($message) |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This method will send an alert. It takes the following named parameters: |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over 4 |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item B<$message> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The message to send. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item L<XAS|XAS> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Copyright (c) 2012-2015 Kevin L. Esteb |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
125
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
|
126
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |