This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcheck_openshift_node_list
executable file
·98 lines (75 loc) · 2.01 KB
/
check_openshift_node_list
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
#!/bin/bash
set -e -u -o pipefail
. /usr/lib/nagios-plugins-openshift/utils
usage() {
echo "Usage: $0 -f <path> [--] <node...>"
echo
echo 'Compare list of nodes in cluster with names specified on command line.'
echo
echo 'Options:'
echo ' -f Config file path'
}
opt_cfgfile=
while getopts 'hf:' opt; do
case "$opt" in
h)
usage
exit 0
;;
f) opt_cfgfile="$OPTARG" ;;
*)
usage >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ -z "$opt_cfgfile" || "$#" < 1 ]]; then
usage >&2
exit 1
fi
tmpfile=$(mktemp)
trap 'rm -f "$tmpfile"' EXIT
get_node_names() {
local cfgfile="$1"
run_oc "$cfgfile" get node \
--output=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
}
# Capture stderr in variable and redirect stdout to file
# shellcheck disable=SC2069
if ! msg=$(get_node_names "$opt_cfgfile" 2>&1 >"$tmpfile"); then
echo "$msg"
exit "$state_critical"
fi
readarray -t nodes < "$tmpfile"
array_sort nodes ${nodes[@]+"${nodes[@]}"}
array_sort expected ${@+"$@"}
array_uniq nodes ${nodes[@]+"${nodes[@]}"}
array_uniq expected ${expected[@]+"${expected[@]}"}
array_sub missing nodes expected
array_sub unexpected expected nodes
# Expected nodes actually found
array_and found nodes expected
exit_status="$state_ok"
output=()
if [[ -n "${missing[*]+${missing[*]}}" ]]; then
output+=( "missing: ${missing[*]}" )
exit_status=$(merge_status "$exit_status" "$state_critical")
fi
if [[ -n "${unexpected[*]+${unexpected[*]}}" ]]; then
output+=( "unexpected: ${unexpected[*]}" )
exit_status=$(merge_status "$exit_status" "$state_critical")
fi
if [[ -n "${found[*]+${found[*]}}" ]]; then
output+=( "found: ${found[*]}" )
fi
# http://docs.icinga.org/latest/en/perfdata.html#perfdata-format
metrics=(
"'nodecount'=${#nodes[@]};;;0"
"'missing'=${#missing[@]};;;0"
"'unexpected'=${#unexpected[@]};;;0;${#nodes[@]}"
)
finish "$exit_status" \
"$(join_args ', ' ${output[@]+"${output[@]}"})" \
"${metrics[*]+${metrics[*]}}"
# vim: set sw=2 sts=2 et :