Community discussions

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

Dude v6 - SMS notification through another ROS - using ssh-exec

Fri Mar 18, 2022 2:49 am

Related solutions
Dude v6 - SMS notification

Requirements
1. Mikrotik ROS-1 with installed Dude server
2. Mikrotik ROS-2 with access to send SMS
3. Account on smspilot.ru

Architecture
Dude-v6-SMS-notification-through-another-ROS-using-ssh-exec-01.png
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
ssh-keygen -f sms-sender -t rsa -b 4096 -m PEM -C sms-sender
********
Note: Remember passphrase for next steps

2. Import sms-sender keys on ROS-1 (Dude)
# 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)
# 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
# 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:
# 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:
# Define Subject
:global notificationtext "Service [Probe.Name] on [Device.Name] is now [Service.Status]"

# Run script
system script run SMS-Notification-smspilot.ru
And test it via pressing Test button

7. Now you can use it
Dude-v6-SMS-notification-through-another-ROS-using-ssh-exec-02.png

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
You do not have the required permissions to view the files attached to this post.
Last edited by stmx38 on Sun May 08, 2022 11:32 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 9569
Joined: Tue Feb 25, 2014 12:49 pm
Location: 🇮🇹, my 💔 is in 🇺🇦

Re: Dude v6 - SMS notification through another ROS - using ssh-exec

Sat Apr 02, 2022 11:20 pm

Sorry... but... is not more simple to simply give access to internet to ROS-1, at least to the sms site, and call the url directly inside The Dude???
(like what already I do for SMS and WhatsApp?)
 
User avatar
stmx38
Long time Member
Long time Member
Topic Author
Posts: 582
Joined: Thu Feb 14, 2008 4:03 pm
Location: Moldova, Chisinau

Re: Dude v6 - SMS notification through another ROS - using ssh-exec

Sun Apr 03, 2022 12:02 am

Maybe you are right but, this was just a lab configuration to solve real case when ROS-1 have Dude installed and ROS-2 have USB modem to send SMS.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 9569
Joined: Tue Feb 25, 2014 12:49 pm
Location: 🇮🇹, my 💔 is in 🇺🇦

Re: Dude v6 - SMS notification through another ROS - using ssh-exec

Sun Apr 03, 2022 12:13 am

Ok, understand, on example I do not see any "USB" related commands... but is more important The Dude... If the connection between the two fail?
Better move the USB modem to send SMS directly to The Dude machine...

P.S.: I hope the api key you post is fake... right???

P.P.S.: I have stopped using or recommending any .ru service...
You are only 160Km from Одеса...

Only 50Km from Україна...
I hope good fortune to you...
 
User avatar
stmx38
Long time Member
Long time Member
Topic Author
Posts: 582
Joined: Thu Feb 14, 2008 4:03 pm
Location: Moldova, Chisinau

Re: Dude v6 - SMS notification through another ROS - using ssh-exec

Sun Apr 03, 2022 8:37 am

On my lab I don't have an USB modem and used SMS via API service to test and describe this solution. In the Adaptation section I also described how it can be updated for USB modem.

It is not my configuration and I don't know so much details about it, maybe it is the case that Dude is installed on VM (CHR) and USB modem is plugged into Routerboard.

Who is online

Users browsing this forum: Google [Bot] and 6 guests