Is counting TCP connections without using Agent possible?

Started by ChrisC, December 13, 2021, 03:27:47 PM

Previous topic - Next topic

ChrisC

https://www.netxms.org/forum/general-support/how-to-countgraphcheck-tcp-connection-states-table-with-netxms/msg2031/#msg2031 nicely explains how to do it using the Agent, but I was wondering if there is a way of counting OIDs that match a certain criteria without having to have an Agent installed, as some of this is available via SNMP.

For example, OID:
.1.3.6.1.2.1.6.13.1.4.xxx.xxx.xxx.xxx.ssss.yyy.yyy.yyy.yyy.dddd

xxx.xxx.xxx.xxx is the local IP address, and ssss is the local port.
yyy.yyy.yyy.yyy is the remote IP address, and dddd is the remote port.
If I could count the number of times ".1.3.6.1.2.1.6.13.1.4.xxx.xxx.xxx.xxx.ssss.*" appears in the list, I could count how many connections there are to a specific service.

Is this possible somehow?

Filipp Sudanov

Yes, you can create a script DCI. Scripts are written using NXSL language, there's support for snmpget and snmpwalk. Here's a simple example, pls inform if you need more information on how to write a script
https://www.netxms.org/documentation/nxsl-latest/#_read_snmp_value_from_node

ChrisC

Thank you.
This Manual page helped immensely: https://wiki.netxms.org/wiki/NXSL:SNMPWalk

The following works perfectly:

// Call this function with the following parameters:
// $1 = port number (eg 5900 for VNC)
// $2 = IP address (xxx.xxx.xxx.xxx)


transport = CreateSNMPTransport($node);
if (transport == null)
           return -1;
oid = ".1.3.6.1.2.1.6.13.1.4." . $2 . "." . $1 ; // IP connections
vars = SNMPWalk(transport, oid);
if (vars == null)
           return -2; // SNMPWalk failed
count = 0;
foreach (v: vars) {
  //trace(1, "SNMP WALK ".v->name."=".v->value);
  count = count +1;
}
return count;