Returning comment in Netwatch

Hi,

I’m trying to create a generic script to use in Netwatch, where it will send an e-mail with the text in the device’s Comment field and saying if it is UP or DOWN.

I’ve sorted all the e-mail bits and getting the comment field, but I’m stuck when I have to put in the index-id of the object I want to retrieve the comment of.

Let me explain. If I use

:log info [get 2 comment]

on a commandline, this works fine as it returns the comment of object number 2, but I want a generic line which I can just copy/paste into each Netwatch entry… something like

:log info [get > $myself > comment]

How can I get the netwatch object number which called the script?

could you explain exactly what you want to achieve, and why you want to get that number?

Maybe setting :global variable inside netwatch entry before it executes script that this is the item.

Also, netwatch executes scripts as if they where from the root menu. where you do not have any entries and don’t have :get

:log info [/tool netwatch get 2 comment]

will get the comment field.

Hey,

At our hotspot sites, I use Netwatch to monitor all APs and switches and send us an e-mail if a ping fails.

OnUp=

:local alerttext "Balcony AP on LEVEL 3 UP"

:log warning $alerttext
/tool e-mail send to=itsupport@mydomain.com subject=$alerttext

OnDown=

:local alerttext "Balcony AP on LEVEL 3 DOWN"

:log warning $alerttext
/tool e-mail send to=itsupport@mydomain.com subject=$alerttext

For easy of use, we also copy the first line (in this case “Balcony AP on LEVEL 3”) to the comment field of the Netwatch entry, so we (or the client which owns the hotspot) can instantly see which APs/switches have failed.

As you can see, in this way we have to manually modify the first line for each OnUP and OnDOWN event as well as the comment field for EACH entry. When you have a setup of 30 APs, that is 90 modifications in total…

Also, for AP moves, the installer must remember to change the test on the comment field as well as on the first line of the OnUp and OnDown scripts.


If we could retrieve the comment field of the netwatch entry which is calling the script, we could replace the above with a single script as follows (pseudo-code):

:local alerttext [/tool netwatch get *MY_OWN_ID* comment] [/tool netwatch get *MY_OWN_ID* status]

:log warning $alerttext
/tool e-mail send to=itsupport@mydomain.com subject=$alerttext body=$alerttext

I’m only missing the MY_OWN_ID part.. how do I retrieve that? Can I do this at all?


Sidenote: I also use The Dude installed centrally at our office for more in-depth monitoring, but the local Netwatch is useful because there are no WAN links involved so I can ping more frequently and never lose packets like I would over the internet.

Did you ever figure this out? I am trying to do the exact same thing here

Did you ever figure this out? I am trying to do the exact same thing.

If you move an AP, does it keep the same IP address? If it does you would only change the comment for the new location and use a variation of this code;

:put [get [/tool netwatch find where host=xxx.xxx.xxx.xxx] comment]

This could be even easier if MikroTik would add a “name” for each netwatch entry, then you could change the IP address and still find it.

No I’ve never really figured it out.

I see what you mean, however I was looking for a way of creating a ‘generic’ script which I can just copy/paste into all Netwatchers on all our routers, so I need the Netwatch to be ‘self-aware’.

When I looked at netwatch, searching by IP address seemed to be the only way to locate the comment. I don’t see how a generic script could do everything because you still have to tell netwatch what IP address to ping and put the location in the comment.

I don’t see why you couldn’t duplicate the netwatch function in a separate script. That would give you more control and flexibility, but you still have to tell this script what to ping and what the location name is. Unless you can figure out a creative way for the router to figure out where it is.

What I’m looking for is a generic script which I can always dump into the OnUp/OnDown boxes. Obviously, I would still need to specify the IP address of the device. The idea is that the script takes the description of the device from the Comment which I add to that specific netwatcher, so when it sends an e-mail saying the device is up/down, it takes the name of the device from the comment.

This would mean putting in the name of the device just once (in the comment field) rather than having to put in the name of the device three times (once as a comment + once in the OnDown script + once in the OnUp script).

Ok, so the line of code that I gave would only work if you could get the IP address that netwatch is pinging automatically. Now I don’t know your setup and how the pinged address is related. The AP has to be programmed when it is set up and possibly when it is moved. If you can find a place to leave the IP address in a predictable place, the script could retrieve it.

For example, if you were pinging “Gateway #1” and you put “Gateway #1 xxx.xxx.xxx.xxx” in a comment somewhere when you initially set it up, the script could find that, parse out the IP address, then use that IP address to find the location name in netwatch.