Browse Source

added maintenance mode

Volker Tanger 4 months ago
parent
commit
7146dd9dc3
4 changed files with 48 additions and 4 deletions
  1. 3 0
      README.md
  2. 37 4
      functions.moshel
  3. 4 0
      history.txt
  4. 4 0
      moshel.example

+ 3 - 0
README.md

@@ -99,6 +99,9 @@ Edit the MOSHEL file and set the environment
 	
 	CMPDIR	location the tamper-detection files are copied to
 
+	MAINTENANCE	maintenance message 
+			disables +all+ checks if not empty
+			
 Copy the moshel.example shell script to moshel file and configure the 
 checks to be run - usually you can set alert trigger levels
 

+ 37 - 4
functions.moshel

@@ -8,7 +8,7 @@
 #
 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-MOSHELVERSION="2.1.4"
+MOSHELVERSION="2.1.5"
 
 #---------------------------------------------------------
 # init library and files
@@ -83,6 +83,9 @@ CheckValueUnder () {
     Value="$4"
     Message="$5"
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     RESULT=$( /bin/bash -c "$Command" | awk "$Awk" | cut -d "." -f 1 | cut -d "," -f 1  )
 
     if [ -z "$RESULT" ]; then
@@ -106,6 +109,9 @@ CheckValueOver () {
     Value="$4"
     Message="$5"
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     RESULT=$( /bin/bash -c "$Command" | awk "$Awk" | cut -d "." -f 1 | cut -d "," -f 1  )
 
     if [ -z "$RESULT" ]; then
@@ -129,6 +135,9 @@ CheckCountLessThan () {
     Value="$4"
     Message="$5"
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     RESULT=$( /bin/bash -c "$Command" | awk "$Awk" | wc -l  )
 
     if [ -z "$RESULT" ]; then
@@ -151,6 +160,9 @@ CheckCountMoreThan () {
     Value="$4"
     Message="$5"
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     RESULT=$( /bin/bash -c "$Command" | awk "$Awk" | wc -l  )
 
     if [ -z "$RESULT" ]; then
@@ -172,6 +184,9 @@ CheckFileChanges () {
     Filename="$2"
     DIFFF=$( mktemp )
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     diff $CMPDIR/$Name $Filename > $DIFFF
     if [ -s $DIFFF ]; then	
 	MSG=''
@@ -194,6 +209,9 @@ ActionOnAlert () {
     Name="$1"
     Action="$2"
 
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     DIFFF=$( mktemp )
     diff $DATADIR/alertoldold $DATADIR/alertold | grep -F "> ${MYNAME} : ${Name} ! " > "$DIFFF"
     if [ -s $DIFFF ]; then	
@@ -213,6 +231,9 @@ ActionOnAlert () {
 
 #---------------------------------------------------------
 LocalAlertMail () {
+    if [ -n "MAINTENANCE" ]; then
+    	return 1
+    fi
     LALERTTO="$1"
     # alert handling
     # first handle old states, used to identify&deny flip-flopping alerts
@@ -278,14 +299,26 @@ CleanUp () {
 
     # output+logging
     echo "<html><head><meta http-equiv=\"refresh\" content=\"300\" /><title>MoSheL - $MYNAME</title></head><body><h1>MoSheL - $MYNAME</h1>$DATUM $ZEIT &nbsp; - &nbsp;<a href=\"graphs.html\">Graphs</a><ul>" > $WWWDIR/index.html
-    cat /tmp/tmp.$$.moshel_collected.tmp >> $WWWDIR/index.html
+    if [ -n "MAINTENANCE" ]; then
+	cat /tmp/tmp.$$.moshel_collected.tmp >> $WWWDIR/index.html
+    else
+	echo "<b>MAINTENANCE MODE</b> : $MAINTENANCE" >> $WWWDIR/index.html
+    fi
     echo '</ul></body></html>' >> $WWWDIR/index.html
 
     echo "<p><a href=\"$WEBURL\">$MYNAME</a> - $DATUM $ZEIT<br>" > /tmp/tmp.$$.moshel_snippet.tmp
-    cat $DATADIR/alert >> /tmp/tmp.$$.moshel_snippet.tmp
+    if [ -n "MAINTENANCE" ]; then
+    	cat $DATADIR/alert >> /tmp/tmp.$$.moshel_snippet.tmp
+    else
+	echo "$MYNAME : Maintenance Mode: $MAINTENANCE<br>" >> /tmp/tmp.$$.moshel_snippet.tmp
+    fi
 
     echo "<html><head><meta http-equiv=\"refresh\" content=\"300\" /><title>MoSheL - $MYNAME</title><script type=\"text/javascript\"  src=\"data/dygraph-combined.js\"></script></head><body><h1>MoSheL - $MYNAME</h1>$DATUM $ZEIT &nbsp; - &nbsp;<a href=\"index.html\">Text</a><p>" > $WWWDIR/graphs.html
-    cat /tmp/tmp.$$.moshel_graphclips.tmp >> $WWWDIR/graphs.html
+    if [ -n "MAINTENANCE" ]; then
+    	cat /tmp/tmp.$$.moshel_graphclips.tmp >> $WWWDIR/graphs.html
+    else
+	echo "<b>MAINTENANCE MODE</b> : $MAINTENANCE" >> $WWWDIR/graphs.html
+    fi
     echo '</body></html>' >> $WWWDIR/graphs.html
 
 

+ 4 - 0
history.txt

@@ -66,6 +66,10 @@ wanted checks (examples)
 
 ------------------------------------------------------------------------
 
+2024-07-26
+    Volker Tanger <volker.tanger@wyae.de>
+	* feature: added maintenance mode, disabling checks (just insert message)
+	
 2024-05-28
     Volker Tanger <volker.tanger@wyae.de>
 	* bugfix: stabilized OpenDTU + Shelly queries (longer timeout, retries)

+ 4 - 0
moshel.example

@@ -13,6 +13,10 @@ ALERTTO='root_alpha@wyae.de'
 WWWDIR=/home/www/alpha/moshel
 CMPDIR=/usr/local/lib/moshel/Compare
 
+# keep empty if you want checks to run, otherwise state short maintenance message
+MAINTENANCE=""
+# MAINTENANCE="Techniker ist informiert"
+
 
 
 mkdir -p $CMPDIR