| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 11 | ▶ | $USER = $ENV{'USER'} ? $ENV{'USER'} : 'peep'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (exists $NOTIFICATIONS->{$client}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | unless (exists $NOTIFICATION_RECIPIENTS{$client}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return wantarray ? @{$NOTIFICATION_RECIPIENTS{$client}} : $NOTIFICATION_RECIPIENTS{$client}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless (exists $NOTIFICATION_HOSTS{$client}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return wantarray ? @{$NOTIFICATION_HOSTS{$client}} : $NOTIFICATION_HOSTS{$client}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('notification not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
$notification->client || confess('client not found')
$notification->client
Truth table0%0/2
A
A= $notification->client
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (exists $NOTIFICATION_HOSTS{$client} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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}
exists $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} and exists $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | exists $NOTIFICATION_RECIPIENTS{$client} && | ||||||||||||||||||||||||||||||||||||||||||
| 125 | exists $NOTIFICATION_LEVEL{$client}) { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | unless (scalar($self->_getNotificationRecipients($client))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $ok++ if $host =~ /^(all|localhost|127\.0\.0\.1)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $ok = 0, last if $host eq 'none'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $status = $notification->status(); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($NOTIFICATION_LEVEL{$client} eq 'crit' && $status ne 'crit') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} eq "crit" and $status ne "crit"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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)$/
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)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | confess "Cannot notify recipients: No client was specified." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | unless $client; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | confess "Cannot notify recipients: No mail relays were specified." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | unless scalar(@SMTP_RELAYS); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->store($notification); | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($self->_notificationExists($client)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ($self->_timeToSend($client) || $force) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_timeToSend($client) or $force
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$@ or not $return
MC/DC0%0/2
$@ or not $return
$@
not $return
Truth table0%0/3
A or not(B)
A= $@B= not $return
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (scalar($self->_getNotifications($client))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return () unless $self->_notificationExists($client); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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.")
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | || confess "Notification level for client [$client] not found."; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ($level eq 'crit') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
$notification->client || confess('client not found')
$notification->client
Truth table0%0/2
A
A= $notification->client
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if (exists $NOTIFICATIONS->{$client} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if (exists $NOTIFICATIONS->{$client}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if (exists $NOTIFICATIONS->{$client}->{'SEND_TIME'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || confess('client not found')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | delete $NOTIFICATIONS->{$client}->{NOTIFICATIONS} | ||||||||||||||||||||||||||||||||||||||||||
| 371 | if exists $NOTIFICATIONS->{$client} && | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | exists $NOTIFICATIONS->{$client}->{NOTIFICATIONS}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"NOTIFICATIONS"} and exists $Net::Peep::Notifier::NOTIFICATIONS->{$client}{"SEND_TIME"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||