ravin
May 23, 2015, 7:16pm
1
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
May 24, 2015, 10:49am
2
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?
skot
May 27, 2015, 4:53pm
3
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)
skot
May 27, 2015, 5:52pm
5
boen_robot:
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
June 6, 2015, 5:34pm
6
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
}
}