@Override public void visitGroup(final Group group) { //LOG.debug("visitGroup({})", group); m_groupName = group.getName(); }
/** * Verify if the groups list contains a specific group. * <p>One group will be considered the same as another one, if they have the same name.</p> * * @param globalContainer * @param group * @return true, if the list contains the mib object group */ private boolean contains(Collection<Group> groups, Group group) { for (Group g : groups) { if (group.getName().equals(g.getName())) return true; } return false; }
/** * Get a MIB object group from datacollection-group map. * * @param groupName the group name * @param dataCollectionGroupName the data collection group name * @return the group object */ private Group getMibObjectGroup(String groupName, String dataCollectionGroupName) { if (dataCollectionGroupName != null) { DatacollectionGroup dataGroup = externalGroupsMap.get(dataCollectionGroupName); if (dataGroup != null) { for (Group g : dataGroup.getGroups()) { if (g.getName().equals(groupName)) { return g; } } } } for (DatacollectionGroup group : externalGroupsMap.values()) { for (Group g : group.getGroups()) { if (g.getName().equals(groupName)) { return g; } } } return null; }
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); } } } } }
@Override public boolean delete() { Object groupId = groupTable.getValue(); if (groupId != null) { Group group = groupTable.getGroup(groupId); Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be deleted because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } logger.info("SNMP Group " + group.getName() + " has been removed."); groupTable.select(null); groupTable.removeItem(groupId); groupTable.refreshRowCache(); } return true; } @Override
@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; }
if (groups != null) { for (final Group group : groups.getGroups()) { groupMap.put(group.getName(), group);
@Override public boolean delete() { Object groupId = groupTable.getValue(); if (groupId != null) { Group group = groupTable.getGroup(groupId); Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be deleted because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } logger.info("SNMP Group " + group.getName() + " has been removed."); groupTable.select(null); groupTable.removeItem(groupId); groupTable.refreshRowCache(); } return true; } @Override
@Override public boolean save() { Group group = groupForm.getGroup(); if (!isNew && !group.getName().equals(groupForm.getGroupName())) { Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be renamed because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } } logger.info("SNMP Group " + group.getName() + " has been " + (isNew ? "created." : "updated.")); try { groupForm.commit(); groupForm.setReadOnly(true); groupTable.refreshRowCache(); return true; } catch (CommitException e) { String msg = "Can't save the changes: " + e.getMessage(); logger.error(msg); Notification.show(msg, Notification.Type.ERROR_MESSAGE); return false; } } @Override
@Override public boolean save() { Group group = groupForm.getGroup(); if (!isNew && !group.getName().equals(groupForm.getGroupName())) { Set<String> systemDefMap = getParentSystemDefs(dataCollectionConfigDao, group.getName()); if (!systemDefMap.isEmpty()) { final String msg = "The group cannot be renamed because it is being referenced by:\n" + systemDefMap.toString(); Notification.show(msg, Notification.Type.WARNING_MESSAGE); return false; } } logger.info("SNMP Group " + group.getName() + " has been " + (isNew ? "created." : "updated.")); try { groupForm.commit(); groupForm.setReadOnly(true); groupTable.refreshRowCache(); return true; } catch (CommitException e) { String msg = "Can't save the changes: " + e.getMessage(); logger.error(msg); Notification.show(msg, Notification.Type.ERROR_MESSAGE); return false; } } @Override
LOG.debug("processGroupName: OIDs from group '{}:{}' are included for ifType: {}", group.getName(), group.getIfType(), ifType); processObjectList(groupName, groupIfType, group.getMibObjs(), mibObjectList); } else { LOG.debug("processGroupName: OIDs from group '{}:{}' are excluded for ifType: {}", group.getName(), group.getIfType(), ifType);
/** * 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 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; }
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);
/** * 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}"); type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy")); // To avoid requires opennms-services type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName())); data.addResourceType(type); } data.addGroup(group); return group; }
/** * 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}"); type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy")); // To avoid requires opennms-services type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName())); data.addResourceType(type); } data.addGroup(group); return group; }
groupNames.add(group.getName());
groupNames.add(group.getName());