Here are two scripts, one which push's events onto an RSS fees and the other with strikethrough's suppressed/cleared events. Using an Event command we can output events to an RSS feed and allow co-workers to subscribe to them and have the ability to know what the current events are.
Prerequisites:
- The zenoss user must me in the "lock" group so that it is allowed to make a directory in /var/lock to prevent parallel execution of both the scripts.
- The zenoss user must have date,awk,sed,cat in there path
- There must be an xml served up by your favorite web server that mirrors the example in the add2RSS.sh script initialy
- The scripts must be located in $ZENHOME/scripts and they must be executable
- You must replace zenoss-server with the hostname of your zenoss server in the scripts
Setup the Event Command with filters to taste here are what the commands must look like
Command:
$$ZENHOME/scripts/add2RSS.sh '/my/path/to/rss/feed.xml' '${evt/device}' '${evt/summary}' '${evt/severity}' '${evt/ipAddress}' '${evt/firstTime}'
Clear Command:
$$ZENHOME/scripts/strikethroughRSS.sh '/my/path/to/rss/feed.xml' '${evt/device}' '${evt/summary}' '${evt/severity}' '${evt/firstTime}'
--Start Script "add2RSS.sh"
#!/bin/sh
# Written by Eric Enns
# August 5th - For outputing zenoss events to an rss feed.
# usage ./add2RSS.sh 'rss feed file' 'hostname' 'event message' 'event severity' 'ipAddress' 'date the event occured'
#Here is how your rss feed should begin looking like
#<?xml version="1.0" ?>
#<rss version="2.0">
#<channel>
#
# <title>Zenoss Events</title>
# <description>Current Events from Zenoss</description>
# <link>http://zenoss-server:8080</link>
#
#</channel>
#</rss>
#lock the script from executing in paralell
while ! mkdir /var/lock/rsslock
do
sleep 3
done
FILE=$1 #rss feed file
insertLoc=8 #location where the new event will be added
date=$(date --date="$6" -R) #the date that the event was added to the rss feed
message=$(echo $3 | tr '\n' ' ' | sed -e 's/^[ \t]*//' | sed 's/[ \t]*$//') #the events message with newline characters turned into spaces
hostname=$2 #the hostname of the device that triggered the event
ipAddress=$5 #the ip address of the device that triggered the event
zenossAddr="http://zenoss-server:8080" #the web address of zenoss eg 'http://zenoss-server:8080'
#variables used in removing events older than 24 hours
yestDate=$(date -R --date="$6 1 day ago" | sed 's/.*, //g' | sed 's/:.*//g' | sed 's/ \([0-9]\)\([0-9]\)$/ [0-\1][0-\2]/g' | sed 's/^\([0-9]\)\([0-9]\)/[0-\1][0-\2]/g')
dateMatch=$(sed -n "/$yestDate/ =" $1 | head -1)
lastEvent=$(echo "$dateMatch -3" | bc)
#translate the severity number of the event into its word representation
if [ "$4" = "5" ]
then
severity="Critical"
elif [ "$4" = "4" ]
then
severity="Error"
elif [ "$4" = "3" ]
then
severity="Warning"
elif [ "$4" = "2" ]
then
severity="Info"
elif [ "$4" = "1" ]
then
severity="Debug"
else
severity="Clear"
fi
#redirect stdout to /tmp/futureRSS
exec > /tmp/futureRSS
#print the first part of the rss feed to the insertion location
awk -v pos="$insertLoc" '{
if(NR<=pos)
}' $FILE
#insert the new event into the rss feed
echo " <item>"
echo " <title>$hostname</title>"
echo " <pubDate>$date</pubDate>"
echo " <description>[$severity] $message</description>"
echo " <link>$zenossAddr/zport/dmd/deviceSearchResults?query=$ipAddress</link>"
echo " </item>"
echo ""
#print the last part of the rss feed after the insertion location
if [ "$dateMatch" != "" ]
then
awk -v pos="$insertLoc" -v end="$lastEvent" '{
if(NR>pos && NR <=end)
}' $FILE
echo "</channel>"
echo "</rss>"
else
awk -v pos="$insertLoc" '{
if(NR>pos)
}' $FILE
fi
#write the rss feed with the event added back to the main file
cat /tmp/futureRSS > $FILE
#unlock the script so that another instance can execute
rm -rf /var/lock/rsslock
--End Script
--Start Script "strikethroughRSS.sh"
#!/bin/sh
# Written by Eric Enns
# August 5th - For striking out cleared events from zenoss rss feed.
# usage ./strikethroughRSS.sh 'rss feed file' 'hostname of device' 'event message' 'event severity' 'date the event occured'
#lock the script from executing in paralell
while ! mkdir /var/lock/rsslock
do
sleep 3
done
FILE=$1
hostname=$2
message=$(echo $3 | tr '\n' ' ' | sed -e 's/^[ \t]*//' | sed 's/[ \t]*$//')
date=$(date -d "$5" -R)
if [ "$4" = "5" ]
then
severity="Critical"
elif [ "$4" = "4" ]
then
severity="Error"
elif [ "$4" = "3" ]
then
severity="Warning"
elif [ "$4" = "2" ]
then
severity="Info"
elif [ "$4" = "1" ]
then
severity="Debug"
else
severity="Clear"
fi
text="[$severity] $message"
text=$(echo $text | sed 's/ /\\ /g')
text=$(echo $text | sed 's/\//\\\//g')
text=$(echo $text | sed 's/\[/\\[/g')
text=$(echo $text | sed 's/\]/\\]/g')
matchLoc="-1"
declare -a deviceLoc
declare -a timeLoc
deviceLoc=(`sed -n "/<title>$hostname<\/title>/ =" "$FILE"`)
timeLoc=(`sed -n "/<pubDate>$date<\/pubDate>/ =" "$FILE"`)
deviceLocLen=${#deviceLoc[*]}
timeLocLen=${#timeLoc[*]}
i=0
j=0
while [ $i -lt $deviceLocLen ]
do
let iplus=${deviceLoc[$i]}+1
j=0
while [ $j -lt $timeLocLen ]
do
if [ "$iplus" = "${timeLoc[$j]}" ]
then
let line=iplus+1
matchLoc=$(awk -v pos="$line" "/description>$text<\/description>/{
if(NR==pos)
print NR
}" $FILE)
if [ "$matchLoc" = "$line" ]
then
break
fi
fi
let j=j+1
done
let i=i+1
done
if [ "$matchLoc" != "-1" ]
then
if [ "$matchLoc" != "" ]
then
exec > /tmp/futureRSS
sed "$matchLoc""s/<description>$text<\/description>/<description><!\[CDATA\[<del>$text<\/del>\]\]><\/description>/g" $FILE
cat /tmp/futureRSS > $FILE
fi
fi
#unlock the script so that another instance can execute
rm -rf /var/lock/rsslock
-- End Script