${checkdaylight} || exit 3
-# createAlert <alias> <message> <description>
+# createAlert <alias> <message> <priority> <description>
createAlert() {
local alias="${1}"
local message="${2}"
- local description="${3}"
+ local priority="${3}"
+ local description="${4}"
+ local date="$(date)"
if [ -z "${alias}" ]; then
echo "ERROR: Empty alert alias"
return
fi
+ if [ -z "${priority}" ]; then
+ priority="P3"
+ fi
+
curl -o /dev/null -s \
-X POST https://${API_HOST}/v2/alerts \
-H "Content-Type: application/json" \
"{
\"message\":\"${message}\",
\"alias\":\"${alias}\",
- \"description\":\"${description}\"
+ \"priority\":\"${priority}\",
+ \"description\":\"${description}\",
+ \"note\":\"Localtime ${date}\"
}"
}
echo "OK"
return
fi
-
+
echo "ERROR: WR${wradresse} ${wrleistung}W Serial:${wrserial}"
return 1
}
return 0
}
+# calcPriority <outfile> <failures>
+# returns an Opsgenie priority string
+# If all devies fail return P1, otherwise stick with P3.
+calcPriority() {
+ local outfile="${1}"
+ local failures="${2}"
+ local priority="P3"
+ local numWR="$(grep -c cLink ${outfile})"
+ # to be able to count with grep, we've to have our pattern ones per line
+ local numFailed=$(echo "${failures}"| tr ' ' '\n' | grep -c 'WR')
+
+ if [ "${numWR}" -eq "${numFailed}" ]; then
+ priority="P1"
+ fi
+
+ echo "${priority}"
+}
+
### main loop
for dev in mc1 mc2; do
outfile="/tmp/${dev}.html"
# handle failures and alerting
if ! [ -z "${failures}" ]; then
+ priority=$(calcPriority "${outfile}" "${failures}")
checkAlertState "${statefile}" "FAILED" && \
- createAlert "${dev}" "PV ${dev}" "${failures}"
+ createAlert "${dev}" "PV Ossendorf ${dev}" "${priority}" "${failures}"
continue
fi