use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class EventUtilDaoImpl method getAssetFieldValue.
@Override
public String getAssetFieldValue(String parm, long nodeId) {
final Matcher matcher = ASSET_PARM_PATTERN.matcher(parm);
if (!matcher.matches()) {
LOG.warn("Unsupported asset field parameter '{}'.", parm);
return null;
}
final String assetField = matcher.group(1).toLowerCase();
OnmsAssetRecord assetRecord = assetRecordDao.findByNodeId((int) nodeId);
if (assetRecord == null) {
return null;
}
return getStringPropertyByName(assetField, assetRecord, assetDescriptorsByName);
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class OpenlayersWidgetCompontentTest method testGeolocation.
@Test
@Ignore
public void testGeolocation() throws Exception {
final OnmsNode node = new OnmsNode();
final OnmsAssetRecord asset = new OnmsAssetRecord();
final OnmsGeolocation geo = new OnmsGeolocation();
node.setId(1);
node.setAssetRecord(asset);
asset.setGeolocation(geo);
geo.setAddress1("220 Chatham Business Dr.");
geo.setCity("Pittsboro");
geo.setState("NC");
geo.setZip("27312");
assertEquals("220 Chatham Business Dr., Pittsboro, NC 27312", geo.asAddressString());
EasyMock.expect(m_geocoder.getCoordinates(geo.asAddressString())).andReturn(new Coordinates(-1.0f, 1.0f)).times(1);
final PaintTarget target = EasyMock.createMock(PaintTarget.class);
m_assetDao.saveOrUpdate(EasyMock.isA(OnmsAssetRecord.class));
target.startTag(EasyMock.eq("1"));
target.addAttribute(EasyMock.eq("longitude"), EasyMock.eq("-1.0"));
target.addAttribute(EasyMock.eq("latitude"), EasyMock.eq("1.0"));
target.endTag(EasyMock.eq("1"));
EasyMock.replay(m_nodeDao, m_assetDao, m_geocoder, target);
// m_component.paintNode(target, node);
EasyMock.verify(m_nodeDao, m_assetDao, m_geocoder, target);
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class AssetRecordDaoHibernate method getDistinctProperties.
@Override
public List<OnmsAssetRecord> getDistinctProperties() {
DetachedCriteria criteria = DetachedCriteria.forClass(OnmsAssetRecord.class);
ProjectionList projList = Projections.projectionList();
// projList.add(Projections.alias(Projections.property("geolocation"), "geolocation"));
projList.add(Projections.alias(Projections.property("additionalhardware"), "additionalhardware"));
projList.add(Projections.alias(Projections.property("geolocation.address1"), "address1"));
projList.add(Projections.alias(Projections.property("geolocation.address2"), "address2"));
projList.add(Projections.alias(Projections.property("admin"), "admin"));
projList.add(Projections.alias(Projections.property("assetNumber"), "assetNumber"));
projList.add(Projections.alias(Projections.property("autoenable"), "autoenable"));
projList.add(Projections.alias(Projections.property("building"), "building"));
projList.add(Projections.alias(Projections.property("category"), "category"));
projList.add(Projections.alias(Projections.property("circuitId"), "circuitId"));
projList.add(Projections.alias(Projections.property("geolocation.city"), "city"));
projList.add(Projections.alias(Projections.property("comment"), "comment"));
projList.add(Projections.alias(Projections.property("connection"), "connection"));
projList.add(Projections.alias(Projections.property("geolocation.longitude"), "longitude"));
projList.add(Projections.alias(Projections.property("geolocation.latitude"), "latitude"));
projList.add(Projections.alias(Projections.property("cpu"), "cpu"));
projList.add(Projections.alias(Projections.property("department"), "department"));
projList.add(Projections.alias(Projections.property("description"), "description"));
projList.add(Projections.alias(Projections.property("displayCategory"), "displayCategory"));
projList.add(Projections.alias(Projections.property("division"), "division"));
projList.add(Projections.alias(Projections.property("enable"), "enable"));
projList.add(Projections.alias(Projections.property("floor"), "floor"));
projList.add(Projections.alias(Projections.property("hdd1"), "hdd1"));
projList.add(Projections.alias(Projections.property("hdd2"), "hdd2"));
projList.add(Projections.alias(Projections.property("hdd3"), "hdd3"));
projList.add(Projections.alias(Projections.property("hdd4"), "hdd4"));
projList.add(Projections.alias(Projections.property("hdd5"), "hdd5"));
projList.add(Projections.alias(Projections.property("hdd6"), "hdd6"));
projList.add(Projections.alias(Projections.property("inputpower"), "inputpower"));
projList.add(Projections.alias(Projections.property("lease"), "lease"));
projList.add(Projections.alias(Projections.property("maintcontract"), "maintcontract"));
projList.add(Projections.alias(Projections.property("manufacturer"), "manufacturer"));
projList.add(Projections.alias(Projections.property("modelNumber"), "modelNumber"));
projList.add(Projections.alias(Projections.property("notifyCategory"), "notifyCategory"));
projList.add(Projections.alias(Projections.property("numpowersupplies"), "numpowersupplies"));
projList.add(Projections.alias(Projections.property("operatingSystem"), "operatingSystem"));
projList.add(Projections.alias(Projections.property("pollerCategory"), "pollerCategory"));
projList.add(Projections.alias(Projections.property("port"), "port"));
projList.add(Projections.alias(Projections.property("rack"), "rack"));
projList.add(Projections.alias(Projections.property("ram"), "ram"));
projList.add(Projections.alias(Projections.property("region"), "region"));
projList.add(Projections.alias(Projections.property("room"), "room"));
projList.add(Projections.alias(Projections.property("serialNumber"), "serialNumber"));
projList.add(Projections.alias(Projections.property("slot"), "slot"));
projList.add(Projections.alias(Projections.property("snmpcommunity"), "snmpcommunity"));
projList.add(Projections.alias(Projections.property("geolocation.state"), "state"));
projList.add(Projections.alias(Projections.property("storagectrl"), "storagectrl"));
projList.add(Projections.alias(Projections.property("supportPhone"), "supportPhone"));
projList.add(Projections.alias(Projections.property("thresholdCategory"), "thresholdCategory"));
projList.add(Projections.alias(Projections.property("username"), "username"));
projList.add(Projections.alias(Projections.property("vendor"), "vendor"));
projList.add(Projections.alias(Projections.property("vendorAssetNumber"), "vendorAssetNumber"));
projList.add(Projections.alias(Projections.property("vendorFax"), "vendorFax"));
projList.add(Projections.alias(Projections.property("vendorPhone"), "vendorPhone"));
projList.add(Projections.alias(Projections.property("geolocation.zip"), "zip"));
projList.add(Projections.alias(Projections.property("vmwareManagedObjectId"), "vmwareManagedObjectId"));
projList.add(Projections.alias(Projections.property("vmwareManagedEntityType"), "vmwareManagedEntityType"));
projList.add(Projections.alias(Projections.property("vmwareManagementServer"), "vmwareManagementServer"));
projList.add(Projections.alias(Projections.property("vmwareTopologyInfo"), "vmwareTopologyInfo"));
projList.add(Projections.alias(Projections.property("vmwareState"), "vmwareState"));
criteria.setProjection(Projections.distinct(projList));
criteria.setResultTransformer(Transformers.aliasToBean(OnmsAssetRecord.class));
@SuppressWarnings("unchecked") List<OnmsAssetRecord> result = (List<OnmsAssetRecord>) getHibernateTemplate().findByCriteria(criteria);
return result;
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class BSFNotificationStrategy method declareBeans.
private static void declareBeans(BSFNotificationStrategy obj) throws BSFException {
// Retrieve the parameters before accessing them
obj.retrieveParams();
Integer nodeId;
try {
nodeId = Integer.valueOf(obj.m_notifParams.get(NotificationManager.PARAM_NODE));
} catch (NumberFormatException nfe) {
nodeId = null;
}
OnmsNode node = null;
OnmsAssetRecord assets = null;
final List<String> categories = new ArrayList<String>();
String nodeLabel = null;
String foreignSource = null;
String foreignId = null;
if (nodeId != null) {
final BeanFactoryReference bf = BeanUtils.getBeanFactory("notifdContext");
final NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
// Redeclare the node id as final
final int theNodeId = nodeId;
node = transTemplate.execute(new TransactionCallback<OnmsNode>() {
@Override
public OnmsNode doInTransaction(final TransactionStatus status) {
final OnmsNode node = nodeDao.get(theNodeId);
// Retrieve the categories in the context of the transaction
if (node != null) {
for (OnmsCategory cat : node.getCategories()) {
categories.add(cat.getName());
}
}
return node;
}
});
if (node == null) {
LOG.error("Could not find a node with id: {}", theNodeId);
} else {
nodeLabel = node.getLabel();
assets = node.getAssetRecord();
foreignSource = node.getForeignSource();
foreignId = node.getForeignId();
}
} catch (final RuntimeException e) {
LOG.error("Error while retrieving node with id {}", nodeId, e);
}
}
s_bsfManager.declareBean("bsf_notif_strategy", obj, BSFNotificationStrategy.class);
s_bsfManager.declareBean("logger", LOG, Logger.class);
s_bsfManager.declareBean("notif_params", obj.m_notifParams, Map.class);
s_bsfManager.declareBean("node_label", nodeLabel, String.class);
s_bsfManager.declareBean("foreign_source", foreignSource, String.class);
s_bsfManager.declareBean("foreign_id", foreignId, String.class);
s_bsfManager.declareBean("node_assets", assets, OnmsAssetRecord.class);
s_bsfManager.declareBean("node_categories", categories, List.class);
s_bsfManager.declareBean("node", node, OnmsNode.class);
for (Argument arg : obj.m_arguments) {
if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NODE.equals(arg.getSwitch()))
s_bsfManager.declareBean("node_id", arg.getValue(), String.class);
if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch()))
s_bsfManager.declareBean("ip_addr", arg.getValue(), String.class);
if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch()))
s_bsfManager.declareBean("svc_name", arg.getValue(), String.class);
if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch()))
s_bsfManager.declareBean("subject", arg.getValue(), String.class);
if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("email", arg.getValue(), String.class);
if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("pager_email", arg.getValue(), String.class);
if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch()))
s_bsfManager.declareBean("xmpp_address", arg.getValue(), String.class);
if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("work_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("home_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("mobile_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("phone_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch()))
s_bsfManager.declareBean("microblog_username", arg.getValue(), String.class);
}
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class AssetRecordDaoIT method testAddUserName.
@Test
@Transactional
public void testAddUserName() {
OnmsNode onmsNode = new OnmsNode(m_locationDao.getDefaultLocation(), "myNode");
m_nodeDao.save(onmsNode);
OnmsAssetRecord assetRecord = onmsNode.getAssetRecord();
assetRecord.setAssetNumber("imported-id: 7");
assetRecord.setUsername("antonio");
assetRecord.setPassword("password");
assetRecord.setEnable("cisco");
assetRecord.setConnection(OnmsAssetRecord.TELNET_CONNECTION);
m_assetRecordDao.update(assetRecord);
m_assetRecordDao.flush();
//Test findAll method
int id = assetRecord.getId();
OnmsAssetRecord assetRecordFromDb = m_assetRecordDao.get(id);
assertEquals(assetRecord.getUsername(), assetRecordFromDb.getUsername());
assertEquals(assetRecord.getPassword(), assetRecordFromDb.getPassword());
assertEquals(assetRecord.getEnable(), assetRecordFromDb.getEnable());
assertEquals(assetRecord.getConnection(), assetRecordFromDb.getConnection());
}
Aggregations