Community discussions

MikroTik App
 
donv
just joined
Topic Author
Posts: 9
Joined: Tue May 08, 2007 1:32 am
Location: Iowa - USA
Contact:

netwatch: how to create up_action and down_action email scri

Tue Aug 28, 2007 12:03 am

Hello,

I am trying to monitor a group of hosts on a hotspot network.

I have created netwatch rules successfully to monitor the hosts.
such as this:
0 ;;; workstation 1
192.168.120.1 5m 1m up

I am trying to figure out how to create a single up_action and a single down_action script that will run if any monitored machine goes down. I dont understand how to pass the ip address to the script. I am monitoring like 100 machines and dont want to create a unique up action and down action for each machine.

my current script is:

0 name="workstation_down" owner="admin"
policy=ftp,reboot,read,write,policy,test,winbox,password run-count=0
source=/tool e-mail send from="mikrotik@xyzcustomer.com"
server="67.55.143.33" body="TEST BY DON - workstation is Down"
subject="TEST BY DON - workstaiton is down at xyzcustomer"
to="xyztest@rdi1.com"

I need to change this script so that I can feed the IPaddress of the up or down machine to the up_action or down_action script.

I read a ton of stuff and cant figure out how to do this.

Can anyone tell me how to pipe the IP address of the netwatch machine that called this script into the body of the email message?

Thanks in advance!

-d
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: netwatch: how to create up_action and down_action email scri

Tue Aug 28, 2007 4:32 pm

in netwatch
you can use global variable and set the value you want
and run script that will use that variable

like
:global myGlobal globalVaue
{:global myGlobal
:put $myGlobal}
 
User avatar
andreasj8
just joined
Posts: 6
Joined: Tue May 29, 2007 11:28 am

Re: netwatch: how to create up_action and down_action email scri

Wed Oct 24, 2007 6:58 pm

All about GLOBAL Variabale is clear, but it do not work.
I have same problem (task).
CAN U HELP ME ?

in netwatch actions (tabs UP & DONW) for ip 10.0.0.12 i have only one word, with out any ; {} etc ... and this work. - that word is name of my script placed into /system scripts

for UP name of "/system script " : sendAlertNetWatchUP
for DOWN name of "/system script " : sendAlertNetWatchDOWN
all scripts above like this (different only subject and body for UP and DOWN actions) :
- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -
/tool e-mail send server=10.0.0.1 to="trouble@bla-bla.net" from="mt-router@bla-blab.net" subject="$gg1 SWITCH UP" body="SOME HOST UP"
- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -- - - -

Now i want pass ip 10.0.0.12 into both of these scripts.
HOW i must do it ?

i try for UP :
{:global gg1 "10.0.0.12" }; sendAlertNetWatchUP;
and then try
{:global gg1 "10.0.0.12"; sendAlertNetWatchUP;}

result was SAME - NOTHING happens.

Do u have real help with it ?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: netwatch: how to create up_action and down_action email scri

Thu Oct 25, 2007 9:31 am

Only script code or only script name is supported. You can't mix them both.

Use:
:global gg1 "10.0.0.12";
/system script run sendAlertNetWatchUP;
 
User avatar
butche
Trainer
Trainer
Posts: 430
Joined: Fri May 28, 2004 6:14 pm
Location: Missouri, USA
Contact:

Re: netwatch: how to create up_action and down_action email scri

Sat Jan 05, 2008 3:34 am

Do u have real help with it ?
While I haven't done the whole script, you can gather the IP address using something like this:
:set hostip [/tool netwatch get [find status=up ] host] ; :environment print
That works on 2.9.x, but not sure on 3.x (I think it will work there, too).