68 unless ( -e $opt{logfile} ) { |
68 unless ( -e $opt{logfile} ) { |
69 print "RSNAPSHOT CRITICAL: logfile '$opt{logfile}' - don't exists\n"; |
69 print "RSNAPSHOT CRITICAL: logfile '$opt{logfile}' - don't exists\n"; |
70 exit $ERRORS{CRITICAL}; |
70 exit $ERRORS{CRITICAL}; |
71 } |
71 } |
72 |
72 |
73 if ( (localtime)[3] == 1 ) { |
73 if ( (localtime)[3] == 1 || (localtime)[3] == 2 ) { |
74 $opt{logfile} = "$opt{logfile}.1.gz"; |
74 $opt{logfile} = "$opt{logfile}.1.gz"; |
75 } |
75 } |
76 |
76 |
77 if ( -z $opt{logfile} ) { |
77 if ( -z $opt{logfile} ) { |
78 print "RSNAPSHOT WARNING: logfile $opt{logfile} - has zero size\n"; |
78 print "RSNAPSHOT WARNING: logfile $opt{logfile} - has zero size\n"; |
79 exit $ERRORS{WARNING}; |
79 exit $ERRORS{WARNING}; |
80 } |
80 } |
81 |
81 |
82 if ( ( time() - ( stat( $opt{logfile} ) )[9] ) > $opt{seconds} ) { |
82 if ( !$opt{logfile} =~ /\.gz$/ ) { |
83 print |
83 if ( ( time() - ( stat( $opt{logfile} ) )[9] ) > $opt{seconds} ) { |
|
84 print |
84 "RSNAPSHOT CRITICAL: logfile $opt{logfile} - last modification is longer than $opt{seconds} seconds ago\n"; |
85 "RSNAPSHOT CRITICAL: logfile $opt{logfile} - last modification is longer than $opt{seconds} seconds ago\n"; |
85 exit $ERRORS{CRITICAL}; |
86 exit $ERRORS{CRITICAL}; |
|
87 } |
86 } |
88 } |
87 |
89 |
88 my $status = get_status( $opt{logfile} ); |
90 my $status = get_status( $opt{logfile} ); |
89 report($status); |
91 report($status); |
90 } |
92 } |
97 unless ($date) { |
99 unless ($date) { |
98 print "RSNAPSHOT CRITICAL: can't parse date [$opt{date}]\n"; |
100 print "RSNAPSHOT CRITICAL: can't parse date [$opt{date}]\n"; |
99 exit $ERRORS{CRITICAL}; |
101 exit $ERRORS{CRITICAL}; |
100 } |
102 } |
101 |
103 |
102 if ($logfile =~ /\.gz$/) { |
104 if ( $logfile =~ /\.gz$/ ) { |
103 my $gz = gzopen($logfile, "rb") |
105 my $gz = gzopen( $logfile, "rb" ) |
104 or print "RSNAPSHOT CRITICAL: Cannot open $logfile: $gzerrno\n" and exit $ERRORS{CRITICAL}; |
106 or print "RSNAPSHOT CRITICAL: Cannot open $logfile: $gzerrno\n" |
105 while ($gz->gzreadline($_) > 0) { |
107 and exit $ERRORS{CRITICAL}; |
106 next unless (/^\[$date/); |
108 while ( $gz->gzreadline($_) > 0 ) { |
107 if (/^\[$date:.*ERROR/) { |
109 next unless (/^\[$date/); |
108 $error = $_; |
110 if (/^\[$date:.*ERROR/) { |
109 last; |
111 $error = $_; |
110 } |
112 last; |
111 $found_date = 1; |
113 } |
112 } |
114 $found_date = 1; |
113 print "RSNAPSHOT CRITICAL: Error reading from $logfile: $gzerrno\n" and exit $ERRORS{CRITICAL} |
115 } |
114 if $gzerrno != Z_STREAM_END; |
116 print "RSNAPSHOT CRITICAL: Error reading from $logfile: $gzerrno\n" |
115 $gz->gzclose(); |
117 and exit $ERRORS{CRITICAL} |
116 } else { |
118 if $gzerrno != Z_STREAM_END; |
117 open( FH, $logfile ) |
119 $gz->gzclose(); |
118 or print "RSNAPSHOT CRITICAL: $logfile - $!\n" and exit $ERRORS{CRITICAL}; |
120 } |
119 while (<FH>) { |
121 else { |
120 next unless (/^\[$date/); |
122 open( FH, $logfile ) |
121 if (/^\[$date:.*ERROR/) { |
123 or print "RSNAPSHOT CRITICAL: $logfile - $!\n" |
122 $error = $_; |
124 and exit $ERRORS{CRITICAL}; |
123 last; |
125 while (<FH>) { |
124 } |
126 next unless (/^\[$date/); |
125 $found_date = 1; |
127 if (/^\[$date:.*ERROR/) { |
126 } |
128 $error = $_; |
127 close(FH); |
129 last; |
128 } |
130 } |
|
131 $found_date = 1; |
|
132 } |
|
133 close(FH); |
|
134 } |
129 |
135 |
130 unless ($found_date) { |
136 unless ($found_date) { |
131 $error = "can't find rsnapshot run from [$date]\n"; |
137 $error = "can't find rsnapshot run from [$date]\n"; |
132 } |
138 } |
133 |
139 |