lib/HON/EC2/Snapshots/Monitoring.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 14 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 97.1% 68 / 70 CC 12 SCAR 16.6
CC
12
Cov
98%
isLogOk
7.0
findLogsOfTheDay
6.0
BEGIN
1.0
CRAP 5.2
↑ Summary script/hon-ec2-snapshots-monitoring.pl »
1 package HON::EC2::Snapshots::Monitoring;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 HON::EC2::Snapshots::Monitoring - Log file monitoring
10  
11 =head1 VERSION
12  
13 Version 0.03
14  
15 =cut
16  
17 2 our $VERSION = '0.04';
18  
19 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 our @EXPORT_OK = qw/findLogsOfTheDay isLogOk/;
21  
22 =head1 SYNOPSIS
23  
24 use HON::EC2::Snapshots::Monitoring;
25  
26 my @logs = findLogsOfTheDay(\@lines, '12-18-2015');
27 isLogOk(@logs);
28  
29 =head1 DESCRIPTION
30  
31 Several utilities functions
32  
33 =head1 SUBROUTINES/METHODS
34  
35 =head2 findLogsOfTheDay
36  
37 Find logs of the day
38  
39 =cut
40  
41 3 ▶sub findLogsOfTheDay {
Subroutine findLogsOfTheDay: called CC=6 SCAR=17.9
Pod documented
42 3 my ( $refLines, $date ) = @_;
43 3 my @logsOfTheDay = ();
44 3 my $keepLogs = 0;
45  
46 3 foreach my $line ( @{$refLines} ) {
47 151 ▶ if ( $line =~ m/Starting\s\w+\sBackup\s--\s(\d{1,2}-\d{2}-\d{4})/xmsgi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Starting\s\w+\sBackup\s--\s(\d{1,2}-\d{2}-\d{4})/gimsx) 9 142 151
48 9 ▶ if ( $1 eq $date ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq $date) 3 6 9
49 3 $keepLogs = 1;
50 }
51 }
52  
53 151 ▶ if ( $keepLogs == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keepLogs == 1) 73 78 151
54 73 push @logsOfTheDay, $line;
55 }
56  
57 151 ▶ if ( $line =~ m/Backup\sdone/xmsgi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Backup\sdone/gimsx) 9 142 151
58 9 $keepLogs = 0;
59 }
60 }
61 3 return @logsOfTheDay;
62 }
63  
64 =head2 isLogOk
65  
66 Verify specific part of the log
67  
68 =cut
69  
70 3 ▶sub isLogOk {
Subroutine isLogOk: called CC=7 SCAR=19.5
Pod documented
71 3 my @lines = @_;
72 3 my $isSnapshot = 0;
73 3 my $isTagging = 0;
74 3 my $isPurging = 0;
75  
76 3 foreach my $line (@lines) {
77 73 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Snapshots\staken\sby\sec2-automate-backup-awscli[.]sh/gimsx) 2 71 73
78 $line =~ m/^Snapshots\staken\sby\sec2-automate-backup-awscli[.]sh/xmsgi )
79 {
80 2 $isSnapshot = 1;
81 }
82 73 ▶ if ( $line =~ m/Tagging\sSnapshot\ssnap-/xmsgi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Tagging\sSnapshot\ssnap-/gimsx) 2 71 73
83 2 $isTagging = 1;
84 }
85 73 ▶ if ( $line =~ m/Snapshot\sPurging\sis/xmsgi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Snapshot\sPurging\sis/gimsx) 1 72 73
86 1 $isPurging = 1;
87 }
88 }
89  
90 3 ▶ return ( $isSnapshot and $isTagging and $isPurging );
Condition83%5/6
$isSnapshot && $isTagging && $isPurging
!ll&&!rl&&r
201
$isSnapshot and $isTagging
!ll&&!rl&&r
111
MC/DC66%2/3
$isSnapshot && $isTagging && $isPurging
$isSnapshot $isTagging $isPurging
Truth table75%3/4
A and B && C
A= $isSnapshotB= $isTaggingC= $isPurging
ABCresult
0XX0
10X0
1100
1111
91 }
92  
93 =head1 AUTHOR
94  
95 William Belle, C<< <william.belle at gmail.com> >>
96  
97 =head1 BUGS AND LIMITATIONS
98  
99 Please report any bugs or feature requests to C<bug-hon-ec2-snapshots-monitoring at rt.cpan.org>, or through
100 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HON-EC2-Snapshots-Monitoring>. I will be notified, and then you'll
101 automatically be notified of progress on your bug as I make changes.
102  
103  
104  
105  
106 =head1 SUPPORT
107  
108 You can find documentation for this module with the perldoc command.
109  
110 perldoc HON::EC2::Snapshots::Monitoring
111  
112  
113 You can also look for information at:
114  
115 =over 4
116  
117 =item * RT: CPAN's request tracker (report bugs here)
118  
119 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HON-EC2-Snapshots-Monitoring>
120  
121 =item * AnnoCPAN: Annotated CPAN documentation
122  
123 L<http://annocpan.org/dist/HON-EC2-Snapshots-Monitoring>
124  
125 =item * CPAN Ratings
126  
127 L<http://cpanratings.perl.org/d/HON-EC2-Snapshots-Monitoring>
128  
129 =item * Search CPAN
130  
131 L<http://search.cpan.org/dist/HON-EC2-Snapshots-Monitoring/>
132  
133 =back
134  
135  
136 =head1 ACKNOWLEDGEMENTS
137  
138  
139 =head1 LICENSE AND COPYRIGHT
140  
141 Copyright 2015 William Belle.
142  
143 This program is free software; you can redistribute it and/or modify
144 it under the terms of the GNU General Public License as published by
145 the Free Software Foundation; version 2 dated June, 1991 or at your option
146 any later version.
147  
148 This program is distributed in the hope that it will be useful,
149 but WITHOUT ANY WARRANTY; without even the implied warranty of
150 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151 GNU General Public License for more details.
152  
153 A copy of the GNU General Public License is available in the source tree;
154 if not, write to the Free Software Foundation, Inc.,
155 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
156  
157  
158 =cut
159  
160 2 1; # End of HON::EC2::Snapshots::Monitoring
↑ Summary script/hon-ec2-snapshots-monitoring.pl »