28. 10. 2022 Juergen Vigna Contribution, NetEye

Receiving and Handling Incoming SMS’s on NetEye in Tornado (Part 1/2)

Most physical NetEye servers have an SMS Gateway attached in order to send CRITICAL notifications via an SMS message, since this will work even when the main network is down. However, sometimes you just want to send messages to your NetEye server’s SMS Gateway in order to effect certain actions, for example just to check that the SMS Gateway is working correctly.

To handle this you have to start by configuring the SMS Daemon (smsd.conf), normally hosted in “/neteye/local/smsd/conf/smsd.conf“, adding this line:

eventhandler = /neteye/shared/monitoring/bin/tornado_sms_handler.sh

Next you’ll need the script which is referred to in the configuration line above (/neteye/shared/monitoring/bin/tornado_sms_handler.sh). You can create it using this code:

#! /bin/sh
export PATH=/usr/local/bin:/bin:/usr/bin:$PATH

if [ "$1" = "RECEIVED" ]
then
  FILE=$2
  FROM=$(cat $2 | grep '^From:' | awk '{ print $2 }')
  SENT=$(cat $2 | grep '^Sent:' | sed -e 's/Sent: //g')
  RECEIVED=$(cat $2 | grep '^Received:' | sed -e 's/Received: //g')
  MODEM=$(cat $2 | grep '^Modem:' | awk '{ print $2 }')
  HOST=$(hostname)
  DATA=$(cat $2 | tail -n 1)
  curl -k -s -X POST 'https://neteye.neteyelocal/tornado/webhook/event/sms?token=mytoken' -H 'Content-Type: application/json' -d "{\"file\":\"$FILE\",\"from\":\"$FROM\",\"sent\":\"$SENT\",\"received\":\"$RECEIVED\",\"modem\":\"$MODEM\",\"host\":\"$HOST\",\"data\":\"$DATA\"}"
fi

rm -f $2

If the directory doesn’t exist, go ahead and create it. Don’t forget to make the file executable with “chmod 0755“.

As you can see, this script uses a Tornado Webhook Collector. So the next thing to configure is the webhook itself. To do that, create the file /neteye/shared/tornado_webhook_collector/conf/webhooks/webhook_sms.json with this content:

{
  "id": "sms",
  "token": "mytoken",
  "collector_config": {
    "event_type": "webhook-sms",
    "payload": {
      "file": "${file}",
      "from": "${from}",
      "sent": "${sent}",
      "received": "${received}",
      "modem": "${modem}",
      "host": "${host}",
      "data": "${data}"
    }
  }
}

It’s important that you keep the files exactly as shown here, since the webhook definition goes hand in hand with the JSON sent in the curl of the smsd-eventhandler script.

Now restart the tornado_webhook_collector service and then the smsd service. Your Backend Engine for receiving SMS messages inside Tornado will now be active.

Stay tuned to this channel because soon I’ll be showing you a real use case where you can actively check that your SMS Gateways are working correctly.

Juergen Vigna

Juergen Vigna

NetEye Solution Architect at Würth Phoenix
I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

Author

Juergen Vigna

I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive