30
30
# 20180926 beta7 Handle a workflow in status 'updating' as warning, not critical #
31
31
# 20181107 beta8 Missing pod check type in help, documentation completed #
32
32
# 20181109 1.0.0 Do not alert for succeeded pods #
33
- # #########################################################################################
34
- # todos:
35
- # - check type: nodes (inside a given cluster)
33
+ # 20190308 1.1.0 Added node(s) check #
36
34
# #########################################################################################
37
35
# (Pre-)Define some fixed variables
38
36
STATE_OK=0 # define the exit code if status is OK
@@ -41,7 +39,7 @@ STATE_CRITICAL=2 # define the exit code if status is Critical
41
39
STATE_UNKNOWN=3 # define the exit code if status is Unknown
42
40
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH # Set path
43
41
proto=http # Protocol to use, default is http, can be overwritten with -S parameter
44
- version=1.0 .0
42
+ version=1.1 .0
45
43
46
44
# Check for necessary commands
47
45
for cmd in jshon curl [
54
52
done
55
53
# ########################################################################
56
54
# We all need help from time to time
57
- help= " check_rancher2 v ${version} (c) 2018 Claudio Kuenzler (published under GPLv2)\n
55
+ help= " check_rancher2 v ${version} (c) 2018-2019 Claudio Kuenzler (published under GPLv2)\n
58
56
Usage: $0 -H Rancher2Address -U user-token -P password [-S] -t checktype [-c cluster] [-p project] [-w workload]\n
59
57
\nOptions:\n
60
58
\t-H Address of Rancher 2 API (e.g. rancher.example.com)\n
@@ -71,6 +69,7 @@ Usage: $0 -H Rancher2Address -U user-token -P password [-S] -t checktype [-c clu
71
69
\nCheck Types:\n
72
70
\tinfo -> Informs about available clusters and projects and their API ID's. These ID's are needed for specific checks.\n
73
71
\tcluster -> Checks the current status of all clusters or of a specific cluster (defined with -c clusterid)\n
72
+ \tnode -> Checks the current status of all nodes or of nodes in a specific cluster (defined with -c clusterid)\n
74
73
\tproject -> Checks the current status of all projects or of a specific project (defined with -p projectid)\n
75
74
\tworkload -> Checks the current status of all or a specific (-w workloadname) workload within a project (-p projectid must be set!)\n
76
75
\tpod -> Checks the current status of all or a specific (-o podname -n namespace) pod within a project (-p projectid must be set!)\n
@@ -221,6 +220,75 @@ else
221
220
fi
222
221
;;
223
222
223
+ # --- node status check --- #
224
+ node)
225
+ if [[ -z $clustername ]]; then
226
+
227
+ # Check status of all nodes in all clusters
228
+ api_out_nodes=$( curl -s -u " ${apiuser} :${apipass} " " ${proto} ://${apihost} /v3/nodes" )
229
+ declare -a node_names=( $( echo " $api_out_nodes " | jshon -e data -a -e nodeName -u) )
230
+ declare -a node_status=( $( echo " $api_out_nodes " | jshon -e data -a -e state -u) )
231
+ declare -a node_cluster_member=( $( echo " $api_out_nodes " | jshon -e data -a -e clusterId -u) )
232
+
233
+ i=0
234
+ for node in ${node_names[*]}
235
+ do
236
+ for status in ${node_status[$i]}
237
+ do
238
+ if [[ ${status} != active ]]; then
239
+ nodeerrors[$i ]=" ${node} in cluster ${node_cluster_member[$i]} is ${node_status[$i]} -"
240
+ fi
241
+ done
242
+ let i++
243
+ done
244
+
245
+ if [[ ${# nodeerrors[*]} -gt 0 ]]
246
+ then
247
+ echo " CHECK_RANCHER2 CRITICAL - ${nodeerrors[*]} |'nodes_total'=${# node_names[*]} ;;;; 'node_errors'=${# nodeerrors[*]} ;;;;"
248
+ exit ${STATE_CRITICAL}
249
+ else
250
+ echo " CHECK_RANCHER2 OK - All ${# node_names[*]} nodes are active|'nodes_total'=${# node_names[*]} ;;;; 'node_errors'=${# nodeerrors[*]} ;;;;"
251
+ exit ${STATE_OK}
252
+ fi
253
+
254
+ else
255
+
256
+ # Check status of all nodes in a specific clusters
257
+ api_out_nodes=$( curl -s -u " ${apiuser} :${apipass} " " ${proto} ://${apihost} /v3/nodes/?clusterId=${clustername} " )
258
+
259
+ # Check if that given cluster name exists
260
+ if [[ -n $( echo " $api_out_nodes " | grep -i " error" ) ]]
261
+ then echo " CHECK_RANCHER2 CRITICAL - Cluster $clustername not found. Hint: Use '-t info' to identify cluster and project names." ; exit ${STATE_CRITICAL}
262
+ fi
263
+
264
+ declare -a node_names=( $( echo " $api_out_nodes " | jshon -e data -a -e nodeName -u) )
265
+ declare -a node_status=( $( echo " $api_out_nodes " | jshon -e data -a -e state -u) )
266
+
267
+ i=0
268
+ for node in ${node_names[*]}
269
+ do
270
+ for status in ${node_status[$i]}
271
+ do
272
+ if [[ ${status} != active ]]; then
273
+ nodeerrors[$i ]=" ${node} in cluster ${clustername} is ${node_status[$i]} -"
274
+ fi
275
+ done
276
+ let i++
277
+ done
278
+
279
+ if [[ ${# nodeerrors[*]} -gt 0 ]]
280
+ then
281
+ echo " CHECK_RANCHER2 CRITICAL - ${nodeerrors[*]} |'nodes_total'=${# node_names[*]} ;;;; 'node_errors'=${# nodeerrors[*]} ;;;;"
282
+ exit ${STATE_CRITICAL}
283
+ else
284
+ echo " CHECK_RANCHER2 OK - All ${# node_names[*]} nodes are active|'nodes_total'=${# node_names[*]} ;;;; 'node_errors'=${# nodeerrors[*]} ;;;;"
285
+ exit ${STATE_OK}
286
+ fi
287
+
288
+ fi
289
+ ;;
290
+
291
+
224
292
# --- project status check --- #
225
293
project)
226
294
if [[ -z $projectname ]]; then
0 commit comments