From b7ca6b9ed32550ec04a330c13313bfa50d7e18db Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Wed, 30 Oct 2024 10:06:23 +0100
Subject: [PATCH] xheck_gitlab_tokens: GITLAB_TOKEN=SKIP responds OK without
 tests

---
 check_gitlab_tokens | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/check_gitlab_tokens b/check_gitlab_tokens
index 0d22f9c..fb02456 100755
--- a/check_gitlab_tokens
+++ b/check_gitlab_tokens
@@ -5,24 +5,25 @@
 # It warns if tokens expire soon.
 #
 # requirements:
-# - inc/rest-api-client.sh
+# - rest-api-client - https://git-repo.iml.unibe.ch/iml-open-source/bash-rest-api-client
 # - curl
 #
 # ----------------------------------------------------------------------
-# 2024-10-29  v1.0  <axel.hahn@iml.unibe.ch>
+# 2024-10-29  v1.0  <axel.hahn@unibe.ch>
+# 2024-10-30  v1.1  <axel.hahn@unibe.ch>  GITLAB_TOKEN=SKIP responds OK without tests
 # ======================================================================
 
 cd "$( dirname "$0" )" || exit
 . "$( dirname $0 )/inc_pluginfunctions" || exit 1
 
-export self_APPVERSION=1.0
-
+export self_APPVERSION=1.1
 
+sSkipvalue="SKIP"
 GITLAB_API='https://gitlab.example.com/api/v4'
-GITLAB_TOKEN='glpat-12345678'
+GITLAB_TOKEN="$sSkipvalue"
 
 GITLAB_CONFIG=/etc/icinga2/gitlab.cfg
-REST_CLIENT="$( dirname $0 )/../inc/rest-api-client.sh"
+REST_CLIENT="/opt/rest-api-client/rest-api-client.sh"
 
 projectUrls=
 
@@ -75,7 +76,15 @@ OPTIONS:
     -c VALUE       critical level (default: $iCriticalLimit)
 
     -g FILE        path to GITLAB_CONFIG; default: $GITLAB_CONFIG
-    -r FILE        path to REST_CLIENT; default: $REST_CLIENT
+                   There you can set/ override:
+
+                     GITLAB_API='${GITLAB_API}'
+                     GITLAB_CONFIG=<TOKEN>
+                     REST_CLIENT="${REST_CLIENT}"
+
+    -r FILE        path to REST api client
+                   default: $REST_CLIENT
+                   The parameter overrides the variable REST_CLIENT.
 
     -s DAYS        Number of days for max age of token; default: $iSince
 
@@ -194,8 +203,14 @@ GITLAB_CONFIG=$( ph.getValueWithParam $GITLAB_CONFIG g "$@")
 
 # --- check requirements
 ph.require curl
-. "${GITLAB_CONFIG}" || ph.abort "UNKNOWN: Could not read gitlab config $GITLAB_CONFIG"
-. "${REST_CLIENT}"   || ph.abort "UNKNOWN: Could not read $REST_CLIENT"
+. "${GITLAB_CONFIG}" || ph.abort "UNKNOWN: Could not source gitlab config $GITLAB_CONFIG"
+
+if [ "$GITLAB_TOKEN" = "$sSkipvalue" ]; then
+    ph.status "The check was configured to skip: GITLAB_TOKEN=$sSkipvalue"
+    ph.exit
+fi
+
+. "${REST_CLIENT}"   || ph.abort "UNKNOWN: Could not source $REST_CLIENT"
 http.help >/dev/null || ph.abort "UNKNOWN: http functions not available. Check -r $REST_CLIENT."
 
 
-- 
GitLab