From 9835669677cf27d176c59682375cc426c3f4523b Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Wed, 12 May 2021 15:04:30 +0200
Subject: [PATCH] icingacli - detect unreadable config or non writable output
 file

---
 icinga-cli.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/icinga-cli.sh b/icinga-cli.sh
index 4f55839..4d4a782 100755
--- a/icinga-cli.sh
+++ b/icinga-cli.sh
@@ -14,7 +14,7 @@
 
 
 _product="ICINGA PASSIVE CLIENT"
-_version="0.3"
+_version="0.4"
 _license="GNU GPL 3.0"
 _copyright='(c) 2020 Institute for Medical Education * University of Bern'
 
@@ -178,6 +178,11 @@ function processAllChecks(){
 function _parseCheckConfig(){
   local _myconfig=$1
 
+  if [ ! -r $_myconfig ]; then
+    echo "ERROR: config file is not readable [$_myconfig]"
+    exit 1
+  fi
+
   # EXAMPLE a config contains ...
   # checkname=check_cronstatus
   # command=check_cronstatus -param1 -param2
@@ -308,6 +313,11 @@ function processCheck(){
       # $myFullscript $myparams | tee $_outfile
       eval $myFullscript $myparams > $_outfile
       rc=$?
+      if [ $rc -ne 0 ]; then
+	echo "ERROR: unable to write file $_outfile. Maybe the setup is inclomplete or someone created a file as root."
+	ls -ld ${dir_data} $_outfile
+	exit 1
+      fi
       typeset -i local iTsEnd=`date +%s`
       outPerfdata=`grep '|' $_outfile | cut -f 2 -d '|'`
       echo
-- 
GitLab