java API: create threshold for DCI

Started by hoeth, January 28, 2021, 09:59:30 PM

Previous topic - Next topic

hoeth

Hi,

I'm using the java API to create DCIs. This works fine for the basic stuff like name, description, polling interval, etc. But how can I attach a Threshold object to the DataCollectionItem?

Thanks a lot,

Hendrik

hoeth

Brief update: Looking at the netxms-client sources it seems that there is no setThreshods() method for DataCollectionItem. I think something like this needs to be added to org/netxms/client/datacollection/DataCollectionItem.java:

/**
* @param thresholds the thresholds to set
*/
public void setThresholds(ArrayList<Threshold> thresholds)
{
this.thresholds = thresholds;
}

Is that correct?

tolimanjo

Was stuck on this as well. The use of '.getThresholds().add()' solved it for me:

DataCollectionConfiguration objDcc = objNxcSession.openDataCollectionConfiguration(intTemplateId);
DataCollectionItem objDci = new DataCollectionItem(objDcc, 0);

Threshold objThreshold = new Threshold();

objThreshold.setFunction(Threshold.F_DIFF); // "Diff with previous value", for example
// define additional threshold parameters...

objDci.getThresholds().add(objThreshold);
objDcc.modifyObject(objDci);

hoeth

Great, that works! Thanks!

I still think a "setThresholds()" method would be nice, but I'm glad I can go on now.    :)