Search in sources :

Example 76 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class WsManCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", null);
    if (collectionName == null) {
        throw new IllegalArgumentException("Collector configuration does not include the required 'collection' parameter.");
    }
    final Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException("No collection found with name: " + collectionName);
    }
    final OnmsNode node = m_nodeDao.get(agent.getNodeId());
    if (node == null) {
        throw new IllegalArgumentException("Could not find node with id: " + agent.getNodeId());
    }
    final Definition agentConfig = m_wsManConfigDao.getAgentConfig(agent.getAddress());
    final Groups groups = new Groups(m_wsManDataCollectionConfigDao.getGroupsForAgent(collection, agent, agentConfig, node));
    runtimeAttributes.put(WSMAN_AGENT_CONFIG_KEY, agentConfig);
    runtimeAttributes.put(WSMAN_GROUPS_KEY, groups);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) Groups(org.opennms.netmgt.config.wsman.Groups) Definition(org.opennms.netmgt.config.wsman.Definition) Collection(org.opennms.netmgt.config.wsman.Collection)

Example 77 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class DnsProvisioningAdapter method createDnsRecordMap.

private void createDnsRecordMap() {
    List<OnmsNode> nodes = m_nodeDao.findAllProvisionedNodes();
    m_nodeDnsRecordMap = new ConcurrentHashMap<Integer, DnsRecord>(nodes.size());
    for (OnmsNode onmsNode : nodes) {
        m_nodeDnsRecordMap.putIfAbsent(onmsNode.getId(), new DnsRecord(onmsNode, m_level));
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode)

Example 78 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class DnsProvisioningAdapter method doUpdate.

private void doUpdate(AdapterOperation op) {
    OnmsNode node = null;
    LOG.debug("doUpdate: operation: {}", op.getType().name());
    try {
        node = m_nodeDao.get(op.getNodeId());
        if (node == null) {
            doDelete(op);
            return;
        }
        DnsRecord record = new DnsRecord(node, m_level);
        LOG.debug("doUpdate: DnsRecord: hostname: {} zone: {} ip address {}", record.getIp().getHostAddress(), record.getHostname(), record.getZone());
        DnsRecord oldRecord = m_nodeDnsRecordMap.get(Integer.valueOf(node.getId()));
        Update update = new Update(Name.fromString(record.getZone()));
        if (oldRecord != null && oldRecord.getHostname() != record.getHostname()) {
            update.delete(Name.fromString(oldRecord.getHostname()), Type.A);
        }
        update.replace(Name.fromString(record.getHostname()), Type.A, 3600, record.getIp().getHostAddress());
        m_resolver.send(update);
        m_nodeDnsRecordMap.put(Integer.valueOf(op.getNodeId()), record);
    } catch (Throwable e) {
        LOG.error("addNode: Error handling node added event.", e);
        sendAndThrow(op.getNodeId(), e);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Update(org.xbill.DNS.Update)

Example 79 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class WSManDataCollectionConfigDaoJaxbTest method canEvaluteSystemDefinitionRules.

@Test
public void canEvaluteSystemDefinitionRules() throws UnknownHostException {
    OnmsNode node = mock(OnmsNode.class);
    CollectionAgent agent = mock(CollectionAgent.class);
    Definition config = new Definition();
    config.setProductVendor("Dell Inc.");
    config.setProductVersion(" iDRAC 6");
    SystemDefinition sysDef = new SystemDefinition();
    sysDef.addRule("#productVendor matches 'Dell.*' and #productVersion matches '.*DRAC.*'");
    assertTrue("agent should be matched", WSManDataCollectionConfigDaoJaxb.isAgentSupportedBySystemDefinition(sysDef, agent, config, node));
}
Also used : SystemDefinition(org.opennms.netmgt.config.wsman.SystemDefinition) OnmsNode(org.opennms.netmgt.model.OnmsNode) SystemDefinition(org.opennms.netmgt.config.wsman.SystemDefinition) Definition(org.opennms.netmgt.config.wsman.Definition) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 80 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class HibernateCriteriaConverterIT method testDistinctQuery.

@Test
@JUnitTemporaryDatabase
public void testDistinctQuery() {
    List<OnmsNode> nodes = null;
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
    cb.isNotNull("id").distinct();
    cb.eq("label", "node1").join("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN).eq("ipInterface.ipAddress", "192.168.1.1");
    nodes = m_nodeDao.findMatching(cb.toCriteria());
    assertEquals(1, nodes.size());
    assertEquals(Integer.valueOf(1), nodes.get(0).getId());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23