File Coverage

blib/lib/App/MonM/Channel.pm
Criterion Covered Total %
statement 24 74 32.4
branch 0 16 0.0
condition 0 3 0.0
subroutine 8 16 50.0
pod 8 8 100.0
total 40 117 34.1


line stmt bran cond sub pod time code
1             package App::MonM::Channel;
2 1     1   5 use warnings;
  1         1  
  1         25  
3 1     1   3 use strict;
  1         2  
  1         14  
4 1     1   3 use utf8;
  1         1  
  1         5  
5              
6             =encoding utf-8
7              
8             =head1 NAME
9              
10             App::MonM::Channel - The MonM channel class
11              
12             =head1 VERSION
13              
14             Version 1.00
15              
16             =head1 SYNOPSIS
17              
18             use App::MonM::Channel;
19              
20             =head1 DESCRIPTION
21              
22             This module provides channel base methods
23              
24             =head2 new
25              
26             my $channel = App::MonM::Notifier::Channel->new;
27              
28             Returns the channel object
29              
30             =head2 chconf
31              
32             my $channel_conf = $channel->chconf;
33              
34             Returns current channel config structure
35              
36             =head2 cleanup
37              
38             my $self = $channel->cleanup;
39              
40             Cleaning up of working variables
41              
42             =head2 error
43              
44             my $error = $channel->error;
45             my $error = $channel->error( "New error" );
46              
47             Sets/gets error message
48              
49             =head2 message
50              
51             my $email = $channel->message;
52             my $email = $channel->message( App::MonM::Message->new );
53              
54             Gets/sets the App::MonM::Message object
55              
56             =head2 type
57              
58             my $type = $channel->type;
59             my $type = $channel->type( "File" );
60              
61             Gets/sets the type value
62              
63             =head2 sendmsg
64              
65             my $status = $channel->sendmsg( $message, $chconf )
66             or die($channel->error);
67              
68             This method runs process of sending message to channel and returns
69             operation status.
70              
71             =head2 scheduler
72              
73             my $scheduler = $channel->scheduler;
74              
75             Returns App::MonM::Util::Sheduler object
76              
77             =over 4
78              
79             =item C<$message>
80              
81             The App::MonM::Message object
82              
83             =item C<$chconf>
84              
85             Channel config structure (hash)
86              
87             =back
88              
89             =head1 CONFIGURATION DIRECTIVES
90              
91             General configuration options (directives) detailed describes in L
92              
93             The channel configuration directives are specified in named
94             sections where NAME is the name of the channel section.
95             The NAME is REQUIRED attribute. For example:
96              
97            
98             Type Email
99             Enable on
100             From to@example.com
101             From from@example.com
102            
103              
104             Each the channel section can contain the following basic directives:
105              
106             =over 4
107              
108             =item B
109              
110             At Sun-Sat[00:00-23:59]
111             At Sun[6:30-12:00,14-20:30];Mon[7:00-20:30];Tue-Thu[9:00-17:00];Fri-Sat[off]
112              
113             This directive describes the notification schedule.
114             Notification schedule allows you to schedule time intervals for sending different types of notification to end recipients.
115             Intervals can be specified based the channel level ( sections) or user level ( sections).
116             For defining the days of the week in which the schedule is active use a directive B.
117             The B directive consists of blocks separated by semicolons in the format:
118              
119             Weekday[interval]
120             Weekday[interval,interval,...]
121             Weekday-Weekday[interval,interval,...]
122              
123             The "Weekday" should be defined as a name of the day of the week in full or abbreviated form:
124              
125             Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
126             Sun, Mon, Tue, Wed, Thu, Fri, Sat
127              
128             Define how you want to use a schedule. If you want to activate a notification template only during specific
129             time spans you have the option to combine recurring days of the week into daily intervals by defining
130             the week interval for these days. You can unite several days into block for repetitive notification use
131             according to the appointed block settings. In this case Days of the week should be separating them
132             with "-" character, for example, "Sun-Sat" (all days from Sunday to Saturdays inclusive), or
133             "Mon-Sun" (all days from Monday to Sunday inclusive). If some day of the week is omitted, then this day
134             is automatically excluded from the notification schedule
135              
136             The "Interval" is the Time intervals. To define the hours of the day in which the schedule is
137             active use an Interval. Time intervals should be written in the form: hh:mm-hh:mm, for example:
138              
139             00:00-10:00
140             12-14:50
141             15-16
142              
143             If interval is not specified, interval 00:00-23:59 would be applied by default.
144             You can use the "off" (or "none", "-") value to disable selected day of shedule.
145             When the time will set as a 00:00-00:00 - it will lead to cancel all notifications for the day
146              
147              
148             B
149             If the At directive is not specified the check scheduling will be disabled and the end user will receive
150             messages at any time of the day and day of the week. The same effect will have setting of the value of
151             the At directive as Sun-Sat[00:00-23:59]
152              
153             Default: Sun-Sat[00:00-23:59]
154              
155             =item B
156              
157            
158             Filename payment.pdf
159             Type application/pdf
160             Encoding base64
161             Disposition attachment
162             Path /tmp/payment.pdf
163            
164              
165             Section (sections) that defines attachments for each message
166              
167             Default: no attachments
168              
169             See also L
170              
171             =item B
172              
173             BasedOn SendMail
174              
175             Sets name of the common channel (not user channel) for loading directives from it
176              
177             =item B
178              
179             Sets the charset
180              
181             Default: utf-8
182              
183             See also L
184              
185             =item B
186              
187             Sets the content type
188              
189             Default: text/plain
190              
191             See also L
192              
193             =item B
194              
195             Enable yes
196              
197             The main switcher of the channel section
198              
199             Default: no
200              
201             =item B
202              
203             Sets encoding (8bit, base64, quoted-printable)
204              
205             Default: 8bit
206              
207             See also L
208              
209             =item B
210              
211            
212             X-Foo foo
213             X-Bar bar
214            
215              
216             Container for MIME headers definitions
217              
218             =item B
219              
220             Defines type of channel
221              
222             Allowed types: File, Command, Email
223              
224             =back
225              
226             The "Email" channel directives are describes in L,
227             the "Command" channel directives are describes in L,
228             the "File" channel directives are describes in L
229              
230             =head1 HISTORY
231              
232             See C file
233              
234             =head1 TO DO
235              
236             See C file
237              
238             =head1 SEE ALSO
239              
240             L
241              
242             =head1 AUTHOR
243              
244             Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE
245              
246             =head1 COPYRIGHT
247              
248             Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved
249              
250             =head1 LICENSE
251              
252             This program is free software; you can redistribute it and/or
253             modify it under the same terms as Perl itself.
254              
255             See C file and L
256              
257             =cut
258              
259 1     1   59 use vars qw/$VERSION/;
  1         1  
  1         34  
260             $VERSION = '1.00';
261              
262 1     1   4 use mro;
  1         1  
  1         12  
263              
264 1     1   19 use CTK::ConfGenUtil;
  1         1  
  1         64  
265 1     1   5 use CTK::TFVals qw/ :ALL /;
  1         2  
  1         154  
266              
267 1         4 use parent qw/
268             App::MonM::Channel::File
269             App::MonM::Channel::Email
270             App::MonM::Channel::Command
271 1     1   5 /;
  1         2  
272              
273             sub new {
274 0     0 1   my $class = shift;
275 0           my %args = @_;
276              
277             # Create Sheduler object
278 0           my $scheduler = App::MonM::Util::Scheduler->new;
279              
280 0           my $self = bless {
281             error => "",
282             type => "",
283             message => undef,
284             chconf => {},
285             content => undef, # Output content
286             exitval => 0, # ExitVal code
287             scheduler => $scheduler,
288             }, $class;
289              
290 0           return $self;
291             }
292              
293             sub cleanup {
294 0     0 1   my $self = shift;
295 0           $self->{error} = ''; # Error message
296 0           $self->{type} = ''; # email/file/command
297 0           $self->{message} = undef; # Message object
298 0           $self->{chconf} = {}; # Channel config
299 0           return $self;
300             }
301             sub error {
302 0     0 1   my $self = shift;
303 0           my $v = shift;
304 0 0         $self->{error} = $v if defined $v;
305 0           return $self->{error};
306             }
307             sub type {
308 0     0 1   my $self = shift;
309 0           my $v = shift;
310 0 0         $self->{type} = $v if defined $v;
311 0           return $self->{type};
312             }
313             sub chconf {
314 0     0 1   my $self = shift;
315 0           my $v = shift;
316 0 0         $self->{chconf} = $v if defined $v;
317 0           return $self->{chconf};
318             }
319             sub message {
320 0     0 1   my $self = shift;
321 0           my $v = shift;
322 0 0         $self->{message} = $v if defined $v;
323 0           return $self->{message};
324             }
325             sub scheduler {
326 0     0 1   my $self = shift;
327 0           return $self->{scheduler};
328              
329             }
330              
331             sub sendmsg {
332 0     0 1   my $self = shift;
333 0           my $message = shift; # App::MonM::Message->new
334 0           my $chconf = shift; # Channel config section
335 0           $self->cleanup;
336              
337             # Check message object
338 0 0         unless ($message) {
339 0           $self->error("Incorrect App::MonM::Message object");
340 0           return;
341             }
342              
343             # Enable?
344 0 0 0       unless (lvalue($chconf, 'enable') || lvalue($chconf, 'enabled')) {
345 0           $self->error("Channel is disabled. Set \"Enable\" option to \"on\"");
346 0           return 1; # SKIP
347             }
348              
349             # Schedule
350 0           my $scheduler = $self->scheduler;
351 0           my $chname = value($chconf, 'chname');
352 0 0         if ($chname) {
353 0           $scheduler->add($chname, lvalue($chconf, 'at'));
354 0 0         unless ($scheduler->check($chname)) {
355 0           $self->error(sprintf("Skipped by the \"%s\" schedule conditions", $chname));
356 0           return 1; # SKIP
357             }
358             }
359              
360             # Set data
361 0           $self->chconf($chconf);
362 0           $self->message($message);
363 0           $self->type(lc(uv2null(value($chconf, 'type'))));
364              
365             #printf "Oops: %s\n", $self->type;
366              
367             # Go to backend!
368 0           return $self->maybe::next::method();
369             }
370              
371             1;
372              
373             __END__