Munin HP plugin

De Linux Server Wiki
Aller à la navigation Aller à la recherche

hpacu HP Array Controllers

#!/usr/bin/env perl
#
# hpacu - Munin plugin for HP Array Controllers
#
# Copyright (C) 2010 Magnus Hagander
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 NAME

hpacu - Munin plugin to monitor HP Array Controllers

=head1 CONFIGURATION

The plugin needs to be able to execute /usr/sbin/hpacucli, which requires
root permissions. The following configuration is needed:

  [hpacu]
  user=root

=head1 INTERPRETATION

The graph will show information about number of controllers,
logical drives and physical drives that are ok or degraded.

=head1 MAGIC MARKERS

 #%# family=contrib

=head1 AUTHOR

Magnus Hagander <magnus@hagander.net>

=head1 LICENSE

GPLv2

=cut

use strict;
use warnings;

use Munin::Plugin;

if ( $ARGV[0] and $ARGV[0] eq "autoconf") {
   print "no\n";
   exit(0);
}

if ( $ARGV[0] and $ARGV[0] eq "config") {
   print "graph_title HP Smart Array\n";
   print "graph_category disk\n";
   print "hpacu_controllers_ok.label Controllers OK\n";
   print "hpacu_controllers_ok.type GAUGE\n";
   print "hpacu_controllers_ok.min 0\n";
   print "hpacu_controllers_deg.label Controllers degraded\n";
   print "hpacu_controllers_deg.type GAUGE\n";
   print "hpacu_controllers_deg.min 0\n";
   print "hpacu_controllers_deg.critical 1\n";
   print "hpacu_logicaldrives_ok.label Logical Drives OK\n";
   print "hpacu_logicaldrives_ok.type GAUGE\n";
   print "hpacu_logicaldrives_ok.min 0\n";
   print "hpacu_logicaldrives_deg.label Logical Drives degraded\n";
   print "hpacu_logicaldrives_deg.type GAUGE\n";
   print "hpacu_logicaldrives_deg.min 0\n";
   print "hpacu_logicaldrives_deg.critical 1\n";
   print "hpacu_physicaldrives_ok.label Physical Drives OK\n";
   print "hpacu_physicaldrives_ok.type GAUGE\n";
   print "hpacu_physicaldrives_ok.min 0\n";
   print "hpacu_physicaldrives_deg.label Physical Drives degraded\n";
   print "hpacu_physicaldrives_deg.type GAUGE\n";
   print "hpacu_physicaldrives_deg.min 0\n";
   print "hpacu_physicaldrives_deg.critical 1\n";
   exit(0);
}

my @slots;
open(HPACU, "/usr/sbin/hpacucli controller all show |") || die "Could not run hpacucli\n";
while (<HPACU>) {
   if (/Smart Array.* in Slot (\d+)/) {
      push @slots, $1;
   }
}
close(HPACU);

my $controllers_ok = 0;
my $controllers_degrad = 0;
my $logicaldrives_ok = 0;
my $logicaldrives_degrad = 0;
my $physicaldrives_ok = 0;
my $physicaldrives_degrad = 0;
my $controllers_msg = '';
my $logicaldrives_msg = '';
my $physicaldrives_msg = '';

foreach my $slot (@slots) {
   open(HPACU, "/usr/sbin/hpacucli controller slot=$slot show |") || die "Could not run hpacucli\n";
   my $ok = 1;
   while (<HPACU>) {
      if (/^\s+(Controller Status|Cache Status|Battery\/Capacitor Status):\s+([^\s]+)/) {
         unless ($2 eq "OK") {
            $ok = 0;
            $controllers_msg .= "Controller $slot, $1: $2\n";
         }
      }
   }
   close(HPACU);
   if ($ok) { $controllers_ok++ } else { $controllers_degrad++ }

   # Check logical drives
   open(HPACU, "/usr/sbin/hpacucli controller slot=$slot logicaldrive all show |") || die "Could not run hpacucli\n";
   while (<HPACU>) {
      if (/logicaldrive \d+ \(.*, .*, (.*)\)/) {
         if ($1 eq "OK") {
            $logicaldrives_ok++;
         } else {
            $logicaldrives_degrad++;
            $logicaldrives_msg .= $_;
         }
      }
   }

   # Finally, check physical drives
   open(HPACU, "/usr/sbin/hpacucli controller slot=$slot physicaldrive all show |") || die "Could not run hpacucli\n";
   while (<HPACU>) {
      if (/physicaldrive .* \(.*, .*, .*, (.*)\)/) {
         if ($1 eq "OK") {
            $physicaldrives_ok++;
         } else {
            $physicaldrives_degrad++;
            $physicaldrives_msg .= $_;
         }
      }
    }
   close(HPACU);
}

$controllers_msg =~ s/\n/ :: /g;
$logicaldrives_msg =~ s/\n/ :: /g;
$physicaldrives_msg =~ s/\n/ :: /g;

print "hpacu_controllers_ok.value $controllers_ok\n";
print "hpacu_controllers_deg.value $controllers_degrad\n";
print "hpacu_controllers_deg.extinfo $controllers_msg\n" if ($controllers_msg);
print "hpacu_logicaldrives_ok.value $logicaldrives_ok\n";
print "hpacu_logicaldrives_deg.value $logicaldrives_degrad\n";
print "hpacu_logicaldrives_deg.extinfo $logicaldrives_msg\n" if ($logicaldrives_msg);
print "hpacu_physicaldrives_ok.value $physicaldrives_ok\n";
print "hpacu_physicaldrives_deg.value $physicaldrives_degrad\n";
print "hpacu_physicaldrives_deg.extinfo $physicaldrives_msg\n" if ($physicaldrives_msg);

hpfan - Munin plugin for HP server fans

#!/usr/bin/env perl
#
# hpfan - Munin plugin for HP server fans
#
# Copyright (C) 2010 Magnus Hagander
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 NAME

hpfan - Munin plugin to monitor HP server fans

=head1 CONFIGURATION

The plugin needs to be able to execute /sbin/hplog, which requires
root permissions. The following configuration is needed:

  [hpfan]
  user=root

=head1 INTERPRETATION

The graph will show information about how many fans are ok and how
many are degratded.
It does not, currently, show the speed of the fans.

=head1 MAGIC MARKERS

 #%# family=contrib

=head1 AUTHOR

Magnus Hagander <magnus@hagander.net>

=head1 LICENSE

GPLv2

=cut

use strict;
use warnings;

use Munin::Plugin;

if ( $ARGV[0] and $ARGV[0] eq "autoconf") {
   print "no\n";
   exit(0);
}

if ( $ARGV[0] and $ARGV[0] eq "config") {
   print "graph_title HP Fans\n";
   print "graph_category sensors\n";
   print "ok.label Fans OK\n";
   print "ok.type GAUGE\n";
   print "ok.min 0\n";
   print "degraded.label Fans degraded\n";
   print "degraded.type GAUGE\n";
   print "degraded.min 0\n";
   print "degraded.critical 1\n";
   exit(0);
}

open(HPLOG, "/sbin/hplog -f |") || die "Could not run hplog\n";
my $ok=0;
my $degraded=0;

while (<HPLOG>) {
   next if /^\s*$/;
   next if /^\s*ID/;
   if (/\s+(Normal|Nominal)\s+/) {
      $ok++;
   }
   elsif (/\s+Absent\s+/) {
      # unknown, we don't track that
   }
   else {
      $degraded++;
   }
}
close(HPLOG);

print "ok.value $ok\n";
print "degraded.value $degraded\n";

hppower

==
#!/usr/bin/env perl
#
# hppower - Munin plugin for HP server power supplies
#
# Copyright (C) 2010 Magnus Hagander
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 NAME

hppower - Munin plugin to monitor HP server fans

=head1 CONFIGURATION

The plugin needs to be able to execute /sbin/hplog, which requires
root permissions. The following configuration is needed:

  [hppower]
  user=root

=head1 INTERPRETATION

The graph will show information about how many power supplies are ok and how
many are degratded.

=head1 MAGIC MARKERS

 #%# family=contrib

=head1 AUTHOR

Magnus Hagander <magnus@hagander.net>

=head1 LICENSE

GPLv2

=cut

use strict;
use warnings;

use Munin::Plugin;

if ( $ARGV[0] and $ARGV[0] eq "autoconf") {
   print "no\n";
   exit(0);
}

if ( $ARGV[0] and $ARGV[0] eq "config") {
   print "graph_title HP Power Supplies\n";
   print "graph_category sensors\n";
   print "ok.label Power Supplies OK\n";
   print "ok.type GAUGE\n";
   print "ok.min 0\n";
   print "degraded.label Power Supplies degraded\n";
   print "degraded.type GAUGE\n";
   print "degraded.min 0\n";
   print "degraded.critical 1\n";
   exit(0);
}

open(HPLOG, "/sbin/hplog -p |") || die "Could not run hplog\n";
my $ok=0;
my $degraded=0;

while (<HPLOG>) {
   next if /^\s*$/;
   next if /^\s*ID/;
   if (/\s+(Normal|Nominal)\s+/) {
      $ok++;
   }
   elsif (/\s+Absent\s+/) {
      # unknown, we don't track that
   }
   else {
      $degraded++;
   }
}
close(HPLOG);

print "ok.value $ok\n";
print "degraded.value $degraded\n";

hptemp

diff from https://github.com/mhagander/munin-plugins:

<    if (/^\s*(\d+)\s*Basic Sensor\s+(CPU \(\d+\)|Ambient|Processor Zone|Memory Board|System Board|Pwr\. Supply Bay|I\/O Zone|SCSI Backplane)\s+(\S+)\s+\d+F\/\s*(\d+)C\s+\d+F\/\s*(\d+)C/) {
---
>    if (/^\s*(\d+)\s*Basic Sensor\s+(CPU \(\d+\)|Processor Zone|I\/O Zone)\s+(\S+)\s+\d+F\/\s*(\d+)C\s+\d+F\/\s*(\d+)C/) {

working plugin:

#!/usr/bin/env perl
#
# hptemp - Munin plugin for HP server temperature 
#
# Copyright (C) 2010 Magnus Hagander
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 NAME

hptemp - Munin plugin to monitor HP server temp 

=head1 CONFIGURATION

The plugin needs to be able to execute /sbin/hplog, which requires
root permissions. The following configuration is needed:

  [hptemp]
  user=root

=head1 INTERPRETATION

The graphs will show the temperature measured at different locations
in the server.

=head1 MAGIC MARKERS

 #%# family=contrib

=head1 AUTHOR

Magnus Hagander <magnus@hagander.net>

=head1 LICENSE

GPLv2

=cut

use strict;
use warnings;

use Munin::Plugin;

if ( $ARGV[0] and $ARGV[0] eq "autoconf") {
   print "no\n";
   exit(0);
}

my @sensors;
open(HPLOG, "/sbin/hplog -t |") || die "Could not run hplog\n";
while (<HPLOG>) {
   next if /^\s*$/;
   next if /^ID/;
   if (/^\s*(\d+)\s*Basic Sensor\s+(CPU \(\d+\)|Ambient|Processor Zone|Memory Board|System Board|Pwr\. Supply Bay|I\/O Zone|SCSI Backplane)\s+(\S+)\s+\d+F\/\s*(\d+)C\s+\d+F\/\s*(\d+)C/) {
      push @sensors, {
	'id' => $1,
	'name' => $2,
	'state' => $3,
	'current' => $4,
	'threshold' => $5
	};
   }
   else {
      die "Could not parse line $_";
   }
}
close(HPLOG);

if ( $ARGV[0] and $ARGV[0] eq "config") {
   print "graph_title HP temperature\n";
   print "graph_category sensors\n";
   for my $sensor (@sensors) {
      print "s" . $sensor->{'id'} . ".label " . $sensor->{'name'} . "\n";
      print "s" . $sensor->{'id'} . ".type GAUGE\n";
      print "s" . $sensor->{'id'} . ".min 0\n";
      print "s" . $sensor->{'id'} . ".warning " . ($sensor->{'threshold'}-10) . "\n";
      print "s" . $sensor->{'id'} . ".critical " . $sensor->{'threshold'} . "\n";
   }
   print "degraded.label Temperature sensors not normal\n";
   print "degraded.type GAUGE\n";
   print "degraded.min 0\n";
   print "degraded.critical 1\n";
   exit(0);
}

my $notok = 0;
for my $sensor (@sensors) {
    print "s" . $sensor->{'id'} . ".value " . $sensor->{'current'} . "\n";
    $notok++ if ($sensor->{'state'} ne "Normal");
}
print "degraded.value $notok\n";