Added support for group alert messages (#890)

* Added support for group alert messages

Signed-off-by: Gerard Hickey <hickey@kinetic-compute.com>

* Fixed category for AAM group names setting

Signed-off-by: Gerard Hickey <hickey@kinetic-compute.com>

* Revised aredn_message.sh to handle group messages better

Signed-off-by: Gerard Hickey <hickey@kinetic-compute.com>

---------

Signed-off-by: Gerard Hickey <hickey@kinetic-compute.com>
This commit is contained in:
Gerard Hickey 2023-07-09 01:09:02 -04:00 committed by GitHub
parent be9957183c
commit f4321ff19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 35 deletions

View File

@ -33,6 +33,27 @@ true <<'LICENSE'
LICENSE LICENSE
function retrieve_alert() {
url=$1
file=$2
label=$3
# label is an optional argument
[ -z "$label" ] && label=$file
wget -q -O "${file}" -P /tmp "${url}"
if [ -s "/tmp/${file}" ]; then
echo "<strong>&#8611; ${label}:</strong>"|cat - "/tmp/${file}" > /tmp/out &&
echo "<p>" >> /tmp/out &&
mv /tmp/out "/tmp/${file}"
# return success
return 0
else
return 1
fi
}
# does the node have access to downloads.arednmesh.org # does the node have access to downloads.arednmesh.org
ping -q -W10 -c1 downloads.arednmesh.org > /dev/null && ping -q -W10 -c1 downloads.arednmesh.org > /dev/null &&
online=true; online=true;
@ -44,23 +65,14 @@ nodename=$(echo "$HOSTNAME" | tr 'A-Z' 'a-z')
if [ "$online" = "true" ] if [ "$online" = "true" ]
then then
# fetch node specific message file # fetch node specific message file
wget -q -O aredn_message -P /tmp http://downloads.arednmesh.org/messages/"${nodename}".txt && retrieve_alert http://downloads.arednmesh.org/messages/${nodename}.txt aredn_message ${nodename}
[ -s /tmp/aredn_message ] &&
echo "<strong>&#8611; ${nodename}:</strong>"|cat - /tmp/aredn_message > /tmp/out &&
mv /tmp/out /tmp/aredn_message
if [ $? -ne 0 ] # no node specific file if [ $? -ne 0 ] # no node specific file
then then
# fetch broadcast message file # fetch broadcast message file
wget -q -O aredn_message -P /tmp http://downloads.arednmesh.org/messages/all.txt && retrieve_alert http://downloads.arednmesh.org/messages/all.txt aredn_message "all nodes"}
[ -s /tmp/aredn_message ] &&
echo "<strong>&#8611; all nodes:</strong>"|cat - /tmp/aredn_message > /tmp/out &&
mv /tmp/out /tmp/aredn_message
else else
# need to append to node file # need to append to node file
wget -q -O aredn_message_all -P /tmp http://downloads.arednmesh.org/messages/all.txt && retrieve_alert http://downloads.arednmesh.org/messages/all.txt aredn_message_all "all nodes"
[ -s /tmp/aredn_message_all ] &&
echo "<strong>&#8611; all nodes:</strong>"|cat - /tmp/aredn_message_all > /tmp/out &&
mv /tmp/out /tmp/aredn_message_all
echo "<br />" >> /tmp/aredn_message echo "<br />" >> /tmp/aredn_message
cat /tmp/aredn_message_all >> /tmp/aredn_message cat /tmp/aredn_message_all >> /tmp/aredn_message
rm /tmp/aredn_message_all rm /tmp/aredn_message_all
@ -68,29 +80,35 @@ then
fi fi
# are local alerts enabled? uci: aredn.alerts.localpath != NULL # are local alerts enabled? uci: aredn.alerts.localpath != NULL
#
alertslocalpath=$(uci -q get aredn.@alerts[0].localpath) alertslocalpath=$(uci -q get aredn.@alerts[0].localpath)
if [ ! -z "$alertslocalpath" ]; then if [ -n "$alertslocalpath" ]; then
# fetch node specific message file
wget -q -O local_message -P /tmp "${alertslocalpath}/${nodename}".txt && # try node specific message file
[ -s /tmp/local_message ] && retrieve_alert "${alertslocalpath}/${nodename}.txt" "${nodename}-alert" "${nodename}" &&
echo "<strong>&#8611; ${nodename}:</strong>"|cat - /tmp/local_message > /tmp/out && FILES="${nodename}"
mv /tmp/out /tmp/local_message
if [ $? -ne 0 ] # no node specific file # try group messages uci: aredn.alerts.groups != NULL
then alertgroups=$(uci -q get aredn.@alerts[0].groups)
# fetch broadcast message file if [ -n "$alertgroups" ]; then
wget -q -O local_message -P /tmp "${alertslocalpath}/all.txt" && IFS=',' # split multiple groups on comma
[ -s /tmp/local_message ] && for group in $alertgroups; do
echo "<strong>&#8611; all nodes:</strong>"|cat - /tmp/local_message > /tmp/out && groupname=$(echo $group | xargs | tr 'A-Z' 'a-z')
mv /tmp/out /tmp/local_message retrieve_alert "${alertslocalpath}/${groupname}.txt" "${groupname}-alert" "${groupname}" &&
else FILES="${FILES} ${groupname}"
# need to append to node file done
wget -q -O local_message_all -P /tmp "${alertslocalpath}/all.txt" && IFS=' ' # reset IFS
[ -s /tmp/local_message_all ] && fi
echo "<strong>&#8611; all nodes:</strong>"|cat - /tmp/local_message_all > /tmp/out &&
mv /tmp/out /tmp/local_message_all # try broadcast message file
echo "<br />" >> /tmp/local_message retrieve_alert "${alertslocalpath}/all.txt" "all-alert" "all nodes" &&
cat /tmp/local_message_all >> /tmp/local_message && FILES="${FILES} all"
rm /tmp/local_message_all
# combine all files
if [ -n "$FILES" ];then
cat /dev/null > /tmp/local_message
for FILE in $FILES; do
cat /tmp/${FILE}-alert >> /tmp/local_message
rm /tmp/${FILE}-alert
done
fi fi
fi fi

View File

@ -408,6 +408,13 @@ local settings = {
desc = "<b>Alert Message Local URL</b> - location from which local AREDN Alerts can be downloaded<br><br><small>aredn.@alerts[0].localpath</small>", desc = "<b>Alert Message Local URL</b> - location from which local AREDN Alerts can be downloaded<br><br><small>aredn.@alerts[0].localpath</small>",
default = "" default = ""
}, },
{
category = "AREDN Alert Settings",
key = "aredn.@alerts[0].groups",
type = "string",
desc = "<b>Alert Message Groups</b> - comma seperated list of group names to check for alert messages<br><br><small>aredn.@alerts[0].groups</small>",
default = ""
},
{ {
category = "AREDN Alert Settings", category = "AREDN Alert Settings",
key = "aredn.@alerts[0].pollrate", key = "aredn.@alerts[0].pollrate",