Community discussions

MikroTik App
 
exeGames
just joined
Topic Author
Posts: 1
Joined: Sun Feb 14, 2016 2:32 pm

Probe execute function

Sun Feb 14, 2016 2:56 pm

Hello,
I've explored the dude for a while and was trying to figure out how to monitor a specific TCP port in windows server.
SNMP is enabled but my local port (from host) is changed randomly and I only want to monitor the remote port (to host).
I've tried many options but none of them worked so I've decided to implement my own tool in c# and return an exit code which indicate the port status and for debug porpuse always returns 1.
However this is not works either:
I created a new probe:

type: function
agent: default
available: if (execute("c:\temp\myFlag.exe")>0, 0, -1)
error: if (execute("c:\temp\myFlag.exe")>0, "", "port is down")

am I missing something?

thanks a lot!
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Probe execute function

Tue Feb 16, 2016 6:55 pm

Your available line will always return true, -1 is not null. There is always some difficulty getting the return value passed back correctly. Put your execute on the appearance of a device and verify that the function works. If you search my posts for execute you will find some good detail. Something like this... execute("test.bat","test.txt","c:\\") double backslashes are required.
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Probe execute function

Tue Feb 16, 2016 6:59 pm

What port do you want to check? Say you want to test if port 81 is open, start a new probe, select TCP or UDP, enter the port and check connect only. This will cause the dude to only check if the port is open.
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Probe execute function

Tue Feb 16, 2016 8:50 pm

Your available line will always return true, -1 is not null.
^^^^ is not exactly correct... First the available line is only used when using "discover" to automatically add a probe to a device. The dude attempts to use the available line of the probe on the device when you click discover on the services tab of that device and the probe is configured to be allowed on that device type. These controls are in the device types.

Let me elaborate, the if statement is such that when true it returns the 2nd parameter if false returns the 3rd parameter
if (x, 1, -1) When the dude evaluates x it will return 1 when true and -1 when false BUT the dude will find -1 as a number and not null and therefore decide that this probe is "Available" to be used.

In the case of your available line "if (execute("c:\temp\myFlag.exe")>0, 0, -1)" execute is exiting with a -1 not the if since the parameters are incorrect, c:\\temp\\myFlag.exe, might work, and if it returned the port number, the 0 in the 2nd parameter would be returned. BUT Since it always fails it returns -1 the dude assumes that the probe worked and can be installed on this device. You could just put 1 on the available line.

Since you manually installed the probe it only uses the function built on the Error line. The code on the error line has the wrong parameters for execute, the return is -1 every time. Maybe this will work; if (execute("c:\\temp\\myFlag.exe")>0, "", "port is not open") or; if(execute(myFlag.exe,,c:\\temp)>0,"","Port is not open").

The bigger problem is you have 3 places you have values returned and what they should be must tracked and presented to the next step in the probe to get the value evaluated correctly. Those 3 places are the error line, the if statement and the execute statement. Ideally the execute statement just returns 1 when the port is open. then the return code is either 1, 0, or -1. The if statement needs to make sure the value is >0 so that negative number is false, then the error can be evaluated as "" = UP or "anything"=Down.

Also you could use an array index to return the element you are interested in if you want the actual number.

yuk too many words... sorry.

Who is online

Users browsing this forum: No registered users and 60 guests