Search in sources :

Example 11 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class PersistenceSerializationTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    fa = new FileAnticipator();
    fsr = new MockForeignSourceRepository();
    fsr.save(new ForeignSource("cheese"));
    fsr.flush();
    fs = fsr.getForeignSource("cheese");
    //        fs.setScanInterval(scanInterval)
    XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar("2009-02-25T12:45:38.800-05:00");
    fs.setDateStamp(cal);
    List<PluginConfig> detectors = new ArrayList<PluginConfig>();
    final PluginConfig detector = new PluginConfig("food", "org.opennms.netmgt.provision.persist.detectors.FoodDetector");
    detector.addParameter("type", "cheese");
    detector.addParameter("density", "soft");
    detector.addParameter("sharpness", "mild");
    detectors.add(detector);
    fs.setDetectors(detectors);
    List<PluginConfig> policies = new ArrayList<PluginConfig>();
    PluginConfig policy = new PluginConfig("lower-case-node", "org.opennms.netmgt.provision.persist.policies.NodeCategoryPolicy");
    policy.addParameter("label", "~^[a-z]$");
    policy.addParameter("category", "Lower-Case-Nodes");
    policies.add(policy);
    policy = new PluginConfig("all-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.InclusiveInterfacePolicy");
    policies.add(policy);
    policy = new PluginConfig("10-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.MatchingInterfacePolicy");
    policy.addParameter("ipaddress", "~^10\\..*$");
    policies.add(policy);
    policy = new PluginConfig("cisco-snmp-interfaces", "org.opennms.netmgt.provision.persist.policies.MatchingSnmpInterfacePolicy");
    policy.addParameter("ifdescr", "~^(?i:LEC).*$");
    policies.add(policy);
    fs.setPolicies(policies);
    fsw = new ForeignSourceCollection();
    fsw.getForeignSources().addAll(fsr.getForeignSources());
    c = JAXBContext.newInstance(ForeignSourceCollection.class, ForeignSource.class);
    m = c.createMarshaller();
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setNormalize(true);
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 12 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class QueueingForeignSourceRepositoryTest method testDefaultForeignSource.

@Test
public void testDefaultForeignSource() throws Exception {
    createRequisition();
    List<String> detectorList = Arrays.asList(new String[] { "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP", "SSH" });
    String uuid = UUID.randomUUID().toString();
    ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
    assertEquals("name must match requested foreign source repository name", uuid, defaultForeignSource.getName());
    assertEquals("scan-interval must be 1 day", 86400000, defaultForeignSource.getScanInterval().getMillis());
    assertEquals("foreign source must have no default policies", 0, defaultForeignSource.getPolicies().size());
    List<String> fsNames = new ArrayList<String>();
    for (PluginConfig config : defaultForeignSource.getDetectors()) {
        fsNames.add(config.getName());
    }
    assertEquals("detector list must match expected defaults", detectorList, fsNames);
    assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class DefaultForeignSourceService method deletePolicy.

/** {@inheritDoc} */
@Override
public ForeignSource deletePolicy(String foreignSource, String name) {
    ForeignSource fs = getForeignSource(foreignSource);
    List<PluginConfig> policies = fs.getPolicies();
    for (Iterator<PluginConfig> i = policies.iterator(); i.hasNext(); ) {
        PluginConfig pc = i.next();
        if (pc.getName().equals(name)) {
            i.remove();
            break;
        }
    }
    m_pendingForeignSourceRepository.save(fs);
    return fs;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 14 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class ProvisionerRescanExistingFalseIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging(true, "ERROR");
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    assertTrue(m_snmpPeerFactory instanceof ProxySnmpAgentConfigFactory);
    m_eventAnticipator = m_mockEventIpcManager.getEventAnticipator();
    //((TransactionAwareEventForwarder)m_provisioner.getEventForwarder()).setEventForwarder(m_mockEventIpcManager);
    m_provisioner.start();
    m_foreignSource = new ForeignSource();
    m_foreignSource.setName("noRescanOnImport");
    m_foreignSource.setScanInterval(Duration.standardDays(1));
    final PluginConfig icmpDetector = new PluginConfig("ICMP", IcmpDetector.class.getName());
    icmpDetector.addParameter("timeout", "500");
    icmpDetector.addParameter("retries", "0");
    m_foreignSource.addDetector(icmpDetector);
    final PluginConfig snmpDetector = new PluginConfig("SNMP", SnmpDetector.class.getName());
    snmpDetector.addParameter("timeout", "500");
    snmpDetector.addParameter("retries", "0");
    m_foreignSource.addDetector(snmpDetector);
    m_foreignSourceRepository = new MockForeignSourceRepository();
    m_foreignSourceRepository.save(m_foreignSource);
    m_foreignSourceRepository.flush();
    m_provisionService.setForeignSourceRepository(m_foreignSourceRepository);
    m_scheduledExecutor.pause();
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) IcmpDetector(org.opennms.netmgt.provision.detector.icmp.IcmpDetector) SnmpDetector(org.opennms.netmgt.provision.detector.snmp.SnmpDetector) ProxySnmpAgentConfigFactory(org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Before(org.junit.Before)

Example 15 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class ForeignSourceRestService method removeEntry.

private static PluginConfig removeEntry(List<PluginConfig> plugins, String name) {
    PluginConfig removed = null;
    java.util.Iterator<PluginConfig> i = plugins.iterator();
    while (i.hasNext()) {
        PluginConfig pc = i.next();
        if (pc.getName().equals(name)) {
            removed = pc;
            i.remove();
            break;
        }
    }
    return removed;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)

Aggregations

PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)33 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)30 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 DELETE (javax.ws.rs.DELETE)2 Path (javax.ws.rs.Path)2 ProxySnmpAgentConfigFactory (org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory)2 OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)2 SnmpDetector (org.opennms.netmgt.provision.detector.snmp.SnmpDetector)2 NodeCategorySettingPolicy (org.opennms.netmgt.provision.persist.policies.NodeCategorySettingPolicy)2 Transactional (org.springframework.transaction.annotation.Transactional)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 IcmpDetector (org.opennms.netmgt.provision.detector.icmp.IcmpDetector)1 ForeignSourceCollection (org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection)1