I would like to add a delay of 5 minutes to my netwatch script. Does adding a delay to a script effect network performance in any way? Does it slow down the network, or in any way effect the router? If so, I will not use it. Thanks.
Someone must know if delays cause issues with the network?
It shouldn’t, but if netwatch isn’t threaded then in theory you could cause ALL of the netwatches to hang on that delay. I’d have to know how they wrote the underlying netwatch mechanism to be able to answer that.
What if it’s not netwatch, just say another script that runs.
It really just depends how the processing works. Suppose there is a single thread (process) that runs ALL of the scripts… then all of them will be waiting for that one to finish before they can run. Suppose on the other hand that there are multiple threads (one for each script) then it would be fine. I assume that they are threaded, but I’d have to play with it and build some tests to figure that out. You could also ask MikroTik if those are threaded or not… realistically each could perform differently (e.g. scheduled vs script vs netwatch). It is entirely dependent on how they wrote the code that runs the script.
It shouldn’t change network performance since I know that is a different thread, but what it will do to other scheduled scripts, netwatches, etc is what I don’t know.
Why do you need the script to wait that long anyways? Generally you should be able to write them as “stateless”…
I am trying to write a script that will monitor all devices. If they go down, I want it to ping it several times for 30 minutes. If after 30 minutes the device is still down, then it sends an email.
There are other things too. I am working on it today.
Why not just make variables and let the script end?
Sent from my SCH-I545 using Tapatalk
Here is what I am thinking:
ping address
if ping good, and x=false, send email up
set x=true
if ping bad, delay 30 min
ping again
if ping bad, create variable x=false, send email down, go back to start
Is this the best way to do it?
Instead of the delay, how about just pinging every 5 minutes for 30 minutes.
So the script would:
ping address
if ping good, and variable x=false, send email device up
set x=true
if ping bad, ping every 5 minutes for 30 minutes
if no good pings, create variable x=false, send email device down, go back to start
Is this the best way to do it?
I’d just use counters and a threshold. I have an example somewhere…
If you can find it I’d love to take a look.
I just realized that I only want to send 1 email that the device is down, not 1 every 30 minutes. How can I have the script send only 1 email when the device is down. Right now it looks like it will send it every time the device pings out after 5 attempts.
ping address
if ping good, and variable “x”=down, send email device up
set “x”=up
if ping bad, set counter to increment by 1 each time script is run
if script runs 5 times and ping still bad,
send email device down
set variable “x”=down
set counter to zero
maybe something like this:
if ping good, and variable “x”=down,
send email device up
set “x”=up
set “z”=true
if ping bad,
set a counter to increment by 1 each time script is run
if script runs 5 times and ping still bad,
(if variable “z”=true send email device down)
set variable “z”=false
set variable “x”=down
set counter to zero
Something like this…
:global pingFailuresWAN
:if ([:typeof $pingFailuresWAN] = “nothing”) do={:set pingFailuresWAN 0}
:set pingResult [ping $pingTarget count=1 interface=$WANInterface]
:if ($pingResult = 0) do={
:if ($pingFailuresWAN < ($failureThreshold+2)) do={
:set pingFailuresWAN ($pingFailuresWAN + 1)
:if ($pingFailuresWAN = $failureThreshold) do={
:set WState1 0
}
}
}
:if ($pingResult = 1) do={
:if ($pingFailuresWAN > 0) do={
:set pingFailuresWAN ($pingFailuresWAN - 1)
:if ($pingFailuresWAN = ($failureThreshold -1)) do={
:set WState1 1
}
}
}You should be able to modify that to do what you want.
Thanks E. I just got this. The forum was down last night. I could not get on. Do you know if it’s just me, or was it a problem?
I will try this out tonight when I get home.
I’m going to have to figure out line by line what it does.
Thanks.
No clue re: the forum.
Eric,
I just went over the script. I get the concept, but I’m confused about it. I wrote some notes below, but they don’t really make sense. If you have time can you comment on what the lines mean in the script? I would appreciate it. If I know what each line means then I can grasp how to put together what I need. Thanks.
:global pingFailuresWAN Why do you need to do this?
:if ([:typeof $pingFailuresWAN] = “nothing”) do={:set pingFailuresWAN 0} What is typeof? What is nothing?
:set pingResult [ping $pingTarget count=1 interface=$WANInterface] Is the interface the ip address? How come you didn’t define pingTarget?
:if ($pingResult = 0) do={ I’m not sure what you are doing here
:if ($pingFailuresWAN < ($failureThreshold+2)) do={
:set pingFailuresWAN ($pingFailuresWAN + 1)
:if ($pingFailuresWAN = $failureThreshold) do={
:set WState1 0 Is this where I would put the script for ip down?
}
}
}
:if ($pingResult = 1) do={ It seems like you are doing 2 things here, but I’m not sure what
:if ($pingFailuresWAN > 0) do={
:set pingFailuresWAN ($pingFailuresWAN - 1)
:if ($pingFailuresWAN = ($failureThreshold -1)) do={
:set WState1 1
}
}
}
I’m still thoroughly confused. I have to learn this. I’m just not that familiar with the code.
Sorry. Got really busy. I may have some time later.
:local WANInterface ether1
:local pingTarget 8.8.8.8
:local failureThreshold 3
:local pingResult
:global pingFailuresWAN
- I think these all define variables.
- Rather than use a variable for ping target and failure threshold, can I just use the numbers?
- I am going to have 20 or 30 of these scripts for each device I monitor on the lan. Does that affect how I define variables? Do I have to use different names of the variables in each script to avoid crossover from script to script?
:if ([:typeof $pingFailuresWAN] = “nothing”) do={:set pingFailuresWAN 0}[/color}
- I think this just sets the counter back to zero
- What does the typeof do, and what is “nothing”?
:set pingResult [ping $pingTarget count=1 interface=$WANInterface] - I think this pings the device.
- Do I really need to say what interface?
- How do I add the interval of 5 minutes in between pings?
:if ($pingResult = 0) do={
:if ($pingFailuresWAN < ($failureThreshold+2)) do={
:set pingFailuresWAN ($pingFailuresWAN + 1)
:if ($pingFailuresWAN = $failureThreshold) do={
:set WState1 0
}
}
}
- I think this says if the ping fails, AND the counter is less than the threshold, add 1 to the counter. If the counter equals the threshold, set the variable to zero and run another script.
:if ($pingResult = 1) do={
:if ($pingFailuresWAN > 0) do={
:set pingFailuresWAN ($pingFailuresWAN - 1)
:if ($pingFailuresWAN = ($failureThreshold -1)) do={
:set WState1 1
}
}
}
- I think this deals with the ping being successful. What I would like to do is if the ping is successful at all, AND the variable WState1 is zero, set the WState 1 to one and run another script.
- That being said, can you explain what is happening here.