public SnmpCollection getSnmpCollection(final String name) { for (final SnmpCollection collection : m_snmpCollections) { if (name.equals(collection.getName())) { return collection; } } return null; }
private static SnmpCollection getSnmpCollection(final FileReloadContainer<DatacollectionConfig> container, final String collectionName) { for (final SnmpCollection collection : container.getObject().getSnmpCollections()) { if (collection.getName().equals(collectionName)) return collection; } return null; }
/** * Sets the SNMP collections. * * @param snmpCollections the new SNMP collections */ public void setSnmpCollections(List<SnmpCollection> snmpCollections) { container.removeAllItems(); for (SnmpCollection sc : snmpCollections) { // Ignoring an internal collection created to handle resource types only if exist if (!sc.getName().equals("__resource_type_collection")) { container.addOnmsBean(sc); } } }
/** * Sets the SNMP collections. * * @param snmpCollections the new SNMP collections */ public void setSnmpCollections(List<SnmpCollection> snmpCollections) { container.removeAllItems(); for (SnmpCollection sc : snmpCollections) { // Ignoring an internal collection created to handle resource types only if exist if (!sc.getName().equals("__resource_type_collection")) { container.addOnmsBean(sc); } } }
collectionGroupMap.put(collection.getName(), groupMap);
/** * Gets the parent SNMP Collections. * <p>The list of SNMP collection that are referencing a given systemDefName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param systemDefName the system definition name * @return the parent collections. */ private Set<String> getParentCollections(final DataCollectionConfigDao dataCollectionConfigDao, String systemDefName) { Set<String> collectionMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final SystemDef systemDef : collection.getSystems().getSystemDefs()) { if (systemDefName.equals(systemDef.getName())) { collectionMap.add(collection.getName()); } } } return collectionMap; }
/** * Gets the parent SNMP Collections. * <p>The list of SNMP collection that are referencing a given systemDefName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param systemDefName the system definition name * @return the parent collections. */ private Set<String> getParentCollections(final DataCollectionConfigDao dataCollectionConfigDao, String systemDefName) { Set<String> collectionMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final SystemDef systemDef : collection.getSystems().getSystemDefs()) { if (systemDefName.equals(systemDef.getName())) { collectionMap.add(collection.getName()); } } } return collectionMap; }
/** * 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); } } }
/** * Gets the parent groups. * <p>The list of groups per SNMP collection that are referencing a given resourceTypeName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param resourceTypeName the resource type name * @return the parent groups. */ private Set<String> getParentGroups(final DataCollectionConfigDao dataCollectionConfigDao, String resourceTypeName) { Set<String> groupMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final Group group : collection.getGroups().getGroups()) { for (final MibObj mibObj : group.getMibObjs()) { if (mibObj.getInstance().equals(resourceTypeName)) { groupMap.add(group.getName() + '@' + collection.getName()); } } } } return groupMap; }
/** * Gets the parent system definitions. * <p>The list of systemDef per SNMP collection that are referencing a given groupName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param groupName the group name * @return the parent system definitions. */ private Set<String> getParentSystemDefs(final DataCollectionConfigDao dataCollectionConfigDao, String groupName) { Set<String> systemDefMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final SystemDef systemDef : collection.getSystems().getSystemDefs()) { for (final String group : systemDef.getCollect().getIncludeGroups()) { if (group.equals(groupName)) { systemDefMap.add(systemDef.getName() + '@' + collection.getName()); } } } } return systemDefMap; }
/** * Gets the parent groups. * <p>The list of groups per SNMP collection that are referencing a given resourceTypeName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param resourceTypeName the resource type name * @return the parent groups. */ private Set<String> getParentGroups(final DataCollectionConfigDao dataCollectionConfigDao, String resourceTypeName) { Set<String> groupMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final Group group : collection.getGroups().getGroups()) { for (final MibObj mibObj : group.getMibObjs()) { if (mibObj.getInstance().equals(resourceTypeName)) { groupMap.add(group.getName() + '@' + collection.getName()); } } } } return groupMap; }
/** * Gets the parent system definitions. * <p>The list of systemDef per SNMP collection that are referencing a given groupName</p> * * @param dataCollectionConfigDao the data collection configuration DAO * @param groupName the group name * @return the parent system definitions. */ private Set<String> getParentSystemDefs(final DataCollectionConfigDao dataCollectionConfigDao, String groupName) { Set<String> systemDefMap = new TreeSet<>(); for (final SnmpCollection collection : dataCollectionConfigDao.getRootDataCollection().getSnmpCollections()) { for (final SystemDef systemDef : collection.getSystems().getSystemDefs()) { for (final String group : systemDef.getCollect().getIncludeGroups()) { if (group.equals(groupName)) { systemDefMap.add(systemDef.getName() + '@' + collection.getName()); } } } } return systemDefMap; }
/** * Add all system definitions defined on a specific data collection group, into a SNMP collection. * * @param collection the target SNMP collection object. * @param dataCollectionGroupName the data collection group name. * @param excludeList the list of regular expression to exclude certain system definitions. */ private void addDatacollectionGroup(SnmpCollection collection, String dataCollectionGroupName, List<String> excludeList) { DatacollectionGroup group = externalGroupsMap.get(dataCollectionGroupName); if (group == null) { throwException("Group " + dataCollectionGroupName + " does not exist.", null); } LOG.debug("addDatacollectionGroup: adding all definitions from group {} to snmp-collection {}", group.getName(), collection.getName()); for (SystemDef systemDef : group.getSystemDefs()) { if (shouldAdd(systemDef.getName(), excludeList)) { addSystemDef(collection, systemDef, group.getName()); } } }
@Override public boolean delete() { Object snmpCollectionId = snmpCollectionTable.getValue(); if (snmpCollectionId != null) { SnmpCollection snmpCollection = snmpCollectionTable.getSnmpCollection(snmpCollectionId); logger.info("SNMP Collection " + snmpCollection.getName() + " has been removed."); snmpCollectionTable.select(null); snmpCollectionTable.removeItem(snmpCollectionId); snmpCollectionTable.refreshRowCache(); saveSnmpCollections(snmpCollectionTable.getSnmpCollections(), logger); Notification.show("Be sure that " + snmpCollection.getName() + " is not being used in collectd-configuration.xml", Notification.Type.WARNING_MESSAGE); // TODO Is this enough } return true; } @Override
@Override public boolean delete() { Object snmpCollectionId = snmpCollectionTable.getValue(); if (snmpCollectionId != null) { SnmpCollection snmpCollection = snmpCollectionTable.getSnmpCollection(snmpCollectionId); logger.info("SNMP Collection " + snmpCollection.getName() + " has been removed."); snmpCollectionTable.select(null); snmpCollectionTable.removeItem(snmpCollectionId); snmpCollectionTable.refreshRowCache(); saveSnmpCollections(snmpCollectionTable.getSnmpCollections(), logger); Notification.show("Be sure that " + snmpCollection.getName() + " is not being used in collectd-configuration.xml", Notification.Type.WARNING_MESSAGE); // TODO Is this enough } return true; } @Override
@Override public void visitSnmpCollection(final SnmpCollection collection) { //LOG.debug("visitSnmpCollection({})", collection); final ResourceTypeImpl ifIndexResourceType = new ResourceTypeImpl("ifIndex", "Interfaces (MIB-2 ifTable)"); ifIndexResourceType.setResourceNameTemplate("${ifDescr}-${ifPhysAddr}"); ifIndexResourceType.setResourceLabelTemplate("${ifDescr}-${ifPhysAddr}"); ifIndexResourceType.setResourceKindTemplate("${ifType}"); ifIndexResourceType.addColumn(".1.3.6.1.2.1.2.2.1.2", "ifDescr", "string"); ifIndexResourceType.addColumn(".1.3.6.1.2.1.2.2.1.6", "ifPhysAddr", "string", "1x:"); ifIndexResourceType.addColumn(".1.3.6.1.2.1.2.2.1.3", "ifType", "string"); ifIndexResourceType.addColumn(".1.3.6.1.2.1.31.1.1.1.1", "ifName", "string"); m_currentSnmpCollection = new SnmpCollectionImpl(collection.getName()); m_currentDataCollectionGroup = new DataCollectionGroupImpl(collection.getName() + "-all"); m_currentSnmpCollection.addDataCollectionGroup(m_currentDataCollectionGroup); m_currentDataCollectionGroup.addResourceType(ifIndexResourceType); }
@Override public boolean save() { SnmpCollection snmpCollection = snmpCollectionForm.getSnmpCollection(); logger.info("SNMP Collection " + snmpCollection.getName() + " has been " + (isNew ? "created." : "updated.")); String oldName = snmpCollection.getName(); Integer oldStep = snmpCollection.getRrd().getStep(); try { snmpCollectionForm.commit(); snmpCollectionForm.setReadOnly(true); snmpCollectionTable.refreshRowCache(); saveSnmpCollections(snmpCollectionTable.getSnmpCollections(), logger); if (!isNew && !oldName.equals(snmpCollectionForm.getSnmpCollectionName())) { Notification.show("Be sure to replace " + oldName + " with " + snmpCollectionForm.getSnmpCollectionName() + " in case the collection is being used in collectd-configuration.xml", Notification.Type.WARNING_MESSAGE); // TODO Is this enough } if (!isNew && oldStep != snmpCollectionForm.getRrdStep()) { Notification.show("Be sure to replace the collection interval from " + oldStep + "s with " + snmpCollectionForm.getRrdStep() + "s in case the collection is being used in collectd-configuration.xml", Notification.Type.WARNING_MESSAGE); // TODO Is this enough } } catch (CommitException e) { String msg = "Can't save the changes: " + e.getMessage(); logger.error(msg); Notification.show(msg, Notification.Type.ERROR_MESSAGE); return false; } return true; } @Override
LOG.info("parse: SNMP collection {} doesn't have any external reference.", collection.getName());
public IDataCollectionConfig toDataCollectionConfig() { final DatacollectionConfig modifiable = new DatacollectionConfig(); modifiable.setRrdRepository(this.getRrdRepository()); final String resourceTypeName = "__resource_type_collection"; final SnmpCollection resourceTypeCollection = this.getSnmpCollection(resourceTypeName); for (final SnmpCollection collection : this.getSnmpCollections()) { if (resourceTypeName.equals(collection.getName())) { // skip the special case collection continue; } final SnmpCollection cloned = collection.clone(); // DefaultDataCollectionConfigDao already does all the include work, so don't pass them along cloned.setIncludeCollections(EMPTY_INCLUDE_LIST); if (resourceTypeCollection != null) { cloned.setResourceTypes(resourceTypeCollection.getResourceTypes()); } modifiable.addSnmpCollection(cloned); } final DataCollectionConfigConverter converter = new DataCollectionConfigConverter(); modifiable.visit(converter); return converter.getDataCollectionConfig(); }
@Override public SnmpCollection clone() { final SnmpCollection newCollection = new SnmpCollection(); newCollection.setGroups(getGroups()); newCollection.setIncludeCollections(getIncludeCollections()); newCollection.setMaxVarsPerPdu(getMaxVarsPerPdu()); newCollection.setName(getName()); newCollection.setResourceTypes(getResourceTypes()); newCollection.setRrd(getRrd()); newCollection.setSnmpStorageFlag(getSnmpStorageFlag()); newCollection.setSystems(getSystems()); return newCollection; } }