Apps/Collector/Process.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary Model/Database/Messaging/Result/Alert.pm »
1 package XAS::Apps::Collector::Process;
2  
3 our $VERSION = '0.01';
4  
5 use XAS::Class
6 0 ▶ debug => 0,
Subroutine BEGIN: called CC=1 SCAR=2.6
7 version => $VERSION,
8 base => 'XAS::Lib::App::Service',
9 mixin => 'XAS::Lib::Mixins::Configs',
10 utils => 'dotid load_module trim',
11 accessors => 'cfg',
12 vars => {
13 SERVICE_NAME => 'XAS_Collector',
14 SERVICE_DISPLAY_NAME => 'XAS Collector',
15 SERVICE_DESCRIPTION => 'The XAS Collector'
16 }
17 1 ;
18  
19 #use Data::Dumper;
20  
21 # ----------------------------------------------------------------------
22 # Public Methods
23 # ----------------------------------------------------------------------
24  
25 sub build_args {
26 my $self = shift;
27 my $section = shift;
28 my $parameters = shift;
29  
30 my @args;
31  
32 foreach my $parameter (@$parameters) {
33  
34 next if ($parameter eq 'module');
35 push(@args, "-$parameter", $self->cfg->val($section, $parameter));
36  
37 }
38  
39 return @args;
40  
41 }
42  
43 sub setup {
44 my $self = shift;
45  
46 my $types;
47 my @sections = $self->cfg->Sections();
48  
49 foreach my $section (@sections) {
50  
51 next if ($section =~ /^collector:\s+input/);
52 next if ($section =~ /^collector:\s+output/);
53 next if ($section =~ /^collector:\s+format/);
54  
55 my ($type) = $section =~ /^collector:(.*)/;
56  
57 my $queue = $self->cfg->val($section, 'queue');
58 my $output = $self->cfg->val($section, 'output');
59 my $format = $self->cfg->val($section, 'format');
60 my $input = $self->cfg->val($section, 'input');
61  
62 $type = trim($type);
63 $types->{$type} = {
64 queue => $queue,
65 format => $format,
66 output => $output,
67 input => $input,
68 };
69  
70 }
71  
72 foreach my $section (@sections) {
73  
74 if ($section =~ /^collector:\s+input/) {
75  
76 my $alias = $self->cfg->val($section, 'alias');
77 my $module = $self->cfg->val($section, 'module');
78 my @parameters = $self->cfg->Parameters($section);
79 my @args = $self->build_args($section, \@parameters);
80  
81 push(@args, '-types', $types);
82  
83 load_module($module);
84 $module->new(@args);
85  
86 $self->service->register($alias);
87  
88 } elsif ($section =~ /^collector:\s+format/) {
89  
90 my $alias = $self->cfg->val($section, 'alias');
91 my $module = $self->cfg->val($section, 'module');
92 my @parameters = $self->cfg->Parameters($section);
93 my @args = $self->build_args($section, \@parameters);
94  
95 load_module($module);
96 $module->new(@args);
97  
98 $self->service->register($alias);
99  
100 } elsif ($section =~ /^collector:\s+output/) {
101  
102 my $alias = $self->cfg->val($section, 'alias');
103 my $module = $self->cfg->val($section, 'module');
104 my @parameters = $self->cfg->Parameters($section);
105 my @args = $self->build_args($section, \@parameters);
106  
107 load_module($module);
108 $module->new(@args);
109  
110 $self->service->register($alias);
111  
112 }
113  
114 }
115  
116 }
117  
118 sub main {
119 my $self = shift;
120  
121 $self->setup();
122  
123 $self->log->info_msg('startup');
124  
125 $self->service->run();
126  
127 $self->log->info_msg('shutdown');
128  
129 }
130  
131 # ----------------------------------------------------------------------
132 # Private Methods
133 # ----------------------------------------------------------------------
134  
135 sub init {
136 my $class = shift;
137  
138 my $self = $class->SUPER::init(@_);
139  
140 $self->load_config();
141  
142 return $self;
143  
144 }
145  
146 1;
147  
148 __END__
149  
150 =head1 NAME
151  
152 XAS::Apps::Collector::Process - A class for the XAS environment
153  
154 =head1 SYNOPSIS
155  
156 use XAS::Apps::Collector::Process;
157  
158 my $app = XAS::Apps::Collector::Process->new(
159 -throws => 'xas-collector'
160 );
161  
162 $app->run();
163  
164 =head1 DESCRIPTION
165  
166 This module will retrieve and process messages from a message queue server.
167 How they are processed is based on the message type and the processing modules
168 that are loaded. These are configured in a configuration file.
169  
170 =head1 CONFIGURATION
171  
172 The configuration file is the familiar Windows .ini format. It has the
173 following stanzas.
174  
175 [collector: xas-logs]
176 queue = /queue/logs
177 format = format-logs
178 output = output-logs
179 input = input-stomp
180  
181 This defines a message type. It specifies the queue to process, the name of
182 the format handler, the name of the output handler and the input handler. More
183 then one message type can be defined. But they need to be unique.
184  
185 [collector: input]
186 module = XAS::Collector::Input::Stomp
187 port = 61613
188 host = localhost
189 alias = input-stomp
190  
191 This defines an input handler. There can be more the one. The names must be
192 unique. So you can have an input1, input2, etc. The standard parameters are
193 the following:
194  
195 module - the module that will handle the input
196 alias - the name of the session handling this module
197  
198 Other parameters may be defined, depending on the module that is being used.
199 Please check their documentation.
200  
201 [collector: format]
202 module = XAS::Collector::Format::Alerts
203 alias = format-alerts
204  
205 This defines a format handler. There can be more then one. The names
206 must be unique, So you can have a format1, format2, etc. A format handler
207 formats the incoming message into a standardized data structure. This
208 structures is then used by the output handlers.
209  
210 The standard parameters are the following:
211  
212 module - the module that will handle the formatting
213 alias - the name of the session handling this module
214  
215 There are no additional parameters.
216  
217 [collector: output]
218 module = XAS::Collector::Output::Database::Alerts
219 alias = output-alerts
220 database = messaging
221  
222 This defines an output handler. There can be more then one. The names
223 must be unique, So you can have a output1, output2, etc. An output handler
224 does something with the created data structure. Usually storing it into a
225 data store of some kind. But it could be used for other things. The standard
226 parameters are the following:
227  
228 module - the module that will handle the output
229 alias - the name of the session handling this module
230  
231 Other parameters may be defined, depending on the module that is being used.
232 Please check their documentation.
233  
234 =head2 EXAMPLE
235  
236 The following is an example of a configuration that would handle the xas-alerts
237 message type.
238  
239 [collector: xas-alerts]
240 queue = /queue/alerts
241 format = format-alerts
242 output = output-alerts
243 input = input-stomp
244  
245 [collector: input]
246 module = XAS::Collector::Input::Stomp
247 port = 61613
248 host = localhost
249 alias = input-stomp
250  
251 [collector: format]
252 module = XAS::Collector::Format::Alerts
253 alias = format-alerts
254  
255 [collector: output]
256 module = XAS::Collector::Output::Database::Alerts
257 alias = output-alerts
258 database = messaging
259  
260 =head1 METHODS
261  
262 =head2 setup
263  
264 This method will configure the process.
265  
266 =head2 main
267  
268 This method will start the processing.
269  
270 =head2 options
271  
272 No additional cli options have been defined.
273  
274 =head1 SEE ALSO
275  
276 =over 4
277  
278 =item L<XAS::Collector|XAS::Collector>
279  
280 =item L<XAS|XAS>
281  
282 =back
283  
284 =head1 AUTHOR
285  
286 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
287  
288 =head1 COPYRIGHT AND LICENSE
289  
290 Copyright (c) 2012-2015 Kevin L. Esteb
291  
292 This is free software; you can redistribute it and/or modify it under
293 the terms of the Artistic License 2.0. For details, see the full text
294 of the license at http://www.perlfoundation.org/artistic_license_2_0.
295  
296 =cut
↑ Summary Model/Database/Messaging/Result/Alert.pm »