NetXMS Support Forum

English Support => General Support => Topic started by: Egert143 on November 02, 2022, 01:24:27 PM

Title: Two snmp requests in one dci
Post by: Egert143 on November 02, 2022, 01:24:27 PM
Hello

What is the best approach to make dci that queries 2 separate snmp oids, does some math with them and then returns the output. is it possible to do in one dci, or is multiple required?

Example:
.1.3.6.1.2.1.25.2.3.1.6.131072 - returns 11320 (/1024 = 11mb)
.1.3.6.1.2.1.25.2.3.1.5.131072 - returns 16384 (/1024 = 16mb)
Output = 16-11 = 4mb

Its Mikrotik disk usage.
Title: Re: Two snmp requests in one dci
Post by: Filipp Sudanov on November 02, 2022, 02:18:09 PM
It's possible to make script DCI that would take values from other DCIs and do the calculation. But if you don't need to keep the intermediary values, they you can do everything just in one DCI.

Create s script in script library and Script DCI that uses that script. Check this example for script contents: https://www.netxms.org/documentation/nxsl-latest/#func-snmpgetvalue

Title: Re: Two snmp requests in one dci
Post by: Egert143 on November 02, 2022, 02:28:30 PM
I hacked together something like this: 

transport = CreateSNMPTransport($node);
if (transport == null) { return null; }

diskSize = SNMPGetValue(transport,".1.3.6.1.2.1.25.2.3.1.5.131072");
diskUsed = SNMPGetValue(transport,".1.3.6.1.2.1.25.2.3.1.6.131072");

if(diskSize == null || diskUsed == null) { return null; }

free = diskSize - diskUsed;
free = free * 1024;


return free;

" free = free * 1024; " is because otherwise unit b(IEC) was showing incorrectly.

is there anything that could be improved on this script?
Title: Re: Two snmp requests in one dci
Post by: Filipp Sudanov on November 03, 2022, 02:17:38 PM
Looks good. There's a small chance that SNMPGetValue may return null (e.g. communication gets broken exactly when these requests are made), so you may want to check diskSize and diskUsed for null.


Title: Re: Two snmp requests in one dci
Post by: Egert143 on November 04, 2022, 08:40:21 AM
is that not good?
if(diskSize == null || diskUsed == null) { return null; }
Title: Re: Two snmp requests in one dci
Post by: Filipp Sudanov on November 04, 2022, 06:12:50 PM
Ups, i missed that line :)

Yes, it's correct