Search in sources :

Example 1 with DatacollectionGroup

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

the class DataCollectionConfigMigrator17Offline method updateDataCollectionConfig.

/**
     * Update data collection configuration.
     *
     * @param snmpCollection the SNMP collection
     * @param dataCollectionGroup the data collection group
     * @throws OnmsUpgradeException the OpenNMS upgrade exception
     */
private void updateDataCollectionConfig(String snmpCollection, String dataCollectionGroup) throws OnmsUpgradeException {
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, sourceFile);
    if (config != null) {
        log("Adding datacollection-group %s to snmp-collection %s", dataCollectionGroup, snmpCollection);
        IncludeCollection ic = new IncludeCollection();
        ic.setDataCollectionGroup(dataCollectionGroup);
        config.getSnmpCollections().stream().filter(s -> s.getName().equals(snmpCollection)).findFirst().get().addIncludeCollection(ic);
        try {
            JaxbUtils.marshal(config, new FileWriter(sourceFile));
        } catch (IOException e) {
            throw new OnmsUpgradeException("Can't update " + sourceFile, e);
        }
    }
}
Also used : DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) Iterator(java.util.Iterator) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) ConfigFileConstants(org.opennms.core.utils.ConfigFileConstants) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) File(java.io.File) AbstractOnmsUpgrade(org.opennms.upgrade.api.AbstractOnmsUpgrade) Matcher(java.util.regex.Matcher) Paths(java.nio.file.Paths) Map(java.util.Map) JaxbUtils(org.opennms.core.xml.JaxbUtils) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 2 with DatacollectionGroup

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

the class JsmiMibParserTest method testNameCutter.

/**
     * Test name cutter
     *
     * @throws Exception the exception
     */
@Test
public void testNameCutter() throws Exception {
    if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
        DatacollectionGroup dcGroup = parser.getDataCollection();
        Assert.assertNotNull(dcGroup);
        System.out.println(JaxbUtils.marshal(dcGroup));
        int count = 0;
        for (final Group group : dcGroup.getGroups()) {
            for (final MibObj mo : group.getMibObjs()) {
                if (mo.getAlias().length() > 19) {
                    // Character restriction.
                    count++;
                }
            }
        }
        // Without the name-cutter the number will be 80.
        Assert.assertEquals(0, count);
    } else {
        Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) MibObj(org.opennms.netmgt.config.datacollection.MibObj) File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) Test(org.junit.Test)

Example 3 with DatacollectionGroup

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

the class JsmiMibParser method getGroup.

/**
     * Gets the group.
     *
     * @param data the data collection group object
     * @param groupName the group name
     * @param resourceType the resource type
     * @return the group
     */
protected Group getGroup(DatacollectionGroup data, String groupName, String resourceType) {
    for (Group group : data.getGroups()) {
        if (group.getName().equals(groupName))
            return group;
    }
    Group group = new Group();
    group.setName(groupName);
    group.setIfType(resourceType == null ? "ignore" : "all");
    if (resourceType != null) {
        ResourceType type = new ResourceType();
        type.setName(resourceType);
        type.setLabel(resourceType);
        type.setResourceLabel("${index}");
        // To avoid requires opennms-services
        type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy"));
        type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName()));
        data.addResourceType(type);
    }
    data.addGroup(group);
    return group;
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 4 with DatacollectionGroup

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

the class JsmiMibParserTest method testGenerateDataCollection.

/**
     * Test generate data collection.
     *
     * @throws Exception the exception
     */
@Test
public void testGenerateDataCollection() throws Exception {
    if (parser.parseMib(new File(MIB_DIR, "IF-MIB.txt"))) {
        DatacollectionGroup dcGroup = parser.getDataCollection();
        Assert.assertNotNull(dcGroup);
        System.out.println(JaxbUtils.marshal(dcGroup));
        Assert.assertEquals(5, dcGroup.getResourceTypes().size());
        Assert.assertEquals(7, dcGroup.getGroups().size());
        Group mibGroup = null;
        for (Group g : dcGroup.getGroups()) {
            if (g.getName().equals("ifTable"))
                mibGroup = g;
        }
        Assert.assertNotNull(mibGroup);
        Assert.assertEquals(22, mibGroup.getMibObjs().size());
        for (MibObj mo : mibGroup.getMibObjs()) {
            Assert.assertEquals("ifEntry", mo.getInstance());
            Assert.assertTrue(mo.getOid().startsWith(".1.3.6.1.2.1.2.2.1"));
            Assert.assertTrue(mo.getType().matches("^(?i)(counter|gauge|timeticks|integer|octetstring|string)?\\d*$"));
        }
    } else {
        Assert.fail("The IF-MIB.txt file couldn't be parsed successfully.");
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) MibObj(org.opennms.netmgt.config.datacollection.MibObj) File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) Test(org.junit.Test)

Example 5 with DatacollectionGroup

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

the class DataCollectionGroupPanel method processDataCollection.

/**
     * Process data collection.
     *
     * @param dataCollectionConfigDao the OpenNMS data collection configuration DAO
     * @param logger the logger
     */
private void processDataCollection(final DataCollectionConfigDao dataCollectionConfigDao, final Logger logger) {
    final DatacollectionGroup dcGroup = getOnmsDataCollection();
    if (isExistingGroup()) {
        ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to override the existig file?\nAll current information will be lost.", "Yes", "No", new ConfirmDialog.Listener() {

            public void onClose(ConfirmDialog dialog) {
                if (dialog.isConfirmed()) {
                    saveFile(existingFile, dcGroup, logger);
                }
            }
        });
    } else {
        if (dataCollectionConfigDao.getAvailableDataCollectionGroups().contains(dcGroup.getName())) {
            Notification.show("There is a group with the same name, please pick another one.");
        } else {
            final File configDir = new File(ConfigFileConstants.getHome(), "etc" + File.separatorChar + "datacollection");
            final File file = new File(configDir, dcGroup.getName().replaceAll(" ", "_") + ".xml");
            saveFile(file, dcGroup, logger);
        }
    }
}
Also used : File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Aggregations

DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)13 File (java.io.File)6 Group (org.opennms.netmgt.config.datacollection.Group)4 MibObj (org.opennms.netmgt.config.datacollection.MibObj)3 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)3 Test (org.junit.Test)2 IncludeCollection (org.opennms.netmgt.config.datacollection.IncludeCollection)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 FileWriter (java.io.FileWriter)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1