Skip to content

Commit aad9bc5

Browse files
authored
Merge pull request #29 from PERBILITY/master
fix for mode pvc and a couple message improvements
2 parents d6cd125 + f0d0a6b commit aad9bc5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Nagios-style checks against Kubernetes API. Designed for usage with Nagios, Icin
66

77
* jq
88
* openssl
9+
* bc (for mode pvc)
910

1011
## Script usage
1112

@@ -125,7 +126,7 @@ All the needed objects (ServiceAccount, ClusterRole, RoleBinding) can be created
125126

126127
kubectl apply -f https://raw.githubusercontent.com/agapoff/check_kubernetes/master/account.yaml
127128

128-
You may also prefer to revise and tighten the RBAC role if you're not going to use all modes. For example you may get rid of secrets permission if you have no need to check the TLS certs.
129+
For mode pvc or tls you need to enable the permissions in the yaml first. Those two can have security implications and are thus disabled by default.
129130

130131
Then in order to get the token just issue this command:
131132

account.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ rules:
2323
resources:
2424
- pods
2525
- nodes
26-
- secrets
26+
# required for mode pvc
27+
# - nodes/proxy
28+
# required for mode tls
29+
# - secrets
2730
- persistentvolumes
2831
verbs:
2932
- get

check_kubernetes.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ mode_nodes() {
164164
.status")"
165165
if [ "$ready" != True ]; then
166166
EXITCODE=2
167-
OUTPUT="${OUTPUT}Node $node not ready. "
167+
OUTPUT="ERROR. ${OUTPUT}Node $node not ready\n"
168168
fi
169169
for condition in OutOfDisk MemoryPressure DiskPressure; do
170170
state="$(echo "$data" | jq -r ".items[] | select(.metadata.name==\"$node\") | \
171171
.status.conditions[] | select(.type==\"$condition\") | \
172172
.status")"
173173
if [ "$state" = True ]; then
174174
[ $EXITCODE -lt 1 ] && EXITCODE=1
175-
OUTPUT="${OUTPUT} $node $condition. "
175+
OUTPUT="WARN. ${OUTPUT} $node $condition\n"
176176
fi
177177
done
178178
done
@@ -253,23 +253,19 @@ mode_pvc() {
253253
((PVC_COUNT++))
254254

255255
if [ "$volume_bytes_utilization" -gt "$WARN" ] && [ "$volume_bytes_utilization" -lt "$CRIT" ]; then
256-
echo "WARNING. High storage utilization on pvc $volume_name (namespace:$volumes_namespace): \
257-
$volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)"
256+
OUTPUT="${OUTPUT}High storage utilization on pvc $volume_name (namespace:$volumes_namespace): $volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)\n"
258257
((WARN_ERROR++))
259258
fi
260259
if [ "$volume_bytes_utilization" -gt "$CRIT" ]; then
261-
echo "CRITICAL. Very high storage utilization on pvc $volume_name: \
262-
$volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)"
260+
OUTPUT="${OUTPUT}Very high storage utilization on pvc $volume_name: $volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)\n"
263261
((CRIT_ERROR++))
264262
fi
265263
if [ "$volume_inodes_utilization" -gt "$WARN" ] && [ "$volume_inodes_utilization" -lt "$CRIT" ]; then
266-
echo "WARNING. High inodes utilization on pvc $volume_name: \
267-
$volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)"
264+
OUTPUT="${OUTPUT}High inodes utilization on pvc $volume_name: $volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)\n"
268265
((WARN_ERROR++))
269266
fi
270267
if [ "$volume_inodes_utilization" -gt "$CRIT" ]; then
271-
echo "CRITICAL. Very high inodes utilization on pvc $volume_name: \
272-
$volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)"
268+
OUTPUT="${OUTPUT}Very high inodes utilization on pvc $volume_name: $volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)\n"
273269
((CRIT_ERROR++))
274270
fi
275271
done
@@ -279,12 +275,15 @@ mode_pvc() {
279275
done
280276

281277
if [ "$WARN_ERROR" -eq "0" ] && [ "$CRIT_ERROR" -eq "0" ]; then
282-
echo "OK. No problem on $PVC_COUNT pvc storage"
278+
echo "OK. No problems on $PVC_COUNT pvc"
283279
elif [ "$WARN_ERROR" -ne "0" ] && [ "$CRIT_ERROR" -eq "0" ]; then
280+
echo "WARNING.\n${OUTPUT}"
284281
exit 1
285282
elif [ "$CRIT_ERROR" -ne "0" ]; then
283+
echo "CRITICAL.\n${OUTPUT}"
286284
exit 2
287285
else
286+
echo "ERROR.\n${OUTPUT}"
288287
exit 3
289288
fi
290289
}

0 commit comments

Comments
 (0)