blib/lib/Net/Peep/Notifier.pm

filter: Statementstmt 20.9% 41 / 196 Branchbran 2.6% 2 / 76 Conditioncond 0.0% 0 / 59 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 30.4% 7 / 23 Podpod 0.0% 0 / 5 totaltotal 12.7% 50 / 393 CC 65 SCAR 51.9
CC
65
Cov
13%
notify
600.0
_getNotifications
42.0
_getNotificationRecipients
30.0
CRAP 179.9
« blib/lib/Net/Peep/Client/Sysmonitor.pm ↑ Summary blib/lib/Net/Peep/Client/Logparser.pm »
1 package Net::Peep::Notifier;
2  
3 11 require 5.005;
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Net::Peep::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Net::Peep::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 require Exporter;
12  
13 11 ▶use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $LOGGER
Subroutine BEGIN: called CC=1 SCAR=0.0
14 $NOTIFICATIONS $NOTIFICATION_INTERVAL
15 %NOTIFICATION_LEVEL %NOTIFICATION_RECIPIENTS
16 %NOTIFICATION_HOSTS
17 11 @SMTP_RELAYS $HOSTNAME $USER $FROM };
18  
19 11 @ISA = qw(Exporter);
20 11 %EXPORT_TAGS = ( );
21 11 @EXPORT_OK = ( );
22 11 @EXPORT = qw( );
23 11 $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
24  
25 11 $LOGGER = Net::Peep::Log->new();
26  
27 11 $NOTIFICATIONS = {}; # used for caching failsafe information
28 11 $NOTIFICATION_INTERVAL = 1800; # seconds
29 11 %NOTIFICATION_LEVEL = ( ); # see below for more information
30 11 %NOTIFICATION_RECIPIENTS = ( );
31 11 %NOTIFICATION_HOSTS = ( );
32 11 @SMTP_RELAYS = ( 'localhost' );
33  
34 11 ▶$HOSTNAME = hostname() ? hostname() : 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
hostname() ? : 11 0 11
35 11 ▶$USER = $ENV{'USER'} ? $ENV{'USER'} : 'peep';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'USER'} ? : 0 11 11
36  
37 11 $FROM = "Peep Notification <$USER\@$HOSTNAME>";
38  
39 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
40  
41 0 my $self = shift;
42 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
43 0 my $this = {};
44 0 bless $this, $class;
45  
46 } # end sub new
47  
48 0 ▶sub _timeToSend {
Subroutine _timeToSend: not called CC=3 SCAR=24.8
49  
50 # answers the question: based on the time that the last
51 # notification was sent, is it time to send another notification
52  
53 0 my $self = shift;
54 0 my $client = shift;
55  
56 0 my $last_send_time;
57 0 ▶ if ($self->_sendTimeExists($client)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_sendTimeExists($client)) { } 0 0 0
58 0 $last_send_time = $self->_getSendTime($client);
59 } else {
60 0 return 1; # if there is no send time, it's time!
61 }
62  
63 0 my $time = time();
64  
65 0 ▶ if ($time - $last_send_time > $NOTIFICATION_INTERVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time - $last_send_time > $Net::Peep::Notifier::NOTIFICATION_INTERVAL) { } 0 0 0
66 0 return 1;
67 } else {
68 0 return 0;
69 }
70  
71 } # end sub _timeToSend
72  
73 0 ▶sub _notificationExists {
Subroutine _notificationExists: not called CC=3 SCAR=24.8
74  
75 # returns 1 if a notification has been sent for a client of the
76 # type stored in the generator object, 0 otherwise
77  
78 0 my $self = shift;
79 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
80  
81 0 ▶ if (exists $NOTIFICATIONS->{$client}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}) { } 0 0 0
82 0 return 1;
83 } else {
84 0 return 0;
85 }
86  
87 } # end sub _notificationExists
88  
89 0 ▶sub _getNotificationRecipients {
Subroutine _getNotificationRecipients: not called CC=5 SCAR=34.0
90  
91 0 my $self = shift;
92 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
93  
94 0 ▶ unless (exists $NOTIFICATION_RECIPIENTS{$client}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client}) 0 0 0
95 0 ▶ return wantarray ? () : [];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
96 }
97  
98 0 ▶ return wantarray ? @{$NOTIFICATION_RECIPIENTS{$client}} : $NOTIFICATION_RECIPIENTS{$client};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
99  
100 } # end sub _getNotificationRecipients
101  
102 0 ▶sub _getNotificationHosts {
Subroutine _getNotificationHosts: not called CC=5 SCAR=34.0
103  
104 0 my $self = shift;
105 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
106  
107 0 ▶ unless (exists $NOTIFICATION_HOSTS{$client}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client}) 0 0 0
108 0 ▶ return wantarray ? () : [];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
109 }
110  
111 0 ▶ return wantarray ? @{$NOTIFICATION_HOSTS{$client}} : $NOTIFICATION_HOSTS{$client};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
112  
113 } # end sub _getNotificationHosts
114  
115 0 ▶sub notify {
Subroutine notify: not called CC=24 SCAR=64.0
Pod undocumented
116  
117 0 my $self = shift;
118 0 ▶ my $notification = shift || confess "notification not found";
Condition0%0/2
shift() || confess('notification not found')
l!l
00
MC/DC0%0/1
shift() || confess('notification not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
119 0 my $force = shift;
120  
121 0 ▶ my $client = $notification->client() || confess "client not found";
Condition0%0/2
$notification->client || confess('client not found')
l!l
00
MC/DC0%0/1
$notification->client || confess('client not found')
$notification->client
Truth table0%0/2
A
A= $notification->client
Aresult
11
00
122  
123 0 ▶ if (exists $NOTIFICATION_HOSTS{$client} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}) { } 0 0 0
Condition0%0/6
exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
!ll&&!rl&&r
000
exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client} exists $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
Truth table0%0/4
A and B and C
A= exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client}B= exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client}C= exists $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
ABCresult
0XX0
10X0
1100
1111
124 exists $NOTIFICATION_RECIPIENTS{$client} &&
125 exists $NOTIFICATION_LEVEL{$client}) {
126 0 ▶ unless (scalar($self->_getNotificationRecipients($client))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar $self->_getNotificationRecipients($client)) 0 0 0
127 0 $LOGGER->debug(1,"Cannot notify recipients for client [$client]: ".
128 "No recipients were specified.");
129 0 return 0;
130 }
131  
132 0 my @hosts = $self->_getNotificationHosts($client);
133  
134 0 ▶ unless (scalar(@hosts)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @hosts) 0 0 0
135 0 $LOGGER->debug(1,"Cannot notify recipients for client [$client]: ".
136 "No acceptable notification hosts [@hosts] were specified.");
137 0 return 0;
138 }
139  
140 0 my $ok = 0;
141
142 0 for my $host (@hosts) {
143 0 $LOGGER->debug(8,"Checking host [$host] against hostname [$HOSTNAME] ...\n");
144 0 ▶ $ok++ if $host eq $HOSTNAME;
Branch: 1 branch
BranchTrueFalseTotal
if $host eq $Net::Peep::Notifier::HOSTNAME 0 0 0
145 0 ▶ $ok++ if $host =~ /^(all|localhost|127\.0\.0\.1)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /^(all|localhost|127\.0\.0\.1)$/ 0 0 0
146 0 ▶ $ok = 0, last if $host eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $host eq "none" 0 0 0
147 }
148
149 0 my $status = $notification->status();
150 0 ▶ if ($NOTIFICATION_LEVEL{$client} eq 'crit' && $status ne 'crit') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq 'crit' and $status ne 'crit') { } 0 0 0
elsif ($Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq 'warn' and not $status =~ /^(warn|crit)$/) { } 0 0 0
Condition0%0/3
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "crit" and $status ne "crit"
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "crit" and $status ne "crit"
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "crit" $status ne "crit"
Truth table0%0/3
A and B
A= $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "crit"B= $status ne "crit"
ABresult
0X0
100
111
151 0 $LOGGER->debug(1,"Notification ignored: Notification level is [$status]. ".
152 "Notifications are only sent at [crit].");
153 0 return 1;
154 ▶ } elsif ($NOTIFICATION_LEVEL{$client} eq 'warn' && $status !~ /^(warn|crit)$/) {
Condition0%0/3
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "warn" and not $status =~ /^(warn|crit)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "warn" and not $status =~ /^(warn|crit)$/
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "warn" not $status =~ /^(warn|crit)$/
Truth table0%0/3
A and not(B)
A= $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "warn"B= not $status =~ /^(warn|crit)$/
ABresult
0X0
100
111
155 0 $LOGGER->debug(1,"Notification ignored: Notification level is [$status]. ".
156 "Notifications are only sent at [crit] or [warn].");
157 0 return 1;
158 } else {
159 # do nothing
160 }
161
162 0 my $return;
163
164 0 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 0 0 0
165
166 0 eval {
167
168 0 ▶ confess "Cannot notify recipients: No client was specified."
Branch: 1 branch
BranchTrueFalseTotal
unless $client 0 0 0
169 unless $client;
170 0 ▶ confess "Cannot notify recipients: No mail relays were specified."
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @Net::Peep::Notifier::SMTP_RELAYS 0 0 0
171 unless scalar(@SMTP_RELAYS);
172
173 0 $self->store($notification);
174
175 0 ▶ if ($self->_notificationExists($client)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_notificationExists($client)) { } 0 0 0
176 0 ▶ if ($self->_timeToSend($client) || $force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_timeToSend($client) or $force) { } 0 0 0
Condition0%0/3
$self->_timeToSend($client) or $force
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_timeToSend($client) or $force
$self->_timeToSend($client) $force
Truth table0%0/3
A or B
A= $self->_timeToSend($client)B= $force
ABresult
1X1
011
000
177 0 $return = $self->_notify($client);
178 } else {
179 0 $return = 1;
180 }
181 } else {
182 0 $return = $self->_notify($client);
183 }
184
185 };
186  
187 0 ▶ if ($@ || ! $return) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $return) 0 0 0
Condition0%0/3
$@ or not $return
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $return
$@ not $return
Truth table0%0/3
A or not(B)
A= $@B= not $return
ABresult
1X1
011
000
188 0 $LOGGER->log(ref($self),": Error generating notification: $@");
189 }
190
191 0 return $return;
192
193 } else {
194
195 0 $LOGGER->debug(1,"Notification ignored: [$HOSTNAME] was not among the list of acceptable notification hosts.");
196 0 return 1;
197
198 }
199  
200 } else {
201  
202 0 $LOGGER->debug(1,"Notification ignored: No notification information is available for client [$client].\n".
203 "\t(Possibly because no notification block was defined for the client in the Peep \n".
204 "\tconfiguration file.)");
205 0 return 1;
206  
207 }
208
209 } # end sub notify
210  
211 0 ▶sub _notify {
Subroutine _notify: not called CC=4 SCAR=30.0
212  
213 # notify the recipients of the notification
214 0 my $self = shift;
215 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
216
217 0 ▶ if (scalar($self->_getNotifications($client))) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->_getNotifications($client)) 0 0 0
218  
219 0 my $mailer = Net::Peep::Mail->new();
220
221 0 $mailer->smtp_server(@SMTP_RELAYS);
222 0 $mailer->from("Peep Notification <$USER\@$HOSTNAME>");
223 0 $mailer->to($self->_getNotificationRecipients($client));
224 0 $mailer->subject("[Peep Notification] $client on $HOSTNAME");
225 0 $mailer->body($self->_getBody($client));
226 0 ▶ if ($mailer->send()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mailer->send) { } 0 0 0
227 0 $self->_setSendTime($client);
228 0 $self->_garbageCollect($client);
229 0 return 1;
230 } else {
231 0 return 0;
232 }
233  
234 }
235  
236 } # end sub _notify
237  
238 0 ▶sub _getNotifications {
Subroutine _getNotifications: not called CC=6 SCAR=37.4
239  
240 # Return only those notifications exceeding the notification
241 # threshhold defined in the Peep configuration file for the
242 # specified client
243  
244 0 my $self = shift;
245 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
246  
247 0 ▶ return () unless $self->_notificationExists($client);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_notificationExists($client) 0 0 0
248  
249 0 ▶ my $level = $NOTIFICATION_LEVEL{$client}
Condition0%0/2
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} || confess("Notification level for client [$client] not found.")
l!l
00
MC/DC0%0/1
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} || confess("Notification level for client [$client] not found.")
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
Truth table0%0/2
A
A= $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client}
Aresult
11
00
250 || confess "Notification level for client [$client] not found.";
251  
252 0 ▶ if ($level eq 'crit') {
Branch: 2 branches
BranchTrueFalseTotal
if ($level eq 'crit') { } 0 0 0
elsif ($level eq 'warn') { } 0 0 0
253 0 return grep $_->status() eq 'crit', @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}};
254 } elsif ($level eq 'warn') {
255 0 return grep $_->status() =~ /warn|crit/, @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}};
256 } else {
257 0 return @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}};
258 }
259  
260 } # end sub _getNotifications
261  
262 0 ▶sub _getBody {
Subroutine _getBody: not called CC=3 SCAR=24.8
263  
264 0 my $self = shift;
265 0 my $client = shift;
266  
267 0 ▶ return undef unless $self->_notificationExists($client);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_notificationExists($client) 0 0 0
268  
269 0 my @notifications = $self->_getNotifications($client);
270  
271 0 my $n_notifications = scalar(@notifications);
272  
273 0 my $time = scalar(localtime(time()));
274  
275 0 my $body = <<"eop";
276 User: $USER
277 Host: $HOSTNAME
278 Client: $client
279 Time: $time
280 Notifications: $n_notifications
281  
282 eop
283  
284 ;
285  
286 0 my $i = 1;
287  
288 # reverse the order of notifications to get the most recent first
289 0 for my $notification (reverse @notifications) {
290  
291 0 my $status = ucfirst($notification->status());
292 0 my $message = $notification->message();
293 0 my $time = scalar(localtime($notification->datetime()));
294  
295 0 $body .= <<"eop";
296 \[Notification $i: $status at $time\]
297 $message
298  
299 eop
300  
301 ;
302  
303 0 $i++;
304  
305 }
306  
307 0 return $body;
308  
309 } # end sub _getBody
310  
311 0 ▶sub store {
Subroutine store: not called CC=2 SCAR=17.9
Pod undocumented
312  
313 # store failsafe information for future reference
314 0 my $self = shift;
315 0 my $notification = shift; # a Net::Peep::Notification object
316  
317 0 ▶ my $client = $notification->client() || confess "client not found";
Condition0%0/2
$notification->client || confess('client not found')
l!l
00
MC/DC0%0/1
$notification->client || confess('client not found')
$notification->client
Truth table0%0/2
A
A= $notification->client
Aresult
11
00
318 0 push @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}}, $notification;
319  
320 0 return 1;
321  
322 } # end sub store
323  
324 0 ▶sub _sendTimeExists {
Subroutine _sendTimeExists: not called CC=4 SCAR=30.0
325  
326 0 my $self = shift;
327 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
328
329 0 ▶ if (exists $NOTIFICATIONS->{$client} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{'SEND_TIME'}) { } 0 0 0
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
Truth table0%0/3
A and B
A= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}B= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
ABresult
0X0
100
111
330 exists $NOTIFICATIONS->{$client}->{'SEND_TIME'}) {
331 0 return 1;
332 } else {
333 0 return 0;
334 }
335  
336 } # end sub _sendTimeExists
337  
338 0 ▶sub _setSendTime {
Subroutine _setSendTime: not called CC=2 SCAR=17.9
339  
340 0 my $self = shift;
341 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
342 0 $NOTIFICATIONS->{$client}->{'SEND_TIME'} = time();
343  
344 } # end sub _setSendTime
345  
346 0 ▶sub _getSendTime {
Subroutine _getSendTime: not called CC=4 SCAR=30.0
347  
348 0 my $self = shift;
349 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
350  
351 0 ▶ if (exists $NOTIFICATIONS->{$client}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}) { } 0 0 0
352 0 ▶ if (exists $NOTIFICATIONS->{$client}->{'SEND_TIME'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{'SEND_TIME'}) { } 0 0 0
353 0 return $NOTIFICATIONS->{$client}->{'SEND_TIME'};
354 } else {
355 0 confess "Cannot find SEND_TIME key for client [$client]";
356 }
357 } else {
358 0 return undef;
359 }
360  
361 } # end sub _getSendTime
362  
363 0 ▶sub _garbageCollect {
Subroutine _garbageCollect: not called CC=4 SCAR=30.0
364  
365 # clear out old notification information
366  
367 0 my $self = shift;
368  
369 0 ▶ my $client = shift || confess "client not found";
Condition0%0/2
shift() || confess('client not found')
l!l
00
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
370 delete $NOTIFICATIONS->{$client}->{NOTIFICATIONS}
371 if exists $NOTIFICATIONS->{$client} &&
372 0 ▶ exists $NOTIFICATIONS->{$client}->{NOTIFICATIONS};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} 0 0 0
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}
Truth table0%0/3
A and B
A= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}B= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}
ABresult
0X0
100
111
373 0 $NOTIFICATIONS->{$client}->{NOTIFICATIONS} = [];
374  
375 0 return 1;
376  
377 } # end sub _garbageCollect
378  
379 0 ▶sub force {
Subroutine force: not called CC=5 SCAR=34.0
Pod undocumented
380  
381 # clear out any unsent notifications whether or not they're ready
382 # to be sent
383 0 my $self = shift;
384  
385 0 my $force = 1;
386  
387 0 my $n;
388  
389 0 for my $client (keys %$NOTIFICATIONS) {
390 0 ▶ if (exists $NOTIFICATIONS->{$client}->{'NOTIFICATIONS'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}) 0 0 0
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
Truth table0%0/3
A and B
A= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}B= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
ABresult
0X0
100
111
391 exists $NOTIFICATIONS->{$client}->{'SEND_TIME'}) {
392 0 my @notifications = @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}};
393 0 $n = @notifications;
394 0 ▶ $self->notify($notifications[0],$force) if @notifications;
Branch: 1 branch
BranchTrueFalseTotal
if @notifications 0 0 0
395 }
396 }
397  
398 0 return $n;
399  
400 } # end sub force
401  
402 0 ▶sub flush {
Subroutine flush: not called CC=4 SCAR=30.0
Pod undocumented
403  
404 # clear out any unsent notifications that are ready to be sent
405 0 my $notifier = Net::Peep::Notifier->new();
406  
407 0 for my $client (keys %$NOTIFICATIONS) {
408 0 ▶ if (exists $NOTIFICATIONS->{$client}->{'NOTIFICATIONS'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}) 0 0 0
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
Truth table0%0/3
A and B
A= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}B= exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
ABresult
0X0
100
111
409 exists $NOTIFICATIONS->{$client}->{'SEND_TIME'}) {
410 0 my @notifications = @{$NOTIFICATIONS->{$client}->{'NOTIFICATIONS'}};
411 0 $notifier->notify($client);
412 }
413 }
414  
415 } # end sub flush
416  
417 11 1;
418  
419 __END__
« blib/lib/Net/Peep/Client/Sysmonitor.pm ↑ Summary blib/lib/Net/Peep/Client/Logparser.pm »