70 my ( $binary, $devices, $warning, $critical ) = @_; |
69 my ( $binary, $devices, $warning, $critical ) = @_; |
71 my $rc; |
70 my $rc; |
72 my %temp; |
71 my %temp; |
73 |
72 |
74 if ( !-x $binary ) { |
73 if ( !-x $binary ) { |
75 say "$NAME CRITICAL: $binary - not found or not executable"; |
74 print "$NAME CRITICAL: $binary - not found or not executable\n"; |
76 exit $ERRORS{CRITICAL}; |
75 exit $ERRORS{CRITICAL}; |
77 } |
76 } |
78 |
77 |
79 my @devices = split( /,/, $devices ); |
78 my @devices = split( /,/, $devices ); |
80 |
79 |
81 foreach my $dev (@devices) { |
80 foreach my $dev (@devices) { |
82 if ( !-r $dev ) { |
81 if ( !-r $dev ) { |
83 say |
82 print |
84 "$NAME CRITICAL: $dev - not exists or not read permission is granted"; |
83 "$NAME CRITICAL: $dev - not exists or not read permission is granted\n"; |
85 exit $ERRORS{CRITICAL}; |
84 exit $ERRORS{CRITICAL}; |
86 } |
85 } |
87 my @line = grep { /^$dev/ } `$binary $dev`; |
86 my @line = grep { /^$dev/ } `$binary $dev`; |
88 |
87 |
89 if ( $line[0] ) { |
88 if ( $line[0] ) { |
122 push @perf, "$dev=$temp{$dev}{'rc'}{'2'};$warning;$critical"; |
121 push @perf, "$dev=$temp{$dev}{'rc'}{'2'};$warning;$critical"; |
123 } |
122 } |
124 } |
123 } |
125 |
124 |
126 if ($crit) { |
125 if ($crit) { |
127 say "$NAME CRITICAL: " |
126 print "$NAME CRITICAL: " |
128 . join( ' ', @output ) . " | " |
127 . join( ' ', @output ) . " | " |
129 . join( ' ', @perf ); |
128 . join( ' ', @perf ) . "\n"; |
130 exit $ERRORS{CRITICAL}; |
129 exit $ERRORS{CRITICAL}; |
131 } |
130 } |
132 elsif ($warn) { |
131 elsif ($warn) { |
133 say "$NAME WARNING: " |
132 print "$NAME WARNING: " |
134 . join( ' ', @output ) . " | " |
133 . join( ' ', @output ) . " | " |
135 . join( ' ', @perf ); |
134 . join( ' ', @perf ) . "\n"; |
136 exit $ERRORS{WARNING}; |
135 exit $ERRORS{WARNING}; |
137 } |
136 } |
138 |
137 |
139 say "$NAME OK: " . join( ' ', @output ) . " | " . join( ' ', @perf ); |
138 print "$NAME OK: " . join( ' ', @output ) . " | " . join( ' ', @perf ) . "\n"; |
140 exit $ERRORS{OK}; |
139 exit $ERRORS{OK}; |
141 } |
140 } |
142 |
141 |
143 sub version($$) { |
142 sub version($$) { |
144 my ( $progname, $version ) = @_; |
143 my ( $progname, $version ) = @_; |
145 |
144 |
146 say <<_VERSION; |
145 print <<_VERSION; |
147 $progname version $version |
146 $progname version $version |
148 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. |
147 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. |
149 |
148 |
150 $ME comes with ABSOLUTELY NO WARRANTY. This is free software, |
149 $ME comes with ABSOLUTELY NO WARRANTY. This is free software, |
151 and you are welcome to redistribute it under certain conditions. |
150 and you are welcome to redistribute it under certain conditions. |