Community discussions

MikroTik App
 
User avatar
stmx38
Long time Member
Long time Member
Topic Author
Posts: 651
Joined: Thu Feb 14, 2008 4:03 pm
Location: Moldova, Chisinau

Dude v6 - SMS notifications through SMS gateway - using fetch tool

Fri May 19, 2017 10:59 am

Related solutions
Dude v6 - SMS notifications

Requirements
1. Mikrotik ROS with installed Dude server
2. Access to SMS gateway

Setup instruction
1. Create new Notification in Dude:
Name: SMS-Notification-Gateway
Type: execute on server
Command:
# Variables
:local notificationtext "Service [Probe.Name] on [Device.Name] is now [Service.Status]"
:local url "http://192.168.1.1/cgi-bin/sendsms"
:local username user
:local password password
:local from dude
#
#
# Firstname Lastname
:local to "+xxxxxxxxxxx"
#
/tool fetch output=none url="$url\?username=$username&password=$password&to=$to&from=$from&text=$notificationtext" keep-result=no
And test it via pressing Test button.

2. Now you can use it:
Dude-v6-SMS-notification-through-SMS-gateway-using-fetch-tool-01.png
----
We got one issue with this type of notification:
1. We can't sent SMS with the text containing spaces.
In ROS, before 6.41rc37 fetch tool failed on 202 HTTP response code. For more information please see the following post: tool fetch - 2xx HTTP response codes.
As a result our final command for two recipients is the following:
# Send SMS notification using SMS Center
#
{
#
# Encode notification text
#
:local notificationtext "Service [Probe.Name] on [Device.Name] is now [Service.Status]"
:local notificationtextEncoded

:for i from=0 to=([:len $notificationtext] - 1) do={ 
  :local char [:pick $notificationtext $i]
  :if ($char = " ") do={
    :set $char "%20"
  }
  :set notificationtextEncoded ($notificationtextEncoded . $char)
}
:put $notificationtextEncoded
#
# Send SMS
#
:local url http://192.168.1.1:8080/cgi-bin/sendsms
:local username user
:local password password
:local from dude
#
# Firstname Lastname
:local to "+xxxxxxxxxxx"
/tool fetch output=none url="$url\?username=$username&password=$password&to=$to&from=$from&text=$notificationtextEncoded" keep-result=no
#
# Firstname2 Lastname2
:local to "+yyyyyyyyyyy"
/tool fetch output=none url="$url\?username=$username&password=$password&to=$to&from=$from&text=$notificationtextEncoded" keep-result=no
#
}

Related Wiki articles
Manual:Tools/Fetch

Related forum topics
Replace characters in string (url encode)
A function for url encoding

Hope this will help someone.
You do not have the required permissions to view the files attached to this post.