rebuilt thermal, now works with all zones available.
discord will now work without hook specified.
This commit is contained in:
+2
-7
@@ -1,10 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# degrees in C
|
||||
THERMAL_ALERT=75
|
||||
|
||||
# see: /sys/class/thermal/thermal_zone*
|
||||
THERMAL_ZONE=0
|
||||
# degrees in Celsius which we regard as too high
|
||||
THERMAL_ALERT=70
|
||||
|
||||
STORAGE_MONITOR=("/")
|
||||
|
||||
@@ -32,7 +29,5 @@ DISCORD_GENERAL_HOOK="<WEBHOOK_URL_HERE>?wait=true"
|
||||
|
||||
DISCORD_RESTAKE_HOOK="<WEBHOOK_URL_HERE>?wait=true"
|
||||
|
||||
DISCORD_THERMAL_HOOK="<WEBHOOK_URL_HERE>?wait=true"
|
||||
|
||||
DISCORD_STORAGE_HOOK="<WEBHOOK_URL_HERE>?wait=true"
|
||||
|
||||
|
||||
+25
-14
@@ -1,21 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCATION=`dirname "$0"`
|
||||
# degrees in Celsius which we regard as too high, defaults to config
|
||||
alertLevel="$1"
|
||||
|
||||
source "${LOCATION}/../config.sh"
|
||||
# load in defaults from config
|
||||
scriptRoot="$(dirname "$0")/.."
|
||||
configFile="$scriptRoot/config.sh"
|
||||
if [[ -f "$configFile" ]]; then
|
||||
source "$configFile"
|
||||
|
||||
thermal=`${LOCATION}/../thermal.sh ${THERMAL_ALERT}`
|
||||
alert=$?
|
||||
if [[ -z "$alertLevel" ]]; then
|
||||
alertLevel="$THERMAL_ALERT"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "0" != "${alert}" ]]; then
|
||||
echo "${thermal}, above threshold ${THERMAL_ALERT} C"
|
||||
${LOCATION}/../discord.sh thermal "${thermal}, above threshold ${THERMAL_ALERT} C"
|
||||
touch "${LOCATION}/thermal.status"
|
||||
elif [[ -f "${LOCATION}/thermal.status" ]]; then
|
||||
rm "${LOCATION}/thermal.status"
|
||||
echo "${thermal}, previously above threshold ${THERMAL_ALERT} C"
|
||||
${LOCATION}/../discord.sh thermal "${thermal}, previously above threshold ${THERMAL_ALERT} C"
|
||||
else
|
||||
echo "${thermal}, below threshold ${THERMAL_ALERT} C"
|
||||
# get current status
|
||||
thermal=$("$scriptRoot/thermal.sh" "$alertLevel")
|
||||
alert="$?"
|
||||
|
||||
if [[ "0" -ne "$alert" ]]; then
|
||||
# if currently in an alert status
|
||||
alertLevelF=`echo "scale=1 ; $alertLevel * 9 / 5 + 32" | bc -l`
|
||||
"$scriptRoot/discord.sh" "$thermal, above threshold $alertLevel C ($alertLevelF F)"
|
||||
touch "$HOME/.thermal.alert"
|
||||
elif [[ -f "$HOME/.thermal.alert" ]]; then
|
||||
# if previously in an alert status
|
||||
alertLevelF=`echo "scale=1 ; $alertLevel * 9 / 5 + 32" | bc -l`
|
||||
"$scriptRoot/discord.sh" "$thermal, previously above threshold $alertLevel C ($alertLevelF F)"
|
||||
rm "$HOME/.thermal.alert"
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCATION=`dirname "$0"`
|
||||
scriptRoot="$(dirname "$0")/.."
|
||||
|
||||
thermal=`${LOCATION}/../thermal.sh`
|
||||
thermal=$("$scriptRoot/thermal.sh")
|
||||
|
||||
echo "${thermal}"
|
||||
${LOCATION}/../discord.sh thermal "${thermal}"
|
||||
"$scriptRoot/discord.sh" "$thermal"
|
||||
|
||||
|
||||
+11
-9
@@ -4,10 +4,16 @@ LOCATION=`dirname "$0"`
|
||||
|
||||
source "${LOCATION}/config.sh"
|
||||
|
||||
HOOK_ARG="$1"
|
||||
BOBBY="$2"
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@:3}" | sed 's/^ *//'`
|
||||
if [[ $# -gt 2 ]]; then
|
||||
HOOK_ARG="$1"
|
||||
BOBBY="$2"
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@:3}" | sed 's/^ *//'`
|
||||
else
|
||||
BOBBY="$1"
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@:2}" | sed 's/^ *//'`
|
||||
fi
|
||||
|
||||
# sed removes blank lines from the end of the message
|
||||
FULL_MESSAGE=`echo "${MESSAGE}" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'`
|
||||
@@ -47,10 +53,6 @@ case $HOOK_ARG in
|
||||
HOOK="restake"
|
||||
HOOK_URL=$DISCORD_RESTAKE_HOOK
|
||||
;;
|
||||
thermal)
|
||||
HOOK="thermal"
|
||||
HOOK_URL=$DISCORD_THERMAL_HOOK
|
||||
;;
|
||||
storage)
|
||||
HOOK="storage"
|
||||
HOOK_URL=$DISCORD_STORAGE_HOOK
|
||||
@@ -71,7 +73,7 @@ fi
|
||||
if [ "${FULL_MESSAGE}" != "${OLD_MSG}" ]; then
|
||||
echo "${FULL_MESSAGE}" > "${LOCATION}/distinct/${BOBBY}.msg"
|
||||
|
||||
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id'
|
||||
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id,.message'
|
||||
|
||||
if [ -n "${EXTRA}" ]; then
|
||||
"${LOCATION}/discord.sh" "${HOOK}" "${EXTRA}"
|
||||
|
||||
+9
-8
@@ -4,9 +4,14 @@ LOCATION=`dirname "$0"`
|
||||
|
||||
source "${LOCATION}/config.sh"
|
||||
|
||||
HOOK_ARG="$1"
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@:2}" | sed 's/^ *//'`
|
||||
if [[ $# -gt 1 ]]; then
|
||||
HOOK_ARG="$1"
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@:2}" | sed 's/^ *//'`
|
||||
else
|
||||
# sed removes spaces before each line
|
||||
MESSAGE=`echo "${@}" | sed 's/^ *//'`
|
||||
fi
|
||||
|
||||
# if message is too long, split it, and after curl, recursively call with remainder
|
||||
# 2k max, but we must account for escaping text in json, so limit to 90% capacity
|
||||
@@ -44,10 +49,6 @@ case $HOOK_ARG in
|
||||
HOOK="restake"
|
||||
HOOK_URL=$DISCORD_RESTAKE_HOOK
|
||||
;;
|
||||
thermal)
|
||||
HOOK="thermal"
|
||||
HOOK_URL=$DISCORD_THERMAL_HOOK
|
||||
;;
|
||||
storage)
|
||||
HOOK="storage"
|
||||
HOOK_URL=$DISCORD_STORAGE_HOOK
|
||||
@@ -60,7 +61,7 @@ if [[ "$MESSAGE" == *"\\u001b"* ]]; then
|
||||
# just here to resolve formatting issue in vim "`"
|
||||
fi
|
||||
|
||||
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id'
|
||||
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id,.message'
|
||||
|
||||
if [ -n "${EXTRA}" ]; then
|
||||
"${LOCATION}/discord.sh" "${HOOK}" "${EXTRA}"
|
||||
|
||||
+1
-1
@@ -39,5 +39,5 @@ function process_git_fetch () {
|
||||
# and call process_git_fetch on each location that was found.
|
||||
# we then work on the folder that contained the ".git" folder.
|
||||
|
||||
find "$followLinks" "$@" -type d -name ".git" | while read file; do process_git_fetch "$file"; done
|
||||
find "$followLinks" "$@" -type d -name ".git" | while read -r file; do process_git_fetch "$file"; done
|
||||
|
||||
|
||||
+1
-1
@@ -39,5 +39,5 @@ function process_git_pull () {
|
||||
# and call process_git_pull on each location that was found.
|
||||
# we then work on the folder that contained the ".git" folder.
|
||||
|
||||
find "$followLinks" "$@" -type d -name ".git" | while read file; do process_git_pull "$file"; done
|
||||
find "$followLinks" "$@" -type d -name ".git" | while read -r file; do process_git_pull "$file"; done
|
||||
|
||||
|
||||
+34
-12
@@ -1,21 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCATION=`dirname "$0"`
|
||||
alertLevel="$1"
|
||||
|
||||
source "${LOCATION}/config.sh"
|
||||
# load in defaults from config
|
||||
scriptRoot=$(dirname "$0")
|
||||
configFile="$scriptRoot/config.sh"
|
||||
if [[ -f "$configFile" ]]; then
|
||||
source "$configFile"
|
||||
|
||||
# this is currently specific to raspberry-pi
|
||||
# since that is the only kind of physical server I have
|
||||
# TODO make this work with all temp in class/thermal
|
||||
name=$(</sys/class/thermal/thermal_zone${THERMAL_ZONE}/type)
|
||||
mc=$(</sys/class/thermal/thermal_zone${THERMAL_ZONE}/temp)
|
||||
if [[ -z "$alertLevel" ]]; then
|
||||
alertLevel="$THERMAL_ALERT"
|
||||
fi
|
||||
fi
|
||||
|
||||
c=`echo "scale=1 ; $mc / 1000.0" | bc -l`
|
||||
f=`echo "scale=1 ; $c * 9 / 5 + 32" | bc -l`
|
||||
# loop over all thermal zones
|
||||
while read -r mcFile; do
|
||||
# each zone has two files we use:
|
||||
# "./temp" <int> zone temp (milli-celsius)
|
||||
# "./type" <string> zone title
|
||||
titleFile=$(echo "$mcFile" | sed 's/temp/type/')
|
||||
title=$( < "$titleFile")
|
||||
mc=$( < "$mcFile")
|
||||
|
||||
echo "${name}: ${c} C ($f F)"
|
||||
# calculate Celcius and Fahrenheit
|
||||
c=$(echo "scale=1 ; $mc / 1000.0" | bc -l)
|
||||
f=$(echo "scale=1 ; $c * 9 / 5 + 32" | bc -l)
|
||||
hot=$(echo "$c >= $alertLevel" | bc -l)
|
||||
|
||||
if (( "$#" > "0" )); then
|
||||
exit `echo "$c >= $1" | bc`
|
||||
echo "$title: $c C ($f F)"
|
||||
|
||||
# if we have reached our alert threshold, mark it as active
|
||||
if [[ -n "$alertLevel" ]] && [[ "$hot" -gt 0 ]]; then
|
||||
alertActive=1
|
||||
fi
|
||||
|
||||
done <<< $(find /sys/class/thermal/thermal*/ -name 'temp')
|
||||
|
||||
# we exit with a status code of 1 to indicate alert level has been reached
|
||||
if [[ "$alertActive" -eq 1 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user