Collector/Output/Database/Alerts.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Collector/Output/Console/Base.pm ↑ Summary Collector/Output/Database/Base.pm »
1 package XAS::Collector::Output::Database::Alerts;
2  
3 our $VERSION = '0.01';
4  
5 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use XAS::Model::Database
9 0 ▶ schema => 'XAS::Model::Database::Messaging',
Subroutine BEGIN: called CC=1 SCAR=2.6
10 table => 'Alert'
11 1 ;
12  
13 use XAS::Class
14 debug => 0,
15 version => $VERSION,
16 base => 'XAS::Collector::Output::Database::Base',
17 ;
18  
19 #use Data::Dumper;
20  
21 # --------------------------------------------------------------------
22 # Public Events
23 # --------------------------------------------------------------------
24  
25 sub store_data {
26 my ($self, $data, $ack, $input) = @_[OBJECT,ARG0...ARG2];
27  
28 my $buffer;
29 my $alias = $self->alias;
30 my $schema = $self->schema;
31  
32 $self->log->debug("$alias: entering store_data()");
33  
34 $buffer = sprintf('%s: hostname = %s; timestamp = %s; priority = %s; facility = %s; message = %s',
35 $alias, $data->{'hostname'}, $data->{'datetime'}, $data->{'priority'},
36 $data->{'facility'}, $data->{'message'}
37 );
38  
39 $self->log->debug($buffer);
40  
41 try {
42  
43 $data->{'revision'} = 1;
44 Alert->create($schema, $data);
45  
46 $self->log->info_msg('collector_processed', $alias, 1, $data->{'hostname'}, $data->{'datetime'});
47  
48 } catch {
49  
50 my $ex = $_;
51  
52 $self->exception_handler($ex);
53 $self->event->publish(
54 -event => 'stop_queue',
55 -args => $alias
56 );
57  
58 };
59  
60 $poe_kernel->post($input, 'write_data', $ack);
61  
62 $self->log->debug("$alias: leaving store_notify()");
63  
64 }
65  
66 # --------------------------------------------------------------------
67 # Public Methods
68 # --------------------------------------------------------------------
69  
70 # --------------------------------------------------------------------
71 # Private Methods
72 # --------------------------------------------------------------------
73  
74 1;
75  
76 __END__
77  
78 =head1 NAME
79  
80 XAS::Collector::Output::Database::Alerts - Perl extension for the XAS Environment
81  
82 =head1 SYNOPSIS
83  
84 use XAS::Collector::Output::Database::Alerts;
85  
86 my $notify = XAS::Collector::Output::Database::Alerts->new(
87 -alias => 'database-alerts',
88 -database => 'messaging',
89 );
90  
91 =head1 DESCRIPTION
92  
93 This module handles the xas-alerts packet type.
94  
95 =head1 METHODS
96  
97 =head2 new
98  
99 This module inherits from L<XAS::Collector::Output::Database::Base|XAS::Collector::Output::Database::Base>
100 and takes the same parameters.
101  
102 =head1 PUBLIC EVENTS
103  
104 =head2 store_data(OBJECT, ARG0, ARG1, ARG2)
105  
106 This event will trigger the storage of xas-alerts packets into the database.
107  
108 =over 4
109  
110 =item B<OBJECT>
111  
112 A handle to the current object.
113  
114 =item B<ARG0>
115  
116 The data to be stored within the database.
117  
118 =item B<ARG1>
119  
120 The acknowledgement to send back to the message queue server.
121  
122 =item B<ARG2>
123  
124 The input to return the ack too.
125  
126 =back
127  
128 =head1 SEE ALSO
129  
130 =over 4
131  
132 =item L<XAS::Collector::Output::Database::Base|XAS::Collector::Output::Database::Base>
133  
134 =item L<XAS::Collector::Output::Database::Logs|XAS::Collector::Output::Database::Logs>
135  
136 =item L<XAS::Collector|XAS::Collector>
137  
138 =item L<XAS|XAS>
139  
140 =back
141  
142 =head1 AUTHOR
143  
144 Kevin Esteb, E<lt>kevin@kesteb.usE<gt>
145  
146 =head1 COPYRIGHT AND LICENSE
147  
148 Copyright (c) 2012-2015 Kevin L. Esteb
149  
150 This is free software; you can redistribute it and/or modify it under
151 the terms of the Artistic License 2.0. For details, see the full text
152 of the license at http://www.perlfoundation.org/artistic_license_2_0.
153  
154 =cut
« Collector/Output/Console/Base.pm ↑ Summary Collector/Output/Database/Base.pm »