use of org.opennms.netmgt.model.HwEntityAttributeType in project opennms by OpenNMS.
the class EntityPhysicalTableRow method getOnmsHwEntity.
/**
* Gets the hardware entity.
*
* @param vendorAttributes the vendor attributes
* @param replacementMap the replacement map
* @return the hardware entity
*/
public OnmsHwEntity getOnmsHwEntity(Map<SnmpObjId, HwEntityAttributeType> vendorAttributes, Map<String, String> replacementMap) {
SnmpValue v = null;
final OnmsHwEntity entity = new OnmsHwEntity();
entity.setEntPhysicalIndex(getEntPhysicalIndex());
entity.setEntPhysicalClass(getEntPhysicalClass());
v = getValue(entPhysicalDescr);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalDescr(v.toDisplayString().trim());
v = getValue(entPhysicalVendorType);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalVendorType(v.toDisplayString().trim());
v = getValue(entPhysicalContainedIn);
if (v != null)
entity.setEntPhysicalContainedIn(v.toInt());
v = getValue(entPhysicalParentRelPos);
if (v != null)
entity.setEntPhysicalParentRelPos(v.toInt());
v = getValue(entPhysicalName);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalName(v.toDisplayString().trim().trim());
v = getValue(entPhysicalHardwareRev);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalHardwareRev(v.toDisplayString().trim());
v = getValue(entPhysicalFirmwareRev);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalFirmwareRev(v.toDisplayString().trim());
v = getValue(entPhysicalSoftwareRev);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalSoftwareRev(v.toDisplayString().trim());
v = getValue(entPhysicalSerialNum);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalSerialNum(v.toDisplayString().trim());
v = getValue(entPhysicalMfgName);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalMfgName(v.toDisplayString().trim());
v = getValue(entPhysicalModelName);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalModelName(v.toDisplayString().trim());
v = getValue(entPhysicalAlias);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalAlias(v.toDisplayString().trim());
v = getValue(entPhysicalAssetID);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalAssetID(v.toDisplayString().trim());
v = getValue(entPhysicalIsFRU);
if (v != null)
entity.setEntPhysicalIsFRU(v.toInt() == 1 ? true : false);
v = getValue(entPhysicalUris);
if (v != null && !v.toDisplayString().trim().isEmpty())
entity.setEntPhysicalUris(v.toDisplayString());
if (vendorAttributes != null && vendorAttributes.size() > 0) {
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity);
for (Map.Entry<SnmpObjId, HwEntityAttributeType> entry : vendorAttributes.entrySet()) {
v = getValue(entry.getKey());
if (v != null && !v.toDisplayString().trim().isEmpty()) {
String typeName = entry.getValue().getName();
if (replacementMap.containsKey(typeName)) {
String property = replacementMap.get(typeName);
if (wrapper.isWritableProperty(property)) {
wrapper.setPropertyValue(property, v.toDisplayString().trim());
}
} else {
entity.addAttribute(entry.getValue(), v.toDisplayString().trim());
}
}
}
}
return entity;
}
use of org.opennms.netmgt.model.HwEntityAttributeType in project opennms by OpenNMS.
the class HardwareInventoryResource method updateTypes.
/**
* Update types.
*
* @param typesMap the types map
* @param entity the entity
*/
private void updateTypes(Map<String, HwEntityAttributeType> typesMap, OnmsHwEntity entity) {
for (OnmsHwEntityAttribute a : entity.getHwEntityAttributes()) {
final String typeName = a.getTypeName();
if (!typesMap.containsKey(typeName)) {
HwEntityAttributeType t = m_hwEntityAttribTypeDao.findTypeByName(typeName);
if (t == null) {
t = a.getType();
m_hwEntityAttribTypeDao.save(t);
}
typesMap.put(t.getName(), t);
}
a.setType(typesMap.get(typeName));
}
for (OnmsHwEntity child : entity.getChildren()) {
updateTypes(typesMap, child);
}
}
use of org.opennms.netmgt.model.HwEntityAttributeType 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.model.HwEntityAttributeType in project opennms by OpenNMS.
the class HwEntityAttributeTypeDaoIT method testEntityCycle.
/**
* Test save type.
*/
@Test
@Transactional
public void testEntityCycle() {
HwEntityAttributeType ram = new HwEntityAttributeType(".1.3.6.1.4.1.9.9.195.1.1.1.1", "ram", "integer");
m_hwEntityAttributeTypeDao.save(ram);
m_hwEntityAttributeTypeDao.flush();
HwEntityAttributeType type = m_hwEntityAttributeTypeDao.findTypeByName("ram");
assertNotNull(type);
assertEquals("ram", type.getName());
assertEquals(".1.3.6.1.4.1.9.9.195.1.1.1.1", type.getOid());
assertEquals("integer", type.getAttributeClass());
assertEquals(new Integer(1), type.getId());
m_hwEntityAttributeTypeDao.flush();
m_hwEntityAttributeTypeDao.delete(type.getId());
}
use of org.opennms.netmgt.model.HwEntityAttributeType in project opennms by OpenNMS.
the class HwEntityDaoIT method testEntityCycle.
/**
* Test find entity.
*/
@Test
@Transactional
public void testEntityCycle() {
HwEntityAttributeType ram = new HwEntityAttributeType(".1.3.6.1.4.1.9.9.195.1.1.1.1", "ram", "integer");
m_hwEntityAttributeTypeDao.save(ram);
m_hwEntityAttributeTypeDao.flush();
OnmsNode node = getNode();
Assert.assertNotNull(node);
Assert.assertNotNull(node.getId());
OnmsHwEntity root = new OnmsHwEntity();
root.setEntPhysicalIndex(1);
root.setEntPhysicalClass("chassis");
root.setEntPhysicalName("Chassis");
OnmsHwEntity m1 = new OnmsHwEntity();
m1.setEntPhysicalIndex(2);
m1.setEntPhysicalClass("module");
m1.setEntPhysicalName("M1");
m1.addAttribute(ram, "4");
OnmsHwEntity m2 = new OnmsHwEntity();
m2.setEntPhysicalIndex(3);
m2.setEntPhysicalClass("module");
m2.setEntPhysicalName("M2");
m2.addAttribute(ram, "2");
root.addChildEntity(m1);
root.addChildEntity(m2);
Assert.assertNotNull(m1.getParent());
Assert.assertNotNull(m2.getParent());
root.setNode(node);
Assert.assertNotNull(root.getNode());
Assert.assertEquals(2, root.getChildren().size());
// Test saving root entity
m_hwEntityDao.saveOrUpdate(root);
m_hwEntityDao.flush();
// Test valid findRootByNodeId
OnmsHwEntity e1 = m_hwEntityDao.findRootByNodeId(node.getId());
Assert.assertNotNull(e1);
Assert.assertNotNull(e1.getNode());
Assert.assertEquals(e1.getNode().getId(), node.getId());
Assert.assertEquals(2, e1.getChildren().size());
Assert.assertEquals("chassis", e1.getEntPhysicalClass());
OnmsHwEntity c = e1.getChildren().iterator().next();
Assert.assertEquals("4", c.getAttributeValue("ram"));
// Test invalid findRootByNodeId
Assert.assertNull(m_hwEntityDao.findRootByNodeId(10000));
// Test findEntityByIndex
OnmsHwEntity e2 = m_hwEntityDao.findEntityByIndex(node.getId(), e1.getEntPhysicalIndex());
Assert.assertTrue(e1.equals(e2));
// Test findEntityByName
OnmsHwEntity e3 = m_hwEntityDao.findEntityByName(node.getId(), e1.getEntPhysicalName());
Assert.assertTrue(e1.equals(e3));
// Test getAttributeValue
Assert.assertEquals("Chassis", m_hwEntityDao.getAttributeValue(node.getId(), 1, "entPhysicalName"));
Assert.assertEquals("4", m_hwEntityDao.getAttributeValue(node.getId(), 2, "ram"));
Assert.assertEquals("chassis", m_hwEntityDao.getAttributeValue(node.getId(), "Chassis", "entPhysicalClass"));
Assert.assertEquals("4", m_hwEntityDao.getAttributeValue(node.getId(), "~^M1", "ram"));
// Test delete
m_hwEntityDao.flush();
m_hwEntityDao.delete(e2.getId());
m_hwEntityDao.flush();
Assert.assertNull(m_hwEntityDao.get(e2.getId()));
}
Aggregations