Projet

Général

Profil

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

root / plugins / disk / hpasmcli2_ @ 8589c6df

Historique | Voir | Annoter | Télécharger (6,02 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
#   user root       -- requrired by hpasmcli
7
#   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
                exit 0;
64
            } else {
65
                my $reason = 'Unknown error';
66
                foreach my $line (@chk_result) {
67
                    if ($line =~ /^ERROR/i) {
68
                        chomp($line);
69
                        $reason = $line;
70
                        last;
71
                    }
72
                }
73
                print "no ($reason)\n";
74
                exit 1;
75
            }
76
        } else {
77
            print "no (hpasmcli not found)\n";
78
            exit 1;
79
        }
80
    } elsif ($ARGV[0] eq 'suggest') {
81
        print "temp\nfans\n";
82
        exit 0;
83
    }
84
}
85
86
$0 =~ /hpasmcli2_(.+)*$/;
87
my $show_target = $1;
88
my @show_result = `$hpasmcli -s \"show $show_target\"`;
89
my %output;
90
91
if (defined($show_target) and $show_target eq 'temp') {
92
    foreach my $line (@show_result) {
93
        if ($line =~ /^#/) {
94
            $line =~ s/\s+/ /g;
95
            $line =~ s/^\s//g;
96
            my ($sensor, $loc, $temp, $threshold) = split(/\s/, $line);
97
            next if ($temp eq "-");
98
            $loc =~ s/\/|#//g;
99
            $temp = $degree eq 'C' ? (split(/\//, $temp))[0] : (split(/\//, $temp))[1];
100
            $temp =~ s/C|F//g;
101
            $threshold = $degree eq 'C' ? (split(/\//, $threshold))[0] : (split(/\//, $threshold))[1];
102
            $threshold =~ s/C|F//g;
103
            $sensor =~s/#//g;
104
            $output{$sensor} = {
105
                'location'  => lc($loc),
106
                'temp'      => $temp,
107
                'threshold' => $threshold
108
            };
109
        }
110
    }
111
    if (defined($ARGV[0]) and $ARGV[0] eq 'config') {
112
        print "graph_title hpasm: Temperature\n";
113
        print "graph_args --base 1000 -l 0\n";
114
        print "graph_vlabel Degrees in $deg_name\n";
115
        print "graph_category sensors\n";
116
        print "graph_info This graph shows the temperatures as reported by hpasmcli.\n";
117
        foreach my $key (sort keys %output) {
118
            print "temp$key.label $output{$key}->{'location'}\n";
119
            print "temp$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n";
120
            print "temp$key.critical $output{$key}->{'threshold'}\n";
121
        }
122
    } else {
123
        foreach my $key (sort keys %output) {
124
            print "temp$key.value $output{$key}->{'temp'}\n";
125
        }
126
    }
127
} elsif (defined($show_target) and $show_target eq 'fans') {
128
    foreach my $line (@show_result) {
129
        if ($line =~ /^#/) {
130
            $line =~ s/\s+/ /g;
131
            $line =~ s/^\s//g;
132
            my ($fan, $loc, $present, $speed, $rate, $redundant, $partner, $pluggable) = split(/\s/, $line);
133
            next if ($present ne "Yes");
134
            $loc =~ s/\/|#//g;
135
            $rate =~ s/\%//g;
136
            my $threshold = '100';
137
            $fan =~s/#//g;
138
            $output{$fan} = {
139
                'location'  => lc($loc),
140
                'rate'      => $rate,
141
                'threshold' => $threshold
142
            };
143
        }
144
    }
145
    if (defined($ARGV[0]) and $ARGV[0] eq 'config') {
146
        print "graph_title hpasm: Fans\n";
147
        print "graph_args --base 1000 -l 0\n";
148
        print "graph_vlabel of max (%)\n";
149
        print "graph_category sensors\n";
150
        print "graph_info This graph shows the info of fans as reported by hpasmcli.\n";
151
        foreach my $key (sort keys %output) {
152
            print "fan$key.label FAN$key $output{$key}->{'location'}\n";
153
            print "fan$key.warning " . ($output{$key}->{'threshold'} * 0.75) . "\n";
154
            print "fan$key.critical $output{$key}->{'threshold'}\n";
155
        }
156
    } else {
157
        foreach my $key (sort keys %output) {
158
            print "fan$key.value $output{$key}->{'rate'}\n";
159
        }
160
    }
161
} else {
162
    die "Unknown target specified ($show_target)\n";
163
}
164
165
exit 0;