From eb86e52595535403578b173053c41c9f2efbccdc Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 15 Jul 2014 15:02:26 +0100 Subject: [PATCH] Use hpasmcli2_ instead of hpasmcli_ --- .../files/default/plugin-conf.d/hpasmcli | 2 - .../files/default/plugin-conf.d/hpasmcli2 | 2 + .../munin/files/default/plugins/hpasmcli2_ | 165 ++++++++++++++++++ .../munin/files/default/plugins/hpasmcli_fans | 54 ------ .../munin/files/default/plugins/hpasmcli_temp | 61 ------- cookbooks/munin/recipes/default.rb | 21 ++- 6 files changed, 184 insertions(+), 121 deletions(-) delete mode 100644 cookbooks/munin/files/default/plugin-conf.d/hpasmcli create mode 100644 cookbooks/munin/files/default/plugin-conf.d/hpasmcli2 create mode 100755 cookbooks/munin/files/default/plugins/hpasmcli2_ delete mode 100755 cookbooks/munin/files/default/plugins/hpasmcli_fans delete mode 100755 cookbooks/munin/files/default/plugins/hpasmcli_temp diff --git a/cookbooks/munin/files/default/plugin-conf.d/hpasmcli b/cookbooks/munin/files/default/plugin-conf.d/hpasmcli deleted file mode 100644 index 50b376380..000000000 --- a/cookbooks/munin/files/default/plugin-conf.d/hpasmcli +++ /dev/null @@ -1,2 +0,0 @@ -[hpasmcli_*] -user root diff --git a/cookbooks/munin/files/default/plugin-conf.d/hpasmcli2 b/cookbooks/munin/files/default/plugin-conf.d/hpasmcli2 new file mode 100644 index 000000000..d7673cd84 --- /dev/null +++ b/cookbooks/munin/files/default/plugin-conf.d/hpasmcli2 @@ -0,0 +1,2 @@ +[hpasmcli2_*] +user root diff --git a/cookbooks/munin/files/default/plugins/hpasmcli2_ b/cookbooks/munin/files/default/plugins/hpasmcli2_ new file mode 100755 index 000000000..7c8a1d6a1 --- /dev/null +++ b/cookbooks/munin/files/default/plugins/hpasmcli2_ @@ -0,0 +1,165 @@ +#!/usr/bin/env perl +# +# Plugin to monitor Proliant server health status using hpasmcli. +# +# Config variables: +# user root -- requrired by hpasmcli +# env.hpasmcli -- path to hpasmcli executable (optional) +# env.degree -- Unit of temperatures (C or F / default value is C) +# +# +# Author: Tsuyoshi Wada +# +# v1.0 2007/12/08 - First version +# +# Copyright (c) 2007 Tsuyoshi Wada +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Magic markers +#%# family=contrib +#%# capabilities=autoconf suggest + +use strict; + +my $hpasmcli = exists $ENV{hpasmcli} ? $ENV{hpasmcli} : undef; +$hpasmcli = `which hpasmcli` unless $hpasmcli; +chomp $hpasmcli; +$hpasmcli = undef unless -x $hpasmcli; +my @dirs = qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin); +until ($hpasmcli or @dirs == 0) { + my $dir = shift @dirs; + my $path = $dir.'/hpasmcli'; + $hpasmcli = $path if -x $path; +} +my $degree = exists $ENV{degree} ? $ENV{degree} : 'C'; +my $deg_name = $degree eq 'C' ? "Celsius": "Fahrenheit"; + +if (defined($ARGV[0])) { + if ($ARGV[0] eq 'autoconf') { + if ($hpasmcli and -x $hpasmcli) { + my @chk_result = `$hpasmcli -s \"help\"`; + if ($? eq "0") { + print "yes\n"; + exit 0; + } else { + my $reason = 'Unknown error'; + foreach my $line (@chk_result) { + if ($line =~ /^ERROR/i) { + chomp($line); + $reason = $line; + last; + } + } + print "no ($reason)\n"; + exit 1; + } + } else { + print "no (hpasmcli not found)\n"; + exit 1; + } + } elsif ($ARGV[0] eq 'suggest') { + print "temp\nfans\n"; + exit 0; + } +} + +$0 =~ /hpasmcli2_(.+)*$/; +my $show_target = $1; +my @show_result = `$hpasmcli -s \"show $show_target\"`; +my %output; + +if (defined($show_target) and $show_target eq 'temp') { + foreach my $line (@show_result) { + if ($line =~ /^#/) { + $line =~ s/\s+/ /g; + $line =~ s/^\s//g; + my ($sensor, $loc, $temp, $threshold) = split(/\s/, $line); + next if ($temp eq "-"); + $loc =~ s/\/|#//g; + $temp = $degree eq 'C' ? (split(/\//, $temp))[0] : (split(/\//, $temp))[1]; + $temp =~ s/C|F//g; + $threshold = $degree eq 'C' ? (split(/\//, $threshold))[0] : (split(/\//, $threshold))[1]; + $threshold =~ s/C|F//g; + $sensor =~s/#//g; + $output{$sensor} = { + 'location' => lc($loc), + 'temp' => $temp, + 'threshold' => $threshold + }; + } + } + if (defined($ARGV[0]) and $ARGV[0] eq 'config') { + print "graph_title hpasm: Temperature\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel Degrees in $deg_name\n"; + print "graph_category sensors\n"; + print "graph_info This graph shows the temperatures as reported by hpasmcli.\n"; + foreach my $key (sort keys %output) { + print "temp$key.label $output{$key}->{'location'}\n"; + print "temp$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n"; + print "temp$key.critical $output{$key}->{'threshold'}\n"; + } + } else { + foreach my $key (sort keys %output) { + print "temp$key.value $output{$key}->{'temp'}\n"; + } + } +} elsif (defined($show_target) and $show_target eq 'fans') { + foreach my $line (@show_result) { + if ($line =~ /^#/) { + $line =~ s/\s+/ /g; + $line =~ s/^\s//g; + my ($fan, $loc, $present, $speed, $rate, $redundant, $partner, $pluggable) = split(/\s/, $line); + next if ($present ne "Yes"); + $loc =~ s/\/|#//g; + $rate =~ s/\%//g; + my $threshold = '100'; + $fan =~s/#//g; + $output{$fan} = { + 'location' => lc($loc), + 'rate' => $rate, + 'threshold' => $threshold + }; + } + } + if (defined($ARGV[0]) and $ARGV[0] eq 'config') { + print "graph_title hpasm: Fans\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel of max (%)\n"; + print "graph_category sensors\n"; + print "graph_info This graph shows the info of fans as reported by hpasmcli.\n"; + foreach my $key (sort keys %output) { + print "fan$key.label FAN$key $output{$key}->{'location'}\n"; + print "fan$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n"; + print "fan$key.critical $output{$key}->{'threshold'}\n"; + } + } else { + foreach my $key (sort keys %output) { + print "fan$key.value $output{$key}->{'rate'}\n"; + } + } +} else { + die "Unknown target specified ($show_target)\n"; +} + +exit 0; diff --git a/cookbooks/munin/files/default/plugins/hpasmcli_fans b/cookbooks/munin/files/default/plugins/hpasmcli_fans deleted file mode 100755 index e440c3fdd..000000000 --- a/cookbooks/munin/files/default/plugins/hpasmcli_fans +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/perl -w -# -# Graph fans on Proliant Servers -# - -use strict; - -my $hpasmcli = "/sbin/hpasmcli"; -my $cmd = "$hpasmcli -s \"show fans\""; -# C/F : graph temp in celsius or fahrenheit - -my @result = `$cmd`; -my %val; - -#(-f $hpasmcli) || exit(1); - -foreach my $line (@result) { - - if ($line =~ /^#/) { - $line =~ s/\s+/ /g; - $line =~ s/^\s//g; - my ($sensor, $loc, $present, $speed_state, $speed, $redundant) = split(/\s/, $line); - next if ($speed eq "-"); - $loc =~ s/\/|#//g; - $speed =~ s/\%//g; - - $sensor =~s/#//g; - $val{$sensor} = {location => lc($loc), - speed => $speed - }; - } - -} - - -if ($ARGV[0] && $ARGV[0] eq "config") { - - print "graph_title Fans\n"; - print "graph_vlabel fans speed as % of max\n"; - print "graph_category sensors\n"; - while (my ($k, $hashref) = each (%val)) { - print "$hashref->{location}.label $hashref->{location}\n"; - print "$hashref->{location}.warning 85\n"; - print "$hashref->{location}.critical 100\n"; - } - -} -else { - while (my ($k, $hashref) = each (%val)) { - print "$hashref->{location}.value $hashref->{speed}\n"; - } -} -exit(0); - diff --git a/cookbooks/munin/files/default/plugins/hpasmcli_temp b/cookbooks/munin/files/default/plugins/hpasmcli_temp deleted file mode 100755 index 0884bb113..000000000 --- a/cookbooks/munin/files/default/plugins/hpasmcli_temp +++ /dev/null @@ -1,61 +0,0 @@ -#! /usr/bin/perl -w -# -# Graph temperature on Proliant Servers -# - -use strict; - -my $hpasmcli = "/sbin/hpasmcli"; -my $cmd = "$hpasmcli -s \"show temp\""; -# C/F : graph temp in celsius or fahrenheit -my $degree = "C"; - -my @result = `$cmd`; -my %val; - -#(-f $hpasmcli) || exit(1); - -foreach my $line (@result) { - - if ($line =~ /^#/) { - $line =~ s/\s+/ /g; - $line =~ s/^\s//g; - my ($sensor, $loc, $temp, $threshold) = split(/\s/, $line); - next if ($temp eq "-"); - $loc =~ s/\/|#//g; - $temp = $degree eq "C" ? (split(/\//, $temp))[0] : (split(/\//, $temp))[1]; - $temp =~ s/C|F//g; - $threshold = $degree eq "C" ? (split(/\//, $threshold))[0] : (split(/\//, $threshold))[1]; - $threshold =~ s/C|F//g; - - $sensor =~s/#//g; - $val{$sensor} = {location => lc($loc), - temp => $temp, - threshold => $threshold - }; - } - -} - - -if ($ARGV[0] && $ARGV[0] eq "config") { - - print "graph_title Temperature\n"; - print "graph_vlabel temperature in °$degree\n"; - print "graph_category sensors\n"; - while (my ($k, $hashref) = each (%val)) { - print "$hashref->{location}.label $hashref->{location}\n"; - print "$hashref->{location}.warning ".($hashref->{threshold} - 5) ."\n"; - print "$hashref->{location}.critical $hashref->{threshold}\n"; - } - -} -else { - while (my ($k, $hashref) = each (%val)) { - print "$hashref->{location}.value $hashref->{temp}\n"; - } -} -exit(0); - - - diff --git a/cookbooks/munin/recipes/default.rb b/cookbooks/munin/recipes/default.rb index 316f738f5..ae5eb6cae 100644 --- a/cookbooks/munin/recipes/default.rb +++ b/cookbooks/munin/recipes/default.rb @@ -155,18 +155,31 @@ else end if File.exists?("/sbin/hpasmcli") - munin_plugin "hpasmcli_temp" - munin_plugin "hpasmcli_fans" + munin_plugin "hpasmcli2_temp" do + target "hpasmcli2_" + end + + munin_plugin "hpasmcli2_fans" do + target "hpasmcli2_" + end else - munin_plugin "hpasmcli_temp" do + munin_plugin "hpasmcli2_temp" do action :delete end - munin_plugin "hpasmcli_fans" do + munin_plugin "hpasmcli2_fans" do action :delete end end +munin_plugin "hpasmcli_temp" do + action :delete +end + +munin_plugin "hpasmcli_fans" do + action :delete +end + munin_plugin "http_loadtime" do action :delete end -- 2.43.2