Community discussions

MikroTik App
 
ravin
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Mon Jan 29, 2007 3:59 pm
Location: mym

check uptime of last host entry in hotspot and send mail

Sat May 23, 2015 10:16 pm

Hello there,

Need script which can check uptime of last host entry in hotspot for less than 10m and if there are no entries then send mail.

Basically I need to check new host entries are getting added and if for 10 minutes there are no new entries then need mail notification so that I can look into the issue.

Thanks
 
ravin
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Mon Jan 29, 2007 3:59 pm
Location: mym

Re: check uptime of last host entry in hotspot and send mail

Sun May 24, 2015 1:49 pm

Tried this but doesn't work:

{
:if ([/ip hotspot host print where uptime < 10m] = 0) do={
/tool e-mail send to=xyz@example.com subject=no-new-host body=no-new-host
}
}

what is wrong in above script?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: check uptime of last host entry in hotspot and send mail

Wed May 27, 2015 7:53 pm

You can check for the number of items using [:len] and [find]. I like to do it in steps.

First, just show the returned entries:
:put [/ip hotspot host find where uptime <10m]
Then, test using [:len], to show the number of entries:
:put [:len [/ip hotspot host find where uptime <10m]]
Put it all together:
:if ([:len [/ip hotspot host find where uptime <10m]] = 0) do={
  /tool email ...
}
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: check uptime of last host entry in hotspot and send mail

Wed May 27, 2015 7:56 pm

You can also use the count-only argument of print, e.g.
:if ([/ip hotspot host print count-only where uptime <10m] = 0) do={
  /tool email ...
}
(and that should be slightly more efficient that "[:len [find]]" too)
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: check uptime of last host entry in hotspot and send mail

Wed May 27, 2015 8:52 pm

You can also use the count-only argument of print, e.g.
:if ([/ip hotspot host print count-only where uptime <10m] = 0) do={
  /tool email ...
}
(and that should be slightly more efficient that "[:len [find]]" too)
Oh yes, I forgot about that. Good call. I got into the habit of using :len and don't use count-only frequently enough that I forget it exists.
 
ravin
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Mon Jan 29, 2007 3:59 pm
Location: mym

Re: check uptime of last host entry in hotspot and send mail

Sat Jun 06, 2015 8:34 pm

Thanks all for the help.

Using below script and working fine:

{
:local upt [/ip hotspot host print count-only where uptime<10m];
:if ($upt=0) do={
/tool e-mail
}
}

Who is online

Users browsing this forum: No registered users and 56 guests