-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathhpssacli.pl
143 lines (118 loc) · 4.36 KB
/
hpssacli.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl
#
# Script to parse HPACUCLI/HPSSACLI's JSON output and expose
# HP SmartArray health as Prometheus metrics.
#
# Tested against HPE Smart Storage Administrator (hpssacli) '2.40.13.0'.
#
# Based on storcli node_exporter example
#
# (c) 2019, Nuno Tavares <[email protected]>
#
# You can find the latest version in:
# https://github.com/ntavares/node-exporter-textfile-collector-scripts
#
use strict;
use warnings;
# These may need changing depending on the configuration of your system
my $hpacucli = '/usr/sbin/hpssacli';
my ( $slot, $fh, $fh2 );
sub exp_exit {
my ($text) = @_;
print STDERR $text;
exit(1);
}
sub add_metric {
my $name = shift;
my $labelsref = shift;
my $value = shift;
my @la = ();
foreach my $k (keys %{$labelsref}) {
my $t = "$k=\"" . $labelsref->{$k} . "\"";
push @la, $t;
}
print "hpsa_" . $name . "{" . join(",", @la) . "}" . " " . $value . "\n";
}
# Check hpacucli is installed
if ( !-e $hpacucli ) {
exp_exit("Can't find HP CLI binary: " . $hpacucli . "\n");
}
# Get controller status
open( $fh, "$hpacucli controller all show status|" )
or exp_exit( "Failed to run $hpacucli" );
# Spin through output
foreach my $line (<$fh>) {
if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i )
{
exp_exit( "Another instance of hpacucli is running!" );
}
elsif ( $line =~ m/Slot (\d+)/i ) {
$slot = $1;
# Now get further status on each controller elements
foreach my $PARAM (qw(array physicaldrive logicaldrive)) {
open( $fh2,
"$hpacucli controller slot=$slot $PARAM all show status|"
)
or exp_exit( "Failed to get info for $PARAM slot $slot" );
foreach my $line2 (<$fh2>) {
if ( $line2 =~ /^\s*$PARAM ([^\s]+).*:\s*(\w+[\w\s]*)$/i ) {
my $pbb = $1;
my $result = $2;
chomp $result;
my %l = ( "slot" => $slot, "locid" => $pbb );
&add_metric($PARAM . "_status", \%l, (( $result ne "OK" )?"0":"1"));
}
}
close($fh2)
or exp_exit( "Failed to get info for $PARAM slot $slot" );
}
# Now get further details on each physicaldrive
open( $fh2,
"$hpacucli controller slot=$slot physicaldrive all show detail|"
)
or exp_exit( "Failed to get info for physicaldrive slot $slot" );
my %pdlist = ();
my $cur_pd = '';
foreach my $line2 (<$fh2>) {
if ( $line2 =~ /^\s+physicaldrive ([^\s]+)$/i ) {
$cur_pd = $1;
$pdlist{$cur_pd} = ();
} elsif ( $line2 =~ /^\s+Rotational Speed: (\d+)$/i ) {
$pdlist{$cur_pd}{"speed"} = $1;
} elsif ( $line2 =~ /^\s+Firmware Revision: (.+)$/i ) {
$pdlist{$cur_pd}{"revision"} = $1;
} elsif ( $line2 =~ /^\s+Serial Number: (.+)$/i ) {
$pdlist{$cur_pd}{"serial"} = $1;
} elsif ( $line2 =~ /^\s+Model: (.+)$/i ) {
$pdlist{$cur_pd}{"model"} = $1;
} elsif ( $line2 =~ /^\s+Current Temperature \(C\): (.+)$/i ) {
my $temp = $1;
my %l = ( "slot" => $slot, "locid" => $cur_pd );
&add_metric('physicaldrive_current_temperature', \%l, $temp);
} elsif ( $line2 =~ /^\s+PHY Transfer Rate: (.+)$/i ) {
my $phyrate = $1;
$phyrate =~ s/^([0-9\.]+).*$/$1/g;
my %l = ( "slot" => $slot, "locid" => $cur_pd );
&add_metric('physicaldrive_phy_transfer_rate', \%l, $phyrate);
}
}
foreach my $pd (keys %pdlist) {
&add_metric('physicaldrive_info', $pdlist{$pd}, 1);
}
close($fh2)
or exp_exit( "Failed to get info for physicaldrive slot $slot" );
}
else {
# Check the overall controller status is OK
if ( $line =~ /^\s+(.*? Status):\s*([\w\s]+).*$/ ) {
my $name = lc $1;
my $result = $2;
$name =~ s/[^a-zA-z0-9]/_/g;
chomp($result);
my %l = ( "slot" => $slot );
&add_metric($name, \%l, (( $result ne "OK" )?"0":"1"));
}
}
}
close($fh)
or exp_exist("Failed to run $hpacucli controller all show status" );