Search in sources :

Example 16 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DefaultDataCollectionConfigDao method getMibObjProperties.

@Override
public List<MibObjProperty> getMibObjProperties(final String cName, final String aSysoid, final String anAddress) {
    LOG.debug("getMibObjProperties: collection: {} sysoid: {} address: {}", cName, aSysoid, anAddress);
    if (aSysoid == null) {
        LOG.debug("getMibObjProperties: aSysoid parameter is NULL...");
        return new ArrayList<>();
    }
    final SnmpCollection collection = getSnmpCollection(getContainer(), cName);
    if (collection == null) {
        return Collections.emptyList();
    }
    final Systems systems = collection.getSystems();
    if (systems == null) {
        return Collections.emptyList();
    }
    final List<SystemDef> systemList = new ArrayList<>();
    for (final SystemDef system : systems.getSystemDefs()) {
        if (systemDefMatches(system, aSysoid, anAddress)) {
            systemList.add(system);
        }
    }
    final List<MibObjProperty> mibProperties = new ArrayList<>();
    for (final SystemDef system : systemList) {
        for (final String grpName : system.getCollect().getIncludeGroups()) {
            processGroupForProperties(cName, grpName, mibProperties);
        }
    }
    return mibProperties;
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) MibObjProperty(org.opennms.netmgt.config.datacollection.MibObjProperty) ArrayList(java.util.ArrayList) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) Systems(org.opennms.netmgt.config.datacollection.Systems)

Example 17 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DataCollectionConfigParserTest method testLoadSimpleWithExclusions.

@Test
public void testLoadSimpleWithExclusions() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-excludes.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(1, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    // 48 systemDef to exclude
    Assert.assertEquals(41, collection.getSystems().getSystemDefs().size());
    // 1 group to exclude (used only on Cisco PIX or Cisco AS)
    Assert.assertEquals(27, collection.getGroups().getGroups().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 18 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class SnmpCollectionForm method createBasicSnmpCollection.

/**
 * Creates the basic SNMP collection.
 *
 * @return the basic example SNMP collection
 */
public SnmpCollection createBasicSnmpCollection() {
    SnmpCollection collection = new SnmpCollection();
    collection.setName("New Collection");
    collection.setSnmpStorageFlag("select");
    Rrd rrd = new Rrd();
    rrd.setStep(300);
    rrd.addRra("RRA:AVERAGE:0.5:1:2016");
    rrd.addRra("RRA:AVERAGE:0.5:12:1488");
    rrd.addRra("RRA:AVERAGE:0.5:288:366");
    rrd.addRra("RRA:MAX:0.5:288:366");
    rrd.addRra("RRA:MIN:0.5:288:366");
    collection.setRrd(rrd);
    return collection;
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) Rrd(org.opennms.netmgt.config.datacollection.Rrd)

Example 19 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class SnmpCollectionPanel method saveSnmpCollections.

/**
 * Save SNMP collections.
 *
 * @param snmpCollections the SNMP collections
 * @param logger the logger
 */
public void saveSnmpCollections(final List<SnmpCollection> snmpCollections, Logger logger) {
    try {
        final DatacollectionConfig dataCollectionConfig = dataCollectionConfigDao.getRootDataCollection();
        File file = ConfigFileConstants.getFile(ConfigFileConstants.DATA_COLLECTION_CONF_FILE_NAME);
        logger.info("Saving data colleciton configuration on " + file);
        // TODO: Normalize the SNMP Collections Content, I'm not sure why
        for (SnmpCollection snmpCollection : snmpCollections) {
            snmpCollection.setGroups(null);
            snmpCollection.setSystems(null);
        }
        dataCollectionConfig.setSnmpCollections(snmpCollections);
        JaxbUtils.marshal(dataCollectionConfig, new FileWriter(file));
        logger.info("The data collection configuration has been saved.");
    } catch (Exception e) {
        logger.error("An error ocurred while saving the data collection configuration: " + (e.getMessage() == null ? "[No Details]" : e.getMessage()));
        if (e.getMessage() == null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            logger.error(sw.toString());
        }
        Notification.show("Can't save data collection configuration. " + e.getMessage(), Notification.Type.ERROR_MESSAGE);
    }
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) File(java.io.File) CommitException(com.vaadin.data.fieldgroup.FieldGroup.CommitException) PrintWriter(java.io.PrintWriter)

Aggregations

SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)19 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)10 Test (org.junit.Test)9 FileSystemResource (org.springframework.core.io.FileSystemResource)7 InputStreamResource (org.springframework.core.io.InputStreamResource)6 Resource (org.springframework.core.io.Resource)6 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)4 Group (org.opennms.netmgt.config.datacollection.Group)4 SystemDef (org.opennms.netmgt.config.datacollection.SystemDef)4 Groups (org.opennms.netmgt.config.datacollection.Groups)3 Systems (org.opennms.netmgt.config.datacollection.Systems)3 ArrayList (java.util.ArrayList)2 MibObj (org.opennms.netmgt.config.datacollection.MibObj)2 CommitException (com.vaadin.data.fieldgroup.FieldGroup.CommitException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1