forked from GOID1989/zbx-adaptec-raid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adaptec-raid.ps1
184 lines (151 loc) · 6.25 KB
/
adaptec-raid.ps1
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<#
.VERSION
0.2
.SYNOPSIS
Script with LLD support for getting data from Adaptec RAID Controller to Zabbix monitoring system.
.DESCRIPTION
The script may generate LLD data for Adaptec RAID Controllers, Logical Drives, Physical Drives.
.NOTES
Author: GOID1989
Github: https://github.com/GOID1989/zbx-adaptec-raid
#>
Param (
[switch]$version = $false,
[ValidateSet("lld","health")][Parameter(Position=0, Mandatory=$True)][string]$action,
[ValidateSet("ad","ld","pd","bt")][Parameter(Position=1, Mandatory=$True)][string]$part,
[string][Parameter(Position=2)]$ctrlid,
[string][Parameter(Position=3)]$partid
)
$cli = "C:\Program Files\Adaptec\Adaptec Storage Manager\arcconf.exe"
function LLDControllers()
{
$response = & $cli "GETVERSION".Split() | Where-Object {$_ -match "^Controllers found"}
$ctrl_count = ($response -replace 'Controllers found: ','').Trim()
for($i = 1; $i -le $ctrl_count; $i++ ){
[array]$response = & $cli "GETCONFIG $i AD".Split()
$ctrl_model = (($response[6] -split ':')[1]).Trim()
$ctrl_sn = (($response[7] -split ':')[1]).Trim()
$ctrl_info = [string]::Format('{{"{{#CTRL.ID}}":"{0}","{{#CTRL.MODEL}}":"{1}","{{#CTRL.SN}}":"{2}"}},',$i,$ctrl_model, $ctrl_sn)
$ctrl_json += $ctrl_info
}
$lld_data = '{"data":[' + $($ctrl_json -replace ',$') + ']}'
return $lld_data
}
function LLDBattery()
{
$response = & $cli "GETVERSION".Split() | Where-Object {$_ -match "^Controllers found"}
$ctrl_count = ($response -replace 'Controllers found: ','').Trim()
for($i = 1; $i -le $ctrl_count; $i++ ){
$response = & $cli "GETCONFIG $i ad".Split() | Where-Object {$_ -match "Controller Battery Information"}
if($response.Length -ne 0){
$response = & $cli "GETCONFIG $i ad".Split() | Where-Object {$_ -match "^\s+Status\s+[:]"}
if($response.Length -gt 0) {
$ctrl_info = [string]::Format('{{"{{#CTRL.ID}}":"{0}","{{#CTRL.BATTERY}}":"{1}"}},',$i,$i)
$ctrl_json += $ctrl_info
}
}
}
$lld_data = '{"data":[' + $($ctrl_json -replace ',$') + ']}'
return $lld_data
}
function LLDLogicalDrives()
{
$response = & $cli "GETVERSION".Split() | Where-Object {$_ -match "^Controllers found"}
$ctrl_count = ($response -replace 'Controllers found: ','').Trim()
for($i = 1; $i -le $ctrl_count; $i++ ){
$response = & $cli "GETCONFIG $i ad".Split() | Where-Object {$_ -match "Logical devices/Failed/Degraded"}
$res = $response -match '[:\s](\d+)'
$ld_count = $Matches[1]
#Get IDs of logical devices
[array]$response = & $cli "GETCONFIG $i ld".Split() | Where-Object {$_ -match "Logical device number"}
foreach($logical_dev in $response){
$res = ($logical_dev -match '\d+$')
$ld_id = $Matches[0]
[array]$response = & $cli "GETCONFIG $i ld $ld_id".Split() | Where-Object {$_ -match "Logical device name|RAID level"}
$ld_name = ($response[0] -split ':')[1].Trim()
$ld_raid = ($response[1] -split ':')[1].Trim()
# If name of LD not set
if($ld_name -eq "") { $ld_name = $ld_id }
$ld_info = [string]::Format('{{"{{#CTRL.ID}}":"{0}","{{#LD.ID}}":"{1}","{{#LD.NAME}}":"{2}","{{#LD.RAID}}":"{3}"}},',$i,$ld_id, $ld_name,$ld_raid)
$ld_json += $ld_info
}
}
$lld_data = '{"data":[' + $($ld_json -replace ',$') + ']}'
return $lld_data
}
function LLDPhysicalDrives()
{
$response = & $cli "GETVERSION".Split() | Where-Object {$_ -match "^Controllers found"}
$ctrl_count = ($response -replace 'Controllers found: ','').Trim()
for($i = 1; $i -le $ctrl_count; $i++ ){
[array]$response = & $cli "GETCONFIG $i pd".Split() | Where-Object {$_ -match "Device\s[#]\d+|Device is "}
for($j = 0; $j -lt $response.Length;){
if($response[$j+1] -match "Hard drive"){
$pd_id = ($response[$j] -replace "Device #").Trim()
$pd_info = [string]::Format('{{"{{#CTRL.ID}}":"{0}","{{#PD.ID}}":"{1}"}},',$i,$pd_id)
$pd_json += $pd_info
}
$j = $j + 2
}
}
$lld_data = '{"data":[' + $($pd_json -replace ',$') + ']}'
return $lld_data
}
function GetControllerStatus()
{
Param (
# Controller component
[ValidateSet("main","battery","temperature")][string]$ctrl_part
)
switch($ctrl_part){
"main" {
$response = & $cli "GETCONFIG $ctrlid ad".Split() | Where-Object {$_ -match "Controller Status"}
$ctrl_status = ($response -split ':')[1].Trim()
}
"battery" {
$response = & $cli "GETCONFIG $ctrlid ad".Split() | Where-Object {$_ -match "^\s+Status\s+[:]"}
if($response.Length -ne 0) {
$ctrl_status = ($response -split ':')[1].Trim()
} else {
$ctrl_status = "No battery module"
}
}
"temperature" {
$response = & $cli "GETCONFIG $ctrlid ad".Split() | Where-Object {$_ -match "^\s+Temperature\s+[:]"}
# Exctract Celsius value
$res = $response -match '(\d+).*[C]'
$ctrl_status = $Matches[1]
}
}
return $ctrl_status
}
function GetLogicalDriveStatus()
{
$response = & $cli "GETCONFIG $ctrlid ld $partid".Split() | Where-Object {$_ -match "Status of logical device"}
$ld_status = ($response -split ':')[1].Trim()
return $ld_status
}
function GetPhysicalDriveStatus()
{
[array]$response = & $cli "GETCONFIG $ctrlid pd".Split() | Where-Object {$_ -match "^\s+State\s+[:] "}
$pd_status = ($response[$partid] -split ':')[1].Trim()
return $pd_status
}
switch($action){
"lld" {
switch($part){
"ad" { write-host $(LLDControllers) }
"ld" { write-host $(LLDLogicalDrives)}
"pd" { write-host $(LLDPhysicalDrives)}
"bt" { write-host $(LLDBattery)}
}
}
"health" {
switch($part) {
"ad" { write-host $(GetControllerStatus -ctrl_part $partid) }
"ld" { write-host $(GetLogicalDriveStatus)}
"pd" { write-host $(GetPhysicalDriveStatus) }
}
}
default {Write-Host "ERROR: Wrong argument: use 'lld' or 'health'"}
}