Senaryo :
Mikrotiğe ait 2 adet WAN portu var ve her iki portunda ip bilgisi sms /mail ile belirtilen ip adresine gönderilecek .
Cihaz herhangi bir şekilde reboot gerçekleşirse bu durumun bilgisi uptime değişkeninde belirtilen süreye ulaştığında sms olarak gönderiyor olacak .
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | # Mikrotik reboot alert / UPTIME CHECK SCRIPT, with prevention of sending FALSE ALARM with optional Email and SMS Alert # Mail gönderimi için Gmail , Sms Göndermi için AybitSMS.com Platformu kullanılmıştır. # By Yavuz Malkoç # https: //bilgi.wi.com.tr # Uptime Bilgisi Değişkene aktarılıyor :local UPTIME [/system resource get uptime] # Uptime Limiti Değişkene aktarılıyor ( bu süre size kalmış istediğiniz gibi belirleyebilirsiniz. ) :local UPTIMELIMIT "00:05:00" # Tarih , Saat bilgileri değişkenlere aktarılıyor. :local date ; :local time; :set date [/system clock get date ]; :set time [/system clock get time]; # Eğer Uptime bilgisi belirtilen limitin altında ise bu konu ile ilgili log' bilgi aktarılıyor ve sms / mail göndderiliyor. By Wi : if ( $UPTIME < $UPTIMELIMIT ) do ={ :log error "ALARM : Router Reboot Edildi . Mevcut uptime durumu $UPTIMELIMIT Dakika , Sms ve Mail Gönderiliyor." ; # Servisler yüklenmek için kısa bir süre bekletiliyor . /by Wi :delay 161s # GMAIL Setup :local gmailid "GmailKullanıcıadı@gmail.com" :local GMAILPASS "GmailPassword" : global gmailsmtp :set gmailsmtp [:resolve "smtp.gmail.com" ]; :local FIRMA "By Wi" # AybitSMS Konfigurasyonu #Eğer AybitSMS hesabınız almanız gerekmektedir. :local SMSURL "api.aybitsms.com" :local KID "aybitkullaniciadi" :local KPASS "Aybitsifre" #Gönderilecek telefon numaraları :local cell1 "03333021909" :local cell2 "0333xxxxxxx" : global WAN1IP : global WAN2IP # 2 PPPOE Bağlantısı kontrol ediliyor ip almışsa bilgileri mail göndermek üzere değişkene aktarılıyor # Eğer pppoe bağlantısı yoksa log 'a bu konuda not düşüyor , işlemi durduruyor . if ([/ interface get ADSL_1 disabled] = yes) do ={ :log error "ADSL_1 Bağlantısı Disable Durumda" }\ else ={[: global WAN1IP [/ip address get [find where interface =ADSL_1] address];]} if ([/ interface get ADSL_2 disabled] = yes) do ={ :log error "ADSL_2 Bağlantısı Disable Durumda " }\ else ={[: global WAN2IP [/ip address get [find where interface =ADSL_2] address];]} # Mail alıcıları tanımlanıyor . 2 mail hesabı için tanım yapıyor . :local mailsendto :set mailsendto [email protected] :local mailsendto2 :set mailsendto2 [email protected] # Set Email Subject :local es "$[/system identity get name] $[/system clock get date] $[/system clock get time] $FIRMA MIKROTIK Reboot Olmuş ! Yeni IP'leri $WAN1IP $WAN2IP Toplam $UPTIME süredir Aktif" # Set Email Body :local eb "$[/system identity get name] $[/system clock get date] $[/system clock get time] $FIRMA MIKROTIK Reboot Olmuş ! Yeni IP'leri $WAN1IP $WAN2IP Toplam $UPTIME süredir Aktif" \n\n Mevcut Uptime Süresi $UPTIME \n\n Powered By Wi !" # 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 "Reboot konusunda mail gönderildi ..." :log warning "Reboot Konusunda Sms Gönderildi. ." # SMS Gönderme İşlemi /tool fetch url= "http://$SMSURL/v1/send-sms/get/?username=$KID&password=$KPASS&receipents=$cell1+$cell2&text=$FIRMA+MIKROTIK+Router+Reboot+Olmus+ve+suan+toplam+$date+$time+Suredir+aktif+Yeni+ipler+$WAN1IP+$WAN2IP+++++++[$FIRMA+ByWi]" # Eğer Uptime Suresi limiti aşılmış ise ( ilk belirtilen süre içerisinde sms mail gönderilmiş ise tekrar mail göndermemek için alarm pasif duruma ve bilgisi giriliyor. } else ={ :log error "Sistem $UPTIMELIMIT süredir aktiftir. herhangi bir sms mail gönderilmesi gerekmiyor." } # Powered By Wi |