forked from brandonjbjelland/nagios_commander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnagios_commander.sh
executable file
·495 lines (469 loc) · 19.4 KB
/
nagios_commander.sh
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
#!/bin/bash -
# Title: nagios_commander.sh
# Author: Brandon J. O'Connor <[email protected]>
# Created: 08.19.12
# Purpose: Provide a CLI interface to query and access common nagios functions remotely
# TODO: password input from a plain text file
# TODO: service group or host group health
# TODO: feedback given when downtime del isn't found or when it successfully dels
# Copyright 2012 Brandon J. O'Connor
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################
unalias -a
# globals can be defined here if desired
#NAG_HOST=''
#USERNAME=''
#PASSWORD=''
NAG_HTTP_SCHEMA='http'
# seconds to poll nagios till downtime is set
NAG_POLL_TIMEOUT=45
USERNAME='<USERNAME>'
function usage {
if [ -z $NAG_HOST ]; then $NAG_HOST='nagios.env/nagios'; fi
PROGNAME=$(basename $0)
DIR="$(cd "$( dirname "$0")" && pwd)"
echo "
-n | --nag-host
nagios HOSTNAME followed by its nagios directory
-N | --nag-http-schema
nagios URI schema (http|https)
-u | --username
USER to execute commands
-p | --password
PASSWORD of the executing user
-q | --query
QUERY a nagios or device in nagios
list (object or group object required)
host_downtime
service_downtime
notifications (global)
event_handlers (global)
active_svc_checks (global)
passive_svc_checks (global)
active_host_checks (global)
passive_host_checks (global)
-c | --command
COMMAND to issue in the form --command [action] [scope] [value]
action: set
del
ack
recheck
scope: (required for all but ack)
downtime
notifications
event_handlers
active_svc_checks
passive_svc_checks
active_host_checks
passive_host_checks
value: (only required for global commands)
enable
disable
-d | --down_id
Downtime id number for deleting a specific downtime
-Q | --quiet
Flag for QUICK execution and QUIET output
-h | --host
HOST to execute the METHOD against. Leave blank to query all hosts.
-H | --hostgroup
HOSTGROUP to execute the METHOD against. -H followed by nothing for listing all.
-s | --service_name
SERVICE as execution object.
-S | --servicegroup
SERVICEGROUP an execution object. Follow with nothing to list all.
-t | --time
TIME in minutes to place on a downtime window, beginning now
-C
COMMENT (required by set downtime, ack)
-*
print this help dialog
Usage: $PROGNAME -n <nagios_instance> -c <commands> <method> -h <host> -H <host_group> -s <service> -S <service_group> -t <time_in_mins> -c <downtime_comment>
Examples:
$DIR/$PROGNAME -n $NAG_HOST -c set downtime -h cfengine01.sea -s PROC_CFAGENT_QUIET -t 1 -C 'downtime comment' -Q -u $USERNAME -p <PASSWORD>
$DIR/$PROGNAME -n $NAG_HOST -q list -h -u $USERNAME -p <PASSWORD>
$DIR/$PROGNAME -n $NAG_HOST -q host_downtime -u $USERNAME -p <PASSWORD>
"
exit 1
}
while [ "$1" != "" ]; do
case $1 in
-n | --nag ) shift; NAG_HOST=$1;;
-N | --nag_http_schema ) shift; NAG_HTTP_SCHEMA=$1;;
-h | --host ) if [[ $2 = [A-Za-z]* ]]; then shift; HOST=$1 ; else HOST=list; fi ;;
-H | --host_group ) if [[ $2 = [A-Za-z]* ]]; then shift; HOSTGROUP=$1; else HOSTGROUP=list; fi;;
-s | --service ) if [[ $2 = [A-Za-z]* ]]; then shift; SERVICE=$1; else SERVICE=list; fi;;
-S | --service_group ) if [[ $2 = [A-Za-z]* ]]; then shift; SERVICEGROUP=$1; else SERVICEGROUP=list; fi;;
-t | --time ) shift; MINUTES=$1;;
-q | --query ) shift; QUERY=$1;;
-c | --command ) shift; ACTION=$1; if [[ ! $ACTION =~ ack ]];then shift; SCOPE=$1; if [[ $2 = [a-z]* ]]; then shift; VALUE=$1; fi; fi;;
-C | --comment ) shift; COMMENT=$1;;
-u | --username ) shift; USERNAME=$1;;
-p | --password ) shift; PASSWORD=$1;;
-d | --down_id ) shift; DOWN_ID=$1;;
-Q | --quiet ) QUIET=1;;
-D | --debug ) DEBUG=1;;
* | --help ) usage;;
esac
shift
done
if [ -n "$DEBUG" ]; then
echo "DEBUG INFO: NAG_HOST=$NAG_HOST, SCOPE=$SCOPE, ACTION=$ACTION, VALUE=$VALUE, HOST=$HOST, HOSTGROUP=$HOSTGROUP, SERVICE=$SERVICE, SERVICEGROUP=$SERVICEGROUP, TIME=$MINUTES, QUERY=$QUERY, COMMENT=$COMMENT, TIME=$TIME, QUIET=$QUIET"
fi
if [ -z $USERNAME ]; then read -p "Username: " USERNAME; fi
if [ -z $PASSWORD ]; then read -s -p "Password for $USERNAME: " PASSWORD; echo ""; fi
if [ $NAG_HOST ] && [ $USERNAME ] && [ $PASSWORD ] ; then
if [ ! $ACTION ] && [ ! $QUERY ]; then
echo "A query or command must be specified."; sleep 1; usage
elif [ $ACTION ] && [ $QUERY ]; then
echo "Cannot execute both a query and command."; sleep 1; usage
fi
else
echo "Script initiated with insufficient inputs. Exiting."; sleep 1; usage
fi
# verify creds are good on the fastest page possible
NAGIOS_INSTANCE="$NAG_HTTP_SCHEMA://$NAG_HOST/cgi-bin"
if [ -n "`curl -Ss $NAGIOS_INSTANCE/ -u $USERNAME:$PASSWORD | grep 'Authorization'`" ]; then
echo "Bad credentials. Exiting"; exit 1
fi
function MAIN {
if [ $QUERY ]; then
if [[ $QUERY = list ]]; then
if [[ $HOST = list ]]; then
DATA="--data hostgroup=all --data style=hostdetail"
LIST_HOSTS
elif [ $HOST ]; then
DATA="--data host=$HOST --data style=detail"
LIST_SERVICES
exit 0
elif [[ $HOSTGROUP = list ]]; then
DATA="--data hostgroup=all --data style=summary"
TYPE='host'
LIST_GROUPS
elif [ $HOSTGROUP ]; then
DATA="--data hostgroup=$HOSTGROUP --data style=hostdetail"
LIST_HOSTS
elif [[ $SERVICEGROUP = list ]]; then
DATA="--data servicegroup=all --data style=summary"
TYPE='service'
LIST_GROUPS
elif [ $SERVICEGROUP ]; then
DATA="--data servicegroup=$SERVICEGROUP --data style=detail"
#LIST_SERVICES
#This function will have to be separated out
echo "Feature pending"
exit
fi
else
if [[ $QUERY = event_handlers ]]; then
SEARCH='Event Handlers Enabled'
elif [[ $QUERY = notifications ]]; then
SEARCH='Notifications Enabled'
elif [[ $QUERY = active_svc_checks ]]; then
SEARCH='Service Checks Being Executed'
elif [[ $QUERY = passive_svc_checks ]]; then
SEARCH='Passive Service Checks'
elif [[ $QUERY = active_host_checks ]]; then
SEARCH='Host Checks Being Executed'
elif [[ $QUERY = passive_host_checks ]]; then
SEARCH='Passive Host Checks'
elif [[ $QUERY = host_downtime ]]; then
SCOPE='hosts'; DOWNTIME_QUERY; exit
elif [[ $QUERY = service_downtime ]]; then
SCOPE='services'; DOWNTIME_QUERY; exit
else
echo "A global object is required."; usage
fi
GLOBAL_QUERY
fi
elif [ $ACTION ]; then
if [ ! $HOST ] && [ ! $HOSTGROUP ] && [ ! $SERVICEGROUP ] && [[ $ACTION = set ]]; then
if [[ $SCOPE = notifications ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='12'; VALUE='enabled'; GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='11'; VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Notifications Enabled'; GLOBAL_QUERY
fi
elif [[ $SCOPE = event_handlers ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='41'; VALUE='enabled';GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='42';VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Event Handlers Enbled'; GLOBAL_QUERY
fi
elif [[ $SCOPE = active_service_checks ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='35'; VALUE='enabled'; GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='36'; VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Service Checks Being Executed'; GLOBAL_QUERY
fi
elif [[ $SCOPE = passive_service_checks ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='37'; VALUE='enabled'; GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='38'; VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Passive Service Checks'; GLOBAL_QUERY
fi
elif [[ $SCOPE = active_host_checks ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='88'; VALUE='enabled'; GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='89'; VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Host Checks Being Executed'; GLOBAL_QUERY
fi
elif [[ $SCOPE = passive_host_checks ]]; then
if [[ $VALUE =~ en ]]; then CMD_TYP='90'; VALUE='enabled'; GLOBAL_COMMAND;
elif [[ $VALUE =~ dis ]]; then CMD_TYP='91'; VALUE='disabled'; GLOBAL_COMMAND;
else
echo "An action is required (enable or disable)"
SEARCH='Passive Host Checks'; GLOBAL_QUERY
fi
fi
elif [[ $ACTION = set ]] || [[ $ACTION = ack ]] ; then
if [[ $SCOPE = downtime ]]; then
if [ $HOST ] && [ ! $SERVICE ]; then
CMD_TYP='55'; DATA="--data host=$HOST --data trigger=0"
elif [ $HOST ] && [ $SERVICE ]; then
CMD_TYP='56'
DATA="--data service=$SERVICE --data host=$HOST --data trigger=0"
elif [ $HOSTGROUP ]; then
CMD_TYP='84'; DATA="--data hostgroup=$HOSTGROUP"
elif [ $SERVICEGROUP ]; then
CMD_TYP='122'; DATA="--data servicegroup=$SERVICEGROUP"
else
echo "$SCOPE needs to be applied to a service, host, hostgroup or servicegroup. Exiting."
exit 1
fi
SET_DOWNTIME
elif [[ $ACTION = ack ]] && [ $HOST ] && [ $SERVICE ] ; then
DATA="--data cmd_typ=34 --data service=$SERVICE"; ACKNOWLEDGE
elif [[ $ACTION = ack ]] && [ $HOST ] ; then
DATA="--data cmd_typ=33"; ACKNOWLEDGE
elif [[ $ACTION = recheck ]] && [ $HOST ] && [ $SERVICE ] ; then
DATA="--data cmd_typ=7 --data service=$SERVICE"; RECHECK
elif [[ $ACTION = recheck ]] && [ $HOST ] ; then
DATA="--data cmd_typ=6"; RECHECK
fi
elif [[ $ACTION = del ]]; then
if [ $DOWN_ID ]; then
CMD_TYP=79 ; DELETE_DOWNTIME; CMD_TYP=78 ; DELETE_DOWNTIME
exit 0
elif [ $SERVICE ] && [ $HOST ]; then
CMD_TYP=79
COUNT=1; SCOPE=services
while [ ! $DOWN_ID ] && [ $COUNT -lt 5 ] ; do
FIND_DOWN_ID; COUNT=$[$COUNT+1]
done
if [ ! $DOWN_ID ]; then echo "Could not find downtime for $HOST. Exiting."
exit 1
fi
DELETE_DOWNTIME; exit 0
elif [ $HOST ]; then
CMD_TYP=78
COUNT=1; SCOPE=hosts
while [ ! $DOWN_ID ] && [ $COUNT -lt 5 ] ; do
FIND_DOWN_ID; COUNT=$[$COUNT+1]
done
if [ ! $DOWN_ID ]; then echo "Could not find downtime for $HOST. Exiting."
exit 1
fi
DELETE_DOWNTIME; exit
else
echo "No host, service or downtime-id specified. Listing current downtimes now."
SCOPE=hosts; DOWNTIME_QUERY; SCOPE=services; DOWNTIME_QUERY
fi
else
echo "Command not recognized."; usage
fi
else
echo "Method not specified."; usage
fi
}
function SET_DOWNTIME {
NOW_ADD_MINS=$(date +"%Y-%m-%dT%H:%M:%S" -d "+$MINUTES minute")
if [ ! $MINUTES ]; then
echo "Time value not set. Cannot submit downtime requests without a duration."
exit
fi
NOW=$(date +"%Y-%m-%dT%H:%M:%S")
curl -sS $DATA $NAGIOS_INSTANCE/cmd.cgi -u "$USERNAME:$PASSWORD" \
--data cmd_typ=$CMD_TYP \
--data cmd_mod=2 \
--data "com_data=$COMMENT" \
--data "start_time=$NOW" \
--data "end_time=$NOW_ADD_MINS" \
--data fixed=1 \
--data hours=2 \
--data minutes=0 \
--data btnSubmit=Commit \
--output /dev/null
if [ $? -eq 1 ]; then echo "curl failed. Command not sent."; exit 1; fi
if [ -z $QUIET ]; then
if [ $SERVICE ]; then SCOPE=services; elif [ $HOST ]; then SCOPE=hosts; fi
if [ $HOST ] || [ $SERVICE ]; then
COUNT=2; FIND_DOWN_ID; OLD_DID=$DOWN_ID;
if [ $OLD_DID ]; then sleep 1; else OLD_DID=1 && DOWN_ID=1; fi
while [ $DOWN_ID -eq $OLD_DID ] && [ $COUNT -le $NAG_POLL_TIMEOUT ] ; do
sleep 1; FIND_DOWN_ID; COUNT=$[$COUNT+1]
done
if [ $DOWN_ID -eq 1 ]; then
echo "Could not find newly created downtime. Exiting."; exit 1
fi
fi
echo $DOWN_ID
fi
exit
}
function FIND_DOWN_ID {
if [[ $SCOPE = hosts ]]; then
DOWN_ID=$(curl -Ss $NAGIOS_INSTANCE/extinfo.cgi -u $USERNAME:$PASSWORD \
--data type=6 | grep "extinfo.cgi" | sed -e'/service=/d' |\
awk -F"<td CLASS='downtime" '{print $2" "$4" "$7" "$10" "$5}' |\
awk -F'>' '{print $3"|||"$10}' | sed -e's/<\/td//g' -e's/<\/A//g' |\
egrep "$HOST" | egrep -o "[0-9]+" | sort -rn | head -n1)
if [ ! $DOWN_ID ]; then DOWN_ID=1; fi
elif [[ $SCOPE = services ]]; then
DOWN_ID=$(curl -Ss $NAGIOS_INSTANCE/extinfo.cgi -u $USERNAME:$PASSWORD \
--data type=6 | grep "extinfo.cgi" | grep "service=" |\
awk -F"<td CLASS='downtime" '{print $2" "$3" "$5" "$7" "$8" "$6" "$11}' |\
awk -F'>' '{print $3"|||"$7"|||"$18}' | sed -e's/<\/td//g' -e's/<\/A//g' |\
column -c8 -t -s"|||" | egrep "$HOST" | grep "$SERVICE" | egrep -o "[0-9]+" |\
sort -rn | head -n1)
if [ ! $DOWN_ID ]; then DOWN_ID=1; fi
if [ $? -eq 1 ]; then echo "curl failed"; exit 1; fi
fi
}
function DOWNTIME_QUERY {
if [[ $SCOPE = hosts ]]; then
curl -Ss $NAGIOS_INSTANCE/extinfo.cgi --data type=6 -u $USERNAME:$PASSWORD |\
grep "extinfo.cgi" | sed -e'/service=/d' |\
awk -F"<td CLASS='downtime" '{print $2" "$4" "$7" "$10" "$5}' |\
awk -F'>' '{print $3"|||"$10"|||"$8"|||"$6"|||"$12}' |\
sed -e's/<\/td//g' -e's/<\/A//g' |\
sed "1 i \Hostname|||Downtime-id|||End_date_and_time|||Author|||Comment" |\
column -c7 -t -s"|||"
elif [[ $SCOPE = services ]]; then
curl -Ss $NAGIOS_INSTANCE/extinfo.cgi --data type=6 -u $USERNAME:$PASSWORD |\
grep "extinfo.cgi" | grep "service=" |\
awk -F"<td CLASS='downtime" '{print $2" "$3" "$5" "$7" "$8" "$6" "$11}' |\
awk -F'>' '{print $3"|||"$7"|||"$18"|||"$14"|||"$10"|||"$16}' |\
sed -e's/<\/td//g' -e's/<\/A//g' |\
sed "1 i \Hostname|||Service|||Downtime-id|||End_date_and_time|||Author|||Comment" |\
column -c8 -t -s"|||"
fi
if [ $? -eq 1 ]; then echo "curl failed"; exit 1; fi
}
function DELETE_DOWNTIME {
curl -Ss --output /dev/null $NAGIOS_INSTANCE/cmd.cgi \
--data cmd_mod=2 \
--data cmd_typ=$CMD_TYP \
--data down_id=$DOWN_ID \
--data btnSubmit=Commit \
-u $USERNAME:$PASSWORD
if [ $? -eq 1 ]; then echo "curl failed"; exit 1; fi
}
function GLOBAL_COMMAND {
curl -sS $DATA \
"$NAGIOS_INSTANCE/cmd.cgi" \
--data cmd_mod=2 \
--data cmd_typ=$CMD_TYP \
--data btnSubmit=Commit \
-u $USERNAME:$PASSWORD |\
grep -o 'Your command request was successfully submitted to Nagios for processing.'
if [ $? -eq 1 ]; then echo "curl failed. Command not sent."; exit 1; fi
QUERY=$SCOPE; RESULT=`MAIN`
until [[ $SCOPE:$VALUE = $RESULT ]]; do sleep 1; RESULT=`MAIN`; done
echo $RESULT
exit 0
}
function GLOBAL_QUERY {
HTML=`curl -sS $NAGIOS_INSTANCE/extinfo.cgi \
--data type=0 \
-u $USERNAME:$PASSWORD | grep "$SEARCH"`
if [ $? -eq 1 ]; then echo "curl failed"; exit 1; fi
MATCH=`echo $HTML | grep -i 'yes'`
if [ -n "$MATCH" ]; then echo "$QUERY:enabled"; exit
else echo "$QUERY:disabled"; exit 0; fi
}
function ACKNOWLEDGE {
curl -sS $DATA \
$NAGIOS_INSTANCE/cmd.cgi \
--data host=$HOST \
--data "com_data=$COMMENT" \
--data cmd_mod=2 \
--data btnSubmit=Commit \
-u $USERNAME:$PASSWORD |\
grep -o 'Your command request was successfully submitted to Nagios for processing.'
if [ $? -eq 1 ]; then echo "curl failed. Command not sent."; exit 1; fi
exi
t
}
function RECHECK {
NOW=$(date +"%Y-%m-%dT%H:%M:%S")
curl -sS $DATA \
$NAGIOS_INSTANCE/cmd.cgi \
--data host=$HOST \
--data "time=$NOW" \ # best effort guess
--data cmd_typ=7 \
--data cmd_mod=2 \ # is this necessary?
--data btnSubmit=Commit \
--data "force_recheck"
-u $USERNAME:$PASSWORD |\
grep -o 'Your command request was successfully submitted to Nagios for processing.'
if [ $? -eq 1 ]; then echo "curl failed. Command not sent."; exit 1; fi
exit 0
}
function SET_STATUS {
# not implemented yet
curl -sS $DATA \
$NAGIOS_INSTANCE/cmd.cgi \
--data host=$HOST \
--data "com_data=$COMMENT" \
--data cmd_mod=2 \
--data btnSubmit=Commit \
-u $USERNAME:$PASSWORD |\
grep -o 'Your command request was successfully submitted to Nagios for processing.'
if [ $? -eq 1 ]; then echo "curl failed. Command not sent."; exit 1; fi
exit
}
function LIST_HOSTS {
echo -e "Hostname\tStatus"
curl -Ss $DATA $NAGIOS_INSTANCE/status.cgi -u $USERNAME:$PASSWORD |\
grep 'extinfo.cgi?type=1&host=' | grep "statusHOST" | awk -F'</A>' '{print $1}' |\
awk -F'statusHOST' '{print $2}' | awk -F"'>" '{print $3"\t"$1}' | sed 's/<\/a> <\/td>//g' | column -c2 -t
exit
}
function LIST_GROUPS {
echo "List of all $TYPE\groups"
echo "---"
curl -Ss $DATA $NAGIOS_INSTANCE/status.cgi -u $USERNAME:$PASSWORD |\
egrep "status(Even|Odd)" | grep "status.cgi?$TYPE\group=" | awk -F'</A>' '{print $1}' |\
awk -F"${TYPE}group=" '{print $2}' | awk -F'&' '{print $1}' | column -c2 -t
exit
}
function LIST_SERVICES {
echo Fetching services and health on $HOST
echo ---
HOSTS=($(curl -Ss $DATA $NAGIOS_INSTANCE/status.cgi -u $USERNAME:$PASSWORD |\
grep "extinfo.cgi?type=2&host=" | cut -d"=" -f8 | cut -d"'" -f1))
STATUSES=($(curl -Ss $DATA $NAGIOS_INSTANCE/status.cgi -u $USERNAME:$PASSWORD |\
egrep "status(OK|CRITICAL|WARNING|UNKNOWN)" | cut -d"'" -f2 | cut -c 7-))
for i in $(seq 0 $(( ${#HOSTS[@]} - 1 )) ); do
COMBINED=(${COMBINED[@]} ${HOSTS[$i]}@${STATUSES[$i]})
done
echo ${COMBINED[@]} | tr ' ' '\n' | sed '1 i \---' | sed '1 i \Service@State' |\
tr '@' ' ' | column -c2 -t
}
MAIN