Loading...
right-arrow (6)Back
Blog

Using the OmniVista 2500 Trap Responder to send Webhook messages to Microsoft Teams Channel

Groupe_887Apr. 04, 2023
At Linköping University, we wanted to get some of the Trap Notifications to be sent to a Microsoft Teams Channel to be able to monitor certain events that we need to pay extra attention to, such as Switches becoming unreachable, dyingGasp Traps (power failures), etc.
omnivista

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:

Create a Webhook in the Teams Channel that should receive your message:
omnivista webhook
omnivista webhook
omnivista webhook

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.

omnivista webhook

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

In the OmniVista admin GUI, we need to create a new Trap Responder, choose which Trap Types we want to send messages on and fill out the Response as stated in the Script file and in the picture below.
omnivista webhook

Conclusion

With this method you may extend the OmniVista 2500 trap handling to inform other systems on specific events.

Medhi Tarzout

Medhi Tarzout is a skilled Network Solutions Architect who brings a unique perspective to his work thanks to his previous experience as part of the IT team at a leading real estate agency. During his time there, Medhi gained valuable networking experience that has served him well in his current role. As a Network Solutions Architect, Medhi specializes in OmniVista and OmniAccess Stellar, and he is known for his great sense of humor, particularly during peak hours.
Loading