root/lib/Resmon/Module/ZPOOLERRS.pm

Revision ae22e3bd765158b778bd93baa267afae17fe7fa2, 1.4 kB (checked in by Mark Harrison <mark@omniti.com>, 6 years ago)

Moving the fresh_status and set_status code outside of the modules themselves,
making module development simpler. Also fixed an issue with the fresh_status
function where it didn't return a cached message, and resmon showed nothing
for the message. refs #1

git-svn-id: https://labs.omniti.com/resmon/trunk@135 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::Module::ZPOOLERRS;
2 use Resmon::ExtComm qw/cache_command/;
3 use Resmon::Module;
4 use vars qw/@ISA/;
5 @ISA = qw/Resmon::Module/;
6
7 # Checks for zpool read write errors by using zpool status -x
8 # Will also notify if a zpool is degraded or not, similar to the basic zpool
9 # check.
10
11 # Sample configuration:
12 # ZPOOLERRS {
13 #   zpools : noop
14 # }
15
16 sub handler {
17     my $arg = shift;
18     my $unit = $arg->{'object'};
19     my $output = cache_command(
20         "zpool status -x", 600);
21     if($output) {
22             my $errstring = "";
23             my $currpool = "";
24             foreach my $line (split(/\n/, $output)) {
25                 if ($line =~ /(all pools are healthy)/) {
26                     return "OK", $1;
27                 }
28                 if ($line =~ /pool: (.+)$/) {
29                     # Pool name
30                     $currpool = $1;
31                 } elsif ($line =~ /state: (.+)$/) {
32                     # Pool state
33                     $errstring .= "$currpool:$1 ";
34                 } elsif ($line =~
35                     /([a-z0-9]+)\s+([A-Z]+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
36                     # Pool errors
37                     if ($3 != 0 || $4 != 0 || $5 != 0) {
38                         $errstring .= "- $1:$2 w/Errs: R:$3 W:$4 Chk:$5 ";
39                     }
40                 }
41             }
42             chop($errstring);
43             return "BAD", $errstring;
44     }
45     return "BAD", "no data"
46 };
47 1;
Note: See TracBrowser for help on using the browser.