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);
}
}
}
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.");
}
}
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;
}
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.");
}
}
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);
}
}
}
Aggregations