Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / hpasmcli2_ @ 64089240

Historique | Voir | Annoter | Télécharger (5,96 ko)

1 65fb3d8e Diego Elio Pettenò
#!/usr/bin/env perl -w
2 b09158b3 Tsuyoshi Wada
#
3
# Plugin to monitor Proliant server health status using hpasmcli.
4
#
5
# Config variables:
6 8713eb37 Lars Kruse
#   user root       -- required by hpasmcli
7 b09158b3 Tsuyoshi Wada
#   env.hpasmcli    -- path to hpasmcli executable (optional)
8
#   env.degree      -- Unit of temperatures (C or F / default value is C)
9
#
10
#
11
# Author: Tsuyoshi Wada <mail@tuyo.jp>
12
#
13
# v1.0  2007/12/08 - First version
14
#
15
# Copyright (c) 2007 Tsuyoshi Wada
16
# All rights reserved.
17
#
18
# Redistribution and use in source and binary forms, with or without
19
# modification, are permitted provided that the following conditions
20
# are met:
21
# 1. Redistributions of source code must retain the above copyright
22
#    notice, this list of conditions and the following disclaimer.
23
# 2. Redistributions in binary form must reproduce the above copyright
24
#    notice, this list of conditions and the following disclaimer in the
25
#    documentation and/or other materials provided with the distribution.
26
#
27
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
#
38
# Magic markers
39
#%# family=contrib
40
#%# capabilities=autoconf suggest
41
42
use strict;
43
44
my $hpasmcli = exists $ENV{hpasmcli} ? $ENV{hpasmcli} : undef;
45
$hpasmcli = `which hpasmcli` unless $hpasmcli;
46
chomp $hpasmcli;
47
$hpasmcli = undef unless -x $hpasmcli;
48
my @dirs = qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin);
49
until ($hpasmcli or @dirs == 0) {
50
    my $dir = shift @dirs;
51
    my $path = $dir.'/hpasmcli';
52
    $hpasmcli = $path if -x $path;
53
}
54
my $degree = exists $ENV{degree} ? $ENV{degree} : 'C';
55
my $deg_name = $degree eq 'C' ? "Celsius": "Fahrenheit";
56
57
if (defined($ARGV[0])) {
58
    if ($ARGV[0] eq 'autoconf') {
59
        if ($hpasmcli and -x $hpasmcli) {
60
            my @chk_result = `$hpasmcli -s \"help\"`;
61
            if ($? eq "0") {
62
                print "yes\n";
63
            } else {
64
                my $reason = 'Unknown error';
65
                foreach my $line (@chk_result) {
66
                    if ($line =~ /^ERROR/i) {
67
                        chomp($line);
68
                        $reason = $line;
69
                        last;
70
                    }
71
                }
72
                print "no ($reason)\n";
73
            }
74
        } else {
75
            print "no (hpasmcli not found)\n";
76
        }
77 e4cd049b Lars Kruse
        exit 0;
78 b09158b3 Tsuyoshi Wada
    } elsif ($ARGV[0] eq 'suggest') {
79
        print "temp\nfans\n";
80
        exit 0;
81
    }
82
}
83
84
$0 =~ /hpasmcli2_(.+)*$/;
85
my $show_target = $1;
86
my @show_result = `$hpasmcli -s \"show $show_target\"`;
87
my %output;
88
89
if (defined($show_target) and $show_target eq 'temp') {
90
    foreach my $line (@show_result) {
91
        if ($line =~ /^#/) {
92
            $line =~ s/\s+/ /g;
93
            $line =~ s/^\s//g;
94
            my ($sensor, $loc, $temp, $threshold) = split(/\s/, $line);
95
            next if ($temp eq "-");
96
            $loc =~ s/\/|#//g;
97
            $temp = $degree eq 'C' ? (split(/\//, $temp))[0] : (split(/\//, $temp))[1];
98
            $temp =~ s/C|F//g;
99
            $threshold = $degree eq 'C' ? (split(/\//, $threshold))[0] : (split(/\//, $threshold))[1];
100
            $threshold =~ s/C|F//g;
101
            $sensor =~s/#//g;
102
            $output{$sensor} = {
103
                'location'  => lc($loc),
104
                'temp'      => $temp,
105
                'threshold' => $threshold
106
            };
107
        }
108
    }
109
    if (defined($ARGV[0]) and $ARGV[0] eq 'config') {
110
        print "graph_title hpasm: Temperature\n";
111
        print "graph_args --base 1000 -l 0\n";
112
        print "graph_vlabel Degrees in $deg_name\n";
113
        print "graph_category sensors\n";
114
        print "graph_info This graph shows the temperatures as reported by hpasmcli.\n";
115
        foreach my $key (sort keys %output) {
116
            print "temp$key.label $output{$key}->{'location'}\n";
117
            print "temp$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n";
118
            print "temp$key.critical $output{$key}->{'threshold'}\n";
119
        }
120
    } else {
121
        foreach my $key (sort keys %output) {
122
            print "temp$key.value $output{$key}->{'temp'}\n";
123
        }
124
    }
125
} elsif (defined($show_target) and $show_target eq 'fans') {
126
    foreach my $line (@show_result) {
127
        if ($line =~ /^#/) {
128
            $line =~ s/\s+/ /g;
129
            $line =~ s/^\s//g;
130
            my ($fan, $loc, $present, $speed, $rate, $redundant, $partner, $pluggable) = split(/\s/, $line);
131
            next if ($present ne "Yes");
132
            $loc =~ s/\/|#//g;
133
            $rate =~ s/\%//g;
134
            my $threshold = '100';
135
            $fan =~s/#//g;
136
            $output{$fan} = {
137
                'location'  => lc($loc),
138
                'rate'      => $rate,
139
                'threshold' => $threshold
140
            };
141
        }
142
    }
143
    if (defined($ARGV[0]) and $ARGV[0] eq 'config') {
144
        print "graph_title hpasm: Fans\n";
145
        print "graph_args --base 1000 -l 0\n";
146
        print "graph_vlabel of max (%)\n";
147
        print "graph_category sensors\n";
148
        print "graph_info This graph shows the info of fans as reported by hpasmcli.\n";
149
        foreach my $key (sort keys %output) {
150
            print "fan$key.label FAN$key $output{$key}->{'location'}\n";
151
            print "fan$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n";
152
            print "fan$key.critical $output{$key}->{'threshold'}\n";
153
        }
154
    } else {
155
        foreach my $key (sort keys %output) {
156
            print "fan$key.value $output{$key}->{'rate'}\n";
157
        }
158
    }
159
} else {
160
    die "Unknown target specified ($show_target)\n";
161
}
162
163
exit 0;