Two snmp requests in one dci

Started by Egert143, November 02, 2022, 01:24:27 PM

Previous topic - Next topic

Egert143

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.

Filipp Sudanov

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


Egert143

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?

Filipp Sudanov

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.



Egert143

is that not good?
if(diskSize == null || diskUsed == null) { return null; }

Filipp Sudanov

Ups, i missed that line :)

Yes, it's correct