Collector/Output/Database/Logs.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/Database/Base.pm ↑ Summary Collector/Output/Socket/Base.pm »
1 package XAS::Collector::Output::Database::Logs;
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 => 'Log'
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; level = %s; facility = %s; message = %s',
35 $alias, $data->{'hostname'},
36 $data->{'datetime'}, $data->{'level'},
37 $data->{'facility'}, $data->{'message'}
38 );
39  
40 $self->log->debug($buffer);
41  
42 try {
43  
44 $data->{'revision'} = 1;
45 Log->create($schema, $data);
46  
47 $self->log->info_msg('collector_processed', $alias, 1, $data->{'hostname'}, $data->{'datetime'});
48 $poe_kernel->post($input, 'write_data', $ack);
49  
50 } catch {
51  
52 my $ex = $_;
53  
54 $self->exception_handler($ex);
55 $self->event->publish(
56 -event => 'stop_queue',
57 -args => $alias
58 );
59  
60 };
61  
62 $self->log->debug("$alias: leaving store_data()");
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::Logs - Perl extension for the XAS Environment
81  
82 =head1 SYNOPSIS
83  
84 use XAS::Collector::Output::Database::Logs;
85  
86 my $output = XAS::Collector::Output::Database::Logs->new(
87 -alias => 'database-logs',
88 -database => 'messaging',
89 );
90  
91  
92 =head1 DESCRIPTION
93  
94 This module handles the xas-logs packet type.
95  
96 =head1 METHODS
97  
98 =head2 new
99  
100 This module inherits from L<XAS::Collector::Output::Database::Base|XAS::Collector::Output::Database::Base>
101 and takes the same parameters.
102  
103 =head1 PUBLIC EVENTS
104  
105 =head2 store_data(OBJECT, ARG0, ARG1, ARG2)
106  
107 This event will trigger the storage of xas-logs packets into the database.
108  
109 =over 4
110  
111 =item B<OBJECT>
112  
113 A handle to the current object.
114  
115 =item B<ARG0>
116  
117 The data to be stored within the database.
118  
119 =item B<ARG1>
120  
121 The acknowledgement to send back to the message queue server.
122  
123 =item B<ARG2>
124  
125 The input to return the ack too.
126  
127 =back
128  
129 =head1 SEE ALSO
130  
131 =over 4
132  
133 =item L<XAS::Collector::Output::Database::Base|XAS::Collector::Output::Database::Base>
134  
135 =item L<XAS::Collector::Output::Database::Alerts|XAS::Collector::Output::Database::Alerts>
136  
137 =item L<XAS::Collector|XAS::Collector>
138  
139 =item L<XAS|XAS>
140  
141 =back
142  
143 =head1 AUTHOR
144  
145 Kevin Esteb, E<lt>kevin@kesteb.usE<gt>
146  
147 =head1 COPYRIGHT AND LICENSE
148  
149 Copyright (c) 2012-2015 Kevin L. Esteb
150  
151 This is free software; you can redistribute it and/or modify it under
152 the terms of the Artistic License 2.0. For details, see the full text
153 of the license at http://www.perlfoundation.org/artistic_license_2_0.
154  
155 =cut
« Collector/Output/Database/Base.pm ↑ Summary Collector/Output/Socket/Base.pm »