Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Nagios-style checks against Kubernetes API. Designed for usage with Nagios, Icin

* jq
* openssl
* bc (for mode pvc)

## Script usage

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

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

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.
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.

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

Expand Down
5 changes: 4 additions & 1 deletion account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ rules:
resources:
- pods
- nodes
- secrets
# required for mode pvc
# - nodes/proxy
# required for mode tls
# - secrets
- persistentvolumes
verbs:
- get
Expand Down
21 changes: 10 additions & 11 deletions check_kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ mode_nodes() {
.status")"
if [ "$ready" != True ]; then
EXITCODE=2
OUTPUT="${OUTPUT}Node $node not ready. "
OUTPUT="ERROR. ${OUTPUT}Node $node not ready\n"
fi
for condition in OutOfDisk MemoryPressure DiskPressure; do
state="$(echo "$data" | jq -r ".items[] | select(.metadata.name==\"$node\") | \
.status.conditions[] | select(.type==\"$condition\") | \
.status")"
if [ "$state" = True ]; then
[ $EXITCODE -lt 1 ] && EXITCODE=1
OUTPUT="${OUTPUT} $node $condition. "
OUTPUT="WARN. ${OUTPUT} $node $condition\n"
fi
done
done
Expand Down Expand Up @@ -253,23 +253,19 @@ mode_pvc() {
((PVC_COUNT++))

if [ "$volume_bytes_utilization" -gt "$WARN" ] && [ "$volume_bytes_utilization" -lt "$CRIT" ]; then
echo "WARNING. High storage utilization on pvc $volume_name (namespace:$volumes_namespace): \
$volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)"
OUTPUT="${OUTPUT}High storage utilization on pvc $volume_name (namespace:$volumes_namespace): $volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)\n"
((WARN_ERROR++))
fi
if [ "$volume_bytes_utilization" -gt "$CRIT" ]; then
echo "CRITICAL. Very high storage utilization on pvc $volume_name: \
$volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)"
OUTPUT="${OUTPUT}Very high storage utilization on pvc $volume_name: $volume_bytes_utilization% ($volume_bytes_used/$volume_bytes_capacity Bytes)\n"
((CRIT_ERROR++))
fi
if [ "$volume_inodes_utilization" -gt "$WARN" ] && [ "$volume_inodes_utilization" -lt "$CRIT" ]; then
echo "WARNING. High inodes utilization on pvc $volume_name: \
$volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)"
OUTPUT="${OUTPUT}High inodes utilization on pvc $volume_name: $volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)\n"
((WARN_ERROR++))
fi
if [ "$volume_inodes_utilization" -gt "$CRIT" ]; then
echo "CRITICAL. Very high inodes utilization on pvc $volume_name: \
$volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)"
OUTPUT="${OUTPUT}Very high inodes utilization on pvc $volume_name: $volume_inodes_utilization% ($volume_inodes_used/$volume_inodes_capacity)\n"
((CRIT_ERROR++))
fi
done
Expand All @@ -279,12 +275,15 @@ mode_pvc() {
done

if [ "$WARN_ERROR" -eq "0" ] && [ "$CRIT_ERROR" -eq "0" ]; then
echo "OK. No problem on $PVC_COUNT pvc storage"
echo "OK. No problems on $PVC_COUNT pvc"
elif [ "$WARN_ERROR" -ne "0" ] && [ "$CRIT_ERROR" -eq "0" ]; then
echo "WARNING.\n${OUTPUT}"
exit 1
elif [ "$CRIT_ERROR" -ne "0" ]; then
echo "CRITICAL.\n${OUTPUT}"
exit 2
else
echo "ERROR.\n${OUTPUT}"
exit 3
fi
}
Expand Down