Quick Note:
Scenario: DUAL DSL wan links are connected with mikrotik [modems are in bridge mode], Configured as PCC along with the pppoe server. USB modem is attached with the Mikrotik via USB port. The OP need an script which can daily send sms or email specific information to admin cell, or whenever admin require on urgent basis via sending sms to mikrotik and it can return back the info to the admin cell.
Dirty Solution:
Following script will collect information from Mikrotik system such as active pppoe users, CPU load, dsl links status etc and send this information to admin via SMS or Email either via scheduler or as receiver command on mikrotik. [I am already using much more advance version of this script in other networks in linux system as BASH is the best ground to support scripting but since linux was not available at this spot, i had to use Mikrotik only with usb modem attached] it can be set as receive command too so that admin can send sms to mikrotik and mikrotik will reply back the current info to the admin mobile. Sometimes its very useful for remote admins.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| # SENDING SMS TO ADMINS FOR DAILY MORNING ALERT # Script Designed by SYED JAHANZAIB # aacable at hotmail dot com / https://aacable.wordpress.com # Morning Hours / 8th Oct, 2015 # Setting various variables / jz :local date; :local time; :local PPP ([/ppp active print count-only]) :local UPTIME [/system resource get uptime] :local CPU [/system resource get cpu-load] :set date [/system clock get date]; :set time [/system clock get time]; :global FTPIP 192.168.0.50 # Following variables are configured via other scripts which scheduled to run after very 1 minutes to update internet/media sharing server status and set these variables # But you can run your own script here to make variable after successful or failed ping results # Ref: https://aacable.wordpress.com/2014/06/12/mikrotik-wan-monitoring-script-with-multiple-host-check/ :local DSL1 [/system script environment get [/system script environment find name="DSL1netstatus"] value]; :local DSL2 [/system script environment get [/system script environment find name="DSL2netstatus"] value]; # Local FTP Sharing Server or any other remote host, should be set via netwatch or local script inside this script #:local FTP [/tool netwatch get number=0 status] # Using one liner code to get FTP ping status and store it in variable, you can use same for above dsl status as well by # forcing routes via specific gateway :global FTP; :if ([/ping $FTPIP count=1] = 0) do {:put ":set FTP value=DOWN"} else={:set FTP value=UP} # Admin SMS Number Config :local cell1 "03333021909" # Gmail Config :global SYSID ([/system identity get name]) :global adminmail1 aacable@hotmail.com :global gmailid GMAILID@gmail.com :global gmailpwd GMAILPASSWORD :global gmailip :set gmailip [:resolve "smtp.gmail.com"]; # Print LOG :log warning "INFO: Daily info for NETWORK @ $date $time\nActive PPPOE Users = $PPP\nUptime is $UPTIME\nCPU Load = $CPU\nDSL1 = $DSL1\nDSL2 = $DSL2\nFTP = $FTP\n\nPowered by J." :log warning "Sending DAILY MORNING ALERT SMS on $cell1 ... by J." # Sending SMS /tool sms send port=usb3 phone-number=$cell1 message="INFO: Daily info for NETWORK @ $date $time\nActive PPPOE Users = $PPP\nUptime = $UPTIME\nCPU Load = $CPU\nDSL1 = $DSL1\nDSL2 = $DSL2\nFTP = $FTP\n\nPowered by J." channel=0 # Sending EMAIL - Use it if if required #/tool e-mail send to=$adminmail1 password=$gmailpwd subject="INFO: Daily info for @ $date $time" body="Active PPPOE Users = $PPP\nUptime = $UPTIME\nCPU Load = $CPU\nDSL1 = $DSL1\nDSL2 = $DSL2\nFTP = $FTP\n\nPowered by J." from=$gmailid server=$gmailip start-tls=yes |
Sample Image of SMS:
Enable Mikrotik to Receive SMS and run script
Use following command to enable SMS receiving on mikrotik.
1
2
3
4
5
| /tool sms set receive-enabled=yes # Its good idea to keep minimum SMS in INBOX /tool sms set receive-enabled=yes keep-max-sms=15 |
From your mobile you can send following message to run script on remote mikrotik.
:cmd 12345 script test
Explanation:
- :cmd to let mikrotik know that its command
- 12345 is secret which you configured in /tool > sms,kind of password / authentication
- script to let mikrotik know that its script related command and
- test is script name you want to run.
More references for mikrotik base sms are available at https://aacable.wordpress.com/tag/mikrotik-sms/
0 comments:
Post a Comment