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());
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class AssetRecordDaoIT method testGeolocation.
@Test
@Transactional
public void testGeolocation() {
OnmsNode onmsNode = new OnmsNode(m_locationDao.getDefaultLocation(), "myNode");
m_nodeDao.save(onmsNode);
OnmsAssetRecord assetRecord = onmsNode.getAssetRecord();
OnmsGeolocation geo = assetRecord.getGeolocation();
if (geo == null) {
geo = new OnmsGeolocation();
assetRecord.setGeolocation(geo);
}
geo.setAddress1("220 Chatham Business Drive");
geo.setCity("Pittsboro");
geo.setState("NC");
geo.setZip("27312");
geo.setCountry("US");
m_assetRecordDao.update(assetRecord);
m_assetRecordDao.flush();
// Test findAll method
int id = assetRecord.getId();
OnmsAssetRecord assetRecordFromDb = m_assetRecordDao.get(id);
assertNotNull(assetRecordFromDb.getGeolocation());
assertEquals(geo.getAddress1(), assetRecordFromDb.getGeolocation().getAddress1());
assertEquals(geo.getCity(), assetRecordFromDb.getGeolocation().getCity());
assertEquals(geo.getState(), assetRecordFromDb.getGeolocation().getState());
assertEquals(geo.getZip(), assetRecordFromDb.getGeolocation().getZip());
assertEquals(geo.getCountry(), assetRecordFromDb.getGeolocation().getCountry());
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class AssetRecordDaoIT method testFindByNodeId.
@Test
@Transactional
public void testFindByNodeId() {
OnmsNode onmsNode = new OnmsNode(m_locationDao.getDefaultLocation(), "myNode");
m_nodeDao.save(onmsNode);
OnmsAssetRecord assetRecord = onmsNode.getAssetRecord();
assetRecord.setAssetNumber("imported-id: 7");
m_assetRecordDao.update(assetRecord);
m_assetRecordDao.flush();
// Test findByNodeId method
OnmsAssetRecord a = m_assetRecordDao.findByNodeId(onmsNode.getId());
assertTrue(a.equals(assetRecord));
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class NodeCacheImpl method populateBodyWithNodeInfo.
/**
* utility method to populate a Map with the most import node attributes
*
* @param body the map
* @param node the node object
*/
private static void populateBodyWithNodeInfo(Map<String, String> body, OnmsNode node) {
body.put("nodelabel", node.getLabel());
body.put("nodesysname", node.getSysName());
body.put("nodesyslocation", node.getSysLocation());
body.put("foreignsource", node.getForeignSource());
body.put("foreignid", node.getForeignId());
body.put("operatingsystem", node.getOperatingSystem());
final StringBuilder categories = new StringBuilder();
for (Iterator<OnmsCategory> i = node.getCategories().iterator(); i.hasNext(); ) {
categories.append(((OnmsCategory) i.next()).getName());
if (i.hasNext()) {
categories.append(",");
}
}
body.put("categories", categories.toString());
if (archiveAssetData) {
// parent information
OnmsNode parent = node.getParent();
if (parent != null) {
if (parent.getLabel() != null)
body.put("parent-nodelabel", parent.getLabel());
if (parent.getNodeId() != null)
body.put("parent-nodeid", parent.getNodeId());
if (parent.getForeignSource() != null)
body.put("parent-foreignsource", parent.getForeignSource());
if (parent.getForeignId() != null)
body.put("parent-foreignid", parent.getForeignId());
}
// assetRecord.
OnmsAssetRecord assetRecord = node.getAssetRecord();
if (assetRecord != null) {
// geolocation
OnmsGeolocation gl = assetRecord.getGeolocation();
if (gl != null) {
if (gl.getLatitude() != null)
body.put("asset-latitude", gl.getLatitude().toString());
if (gl.getLongitude() != null)
body.put("asset-longitude", gl.getLongitude().toString());
}
// assetRecord
if (assetRecord.getRegion() != null && !"".equals(assetRecord.getRegion()))
body.put("asset-region", assetRecord.getRegion());
if (assetRecord.getBuilding() != null && !"".equals(assetRecord.getBuilding()))
body.put("asset-building", assetRecord.getBuilding());
if (assetRecord.getFloor() != null && !"".equals(assetRecord.getFloor()))
body.put("asset-floor", assetRecord.getFloor());
if (assetRecord.getRoom() != null && !"".equals(assetRecord.getRoom()))
body.put("asset-room", assetRecord.getRoom());
if (assetRecord.getRack() != null && !"".equals(assetRecord.getRack()))
body.put("asset-rack", assetRecord.getRack());
if (assetRecord.getSlot() != null && !"".equals(assetRecord.getSlot()))
body.put("asset-slot", assetRecord.getSlot());
if (assetRecord.getPort() != null && !"".equals(assetRecord.getPort()))
body.put("asset-port", assetRecord.getPort());
if (assetRecord.getCategory() != null && !"".equals(assetRecord.getCategory()))
body.put("asset-category", assetRecord.getCategory());
if (assetRecord.getDisplayCategory() != null && !"".equals(assetRecord.getDisplayCategory()))
body.put("asset-displaycategory", assetRecord.getDisplayCategory());
if (assetRecord.getNotifyCategory() != null && !"".equals(assetRecord.getNotifyCategory()))
body.put("asset-notifycategory", assetRecord.getNotifyCategory());
if (assetRecord.getPollerCategory() != null && !"".equals(assetRecord.getPollerCategory()))
body.put("asset-pollercategory", assetRecord.getPollerCategory());
if (assetRecord.getThresholdCategory() != null && !"".equals(assetRecord.getThresholdCategory()))
body.put("asset-thresholdcategory", assetRecord.getThresholdCategory());
if (assetRecord.getManagedObjectType() != null && !"".equals(assetRecord.getManagedObjectType()))
body.put("asset-managedobjecttype", assetRecord.getManagedObjectType());
if (assetRecord.getManagedObjectInstance() != null && !"".equals(assetRecord.getManagedObjectInstance()))
body.put("asset-managedobjectinstance", assetRecord.getManagedObjectInstance());
if (assetRecord.getManufacturer() != null && !"".equals(assetRecord.getManufacturer()))
body.put("asset-manufacturer", assetRecord.getManufacturer());
if (assetRecord.getVendor() != null && !"".equals(assetRecord.getVendor()))
body.put("asset-vendor", assetRecord.getVendor());
if (assetRecord.getModelNumber() != null && !"".equals(assetRecord.getModelNumber()))
body.put("asset-modelnumber", assetRecord.getModelNumber());
}
}
}
use of org.opennms.netmgt.model.OnmsAssetRecord in project opennms by OpenNMS.
the class RancidProvisioningAdapter method getSuitableRancidNodeAuthentication.
private RancidNodeAuthentication getSuitableRancidNodeAuthentication(OnmsNode node) {
// RancidAuthentication
RancidNodeAuthentication r_auth_node = new RancidNodeAuthentication();
r_auth_node.setDeviceName(node.getLabel());
OnmsAssetRecord asset_node = node.getAssetRecord();
//
if (asset_node == null) {
return r_auth_node;
}
if (asset_node.getUsername() != null) {
r_auth_node.setUser(asset_node.getUsername());
}
if (asset_node.getPassword() != null) {
r_auth_node.setPassword(asset_node.getPassword());
}
if (asset_node.getEnable() != null) {
r_auth_node.setEnablePass(asset_node.getEnable());
}
if (asset_node.getAutoenable() != null) {
r_auth_node.setAutoEnable(asset_node.getAutoenable().equals(OnmsAssetRecord.AUTOENABLED));
}
if (asset_node.getConnection() != null) {
r_auth_node.setConnectionMethod(asset_node.getConnection());
} else {
r_auth_node.setConnectionMethod("telnet");
}
return r_auth_node;
}
Aggregations