11
11
usage () {
12
12
cat << - EOF
13
13
Usage $0 [-m <MODE>|-h] [-o <TIMEOUT>] [-H <APISERVER> [-T <TOKEN>|-t <TOKENFILE>]] [-K <KUBE_CONFIG>]
14
- [-N <NAMESPACE>] [-n <NAME>] [-E <EXCLUDENS>] [-w <WARN>] [-c <CRIT>] [-v]
14
+ [-N <NAMESPACE>] [-n <NAME>] [-r <EXCLUDE>] [- E <EXCLUDENS>] [-w <WARN>] [-c <CRIT>] [-v]
15
15
16
16
Options are:
17
17
-m MODE Which check to perform
@@ -20,8 +20,9 @@ usage() {
20
20
-t TOKENFILE Path to file with token in it
21
21
-K KUBE_CONFIG Path to kube-config file for kubectl utility
22
22
-N NAMESPACE Optional namespace for some modes. By default all namespaces will be used
23
- -n NAME Optional deployment name or pod app label depending on the mode being used. By default all objects will be checked
24
- -E EXCLUDENS Optional exclusion of Namespaces patterns as List seperated by comma. Example: -E test,^kube,^version-report$
23
+ -n NAME Optional name of the object depending on the mode being used. By default all objects will be checked
24
+ -e EXCLUDE Optional exclusion of the objects names as a list of patterms seperated by comma. Example: -e redis,^testpod
25
+ -E EXCLUDENS Optional exclusion of namespaces as a list of patterms seperated by comma. Example: -E test,^kube,^version-report$
25
26
-o TIMEOUT Timeout in seconds; default is 15
26
27
-w WARN Warning threshold for
27
28
- TLS expiration days for TLS mode; default is 30
@@ -61,7 +62,7 @@ usage() {
61
62
exit 2
62
63
}
63
64
64
- VERSION=" v1.5.2 "
65
+ VERSION=" v1.5.3 "
65
66
66
67
TIMEOUT=15
67
68
unset NAME
@@ -71,7 +72,7 @@ die() {
71
72
exit " ${2:- 2} "
72
73
}
73
74
74
- while getopts " :m:M:H:T:t:K:N:n:E:o:c:w:h:v" arg; do
75
+ while getopts " :m:M:H:T:t:K:N:n:e: E:o:c:w:h:v" arg; do
75
76
case $arg in
76
77
h) usage ;;
77
78
m) MODE=" $OPTARG " ;;
@@ -83,6 +84,7 @@ while getopts ":m:M:H:T:t:K:N:n:E:o:c:w:h:v" arg; do
83
84
K) export KUBECONFIG=" $OPTARG " ;;
84
85
N) NAMESPACE=" $OPTARG " ;;
85
86
n) NAME=" $OPTARG " ;;
87
+ e) EXCLUDE=" $OPTARG " ;;
86
88
E) EXCLUDENS=" $OPTARG " ;;
87
89
w) WARN=" $OPTARG " ;;
88
90
c) CRIT=" $OPTARG " ;;
@@ -315,9 +317,8 @@ mode_tls() {
315
317
jq -r " .items[] | select (.type==\" kubernetes.io/tls\" )" )
316
318
317
319
if [ " $NAME " ]; then
318
- namespaces=($( echo " $data " | \
319
- jq -r " select(.metadata.name==\" $NAME \" ) | \
320
- .metadata.namespace" | sort -u) )
320
+ namespaces=($( echo " $data " | jq -r " select(.metadata.name==\" $NAME \" ) | \
321
+ .metadata.namespace" | sort -u) )
321
322
else
322
323
namespaces=($( echo " $data " | jq -r " .metadata.namespace" | sort -u) )
323
324
fi
@@ -331,8 +332,13 @@ mode_tls() {
331
332
if [ " $NAME " ]; then
332
333
certs=(" $NAME " )
333
334
else
334
- certs=($( echo " $data " | jq -r " select(.metadata.namespace==\" $ns \" ) | \
335
- .metadata.name" ) )
335
+ if [ " $EXCLUDE " ]; then
336
+ certs=($( echo " $data " | jq -r " select(.metadata.namespace==\" $ns \" ) | \
337
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
338
+ else
339
+ certs=($( echo " $data " | jq -r " select(.metadata.namespace==\" $ns \" ) | \
340
+ .metadata.name" ) )
341
+ fi
336
342
fi
337
343
for cert in " ${certs[@]} " ; do
338
344
notafter=$( echo " $data " | \
@@ -444,14 +450,17 @@ mode_pods() {
444
450
for ns in " ${namespaces[@]} " ; do
445
451
nsdata=" $( echo " $data " | jq -c -r " .items[] | select(.metadata.namespace==\" $ns \" )" ) "
446
452
if [ " $NAME " ]; then
447
- pods=($( echo " $nsdata " | \
448
- jq -r " select(.status.reason!=\" Evicted\" \
449
- and .metadata.labels.app==\" $NAME \" ) | \
450
- .metadata.name" ) )
453
+ pods=($( echo " $nsdata " | jq -r " select(.status.reason!=\" Evicted\" \
454
+ and .metadata.labels.app==\" $NAME \" ) | \
455
+ .metadata.name" ) )
451
456
else
452
- pods=($( echo " $nsdata " | \
453
- jq -r " select(.status.reason!=\" Evicted\" ) | \
454
- .metadata.name" ) )
457
+ if [ " $EXCLUDE " ]; then
458
+ pods=($( echo " $nsdata " | jq -r " select(.status.reason!=\" Evicted\" ) | \
459
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
460
+ else
461
+ pods=($( echo " $nsdata " | jq -r " select(.status.reason!=\" Evicted\" ) | \
462
+ .metadata.name" ) )
463
+ fi
455
464
fi
456
465
for pod in " ${pods[@]} " ; do
457
466
containers=($( echo " $nsdata " | \
@@ -490,19 +499,17 @@ mode_pods() {
490
499
done
491
500
492
501
if [ " $EXITCODE " = 0 ]; then
493
- if [ -z " $ns " ]; then
494
- OUTPUT=" No pods found"
495
- EXITCODE=" $MISSING_EXITCODE "
496
- else
497
- OUTPUT=" OK. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
498
- fi
499
- else
500
- if [ " $EXITCODE " = 1 ]; then
501
- OUTPUT=" WARNING. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
502
+ if [ -z " $ns " ]; then
503
+ OUTPUT=" No pods found"
504
+ EXITCODE=" $MISSING_EXITCODE "
502
505
else
503
- OUTPUT=" ERROR. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
504
- fi
506
+ OUTPUT=" OK. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
505
507
fi
508
+ elif [ " $EXITCODE " = 1 ]; then
509
+ OUTPUT=" WARNING. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
510
+ else
511
+ OUTPUT=" ERROR. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
512
+ fi
506
513
}
507
514
508
515
mode_deployments () {
@@ -533,7 +540,11 @@ mode_deployments() {
533
540
if [ " $NAME " ]; then
534
541
deps=(" $NAME " )
535
542
else
536
- deps=($( echo " $nsdata " | jq -r " .name" ) )
543
+ if [ " $EXCLUDE " ]; then
544
+ deps=($( echo " $nsdata " | jq -r " .name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
545
+ else
546
+ deps=($( echo " $nsdata " | jq -r " .name" ) )
547
+ fi
537
548
fi
538
549
for dep in " ${deps[@]} " ; do
539
550
if [[ " ${availdeps[@]} " =~ " $dep " ]]; then
@@ -588,8 +599,13 @@ mode_daemonsets() {
588
599
if [ " $NAME " ]; then
589
600
daemonsets=(" $NAME " )
590
601
else
591
- daemonsets=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
592
- .metadata.name" ) )
602
+ if [ " $EXCLUDE " ]; then
603
+ daemonsets=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
604
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
605
+ else
606
+ daemonsets=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
607
+ .metadata.name" ) )
608
+ fi
593
609
fi
594
610
for ds in " ${daemonsets[@]} " ; do
595
611
declare -A statusArr
@@ -652,9 +668,13 @@ mode_replicasets() {
652
668
if [ " $NAME " ]; then
653
669
replicasets=(" $NAME " )
654
670
else
655
- replicasets=($( echo " $data " | \
656
- jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
657
- .metadata.name" ) )
671
+ if [ " $EXCLUDE " ]; then
672
+ replicasets=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
673
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
674
+ else
675
+ replicasets=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
676
+ .metadata.name" ) )
677
+ fi
658
678
fi
659
679
for rs in " ${replicasets[@]} " ; do
660
680
declare -A statusArr
@@ -713,9 +733,15 @@ mode_statefulsets() {
713
733
if [ " $NAME " ]; then
714
734
statefulsets=(" $NAME " )
715
735
else
716
- statefulsets=($( echo " $data " | \
717
- jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
718
- .metadata.name" ) )
736
+ if [ " $EXCLUDE " ]; then
737
+ statefulsets=($( echo " $data " | \
738
+ jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
739
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
740
+ else
741
+ statefulsets=($( echo " $data " | \
742
+ jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
743
+ .metadata.name" ) )
744
+ fi
719
745
fi
720
746
for sts in " ${statefulsets[@]} " ; do
721
747
declare -A statusArr
@@ -780,9 +806,13 @@ mode_jobs() {
780
806
if [ " $NAME " ]; then
781
807
jobs=(" $NAME " )
782
808
else
783
- jobs=($( echo " $data " | \
784
- jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
785
- .metadata.name" ) )
809
+ if [ " $EXCLUDE " ]; then
810
+ jobs=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
811
+ .metadata.name" | grep -vE " ${EXCLUDE// ,/ |} " ) )
812
+ else
813
+ jobs=($( echo " $data " | jq -r " .items[] | select(.metadata.namespace==\" $ns \" ) | \
814
+ .metadata.name" ) )
815
+ fi
786
816
fi
787
817
for job in " ${jobs[@]} " ; do
788
818
(( total_jobs++ ))
0 commit comments