Using the OmniVista 2500 Trap Responder to send Webhook messages to Microsoft Teams Channel
I had seen in OmniVista 2500 the “Trap Responder” functionality “Run an application on the server”.
I also had noticed while playing around in OmniVista “The Virtual Appliance Menu” CLI that the curl binary was accessible via the “Advanced Mode”. Then I thought it must be possible to combine them to create a webhook. With the help of Sales Engineer at Alcatel-Lucent Enterprise, I got an example on how to execute curl via a shell script.
How to make it happen:
Configuration in OmniVista 2500
The Script:
First of all, we need a shell script to take care of the output from OmniVista 2500 Trap Responder.
Transfer the script via SFTP to OmniVista 2500 server using the user cliadmin (I used WinSCP for this step).
As OmniVista will have to execute the script from the server we have to give it proper executable rights. I set write on every user as we don’t have users logging in to OmniVista part from the cliadmin.
We also need to transfer/create the two logfiles in advance in the same folder.
When connecting to OmniVista with SFTP we end up in the folder /opt/OmniVista_2500_NMS/data/file_server/cliadmin/ and this is the folder we later refer to in the Trap Responder.
#IFS="\n"
#!/bin/bash
#
# Send trap responses from OmniVista2500 via Teams Webhook
# Pär Stolpe, par.stolpe@liu.se, 2023-03-29
#
# Copy this file to OmniVista2500 via cliadmin and sftp and set execute bits.
# The file will end up in the directory:
# /opt/OmniVista_2500_NMS/data/file_server/cliadmin/
#
# In OV configure Trap Responder as follows:
#
# Action: Run an application on the server
# Command: ./teamstrap.sh
# Arguments: $TrapName$ $TrapSeverity$ $TrapSource$ $TrapAgent$ $TrapAgentName$
# Start directory: /opt/OmniVista_2500_NMS/data/file_server/cliadmin/
# Standard input: $TrapSynopsis$
#
# Any file refered by the script must be created first before it may be used.
# ie error.txt and output.txt in the same catalog as this script.
read -r -d '' OV_STDIN
# Webhook URL for Teams Channel
TEAMSURL=''
LOGFILE=/opt/OmniVista_2500_NMS/data/file_server/cliadmin/error.txt
OUTPUTLOG=/opt/OmniVista_2500_NMS/data/file_server/cliadmin/output.txt
# If you ever want a timestamp from the script use this variable
# now=$(TZ=Europe/Stockholm date +"%Y-%m-%d/%T")
# Color the messages accordingly
if [ ${2} == "Critical" ]; then
textcolor="Attention"
elif [ ${2} == "Warning" ]; then
textcolor="Warning"
elif [ ${2} == "Normal" ]; then
textcolor="Good"
else
textcolor="Default"
fi
# A simple Microsoft Teams Adaptive Card layout
TEAMSCARD="{
\"type\":\"message\",
\"attachments\":[
{
\"contentType\":\"application/vnd.microsoft.card.adaptive\",
\"contentUrl\":null,
\"content\":{
\"type\": \"AdaptiveCard\",
\"\$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",
\"version\": \"1.4\",
\"body\": [
{
\"type\": \"TextBlock\",
\"text\": \"${2}: ${5} - ${4}, ${1}\",
\"wrap\": true,
\"size\": \"Large\",
\"weight\": \"Bolder\",
\"color\": \"${textcolor}\"
},
{
\"type\": \"TextBlock\",
\"text\": \"${OV_STDIN}\",
\"wrap\": true,
\"size\": \"Medium\"
}
]
}
}
]
}"
# Post the TEAMSCARD to WebHook
(curl -X POST -H 'Content-Type: application/json' -d "${TEAMSCARD}" $TEAMSURL)&>$LOGFILE
OmniVista 2500 GUI
Conclusion
