getLMS-One-MikroTik-StatsByLMS        getLMS-Multi-MikroTik-StatsByLMS        syncLMS-Multi-MikroTik-DHCP        syncLMS-Multi-MikroTik-PPPoE       

sieć

 

mikrotik

 

ubiquiti

 

mail z uptime po radiu

   15-03-2015 20:00:00       Odwiedziny: 1621

   Skrypt wysyła maila chwile po tym jak urządzenie (adres MAC) połączy się ponownie, z uptime przed rozłączeniem.

#1 ustawienie synchronizacji czasu
# strefa czasowa
/system clock set time-zone-name=Europe/Warsaw

# serwery NTP - dla wesji 6.13 i niższe - wymagane do dynDNS
/system ntp client 
 set enabled=yes mode=unicast primary-ntp=212.244.36.228 secondary-ntp=212.244.36.227

# serwery NTP - dla wesji 6.14 i wyższe - wymagane do dynDNS
/system ntp client 
 set enabled=yes primary-ntp=212.244.36.228 secondary-ntp=212.244.36.227

#1 kod skryptu
/system script add name=upRadioSendMail policy=write,read,test,policy source={
 :local mac "00:00:00:00:00:00";
 :local smtpLogin "alert@domena.pl";
 :local smtpHaslo "HASLO_SMTP";
 :local smtpHost "mail.domena.pl";
 :local smtpPort "587";
 :local smtpMail "alert@domena.pl";
 :local smtpMailDO "odbiorca@mail.pl";


 :global upRadioOld;
 :global secRadioOld;
 :local upRadioNew [/interface wireless registration-table get [find mac-address="$mac"] value-name=uptime];
 :local secRadioNew $upRadioNew;

 :local weeks [:pick $secRadioNew 0 [:find $secRadioNew "w"]]
 :set secRadioNew [:pick $secRadioNew ([:find $secRadioNew "w"]+1) [:len $secRadioNew]]
 :local days [:pick $secRadioNew 0 [:find $secRadioNew "d"]]
 :set secRadioNew [:pick $secRadioNew ([:find $secRadioNew "d"]+1) [:len $secRadioNew]]
 :local hours [:pick $secRadioNew 0 [:find $secRadioNew ":"]]
 :set secRadioNew [:pick $secRadioNew ([:find $secRadioNew ":"]+1) [:len $secRadioNew]]
 :local minutes [:pick $secRadioNew 0 [:find $secRadioNew ":"]]
 :set secRadioNew [:pick $secRadioNew ([:find $secRadioNew ":"]+1) [:len $secRadioNew]]
 :local seconds $secRadioNew
 :set secRadioNew [(($weeks*604800)+($days*86400)+($hours*3600)+($minutes*60)+$seconds)]

 :local date [/system clock get date];
 :local time [/system clock get time];
 
   :if ($secRadioNew < $secRadioOld or [:len $secRadioOld] = 0) do={
	:local body "now: $date $time\nold: $upRadioOld\nnew: $upRadioNew\n";
	:local identity [/system identity get name];
	:local date [/system clock get date];
	:local time [/system clock get time];
	/tool e-mail send server=$smtpHost subject="$identity - $date $time - link down/up" \
		to="$smtpMailDO" from="$smtpMail" user="$smtpLogin" password="$smtpHaslo" \
		port="$smtpPort" body="$body";
   }

 :set upRadioOld $upRadioNew;
 :set secRadioOld $secRadioNew;
}

#1 wykonywanie skryptu co 1 minute
/system scheduler 
 add name="run upRadioSendMail" disabled=no interval=00:01:00 on-event="/system script run upRadioSendMail\r\n"


Copyright seszu © 30.10.2010-2020.