When Mikrotik Closes, Send Log/sms/mail
Scenario:
There are 2 WAN ports belonging to the Mikrotik
and the IP information will be sent to the specified IP address by SMS /mail-in both ports.
If the device is rebooted in any way, the information of this situation will be sent as SMS when it reaches the time specified in the uptime variable.
Mikrotik reboot alert / UPTIME CHECK SCRIPT
, with the prevention of sending FALSE ALARM
with optional Email
and SMS
Alert.
You need to use Gmail for sending mail, and an SMS Platform for Sending Sms.
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 50 51 52 53 54 55 56 57 58 59 | #Transmitting Uptime Information to the Variable :local UPTIME [/system resource get uptime] #Uptime Limit is transferred to the Variable (this time is up to you as you want.) :local UPTIMELIMIT "00:05:00" # Date, Time information is transferred to variables. :local date; :local time; :set date [/system clock get date]; :set time [/system clock get time]; # If Uptime information is below the specified limit, log 'information about this subject is transferred and sms / mail is sent. :if ($UPTIME<$UPTIMELIMIT) do={ :log error "ALARM: Router Rebooted. Current uptime status $ UPTIMELIMIT Minute, Sms and Mail Sending."; # Services are waiting for a short time to load. :delay 161s # GMAIL Setup : local gmailid "GmailUserName@gmail.com" : local GMAILPASS "GmailPassword" : global gmailsmtp : set gmailsmtp [: resolve "smtp.gmail.com"]; : local COMPANY "By Techsoftcenter" # SMSCompany Configuration # You need to get your SMSCompany account. : local SMSURL "api.companysms.com" : local KID "companyusername" : local KPASS "companysifre" Phone numbers to be sent : local cell1 "0493021909" : local cell2 "0493xxxxxxx" :global WAN1IP :global WAN2IP # 2 PPPOE Connection is checked. If it receives a rope, its information is transferred to the variable to send mail. # If there is no pppoe connection, log is noted on this subject, it stops the process. if ([/ interface get ADSL_1 disabled] = yes) do = {: log error "ADSL_1 Connection Disabled"} \ else = {[: global WAN1IP [/ ip address get [find where interface = ADSL_1] address];]} if ([/ interface get ADSL_2 disabled] = yes) do = {: log error "ADSL_2 Connection is Disable"} \ else = {[: global WAN2IP [/ ip address get [find where interface = ADSL_2] address];]} # Mail recipients are defined. Defines 2 mail accounts. : local mailsendto : set mailsendto adminemailaccount@gmail.com : local mailsendto2 : set mailsendto2 technicalemailaccount@gmail.com # Set Email Subject : local es "$ [/ system identity get name] $ [/ system clock get date] $ [/ system clock get time] $ FIRM MICROTIC Reboot! New IPs $ WAN1IP $ WAN2IP Total $ UPTIME active" # Set Email Body : local eb "$ [/ system identity get name] $ [/ system clock get date] $ [/ system clock get time] $ FIRM MIKROTIK Has Been Reboot! New IPs $ WAN1IP $ WAN2IP Total $ UPTIME Active" \ n \ n Current Uptime Duration $ UPTIME \ n \ n Powered By Techsoftcenter! " # Finally send email to both amind email addresses /tool e-mail send to=$mailsendto subject=$es start-tls=yes body=$eb password=$GMAILPASS /tool e-mail send to=$mailsendto2 subject=$es body=$eb start-tls=yes password=$GMAILPASS : log warning "E-mail about Reboot ..." : log warning "Sms Sent About Reboot." # SMS Sending Operation /tool fetch url="http://$SMSURL/v1/send-sms/get/?username=$KID&password=$KPASS&receipents=$cell1 $cell2&text=$COMPANY MIKROTIK Router Reboot has been and now sum $date $time New active threads $WAN1IP $WAN2IP [$COMPANY ByTechsoftcenter]" # If the Uptime Time limit has been exceeded (if sms mail has been sent within the first specified period, alarm passive status and information is entered in order not to send mail again. } else = { : log error "System $ UPTIMELIMIT has been active for some time. No sms mail is required." } |
I hope it was a useful article.