38 my $VERSION = "0.1"; |
42 my $VERSION = "0.1"; |
39 |
43 |
40 sub get_status($); |
44 sub get_status($); |
41 sub report($); |
45 sub report($); |
42 |
46 |
43 my $opt = { |
47 my %opt = ( |
44 fs => undef, |
48 fs => undef, |
45 warning => 5, |
49 warning => 5, |
46 critical => 1, |
50 critical => 1, |
47 twarning => "5days", |
51 twarning => "5days", |
48 tcritical => "1day", |
52 tcritical => "1day", |
49 binary => "/sbin/tune2fs" |
53 binary => "/sbin/tune2fs" |
50 }; |
54 ); |
51 |
55 |
52 MAIN: { |
56 MAIN: { |
53 Getopt::Long::Configure('bundling'); |
57 Getopt::Long::Configure('bundling'); |
54 GetOptions( |
58 GetOptions( |
55 "f|fs=s" => \$opt->{fs}, |
59 "f|fs=s" => \$opt{fs}, |
56 "w|warning=i" => \$opt->{warning}, |
60 "w|warning=i" => \$opt{warning}, |
57 "c|critical=i" => \$opt->{critical}, |
61 "c|critical=i" => \$opt{critical}, |
58 "W|twarning=s" => \$opt->{twarning}, |
62 "W|twarning=s" => \$opt{twarning}, |
59 "C|tcritical=s" => \$opt->{tcritical}, |
63 "C|tcritical=s" => \$opt{tcritical}, |
60 "b|binary=s" => \$opt->{binary}, |
64 "b|binary=s" => \$opt{binary}, |
61 "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, |
65 "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, |
62 "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, |
66 "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, |
63 "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } |
67 "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } |
64 ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
68 ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
65 |
69 |
66 $opt->{fs} // pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
70 ### %opt |
67 |
71 |
68 report( get_status( $opt->{fs} ) ); |
72 report( get_status( $opt{fs} ) ); |
69 } |
73 } |
70 |
74 |
71 sub report($) { |
75 sub report($) { |
72 my $status = shift; |
76 my $status = shift; |
73 my @output = (); |
77 my @output = (); |
111 } |
115 } |
112 exit $ERRORS{OK}; |
116 exit $ERRORS{OK}; |
113 } |
117 } |
114 |
118 |
115 sub get_status($) { |
119 sub get_status($) { |
116 my $fs = shift; |
120 my @fs = split( /,/, shift ); |
117 my @fs = split( /,/, $fs ); |
|
118 |
121 |
119 my %values = (); |
122 my %values = (); |
120 |
123 |
121 foreach $fs (@fs) { |
124 foreach my $fs (@fs) { |
122 unless ( -b $fs && -r $fs ) { |
125 unless ( -b -r $fs ) { |
123 print |
126 say "FSCK CRITICAL $fs - not a block device or no read permission is granted"; |
124 "FSCK CRITICAL $fs - not exists or not read permission is granted"; |
|
125 exit $ERRORS{CRITICAL}; |
127 exit $ERRORS{CRITICAL}; |
126 } |
128 } |
127 foreach ( |
129 foreach ( |
128 grep |
130 grep |
129 /^Mount count:\s+\d+|Maximum mount count:\s+\d+|Next check after:\s+/i |
131 /^Mount count:\s+\d+|Maximum mount count:\s+\d+|Next check after:\s+/i |
130 => `$opt->{binary} -l $fs` ) |
132 => `$opt{binary} -l $fs` ) |
131 { |
133 { |
132 chomp; |
134 chomp; |
133 my ( $index, $value ) = split( /:/, $_, 2 ); |
135 my ( $index, $value ) = split( /\s*:\s*/, $_, 2 ); |
134 ( $value = $value ) =~ s/^\s+//; |
|
135 $values{$fs}{$index} = $value; |
136 $values{$fs}{$index} = $value; |
136 } |
137 } |
137 } |
138 } |
138 |
139 |
139 my $w_time = DateCalc( "today", "+ $opt->{twarning}" ); |
140 ### %values |
140 my $c_time = DateCalc( "today", "+ $opt->{tcritical}" ); |
141 |
141 |
142 my $w_time = DateCalc( "today", "+ $opt{twarning}" ); |
142 foreach $fs ( keys %values ) { |
143 my $c_time = DateCalc( "today", "+ $opt{tcritical}" ); |
|
144 |
|
145 foreach my $fs ( keys %values ) { |
143 my $mounts = |
146 my $mounts = |
144 $values{$fs}{'Maximum mount count'} - $values{$fs}{'Mount count'}; |
147 $values{$fs}{'Maximum mount count'} - $values{$fs}{'Mount count'}; |
145 my $next_check_after = ParseDate( $values{$fs}{'Next check after'} ); |
148 my $next_check_after = ParseDate( $values{$fs}{'Next check after'} ); |
146 |
149 |
147 push( @{ $values{$fs}{mounts} }, $mounts ); |
150 push( @{ $values{$fs}{mounts} }, $mounts ); |
148 |
151 |
149 if ( $mounts <= $opt->{critical} ) { |
152 if ( $mounts <= $opt{critical} ) { |
150 push( @{ $values{$fs}{mstatus} }, "CRITICAL" ); |
153 push( @{ $values{$fs}{mstatus} }, "CRITICAL" ); |
151 } |
154 } |
152 elsif ( $mounts <= $opt->{warning} ) { |
155 elsif ( $mounts <= $opt{warning} ) { |
153 push( @{ $values{$fs}{mstatus} }, "WARNING" ); |
156 push( @{ $values{$fs}{mstatus} }, "WARNING" ); |
154 } |
157 } |
155 else { |
158 else { |
156 push( @{ $values{$fs}{mstatus} }, "OK" ); |
159 push( @{ $values{$fs}{mstatus} }, "OK" ); |
157 } |
160 } |