NetXMS Support Forum

English Support => General Support => Topic started by: hoeth on January 28, 2021, 09:59:30 PM

Title: java API: create threshold for DCI
Post by: hoeth on January 28, 2021, 09:59:30 PM
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
Title: Re: java API: create threshold for DCI
Post by: hoeth on January 29, 2021, 01:42:31 PM
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?
Title: Re: java API: create threshold for DCI
Post by: tolimanjo on January 30, 2021, 04:04:10 AM
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);
Title: Re: java API: create threshold for DCI
Post by: hoeth on January 30, 2021, 12:00:56 PM
Great, that works! Thanks!

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