Last active
February 16, 2024 17:33
-
-
Save Commifreak/15fc60aaab52f09bee833fe4357ac011 to your computer and use it in GitHub Desktop.
LiFePO4wered Pi CheckMK local check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/!bin/bash | |
SVC_NAME='"LiFePo4weredPI"' | |
MPREF="$(hostname)" | |
OUT_STATUS='0' | |
OUT_TEXT="External power active" | |
lifepo4wered-cli get > /dev/null 2>&1 | |
if [ ! $? -eq 0 ] | |
then | |
echo "2 $SVC_NAME - Cannot talk to lifepo4wered-cli" | |
exit 1 | |
fi | |
VBAT_SHDN=$(lifepo4wered-cli get VBAT_SHDN 2>/dev/null) | |
if [ ! $? -eq 0 ] | |
then | |
VBAT_SHDN="could not get shutdown val!" | |
fi | |
VALUES=(VIN VOUT VBAT IOUT) | |
METRICS="" | |
for i in "${VALUES[@]}" | |
do | |
READVAL=$(lifepo4wered-cli get $i 2>/dev/null) | |
if [ ! $? -eq 0 ] | |
then | |
echo "3 $SVC_NAME - Cannot get val for '$i'" | |
exit 1 | |
fi | |
if [ "$i" == "VIN" ] && [ "$READVAL" -eq "0" ] | |
then | |
OUT_STATUS="1" | |
OUT_TEXT="External power outage. Shutdown at vbat $VBAT_SHDN" | |
fi | |
METRICS+="${MPREF}_${i}=$READVAL|" | |
done | |
METRICS=${METRICS::-1} | |
echo "$OUT_STATUS $SVC_NAME $METRICS $OUT_TEXT" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment