use of org.netxms.client.datacollection.DataCollectionConfiguration in project netxms by netxms.
the class CreateInterfraceDci method createInterfaceDci.
/**
* @param iface
* @param dciType
* @param dciInfo
* @throws Exception
*/
private static void createInterfaceDci(NXCSession session, Interface iface, int dciType, InterfaceDciInfo dciInfo, int pollingInterval, int retentionTime, boolean updateDescription, Map<Long, Boolean> lockRequired) throws Exception {
AbstractNode node = iface.getParentNode();
if (node == null)
throw new NXCException(RCC.INTERNAL_ERROR);
DataCollectionConfiguration dcc;
if (lockRequired.get(node.getObjectId())) {
dcc = session.openDataCollectionConfiguration(node.getObjectId());
} else {
dcc = new DataCollectionConfiguration(session, node.getObjectId());
}
final DataCollectionItem dci = (DataCollectionItem) dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
dci.setPollingInterval(pollingInterval);
dci.setRetentionTime(retentionTime);
if (node.hasAgent()) {
dci.setOrigin(DataCollectionItem.AGENT);
if (node.isAgentIfXCountersSupported())
dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
else
dci.setDataType(DataType.COUNTER32);
} else {
dci.setOrigin(DataCollectionItem.SNMP);
if (node.isIfXTableSupported())
dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
else
dci.setDataType(DataType.COUNTER32);
}
dci.setStatus(DataCollectionItem.ACTIVE);
// $NON-NLS-1$
dci.setDescription(updateDescription ? dciInfo.description.replaceAll("@@ifName@@", iface.getObjectName()) : dciInfo.description);
dci.setDeltaCalculation(dciInfo.delta ? DataCollectionItem.DELTA_AVERAGE_PER_SECOND : DataCollectionItem.DELTA_NONE);
if (dci.getOrigin() == DataCollectionItem.AGENT) {
switch(dciType) {
case IFDCI_IN_BYTES:
case IFDCI_IN_BITS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesIn64(" : "Net.Interface.BytesIn(") + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_BYTES:
case IFDCI_OUT_BITS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesOut64(" : "Net.Interface.BytesOut(") + iface.getIfIndex() + ")");
break;
case IFDCI_IN_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsIn64(" : "Net.Interface.PacketsIn(") + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsOut64(" : "Net.Interface.PacketsOut(") + iface.getIfIndex() + ")");
break;
case IFDCI_IN_ERRORS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName("Net.Interface.InErrors(" + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_ERRORS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName("Net.Interface.OutErrors(" + iface.getIfIndex() + ")");
break;
}
} else {
switch(dciType) {
case IFDCI_IN_BYTES:
case IFDCI_IN_BITS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.6" : ".1.3.6.1.2.1.2.2.1.10") + getInterfaceInstance(iface));
break;
case IFDCI_OUT_BYTES:
case IFDCI_OUT_BITS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.10" : ".1.3.6.1.2.1.2.2.1.16") + getInterfaceInstance(iface));
break;
case IFDCI_IN_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.7" : ".1.3.6.1.2.1.2.2.1.11") + getInterfaceInstance(iface));
break;
case IFDCI_OUT_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.11" : ".1.3.6.1.2.1.2.2.1.17") + getInterfaceInstance(iface));
break;
case IFDCI_IN_ERRORS:
// $NON-NLS-1$
dci.setName(".1.3.6.1.2.1.2.2.1.14" + getInterfaceInstance(iface));
break;
case IFDCI_OUT_ERRORS:
// $NON-NLS-1$
dci.setName(".1.3.6.1.2.1.2.2.1.20" + getInterfaceInstance(iface));
break;
}
}
if ((dciType == IFDCI_IN_BITS) || (dciType == IFDCI_OUT_BITS)) {
// $NON-NLS-1$
dci.setTransformationScript("return $1 * 8;");
}
dcc.modifyObject(dci);
if (lockRequired.get(node.getObjectId())) {
dcc.close();
}
}
use of org.netxms.client.datacollection.DataCollectionConfiguration in project netxms by netxms.
the class NXCSession method openDataCollectionConfiguration.
/**
* Open data collection configuration for given node. You must call
* DataCollectionConfiguration.close() to close data collection configuration
* when it is no longer needed.
*
* @param nodeId Node object identifier
* @return Data collection configuration object
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public DataCollectionConfiguration openDataCollectionConfiguration(long nodeId) throws IOException, NXCException {
final DataCollectionConfiguration cfg = new DataCollectionConfiguration(this, nodeId);
cfg.open();
return cfg;
}
use of org.netxms.client.datacollection.DataCollectionConfiguration in project netxms by netxms.
the class DataCollectionTest method testGetThresholds.
public void testGetThresholds() throws Exception {
final NXCSession session = connect();
DataCollectionConfiguration dc = session.openDataCollectionConfiguration(TestConstants.NODE_ID);
final long dciId = dc.createItem(null);
DataCollectionItem dci = (DataCollectionItem) dc.findItem(dciId, DataCollectionItem.class);
dci.setName("TEST");
dci.getThresholds().add(new Threshold());
dc.modifyObject(dciId);
Threshold[] thresholds = session.getThresholds(TestConstants.NODE_ID, dciId);
assertNotNull(thresholds);
assertEquals(1, thresholds.length);
dc.deleteObject(dciId);
dc.close();
session.disconnect();
}
use of org.netxms.client.datacollection.DataCollectionConfiguration in project netxms by netxms.
the class CreateSnmpDci method createDci.
/**
* @param session
* @param value
* @param description
* @param pollingInterval
* @param retentionTime
* @param deltaCalculation
* @param lockRequired
* @throws Exception
*/
private static void createDci(NXCSession session, SnmpValue value, String description, int pollingInterval, int retentionTime, int deltaCalculation, Map<Long, Boolean> lockRequired) throws Exception {
AbstractNode node = (AbstractNode) session.findObjectById(value.getNodeId(), AbstractNode.class);
if (node == null)
throw new NXCException(RCC.INTERNAL_ERROR);
DataCollectionConfiguration dcc;
if (lockRequired.get(node.getObjectId())) {
dcc = session.openDataCollectionConfiguration(node.getObjectId());
} else {
dcc = new DataCollectionConfiguration(session, node.getObjectId());
}
final DataCollectionItem dci = (DataCollectionItem) dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
dci.setPollingInterval(pollingInterval);
dci.setRetentionTime(retentionTime);
dci.setOrigin(DataCollectionItem.SNMP);
dci.setDataType(dciTypeFromAsnType(value.getType()));
dci.setStatus(DataCollectionItem.ACTIVE);
dci.setDescription(description);
dci.setDeltaCalculation(deltaCalculation);
dci.setName(value.getName());
dcc.modifyObject(dci);
if (lockRequired.get(node.getObjectId())) {
dcc.close();
}
}
Aggregations