Skip to content

Commit e5fbbbf

Browse files
author
MMA
committed
add MODE: apicert to check the expiration date
1 parent 49b5dc2 commit e5fbbbf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

check_kubernetes.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ usage() {
3838
3939
Modes are:
4040
apiserver Not for kubectl, should be used for each apiserver independently
41+
apicert Check the apicert expiration date
4142
nodes Check for active nodes
4243
daemonsets Check for daemonsets readiness
4344
deployments Check for deployments availability
@@ -150,6 +151,28 @@ mode_apiserver() {
150151
fi
151152
}
152153

154+
mode_apicert() {
155+
if [ -z "$APISERVER" ]; then
156+
die "Apiserver URL should be defined in this mode"
157+
fi
158+
APICERT=$(echo "$APISERVER" | awk -F "//" '{ print $2 }' | awk -F ":" '{ print $1 }')
159+
APICERTDATE=$(echo | openssl s_client -connect "$APICERT":6443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | sed -e 's#notAfter=##')
160+
a=$(date -d "$APICERTDATE" +%s)
161+
b=$(date +%s)
162+
c=$((a-b))
163+
d=$((c/3600/24))
164+
echo "APICERT expires in $d days"
165+
if [ "$d" -gt "$WARN" ]; then
166+
echo "APICERT is OK"
167+
elif [ $d -le $WARN ] && [ $d -gt $CRIT ]; then
168+
echo "APICERT is in WARN"
169+
EXITCODE=1
170+
elif [ $d -le $CRIT ]; then
171+
echo "APICERT is in CRIT"
172+
EXITCODE=2
173+
fi
174+
}
175+
153176
mode_nodes() {
154177
data="$(getJSON "api/v1/nodes")"
155178
[ $? -gt 0 ] && die "$data"
@@ -723,6 +746,7 @@ mode_jobs() {
723746

724747
case "$MODE" in
725748
(apiserver) mode_apiserver ;;
749+
(apicert) mode_apicert ;;
726750
(daemonsets) mode_daemonsets ;;
727751
(deployments) mode_deployments ;;
728752
(nodes) mode_nodes ;;

0 commit comments

Comments
 (0)