@@ -28,16 +28,19 @@ usage() {
28
28
- Pod restart count in pods mode; default is 30
29
29
- Job failed count in jobs mode; default is 1
30
30
- Pvc storage utilization; default is 80%
31
+ - APICERT expiration days for apicert mode; default is 30
31
32
-c CRIT Critical threshold for
32
33
- Pod restart count (in pods mode); default is 150
33
34
- Unbound Persistent Volumes in unboundpvs mode; default is 5
34
35
- Job failed count in jobs mode; default is 2
35
36
- Pvc storage utilization; default is 90%
37
+ - APICERT expiration days for apicert mode; default is 15
36
38
-M EXIT_CODE Exit code when resource is missing; default is 2 (CRITICAL)
37
39
-h Show this help and exit
38
40
39
41
Modes are:
40
42
apiserver Not for kubectl, should be used for each apiserver independently
43
+ apicert Check the apicert expiration date
41
44
nodes Check for active nodes
42
45
daemonsets Check for daemonsets readiness
43
46
deployments Check for deployments availability
@@ -150,6 +153,37 @@ mode_apiserver() {
150
153
fi
151
154
}
152
155
156
+ mode_apicert () {
157
+ if [ -z " $APISERVER " ]; then
158
+ die " Apiserver URL should be defined in this mode"
159
+ fi
160
+ WARN=${WARN:- 30}
161
+ CRIT=${CRIT:- 15}
162
+ APICERT=$( echo " $APISERVER " | awk -F " //" ' { print $2 }' | awk -F " :" ' { print $1 }' )
163
+ APIPORT=$( echo " $APISERVER " | awk -F " //" ' { print $2 }' | awk -F " :" ' { print $2 }' )
164
+ APIPORT=${APIPORT:= 443}
165
+ timeout " $TIMEOUT " bash -c " </dev/tcp/$APICERT /$APIPORT " & > /dev/null
166
+ if [ $? -ne 0 ]; then
167
+ echo " APICERT is in UNKNOWN"
168
+ exit 3
169
+ fi
170
+ APICERTDATE=$( echo | openssl s_client -connect " $APICERT " :" $APIPORT " 2> /dev/null | openssl x509 -noout -dates | grep notAfter | sed -e ' s#notAfter=##' )
171
+ a=$( date -d " $APICERTDATE " +%s)
172
+ b=$( date +%s)
173
+ c=$(( a- b))
174
+ d=$(( c/ 3600 / 24 ))
175
+ echo " APICERT expires in $d days"
176
+ if [ " $d " -gt " $WARN " ] && [ " $d " -gt " $CRIT " ]; then
177
+ echo " APICERT is OK"
178
+ elif [ " $d " -le " $WARN " ] && [ $d -gt " $CRIT " ]; then
179
+ echo " APICERT is in WARN"
180
+ EXITCODE=1
181
+ elif [ " $d " -le " $CRIT " ]; then
182
+ echo " APICERT is in CRIT"
183
+ EXITCODE=2
184
+ fi
185
+ }
186
+
153
187
mode_nodes () {
154
188
data=" $( getJSON " api/v1/nodes" ) "
155
189
[ $? -gt 0 ] && die " $data "
@@ -723,6 +757,7 @@ mode_jobs() {
723
757
724
758
case " $MODE " in
725
759
(apiserver) mode_apiserver ;;
760
+ (apicert) mode_apicert ;;
726
761
(daemonsets) mode_daemonsets ;;
727
762
(deployments) mode_deployments ;;
728
763
(nodes) mode_nodes ;;
0 commit comments