Dude v6 - SMS notifications
Requirements
1. Mikrotik ROS-1 with installed Dude server
2. Mikrotik ROS-2 with access to send SMS
3. Account on smspilot.ru
Architecture
Code: Select all
ROS-1 (Dude) --> ROS-2 (SMS access) --> SMS recipient
1. On ROS-1 we have installed Dude
2. Dude execute a script on ROS-1
3. Script on ROS-1 uses ssh-exec to send SMS via ROS-2 which have access to send SMS notifications
4. On ROS-2 we can use USB modem, SMS via API or SMS gateway
Setup instruction
1. Generate SSH key on Linux
Code: Select all
ssh-keygen -f sms-sender -t rsa -b 4096 -m PEM -C sms-sender
********
2. Import sms-sender keys on ROS-1 (Dude)
Code: Select all
# Copy generated public and private keys from your Linux to the ROS: sms-sender and sms-sender.pub
scp sms-sender sms-sender.pub admin@192.168.64.3:/
# Import copied public and private keys to the current (admin) user
user ssh-keys private import private-key-file=sms-sender public-key-file=sms-sender.pub
********
# Show imported keys
user ssh-keys private print
[admin@ROS-1] > user ssh-keys private print
Flags: R - RSA, D - DSA
# USER BITS KEY-OWNER
0 R admin 4096 sms-sender
# Remove imported keys files
file remove sms-sender
file remove sms-sender.pub
3. Create sms-sender user on ROS-2 (SMS access)
Code: Select all
# Add group
user group add name=sms-sender policy=ssh,write,test,read
# Add user
user add name=sms-sender group=sms-sender
# Disable SSH password login
ip ssh set always-allow-password-login=no
# Or set strong password for sms-sender user
user set sms-sender password=********
# Copy generated public key from your Linux to the ROS: sms-sender.pub
scp sms-sender.pub admin@192.168.64.4:/
# Import copied public key to the sms-sender user
user ssh-keys import public-key-file=sms-sender.pub user=sms-sender
# Check imported key
user ssh-keys print
[admin@ROS-2] > user ssh-keys print
Flags: R - RSA, D - DSA
# USER BITS KEY-OWNER
0 R sms-sender 4096 sms-sender
4. Test SSH login from ROS-1 to ROS-2 via ssh-exec
Code: Select all
# ROS-1 (Dude) Terminal under admin user
# Using SSH-EXEC
system ssh-exec address=192.168.64.4 user=sms-sender command="ip address print"
# Using SSH
system ssh address=192.168.64.4 user=sms-sender command="ip address print"
5. Create script on ROS-1 (Dude)
System --> Scripts --> + --> SMS-Notification-smspilot.ru
Policy: read, test, Don't Require Permissions
Source:
Code: Select all
# Define subject
:global notificationtext "$notificationtext"
# Define URL
:local url "http://smspilot.ru/api.php"
:local apikey "154YCR22XL9IS4UR8YRO7GFQ81PGN6Z3OD1BXY726N854S52I3046CZ0R8JXR2SH"
#
# Define IP of ROS with SMS access
:local rossms "192.168.64.4"
#
# First Name Last Name
:local to "+xxxxxxxxxxx"
#
# Send SMS
system ssh-exec address="$rossms" user=sms-sender command="/tool fetch output=none url=\"$url\?apikey=$apikey&to=$to&send=$notificationtext\""
6. Create new Notification in Dude
Name: SMS-Notification-smspilot.ru
Type: execute on server
Command:
Code: Select all
# Define Subject
:global notificationtext "Service [Probe.Name] on [Device.Name] is now [Service.Status]"
# Run script
system script run SMS-Notification-smspilot.ru
7. Now you can use it
Adaptation
Described solution can be very easy adapted to use SMS gateway or USB modem described on Dude v6 - SMS notification.
For this you just need in step 5. Create script on ROS-1 (Dude) update the script from an appropriate solution and keep :global notificationtext "$notificationtext" variable because it gets subject from Dude.
Related Wiki topics
Manual:Tools/Fetch
Use SSH to execute commands (public/private key login)
Known issues
1. When we execute ssh/ssh-exec directly from Dude it doesn't work and it maybe related to the fact that imported SSH private key(under admin user) is not accessible to Dude, this is why we:
a) Use script on ROS-1 and not whole script content in Dude notification.
b) Run script on ROS-1 and not ROS-2