NetXMS Support Forum

English Support => General Support => Topic started by: Dani@M3T on March 05, 2014, 10:13:06 PM

Title: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 05, 2014, 10:13:06 PM
I have the following situation:
some firewalls (call it GATEWAY1) with dynamic WAN-IP addresses. There I have to ping the default gateway of the WAN interface from the NetXMS server and the result should be shown on the node GATEWAY1.

I see two possibilities but can't find a working solution:
1.
On GATEWAY1 a DCI: Origin = Internal, Parameter = Dummy, Proxy-node = NetXMS-server. Than in transformation script SNMPGetValue (is functional) and a call of a subagnet icmp.ping. But I could't find a possibility to call a subagent from the script.
2.
put the SNMPGetValue in a script in the script library
On GATEWAY1 a DCI: Origin = NetXMS Agent, Parameter = something like 'icmp.ping(script:getip)', no proxy node

Does anybody have a hint or better a solution? I hope I described the situation accurate
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: andrey--k on March 05, 2014, 10:19:14 PM
May be you would try to use ddns systems in combination with server-side script to resolve current IP?
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 05, 2014, 10:26:09 PM
yes but its not the WAN IP address (which I could get from resolved DDNS name), it's the default gateway address of the WAN subnet. I can get the default gateway IP address from the local routing table by SNMP, thats not the problem. But than I have to 'ping' this IP from the NetXMS server.
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Victor Kirhenshtein on March 05, 2014, 10:28:32 PM
Hi!

Solution #1 seems correct. You can get value from remote agent with AgentReadParameter (http://"http://wiki.netxms.org/wiki/NXSL:AgentReadParameter") function. However, easier would be to use proxy node directly:

On GATEWAY1 a DCI: Origin = Agent, Parameter = Icmp.Ping(ip), Proxy-node = NetXMS-server

No transformation script needed in this case.

Best regards,
Victor
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 05, 2014, 10:41:29 PM
Hi Victor

But in your suggestion, I have first get 'ip' (as you called it in your post) from a SNMPGetValue on node GATEWAY1. Can I use a script in the 'parameter' field of the DCI for this?

thanks
Dani
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Victor Kirhenshtein on March 05, 2014, 11:17:36 PM
Sorry, I misunderstood the situation. Then you can use the following DCI:

Origin = SNMP, Parameter = OID you are using to get IP address

with the following transformation script:


server = FindNodeObject($node, "netxms-server-name");
return AgentReadParameter(server, "Icmp.Ping(" . $1 . ")");


Best regards,
Victor
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 06, 2014, 10:49:51 AM
Hi Victor

Many thanks for the very fast solution. It works

The following line is the solution:
return AgentReadParameter(server, "Icmp.Ping(" . $1 . ")"); [I didn't know that]

But can you explain me the syntax you used 'icmp.ping(" . $1 . ")?
From SubAgent documentation I have this syntax 'Icmp.Ping(target,*timeout*,*psize*)'

thanks a lot!

Dani
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 06, 2014, 11:33:55 AM
another 'problem' is: now the result of the DCI is the latency of the ping (=ok) but it's a string, not an integer. Maybe because the SNMP Data Type is string (it's an IP address) but the result of the transformation script should be an integer.
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 06, 2014, 11:41:59 AM
sorry last post was too early :-)
I changed the Data Type of the DCI to integer and now it's ok. I thought the Data Type must be the type of the SNMP value. But it looks like Data Type is the type of the DCI-result after the transformation script.
So only the question about the icmp.ping syntax is open.
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Victor Kirhenshtein on March 06, 2014, 11:53:54 AM
Timeout and packet size are optional arguments and can be omitted. There is word "optional" deep in parameter description :) All following forms are valid:

Icmp.Ping(10.10.10.1)
Icmp.Ping(10.10.10.1,3000)
Icmp.Ping(10.10.10.1,2000,120)
Icmp.Ping(10.10.10.1,,140)

Best regards,
Victor
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 06, 2014, 11:58:45 AM
Thanks. I saw that in the documentation. But you gave me this:
Icmp.Ping(" . $1 . ")

I don't understand " . $1 . ".
'$1' is the result of the SNMPget, thats clear, but why these points?
I had expected something like Icmp.Ping("$1")
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Victor Kirhenshtein on March 06, 2014, 02:10:09 PM
. is string concatenation operation in NXSL. NXSL does not do macro expansion within strings, so you have to do concatenation. Don't be confused by $ sign - it is valid character in identifiers and has not any special meaning. It's just a naming convention to start names of built-in variables with $. You can name your variable a$ for example.

Best regards,
Victor
Title: Re: use dynamic IP from SNMPget to PING by subagent icmp.ping
Post by: Dani@M3T on March 06, 2014, 04:20:29 PM
now the penny has dropped ;-) thanks!