-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_raid
214 lines (181 loc) · 7 KB
/
check_raid
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/perl
# A lot of TODOs here
# - Fixed Icinga host name
# - Fixed host/service name
# - Uses curl
use strict;
use warnings;
# root@backup7:~# cat /proc/mdstat
# Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
# md0 : active raid1 sdb[2] sdc[1]
# 976630464 blocks super 1.2 [2/1] [_U]
# [======>..............] recovery = 32.9% (322075840/976630464) finish=89.2min speed=122298K/sec
# bitmap: 5/8 pages [20KB], 65536KB chunk
#
# unused devices: <none>
sub submit_result {
my $status = shift;
my $output = shift;
my $perfdata = shift;
my $curl_out = `curl -k -s -S -i -u USER:PASSWORD -H 'Accept: application/json' -X POST 'https://icinga.lan:5665/v1/actions/process-check-result' -d '{ "type": "Service", "filter": "host.name==\\"backup7.lan\\" && service.name==\\"raid /dev/md0\\"", "exit_status": $status, "plugin_output": "$output", "performance_data": [ "$perfdata" ], "check_source": "check-script", "pretty": true }'`;
print $curl_out;
}
# Get state
my $mdadm_out = `mdadm --detail /dev/md0`;
if ( $mdadm_out =~ /^ *State : active *$/m and $mdadm_out =~ /^ *Active Devices : 2$/m and $mdadm_out =~ /^ *Failed Devices : 0$/m ) {
submit_result( 0, "RAID is active, 2 active devices", "" );
exit 0;
}
if ( $mdadm_out =~ /^ *State : clean *$/m and $mdadm_out =~ /^ *Active Devices : 2$/m and $mdadm_out =~ /^ *Failed Devices : 0$/m ) {
submit_result( 0, "RAID is clean, 2 active devices", "" );
exit 0;
}
if ( $mdadm_out =~ /^ *State : clean, degraded *$/m ) {
submit_result( 1, "RAID is clean, degraded", "" );
exit 0;
}
if ( $mdadm_out =~ /^ *State : clean, degraded, recovering *$/m and $mdadm_out =~ /^ *Active Devices : 1$/m ) {
my ( $pct ) = $mdadm_out =~ /^ *Rebuild Status : (\d+)% complete$/m;
submit_result( 1, "RAID is recovering, $pct % complete", "recovery=$pct%" );
exit 0;
}
# After resizing the raid
if ( $mdadm_out =~ /^ *State : clean, resyncing *$/m and $mdadm_out =~ /^ *Active Devices : 2$/m ) {
my ( $pct ) = $mdadm_out =~ /^ *Resync Status : (\d+)% complete$/m;
submit_result( 1, "RAID is clean and resyncing, $pct % complete", "recovery=$pct%" );
exit 0;
}
# After resizing the raid / also, this one here
if ( $mdadm_out =~ /^ *State : active, resyncing *$/m and $mdadm_out =~ /^ *Active Devices : 2$/m ) {
my ( $pct ) = $mdadm_out =~ /^ *Resync Status : (\d+)% complete$/m;
submit_result( 1, "RAID is active and resyncing, $pct % complete", "recovery=$pct%" );
exit 0;
}
if ( $mdadm_out =~ /^ *State : inactive *$/m ) {
submit_result( 2, "RAID is inactive", "" );
exit 0;
}
# No match so far? Return unknown result
submit_result( 3, "Unknown", "" );
die $mdadm_out;
#curl -k -s -S -i -u USER:PASSWORD -H 'Accept: application/json' -X POST 'https://icinga.lan:5665/v1/actions/process-check-result' -d '{ "type": "Service", "filter": "host.name==\"OBJHOSTNAME\" && service.name==\"OBJSERVICENAME\"", "exit_status": 2, "plugin_output": "PING CRITICAL - Packet loss = 100%", "performance_data": [ "rta=5000.000000ms;3000.000000;5000.000000;0.000000", "pl=100%;80;100;0" ], "check_source": "check-script", "pretty": true }'
# Sample output of mdadm during rebuild:
#
# root@backup7:~# mdadm --detail /dev/md0
# /dev/md0:
# Version : 1.2
# Creation Time : Sun Apr 23 14:41:14 2023
# Raid Level : raid1
# Array Size : 976630464 (931.39 GiB 1000.07 GB)
# Used Dev Size : 976630464 (931.39 GiB 1000.07 GB)
# Raid Devices : 2
# Total Devices : 2
# Persistence : Superblock is persistent
#
# Intent Bitmap : Internal
#
# Update Time : Sat Jun 15 16:39:53 2024
# State : clean, degraded, recovering
# Active Devices : 1
# Working Devices : 2
# Failed Devices : 0
# Spare Devices : 1
#
# Consistency Policy : bitmap
#
# Rebuild Status : 63% complete
#
# Name : backup7:0 (local to host backup7)
# UUID : 9368b423:542fb2e5:bdf19812:0ac35b4b
# Events : 14803
#
# Number Major Minor RaidDevice State
# 2 8 16 0 spare rebuilding /dev/sdb
# 1 8 32 1 active sync /dev/sdc
# Sample output when in sync:
# root@backup7:~# cat /proc/mdstat
# Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
# md0 : active raid1 sdb[2] sdc[1]
# 976630464 blocks super 1.2 [2/2] [UU]
# bitmap: 0/8 pages [0KB], 65536KB chunk
#
# unused devices: <none>
# root@backup7:~# mdadm --detail /dev/md0
# /dev/md0:
# Version : 1.2
# Creation Time : Sun Apr 23 14:41:14 2023
# Raid Level : raid1
# Array Size : 976630464 (931.39 GiB 1000.07 GB)
# Used Dev Size : 976630464 (931.39 GiB 1000.07 GB)
# Raid Devices : 2
# Total Devices : 2
# Persistence : Superblock is persistent
#
# Intent Bitmap : Internal
#
# Update Time : Sat Jun 15 17:46:09 2024
# State : clean
# Active Devices : 2
# Working Devices : 2
# Failed Devices : 0
# Spare Devices : 0
#
# Consistency Policy : bitmap
#
# Name : backup7:0 (local to host backup7)
# UUID : 9368b423:542fb2e5:bdf19812:0ac35b4b
# Events : 15612
#
# Number Major Minor RaidDevice State
# 2 8 16 0 active sync /dev/sdb
# 1 8 32 1 active sync /dev/sdc
# Sample output when inactive, only 1 device present
# root@backup7:~# mdadm --detail /dev/md0
# /dev/md0:
# Version : 1.2
# Raid Level : raid0
# Total Devices : 1
# Persistence : Superblock is persistent
#
# State : inactive
# Working Devices : 1
#
# Name : backup7:0 (local to host backup7)
# UUID : 9368b423:542fb2e5:bdf19812:0ac35b4b
# Events : 15612
#
# Number Major Minor RaidDevice
#
# - 8 16 - /dev/sdb
# After changing the size of the raid ('mdadm --grow /dev/md0 --size 1800G')
# root@backup7:~# mdadm --detail /dev/md0
# /dev/md0:
# Version : 1.2
# Creation Time : Sun Apr 23 14:41:14 2023
# Raid Level : raid1
# Array Size : 1887436800 (1800.00 GiB 1932.74 GB)
# Used Dev Size : 1887436800 (1800.00 GiB 1932.74 GB)
# Raid Devices : 2
# Total Devices : 2
# Persistence : Superblock is persistent
#
# Intent Bitmap : Internal
#
# Update Time : Sat Jun 15 21:17:31 2024
# State : clean, resyncing
# Active Devices : 2
# Working Devices : 2
# Failed Devices : 0
# Spare Devices : 0
#
# Consistency Policy : bitmap
#
# Resync Status : 56% complete
#
# Name : backup7:0 (local to host backup7)
# UUID : 9368b423:542fb2e5:bdf19812:0ac35b4b
# Events : 17447
#
# Number Major Minor RaidDevice State
# 2 8 16 0 active sync /dev/sdb
# 3 8 32 1 active sync /dev/sdc