blib/lib/XAS/Lib/Modules/Alerts.pm

filter: Statementstmt 58.3% 14 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 62.5% 20 / 32 CC 1 SCAR 2.9
CC
1
Cov
58%
send
2.0
init
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/XAS/Apps/Test/Service.pm ↑ Summary blib/lib/XAS/Lib/Curl/HTTP.pm »
1 package XAS::Lib::Modules::Alerts;
2  
3 1 our $VERSION = '0.04';
4  
5 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XAS::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 use XAS::Class
10 1 debug => 0,
11 version => $VERSION,
12 base => 'XAS::Singleton',
13 constants => ':alerts',
14 accessors => 'spooler',
15 codec => 'JSON',
16 utils => 'dt2db',
17 filesystem => 'Dir'
18 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # ------------------------------------------------------------------------
21 # Public Methods
22 # ------------------------------------------------------------------------
23  
24 sub send {
25 0 ▶ my $self = shift;
Subroutine send: not called CC=1 SCAR=6.9
Pod documented
26 0 my $p = $self->validate_params(\@_, {
27 -message => 1,
28 -process => 1,
29 -facility => { optional => 1, default => 'systems', regex => ALERT_FACILITY },
30 -priority => { optional => 1, default => 'low', regex => ALERT_PRIORITY },
31 });
32  
33 0 my $dt = DateTime->now(time_zone => 'local');
34  
35 my $data = {
36 hostname => $self->env->host,
37 datetime => dt2db($dt),
38 process => $p->{'process'},
39 pid => $$,
40 tid => 0,
41 msgid => 0,
42 priority => $p->{'priority'},
43 facility => $p->{'facility'},
44 0 message => $p->{'message'},
45 };
46  
47 0 my $json = encode($data);
48  
49 0 $self->spooler->write($json);
50  
51 }
52  
53 # ------------------------------------------------------------------------
54 # Private Methods
55 # ------------------------------------------------------------------------
56  
57 sub init {
58 0 ▶ my $class = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
59  
60 0 my $self = $class->SUPER::init(@_);
61  
62 0 $self->{spooler} = XAS::Factory->module('spooler', {
63 -directory => Dir($self->env->spool, 'alerts'),
64 -mask => 0777
65 });
66  
67 0 return $self;
68  
69 }
70  
71 1 1;
72  
73 __END__
74  
75 =head1 NAME
76  
77 XAS::Lib::Modules::Alerts - The alert module for the XAS environment
78  
79 =head1 SYNOPSIS
80  
81 Your program can use this module in the following fashion:
82  
83 use XAS::Lib::Modules::Alerts;
84  
85 my $alert = XAS::Lib::Modules::Alerts->new();
86  
87 $alert->send(
88 -priority => 'high',
89 -facility => 'huston',
90 -message => 'There is a problem'
91 );
92  
93 =head1 DESCRIPTION
94  
95 This is the module for sending alerts within the XAS environment. It will write
96 an "alert" to the alerts spool directory. It is implemented as a singleton
97 and will auto-load when invoked.
98  
99 =head1 METHODS
100  
101 =head2 new
102  
103 This method initializes the module.
104  
105 =head2 send
106  
107 This method will send an alert. It takes the following named parameters:
108  
109 =over 4
110  
111 =item B<-priority>
112  
113 The notification level, 'high','medium','low'. Default 'low'.
114  
115 =item B<-facility>
116  
117 The notification facility, 'systems', 'dba', etc. Default 'systems'.
118  
119 =item B<-message>
120  
121 The message text for the message
122  
123 =back
124  
125 =head1 SEE ALSO
126  
127 =over 4
128  
129 =item L<XAS|XAS>
130  
131 =back
132  
133 =head1 AUTHOR
134  
135 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
136  
137 =head1 COPYRIGHT AND LICENSE
138  
139 Copyright (C) 2014 Kevin L. Esteb
140  
141 This is free software; you can redistribute it and/or modify it under
142 the terms of the Artistic License 2.0. For details, see the full text
143 of the license at http://www.perlfoundation.org/artistic_license_2_0.
144  
145 =cut
« blib/lib/XAS/Apps/Test/Service.pm ↑ Summary blib/lib/XAS/Lib/Curl/HTTP.pm »