Search in sources :

Example 1 with NodeDao

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());
}
Also used : MockNodeDao(org.opennms.netmgt.dao.mock.MockNodeDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 2 with NodeDao

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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Argument(org.opennms.netmgt.model.notifd.Argument) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) ArrayList(java.util.ArrayList) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) NodeDao(org.opennms.netmgt.dao.api.NodeDao) TransactionCallback(org.springframework.transaction.support.TransactionCallback) OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 3 with NodeDao

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;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) Argument(org.opennms.netmgt.model.notifd.Argument) AsteriskOriginator(org.opennms.netmgt.asterisk.utils.AsteriskOriginator)

Example 4 with NodeDao

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);
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) NodeDao(org.opennms.netmgt.dao.api.NodeDao) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ScriptdConfigFactory(org.opennms.netmgt.config.ScriptdConfigFactory) IOException(java.io.IOException)

Example 5 with 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();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) VmwareConfigDao(org.opennms.netmgt.dao.VmwareConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection) VmwareDatacollectionConfigDao(org.opennms.netmgt.dao.VmwareDatacollectionConfigDao) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Aggregations

NodeDao (org.opennms.netmgt.dao.api.NodeDao)14 OnmsNode (org.opennms.netmgt.model.OnmsNode)10 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)3 VmwareConfigDao (org.opennms.netmgt.dao.VmwareConfigDao)3 InetAddress (java.net.InetAddress)2 Date (java.util.Date)2 Collection (org.opennms.netmgt.config.wsman.Collection)2 Definition (org.opennms.netmgt.config.wsman.Definition)2 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)2 WSManDataCollectionConfigDao (org.opennms.netmgt.dao.WSManDataCollectionConfigDao)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 Argument (org.opennms.netmgt.model.notifd.Argument)2 BeanFactoryReference (org.springframework.beans.factory.access.BeanFactoryReference)2 Resource (org.springframework.core.io.Resource)2 Strings (com.google.common.base.Strings)1 File (java.io.File)1 IOException (java.io.IOException)1