]> git.sven.stormbind.net Git - sven/scripts.git/blobdiff - home/pvmon2opsgenie.sh
Add daylight check based on suntime.lua script
[sven/scripts.git] / home / pvmon2opsgenie.sh
index 34a5c5af86cf68749286487894727e28c4ed0978..d1384b9084f04f01af9e6ab48570ef59bbe3ee00 100755 (executable)
@@ -1,10 +1,26 @@
 #!/bin/sh
-# Checks inverter state as repoted by a metecontrol weblog
+# Checks inverter state as repoted by a meteocontrol weblog
 # device HTML interface, reports issues via Atlassian
 # Opsgenie. Written with the intention to run via cron on
 # a LTE Router with either OpenWRT or Teltonika RutOS.
-# Requires curl for the Opsgenie part, otherwise
-# sh/cut/cat/wget/test are enough.
+# Requires curl other stock sh/cut/cat/test are enough.
+
+### path to the suntime / check for daylight script
+checkdaylight="./suntime.lua"
+
+### opsgenie configuration
+API_HOST="api.eu.opsgenie.com"
+API_KEY=""
+
+# adjust meteocontrol default password and IPs
+# meteocontrol devices must be added to the main loop as well
+mc1="http://admin:ist02@192.168.1.2/html/de/onlineOverWr.html"
+mc2="http://admin:ist02@192.168.1.3/html/de/onlineOverWr.html"
+
+
+### check for daylight, otherwise exit early
+${checkdaylight} || exit 3
+
 
 # createAlert <alias> <message> <description>
 createAlert() {
@@ -84,7 +100,7 @@ parseMcOutput() {
         return
     fi
 
-    grep "cLink" "${file}" | while read line; do 
+    grep "cLink" "${file}" | while read line; do
         result="$(parseMcLine \"${line}\")"
         # good case
         if [ "${result}" = "OK" ]; then
@@ -114,7 +130,7 @@ getMCstates() {
     rm -f "${outfile}"
 
     # ready to try to download the data from meteocontrol
-    if ! wget -q -O "${outfile}" "${url}"; then
+    if ! curl -s -o "${outfile}" "${url}"; then
         echo "ERROR: could not download ${url} into ${outfile}"
         exit 1
     fi
@@ -144,14 +160,6 @@ checkAlertState() {
     return 0
 }
 
-### main configuration
-API_HOST="api.eu.opsgenie.com"
-API_KEY=""
-
-# adjust meteocontrol default password and IPs
-mc1="http://admin:ist02@192.168.1.2:80/html/de/onlineOverWr.html"
-mc2="http://admin:ist02@192.168.1.3:80/html/de/onlineOverWr.html"
-
 ### main loop
 for dev in mc1 mc2; do
     outfile="/tmp/${dev}.html"
@@ -170,7 +178,7 @@ for dev in mc1 mc2; do
         createAlert "${dev}" "PV ${dev}" "${failures}"
         continue
     fi
-    
+
     # update alert state close alert on state change
     checkAlertState "${statefile}" "OK" && \
     closeAlert "${dev}"