@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; } }
/** * Verify the sub-groups of SNMP collection. * * @param collection */ private void checkCollection(SnmpCollection collection) { if (collection.getSystems() == null) collection.setSystems(new Systems()); if (collection.getGroups() == null) collection.setGroups(new Groups()); }
private void doVisit(SnmpCollection snmpCollection, DataCollectionVisitor visitor) { visitor.visitSnmpCollection(snmpCollection); // rrd block doVisit(snmpCollection.getRrd(), visitor); // loop over systems doVisit(snmpCollection.getSystems(), visitor); // loop over groups doVisit(snmpCollection.getGroups(), visitor); visitor.completeSnmpCollection(snmpCollection); }
final SnmpCollection resourceTypeCollection = new SnmpCollection(); resourceTypeCollection.setName("__resource_type_collection"); parser.parseCollection(collection); for (final ResourceType rt : collection.getResourceTypes()) { resourceTypeCollection.addResourceType(rt); resourceTypes.put(rt.getName(), rt); collection.setResourceTypes(new ArrayList<ResourceType>()); for (IncludeCollection include : collection.getIncludeCollections()) { if (include.getDataCollectionGroup() != null) { DatacollectionGroup group = externalGroupMap.get(include.getDataCollectionGroup()); for (final ResourceType rt : group.getResourceTypes()) { resourceTypeCollection.addResourceType(rt); resourceTypes.put(rt.getName(), rt); resourceTypeCollection.setGroups(new Groups()); resourceTypeCollection.setSystems(new Systems()); config.insertSnmpCollection(resourceTypeCollection); dataCollectionGroups.clear();
/** * 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; }
/** * 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; }
LOG.debug("addSystemDef: merging system defintion {} into snmp-collection {}", systemDef.getName(), collection.getName()); if (contains(collection.getSystems().getSystemDefs(), systemDef)) { LOG.warn("addSystemDef: system definition {} from data collection group {} already exist on SNMP collection {}", systemDef.getName(), dcGroup, collection.getName()); } else { LOG.debug("addSystemDef: adding system definition {} from data collection group {} to snmp-collection {}", systemDef.getName(), dcGroup, collection.getName()); collection.getSystems().addSystemDef(systemDef); LOG.warn("addSystemDef: group {} does not exist on any data collection group", groupName); } else { if (contains(collection.getGroups().getGroups(), group)) { LOG.debug("addSystemDef: group {} already exist on SNMP collection {}", groupName, collection.getName()); } else { LOG.debug("addSystemDef: adding mib object group {} from data collection group {} to snmp-collection {}", group.getName(), dcGroup, collection.getName()); collection.getGroups().addGroup(group);
public SnmpCollection getSnmpCollection(final String name) { for (final SnmpCollection collection : m_snmpCollections) { if (name.equals(collection.getName())) { return collection; } } return null; }
@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
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(); }
snmpCollection.setGroups(null); snmpCollection.setSystems(null);
@Override public List<String> getAvailableSystemDefs() { List<String> systemDefs = new ArrayList<>(); for (final SnmpCollection collection : getContainer().getObject().getSnmpCollections()) { if (collection.getSystems() != null) { for (final SystemDef systemDef : collection.getSystems().getSystemDefs()) { systemDefs.add(systemDef.getName()); } } } return systemDefs; }
if (collection.getIncludeCollections().size() > 0) { parseExternalResources(); checkCollection(collection); for (IncludeCollection include : collection.getIncludeCollections()) { if (include.getDataCollectionGroup() != null) { LOG.info("parse: SNMP collection {} doesn't have any external reference.", collection.getName());
@Override public int getStep(final String collectionName) { final SnmpCollection collection = getSnmpCollection(getContainer(), collectionName); return collection == null ? -1 : collection.getRrd().getStep(); }
/** * 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); } } }
@Override public List<String> getAvailableMibGroups() { List<String> groups = new ArrayList<>(); for (final SnmpCollection collection : getContainer().getObject().getSnmpCollections()) { if (collection.getGroups() != null) { for (final Group group : collection.getGroups().getGroups()) { groups.add(group.getName()); } } } return groups; }
/** * 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; }
private void validateResourceTypes(final Collection<SnmpCollection> snmpCollections, final Set<String> allowedResourceTypes) { final String configuredString; if (allowedResourceTypes.size() == 0) { configuredString = "(none)"; } else { configuredString = StringUtils.join(allowedResourceTypes, ", "); } final String allowableValues = "any positive number, 'ifIndex', or any of the configured resourceTypes: " + configuredString; for (final SnmpCollection collection : snmpCollections) { final Groups groups = collection.getGroups(); if (groups != null) { for (final Group group : groups.getGroups()) { for (final MibObj mibObj : group.getMibObjs()) { final String instance = mibObj.getInstance(); if (instance == null) continue; if (MibObject.INSTANCE_IFINDEX.equals(instance)) continue; if (allowedResourceTypes.contains(instance)) continue; try { // Check to see if the value is a non-negative integer if (Integer.parseInt(instance.trim()) >= 0) { continue; } } catch (NumberFormatException e) {} // XXX this should be a better exception throw new IllegalArgumentException("instance '" + instance + "' invalid in mibObj definition for OID '" + mibObj.getOid() + "' in collection '" + collection.getName() + "' for group '" + group.getName() + "'. Allowable instance values: " + allowableValues); } } } } }
/** * 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; }