Thursday, June 27, 2013

Monitoring Solaris zpools with HP OMW


Recently, we've had a few degraded zpools go unnoticed. They went unnoticed because our HP agents weren't monitoring their state (seems fair enough). After having a poke around what logs were available natively (not much) I broached the subject with our Tools Admin. He's always happy to help, so we knocked up the following perl script that gets executed every 15 minutes and reports in the event a zpool is in any state other than ONLINE.

use strict;

sub get_zp_list {
     my $pool_names = `zpool list -H -o name`;
     if ($pool_names eq "no pools available\n") {
          return $pool_names;
     }
     my @pool_names = split("\n",$pool_names);
     return @pool_names;
}

sub get_zp_health {
     my $pool_name = shift;
     my $result = `zpool list -H -o health $pool_name`;
     chomp $result;
     return $result;
}


#START PROCESS>>>

if ( ! -f "/sbin/zpool") {
     $ConsoleMessage->Severity("Minor");
     $ConsoleMessage->Application("zfspool");
     $ConsoleMessage->MsgText("zpools not supported in this sun release");
     $ConsoleMessage->Send();
     exit 1;
}

zpcheck();

sub zpcheck {
     my @zpools = get_zp_list();
     if ($zpools[0] eq "no pools available\n") {
          $ConsoleMessage->Severity("Minor");
          $ConsoleMessage->Application("zfspool");
          $ConsoleMessage->MsgText("no pools defined!");
          $ConsoleMessage->Send();
          return 0;
     }

     foreach my $pool (@zpools) {
          my $health = get_zp_health($pool);
          if ( $health eq "ONLINE" ) {
               # do nothing
          } else {
               $health = "unknown" if (!$health);
               # alarm in HP OMW
               $ConsoleMessage->Severity("Major");
               $ConsoleMessage->Application("zfspool");
               $ConsoleMessage->Object("$pool");
               $ConsoleMessage->MsgText("DNP- Problem with zpool $pool detected, status is $health");
               $ConsoleMessage->Send();
          }
     }
}

No comments:

Post a Comment