use of org.opennms.netmgt.model.OnmsHwEntity in project opennms by OpenNMS.
the class EntityPhysicalTableTracker method rowCompleted.
/* (non-Javadoc)
* @see org.opennms.netmgt.snmp.TableTracker#rowCompleted(org.opennms.netmgt.snmp.SnmpRowResult)
*/
@Override
public void rowCompleted(SnmpRowResult row) {
OnmsHwEntity entity = ((EntityPhysicalTableRow) row).getOnmsHwEntity(vendorAttributes, replacementMap);
LOG.debug("rowCompleted: found entity {}, index: {}, parent: {}", entity.getEntPhysicalName(), entity.getEntPhysicalIndex(), entity.getEntPhysicalContainedIn());
if (entity.getEntPhysicalContainedIn() != null && entity.getEntPhysicalContainedIn() > 0) {
OnmsHwEntity parent = getParent(entity.getEntPhysicalContainedIn().intValue());
if (parent != null) {
LOG.debug("rowCompleted: adding child index {} to parent index {}", entity.getEntPhysicalIndex(), parent.getEntPhysicalIndex());
parent.addChildEntity(entity);
}
}
entities.add(entity);
}
use of org.opennms.netmgt.model.OnmsHwEntity in project opennms by OpenNMS.
the class EventUtilDaoImpl method getHardwareFieldValue.
@Override
public String getHardwareFieldValue(String parm, long nodeId) {
final Matcher matcher = HW_PARM_PATTERN.matcher(parm);
if (!matcher.matches()) {
LOG.warn("Unsupported hardware field parameter '{}'.", parm);
return null;
}
final String hwFieldSelector = matcher.group(1);
final String hwField = matcher.group(2).toLowerCase();
// Retrieve the entity with a like query
if (hwFieldSelector.startsWith("~")) {
final String likeQuery = hwFieldSelector.substring(1);
LOG.debug("Retrieving hardware field value {} on {} with like query {}", parm, nodeId, likeQuery);
Criteria criteria = new Criteria(OnmsHwEntity.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", (int) nodeId)).addRestriction(new LikeRestriction("entPhysicalName", likeQuery)).setOrders(Arrays.asList(new Order[] { Order.desc("id") }));
List<OnmsHwEntity> hwEntities = hwEntityDao.findMatching(criteria);
System.err.println(hwEntities);
if (hwEntities.size() < 1) {
return null;
}
return getStringPropertyByName(hwField, hwEntities.get(0), hwEntityDescriptorsByName);
}
// Retrieve the entity by index if the select is an integer
try {
int index = Integer.parseInt(hwFieldSelector);
OnmsHwEntity hwEntity = hwEntityDao.findEntityByIndex((int) nodeId, index);
if (hwEntity == null) {
// No entry with this index
return null;
}
return getStringPropertyByName(hwField, hwEntity, hwEntityDescriptorsByName);
} catch (NumberFormatException e) {
// pass
}
// Retrieve the entity by name
OnmsHwEntity hwEntity = hwEntityDao.findEntityByName((int) nodeId, hwFieldSelector);
if (hwEntity == null) {
// No entry with this name
return null;
}
return getStringPropertyByName(hwField, hwEntity, hwEntityDescriptorsByName);
}
use of org.opennms.netmgt.model.OnmsHwEntity in project opennms by OpenNMS.
the class EventUtilHibernateIT method getHardwareFieldValue.
@Test
public void getHardwareFieldValue() {
OnmsNode node1 = m_populator.getNode1();
OnmsHwEntity hwEntity = new OnmsHwEntity();
hwEntity.setNode(node1);
hwEntity.setEntPhysicalIndex(0);
hwEntity.setEntPhysicalName("Chassis");
hwEntity.setEntPhysicalDescr("some-physical-d3scr");
m_hwEntityDao.save(hwEntity);
// Access the field by index
String hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[0:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
// Access the field by name
hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[Chassis:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
// Access the field by regex
hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[~%Cha%:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
}
use of org.opennms.netmgt.model.OnmsHwEntity 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.OnmsHwEntity 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);
}
}
Aggregations