use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class ProvisionerIT method testImportWithGeoData.
@Test(timeout = 300000)
@JUnitTemporaryDatabase
public void testImportWithGeoData() throws Exception {
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
final NodeDao nodeDao = getNodeDao();
OnmsNode node = nodeDao.findByForeignId("empty", "4243");
nodeDao.initialize(node.getAssetRecord());
nodeDao.initialize(node.getAssetRecord().getGeolocation());
OnmsGeolocation geolocation = new OnmsGeolocation();
geolocation.setAddress1("220 Chatham Business Dr.");
geolocation.setCity("Pittsboro");
geolocation.setState("NC");
geolocation.setZip("27312");
geolocation.setLatitude(35.715723f);
geolocation.setLongitude(-79.162261f);
node.getAssetRecord().setGeolocation(geolocation);
nodeDao.saveOrUpdate(node);
nodeDao.flush();
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
assertNotNull(geolocation.getLatitude());
assertNotNull(geolocation.getLongitude());
assertEquals(Float.valueOf(35.715723f).doubleValue(), geolocation.getLatitude().doubleValue(), 0.1d);
assertEquals(Float.valueOf(-79.162261f).doubleValue(), geolocation.getLongitude().doubleValue(), 0.1d);
System.err.println("=================================================================BLEARGH");
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
// Ensure it is reset
assertNull(geolocation.asAddressString());
assertNull(geolocation.getLatitude());
assertNull(geolocation.getLongitude());
}
use of org.opennms.netmgt.dao.api.NodeDao 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.dao.api.NodeDao in project opennms by OpenNMS.
the class AsteriskOriginateNotificationStrategy method buildOriginator.
private AsteriskOriginator buildOriginator(final List<Argument> arguments) throws AsteriskOriginatorException {
final AsteriskOriginator ao = new AsteriskOriginator();
for (final Argument arg : arguments) {
final String argSwitch = arg.getSwitch();
final String argValue = arg.getValue();
if (NotificationManager.PARAM_WORK_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_WORK_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_HOME_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_HOME_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_MOBILE_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_MOBILE_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_SUBJECT.equals(argSwitch)) {
LOG.debug("Found: PARAM_SUBJECT => {}", argValue);
ao.setSubject(argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NOTIFY_SUBJECT, argValue);
} else if (NotificationManager.PARAM_TEXT_MSG.equals(argSwitch)) {
LOG.debug("Found: PARAM_TEXT_MSG => {}", argValue);
ao.setMessageText(argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NOTIFY_BODY, argValue);
} else if (NotificationManager.PARAM_TUI_PIN.equals(argSwitch)) {
LOG.debug("Found: PARAM_TUI_PIN => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_USER_PIN, argValue);
} else if (NotificationManager.PARAM_DESTINATION.equals(argSwitch)) {
LOG.debug("Found: PARAM_DESTINATION => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_USERNAME, argValue);
} else if (NotificationManager.PARAM_NODE.equals(argSwitch)) {
LOG.debug("Found: PARAM_NODE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODEID, argValue);
try {
final NodeDao nodeDao = BeanUtils.getBean("notifdContext", "nodeDao", NodeDao.class);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, nodeDao.get(argValue).getLabel());
} catch (final Throwable t) {
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, null);
}
} else if (NotificationManager.PARAM_INTERFACE.equals(argSwitch)) {
LOG.debug("Found: PARAM_INTERFACE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_INTERFACE, argValue);
} else if (NotificationManager.PARAM_SERVICE.equals(argSwitch)) {
LOG.debug("Found: PARAM_SERVICE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_SERVICE, argValue);
} else {
LOG.debug("Unconsumed arg: {} => {}", String.valueOf(argSwitch), String.valueOf(argValue));
}
}
return ao;
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class Scriptd method onInit.
/**
* Initialize the <em>Scriptd</em> service.
*/
@Override
protected void onInit() {
// Load the configuration information
//
ScriptdConfigFactory aFactory = null;
try {
ScriptdConfigFactory.reload();
aFactory = ScriptdConfigFactory.getInstance();
} catch (IOException ex) {
LOG.error("Failed to load scriptd configuration", ex);
throw new UndeclaredThrowableException(ex);
}
// get the node DAO
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
m_executor = new Executor(aFactory, nodeDao);
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class VmwareCollectorComplianceTest method getRequiredBeans.
@Override
public Map<String, Object> getRequiredBeans() {
OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
NodeDao nodeDao = mock(NodeDao.class);
when(nodeDao.get(anyInt())).thenReturn(node);
when(node.getAssetRecord().getVmwareManagementServer()).thenReturn("mdx");
when(node.getAssetRecord().getVmwareManagedEntityType()).thenReturn("tsx");
when(node.getForeignId()).thenReturn("rsx");
VmwareCollection collection = new VmwareCollection();
VmwareDatacollectionConfigDao vmwareDatacollectionConfigDao = mock(VmwareDatacollectionConfigDao.class);
when(vmwareDatacollectionConfigDao.getVmwareCollection(COLLECTION)).thenReturn(collection);
when(vmwareDatacollectionConfigDao.getRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
VmwareServer vmwareServer = new VmwareServer();
vmwareServer.setHostname(InetAddrUtils.getLocalHostAddress().getCanonicalHostName());
Map<String, VmwareServer> serverMap = new ImmutableMap.Builder<String, VmwareServer>().put("mdx", vmwareServer).build();
VmwareConfigDao vmwareConfigDao = mock(VmwareConfigDao.class);
when(vmwareConfigDao.getServerMap()).thenReturn(serverMap);
return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("vmwareDatacollectionConfigDao", vmwareDatacollectionConfigDao).put("vmwareConfigDao", vmwareConfigDao).build();
}
Aggregations