check uptime of last host entry in hotspot and send mail

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

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?

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 ...
}

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.

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
}
}