use of org.opennms.netmgt.config.hardware.HwExtension in project opennms by OpenNMS.
the class DefaultSnmpHwInventoryAdapterConfigDao method translateConfig.
/* (non-Javadoc)
* @see org.opennms.core.xml.AbstractJaxbConfigDao#translateConfig(java.lang.Object)
*/
@Override
protected HwInventoryAdapterConfiguration translateConfig(HwInventoryAdapterConfiguration config) {
final Set<String> oids = new HashSet<String>();
final Set<String> names = new HashSet<String>();
for (HwExtension ext : config.getExtensions()) {
for (Iterator<MibObj> it = ext.getMibObjects().iterator(); it.hasNext(); ) {
MibObj obj = it.next();
final String oid = obj.getOid().toString();
if (oids.contains(oid)) {
LOG.warn("Duplicate OID detected, ignoring {} (please fix the configuration file)", obj);
it.remove();
continue;
} else {
oids.add(oid);
}
if (names.contains(obj.getAlias())) {
LOG.warn("Duplicate Alias detected, ignoring {} (please fix the configuration file)", obj);
it.remove();
continue;
} else {
names.add(obj.getAlias());
}
}
}
return config;
}
use of org.opennms.netmgt.config.hardware.HwExtension in project opennms by OpenNMS.
the class SnmpHardwareInventoryProvisioningAdapterIT method testDiscoverSnmpEntities.
/**
* Test discover SNMP entities.
*
* @throws Exception the exception
*/
@Test
@Transactional
public void testDiscoverSnmpEntities() throws Exception {
HwInventoryAdapterConfiguration config = m_adapter.getHwAdapterConfigDao().getConfiguration();
Assert.assertEquals(3, config.getExtensions().size());
Assert.assertEquals(5, config.getExtensions().get(0).getMibObjects().size());
Assert.assertEquals(12, config.getExtensions().get(1).getMibObjects().size());
Assert.assertEquals(10, config.getExtensions().get(2).getMibObjects().size());
HwExtension ext = config.getExtensions().get(0);
Assert.assertEquals("CISCO-ENTITY-EXT-MIB", ext.getName());
Assert.assertEquals(5, ext.getMibObjects().size());
ext = config.getExtensions().get(1);
Assert.assertEquals("CISCO-ENTITY-ASSET-MIB", ext.getName());
Assert.assertEquals(12, ext.getMibObjects().size());
Assert.assertEquals(27, m_adapter.getVendorAttributeMap().size());
for (TestOperation op : m_operations) {
m_adapter.processPendingOperationForNode(op.operation);
OnmsHwEntity root = m_entityDao.findRootByNodeId(op.nodeId);
Assert.assertNotNull(root);
Assert.assertTrue(root.isRoot());
FileWriter w = new FileWriter("target/" + op.nodeId + ".xml");
JaxbUtils.marshal(root, w);
w.close();
m_nodeDao.flush();
m_entityDao.flush();
}
Assert.assertEquals(112, m_entityDao.countAll());
}
use of org.opennms.netmgt.config.hardware.HwExtension in project opennms by OpenNMS.
the class DefaultSnmpHwInventoryAdapterConfigDaoTest method testInvalidOid.
/**
* Test invalid replace property.
*
* @throws Exception the exception
*/
@Test
public void testInvalidOid() throws Exception {
initDao("src/test/resources/test-config-01.xml");
emulateReload("src/test/resources/test-config-invalid-02.xml");
HwInventoryAdapterConfiguration cfg = dao.getConfiguration();
HwExtension ext = cfg.getExtensions().get(0);
Assert.assertEquals("CISCO-ENTITY-EXT-MIB", ext.getName());
Assert.assertNotNull(cfg);
}
use of org.opennms.netmgt.config.hardware.HwExtension in project opennms by OpenNMS.
the class SnmpHardwareInventoryProvisioningAdapter method initializeVendorAttributes.
/**
* Initialize vendor attributes.
*/
private void initializeVendorAttributes() {
m_vendorAttributes.clear();
for (HwEntityAttributeType type : m_hwEntityAttributeTypeDao.findAll()) {
LOG.debug("Loading attribute type {}", type);
m_vendorAttributes.put(type.getSnmpObjId(), type);
}
for (HwExtension ext : m_hwInventoryAdapterConfigDao.getConfiguration().getExtensions()) {
for (MibObj obj : ext.getMibObjects()) {
HwEntityAttributeType type = m_vendorAttributes.get(obj.getOid());
if (type == null) {
type = new HwEntityAttributeType(obj.getOid().toString(), obj.getAlias(), obj.getType());
LOG.info("Creating attribute type {}", type);
m_hwEntityAttributeTypeDao.save(type);
m_vendorAttributes.put(type.getSnmpObjId(), type);
}
}
}
}
use of org.opennms.netmgt.config.hardware.HwExtension in project opennms by OpenNMS.
the class DefaultSnmpHwInventoryAdapterConfigDaoTest method testDuplicateAlias.
/**
* Test duplicate Alias.
*
* @throws Exception the exception
*/
@Test
public void testDuplicateAlias() throws Exception {
initDao("src/test/resources/test-config-02.xml");
HwInventoryAdapterConfiguration cfg = dao.getConfiguration();
HwExtension ext = cfg.getExtensions().get(0);
Assert.assertEquals("CISCO-ENTITY-EXT-MIB", ext.getName());
Assert.assertEquals(5, ext.getMibObjects().size());
Assert.assertNull(ext.getMibObjectByOid(".1.3.6.1.4.1.9.9.195.1.1.1.2"));
}
Aggregations