public void reinitialize() { reinitialize(false); }
public boolean hasThresholds(final String resourceTypeName, final String attributeName) { boolean ok = false; synchronized(m_thresholdGroups) { for (ThresholdGroup group : m_thresholdGroups) { Map<String,Set<ThresholdEntity>> entityMap = getEntityMap(group, resourceTypeName); if (entityMap != null) { for (final Entry<String, Set<ThresholdEntity>> entry : entityMap.entrySet()) { final Set<ThresholdEntity> value = entry.getValue(); for (final ThresholdEntity thresholdEntity : value) { final Collection<String> requiredDatasources = thresholdEntity.getRequiredDatasources(); if (requiredDatasources.contains(attributeName)) { ok = true; LOG.debug("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } else { LOG.trace("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } } } } } } return ok; }
/** * <p>initialize</p> * @throws ThresholdInitializationException */ protected void initialize() throws ThresholdInitializationException { final String logHeader = "initialize(nodeId=" + m_nodeId + ",ipAddr=" + m_hostAddress + ",svc=" + m_serviceName + ")"; final List<String> groupNameList = getThresholdGroupNames(m_nodeId, m_hostAddress, m_serviceName); synchronized(m_thresholdGroups) { m_thresholdGroups.clear(); for (final String groupName : groupNameList) { try { final ThresholdGroup thresholdGroup = m_thresholdsDao.get(groupName); if (thresholdGroup == null) { LOG.error("{}: Could not get threshold group with name {}", logHeader, groupName); } else { m_thresholdGroups.add(thresholdGroup); LOG.debug("{}: Adding threshold group: {}", logHeader, thresholdGroup); } } catch (Throwable e) { LOG.error("{}: Can't process threshold group {}", logHeader, groupName, e); // It should not throw an exception when we are unable to find the group, see NMS-3532 } } m_hasThresholds = !m_thresholdGroups.isEmpty(); } updateScheduledOutages(); }
/** * <p>Constructor for ThresholdingSet.</p> * * @param nodeId a int. * @param hostAddress a {@link java.lang.String} object. * @param serviceName a {@link java.lang.String} object. * @param repository a {@link org.opennms.netmgt.rrd.RrdRepository} object. * @param interval a long. * @throws ThresholdInitializationException */ public ThresholdingSet(int nodeId, String hostAddress, String serviceName, RrdRepository repository) throws ThresholdInitializationException { m_nodeId = nodeId; m_hostAddress = (hostAddress == null ? null : hostAddress.intern()); m_serviceName = (serviceName == null ? null : serviceName.intern()); m_repository = repository; initThresholdsDao(); initialize(); if (!m_initialized) { throw new ThresholdInitializationException("Failed to initialize thresholding set."); } }
final ThresholdingSet set = new ThresholdingSet(1, "127.0.0.1", "SNMP", new RrdRepository()); assertFalse(set.isNodeInOutage()); assertTrue(set.hasThresholds()); set.reinitialize(true); assertFalse(set.isNodeInOutage()); assertTrue(set.hasThresholds());
ThresholdingConfigFactory.reload(); initThresholdsDao(); mergeThresholdGroups(m_nodeId, m_hostAddress, m_serviceName); updateScheduledOutages(); } catch (final Exception e) { LOG.error("Failed to reinitialize thresholding set. Reverting to previous configuration.", e);
synchronized(m_thresholdGroups) { for (ThresholdGroup group : m_thresholdGroups) { Map<String,Set<ThresholdEntity>> entityMap = getEntityMap(group, resourceWrapper.getResourceTypeName()); if (entityMap != null) { for (final Entry<String, Set<ThresholdEntity>> entry : entityMap.entrySet()) { final Set<ThresholdEntity> value = entry.getValue(); for (final ThresholdEntity thresholdEntity : value) { if (passedThresholdFilters(resourceWrapper, thresholdEntity)) { LOG.info("applyThresholds: Processing threshold {} : {} on resource {}", key, thresholdEntity, resourceWrapper); Collection<String> requiredDatasources = thresholdEntity.getThresholdConfig().getRequiredDatasources();
/** {@inheritDoc} */ @Override protected boolean passedThresholdFilters(CollectionResourceWrapper resource, ThresholdEntity thresholdEntity) { if (resource.isAnInterfaceResource() && !resource.isValidInterfaceResource()) { LOG.info("passedThresholdFilters: Could not get data interface information for '{}' or this interface has an invalid ifIndex. Not evaluating threshold.", resource.getIfLabel()); return false; } return super.passedThresholdFilters(resource, thresholdEntity); }
LOG.debug("{}: Begin merging operation", logHeader); final List<String> existingGroupNameList = m_thresholdGroups.stream().map(ThresholdGroup::getName).collect(Collectors.toList()); List<String> newGroupNameList = getThresholdGroupNames(nodeId, hostAddress, serviceName);
@Test(expected=ThresholdInitializationException.class) public void testBadThresholdingConfigInitialize() throws Exception { System.setProperty("opennms.home", getClass().getResource("testBadThresholdingConfig").getFile()); PollOutagesConfigFactory.init(); new ThresholdingSet(1, "127.0.0.1", "SNMP", new RrdRepository()); }