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
/
check_openshift_node_fluentd
executable file
·114 lines (94 loc) · 2.47 KB
/
check_openshift_node_fluentd
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
#!/bin/bash
set -e -u -o pipefail
. /usr/lib/nagios-plugins-openshift/utils
default_namespace=default
usage() {
echo "Usage: $0 -f <path> [-n <namespace>] [-s <selector>]"
echo
echo 'Check whether all schedulable nodes in a cluster have an instance of'\
'Fluentd running.'
echo
echo 'Options:'
echo ' -f Config file path'
echo " -n Namespace (default: \"$default_namespace\")"
echo ' -s Selector for Fluentd pods, e.g. "component=fluentd"'
}
opt_cfgfile=
opt_namespace=$default_namespace
opt_selector=
while getopts 'hf:n:s:w:c:' opt; do
case "$opt" in
h)
usage
exit 0
;;
f) opt_cfgfile="$OPTARG" ;;
n) opt_namespace="$OPTARG" ;;
s) opt_selector="$OPTARG" ;;
*)
usage >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ "$#" -gt 0 ]]; then
usage >&2
exit 1
fi
if [[ -z "$opt_cfgfile" ]]; then
usage >&2
exit 1
fi
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
# Capture stderr in variable and redirect stdout to file
# shellcheck disable=SC2069
if ! msg=$(run_oc "$opt_cfgfile" get pod \
--output=json \
--namespace="$opt_namespace" \
--selector="$opt_selector" \
2>&1 >"$tmpdir/pod.json"); then
echo "$msg"
exit "$state_critical"
fi
# shellcheck disable=SC2069
if ! msg=$(run_oc "$opt_cfgfile" get node \
--output=json \
--all-namespaces \
2>&1 >"$tmpdir/node.json"); then
echo "$msg"
exit "$state_critical"
fi
# Data structure documentation:
# https://godoc.org/k8s.io/kubernetes/pkg/api/v1>
jq -r '.items[].metadata.name | @text' \
< "$tmpdir/node.json" > "$tmpdir/node.txt"
filter_pods() {
local node="$1"
jq -r "
.items[] |
select(.spec.nodeName == \"${node//\"}\") |
select((.status.conditions // [])[] | select(.type == \"Ready\") | .status == \"True\") |
.metadata.name
"
}
exit_status="$state_ok"
output=()
while read node; do
readarray -t pods < <(filter_pods "$node" < "$tmpdir/pod.json")
if [[ "${#pods[@]}" -eq 1 ]]; then
# Fluentd running
:
elif [[ "${#pods[@]}" -gt 1 ]]; then
output+=( "two or more instances running on $node (${pods[*]})" )
exit_status=$(merge_status "$exit_status" "$state_critical")
else
output+=( "not running on $node" )
exit_status=$(merge_status "$exit_status" "$state_critical")
fi
done < "$tmpdir/node.txt"
finish "$exit_status" \
"$(join_args ', ' ${output[@]+"${output[@]}"})" \
''
# vim: set sw=2 sts=2 et :