@SuppressWarnings("deprecation") @Test public void testThresholdWithGenericResourceTypes() throws Exception { System.err.println("--------------------------------------------------------"); System.setProperty("org.opennms.rrd.storeByGroup", "true"); ThresholdGroup group = m_thresholdsDao.get("generic-snmp"); assertEquals(2, group.getGenericResourceTypeMap().get("frCircuitIfIndex").getThresholdMap().size()); File path = m_fileAnticipator.getTempDir(); File nodeDir = m_fileAnticipator.tempDir(path, "1"); File rtDir = m_fileAnticipator.tempDir(nodeDir, "frCircuitIfIndex"); Properties strings = new Properties(); long start = System.currentTimeMillis(); List<String> sources = new ArrayList<String>(); sources.add("frSentFrames"); sources.add("frSentOctets"); sources.add("frReceivedFrames"); sources.add("frReceivedOctets"); File r1Dir = m_fileAnticipator.tempDir(rtDir, "Se0.100"); File rrd1 = m_fileAnticipator.tempFile(r1Dir, "rfc1315-frame-relay.jrb"); createDsProperties(r1Dir, sources, "rfc1315-frame-relay"); strings.setProperty("frName", "caracas"); strings.setProperty("frDlci", "100"); strings.setProperty("frIntf", "0"); File sFile1 = m_fileAnticipator.tempFile(r1Dir, "strings.properties"); m_out = new FileOutputStream(sFile1); strings.store(m_out, null); m_out.close(); List<String> data1 = new ArrayList<String>(); data1.add("100:200:300:350"); createAndUpdateRrd(rrd1, start, sources, data1); File r2Dir = m_fileAnticipator.tempDir(rtDir, "Se1.200"); File rrd2 = m_fileAnticipator.tempFile(r2Dir, "rfc1315-frame-relay.jrb"); createDsProperties(r2Dir, sources, "rfc1315-frame-relay"); strings.setProperty("frDlci", "200"); strings.setProperty("frIntf", "1"); File sFile2 = m_fileAnticipator.tempFile(r2Dir, "strings.properties"); m_out = new FileOutputStream(sFile2); strings.store(m_out, null); m_out.close(); List<String> data2 = new ArrayList<String>(); data2.add("50:150:400:300"); createAndUpdateRrd(rrd2, start, sources, data2); m_thresholdInterface.getThresholdConfiguration().setThresholdGroup(group); Events events = new Events(); m_snmpThresholder.checkResourceDir(rtDir, m_thresholdInterface, new Date(start), events); assertEquals(2, events.getEventCount()); for (Event e : events.getEvent()) { assertEquals("label", e.getParmCollection().get(9).getParmName()); assertEquals("caracas", e.getParmCollection().get(9).getValue().getContent()); } }
protected void checkResourceDir(File directory, SnmpThresholdNetworkInterface snmpIface, Date date, Events events) throws IllegalArgumentException { if (directory == null || snmpIface.getNodeId() == null || snmpIface.getInetAddress() == null || date == null || events == null) { throw new IllegalArgumentException("Null parameters not permitted."); } if (log().isDebugEnabled()) { log().debug("checkResourceDir: threshold checking generic resource dir: " + directory.getAbsolutePath()); } String resourceType = directory.getName(); if (!directory.exists()) { log().debug("Aborting check because this node does not support Resource Type " + resourceType); return; } SnmpThresholdConfiguration config = snmpIface.getThresholdConfiguration(); if (log().isDebugEnabled()) { log().debug("checkResourceDir: group=" + config.getGroupName() + ", resourceType=" + resourceType); } ThresholdResourceType thresholdResourceType = config.getGenericResourceTypeMap().get(resourceType); if (thresholdResourceType == null) { log().info("No generic resources for group " + config.getGroupName()); return; } Map<String, Set<ThresholdEntity>> thresholdMap = thresholdResourceType.getThresholdMap(); File[] files = directory.listFiles(); for (File file : files) { String resource = file.getName(); for(String threshKey :thresholdMap.keySet()) { if (log().isDebugEnabled()) { log().debug("checkResourceDir: resource=" + resource); } for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { String dsLabelValue = getDataSourceLabel(file, snmpIface, thresholdEntity); processThresholdForResource(file, snmpIface, date, events, thresholdEntity, dsLabelValue); } } } }
SnmpThresholder implements ServiceThresholder { protected void checkResourceDir(File directory, SnmpThresholdNetworkInterface snmpIface, Date date, Events events) throws IllegalArgumentException { if (directory == null || snmpIface.getNodeId() == null || snmpIface.getInetAddress() == null || date == null || events == null) { throw new IllegalArgumentException("Null parameters not permitted."); } if (log().isDebugEnabled()) { log().debug("checkResourceDir: threshold checking generic resource dir: " + directory.getAbsolutePath()); } String resourceType = directory.getName(); if (!directory.exists()) { log().debug("Aborting check because this node does not support Resource Type " + resourceType); return; } SnmpThresholdConfiguration config = snmpIface.getThresholdConfiguration(); if (log().isDebugEnabled()) { log().debug("checkResourceDir: group=" + config.getGroupName() + ", resourceType=" + resourceType); } ThresholdResourceType thresholdResourceType = config.getGenericResourceTypeMap().get(resourceType); if (thresholdResourceType == null) { log().info("No generic resources for group " + config.getGroupName()); return; } Map<String, Set<ThresholdEntity>> thresholdMap = thresholdResourceType.getThresholdMap(); File[] files = directory.listFiles(); for (File file : files) { String resource = file.getName(); for(String threshKey :thresholdMap.keySet()) { if (log().isDebugEnabled()) { log().debug("checkResourceDir: resource=" + resource); } for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { String dsLabelValue = getDataSourceLabel(file, snmpIface, thresholdEntity); processThresholdForResource(file, snmpIface, date, events, thresholdEntity, dsLabelValue); } } } } }
SnmpThresholder implements ServiceThresholder { protected void checkResourceDir(File directory, SnmpThresholdNetworkInterface snmpIface, Date date, Events events) throws IllegalArgumentException { if (directory == null || snmpIface.getNodeId() == null || snmpIface.getInetAddress() == null || date == null || events == null) { throw new IllegalArgumentException("Null parameters not permitted."); } if (log().isDebugEnabled()) { log().debug("checkResourceDir: threshold checking generic resource dir: " + directory.getAbsolutePath()); } String resourceType = directory.getName(); if (!directory.exists()) { log().debug("Aborting check because this node does not support Resource Type " + resourceType); return; } SnmpThresholdConfiguration config = snmpIface.getThresholdConfiguration(); if (log().isDebugEnabled()) { log().debug("checkResourceDir: group=" + config.getGroupName() + ", resourceType=" + resourceType); } ThresholdResourceType thresholdResourceType = config.getGenericResourceTypeMap().get(resourceType); if (thresholdResourceType == null) { log().info("No generic resources for group " + config.getGroupName()); return; } Map<String, Set<ThresholdEntity>> thresholdMap = thresholdResourceType.getThresholdMap(); File[] files = directory.listFiles(); for (File file : files) { String resource = file.getName(); for(String threshKey :thresholdMap.keySet()) { if (log().isDebugEnabled()) { log().debug("checkResourceDir: resource=" + resource); } for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { String dsLabelValue = getDataSourceLabel(file, snmpIface, thresholdEntity); processThresholdForResource(file, snmpIface, date, events, thresholdEntity, dsLabelValue); } } } }  }
SnmpThresholder implements ServiceThresholder { protected void checkResourceDir(File directory, SnmpThresholdNetworkInterface snmpIface, Date date, Events events) throws IllegalArgumentException { if (directory == null || snmpIface.getNodeId() == null || snmpIface.getInetAddress() == null || date == null || events == null) { throw new IllegalArgumentException("Null parameters not permitted."); } if (log().isDebugEnabled()) { log().debug("checkResourceDir: threshold checking generic resource dir: " + directory.getAbsolutePath()); } String resourceType = directory.getName(); if (!directory.exists()) { log().debug("Aborting check because this node does not support Resource Type " + resourceType); return; } SnmpThresholdConfiguration config = snmpIface.getThresholdConfiguration(); if (log().isDebugEnabled()) { log().debug("checkResourceDir: group=" + config.getGroupName() + ", resourceType=" + resourceType); } ThresholdResourceType thresholdResourceType = config.getGenericResourceTypeMap().get(resourceType); if (thresholdResourceType == null) { log().info("No generic resources for group " + config.getGroupName()); return; } Map<String, Set<ThresholdEntity>> thresholdMap = thresholdResourceType.getThresholdMap(); File[] files = directory.listFiles(); for (File file : files) { String resource = file.getName(); for(String threshKey :thresholdMap.keySet()) { if (log().isDebugEnabled()) { log().debug("checkResourceDir: resource=" + resource); } for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { String dsLabelValue = getDataSourceLabel(file, snmpIface, thresholdEntity); processThresholdForResource(file, snmpIface, date, events, thresholdEntity, dsLabelValue); } } } }  String serviceName(); void initialize(Map<?,?> parameters); void reinitialize(); void release(); void initialize(ThresholdNetworkInterface netIface, Map<?,?> parms); void release(ThresholdNetworkInterface iface); int check(ThresholdNetworkInterface netIface, EventProxy eproxy, Map<?,?> parms); ThresholdsDao getThresholdsDao(); void setThresholdsDao(ThresholdsDao thresholdsDao); IfInfoGetter getIfInfoGetter(); void setIfInfoGetter(IfInfoGetter ifInfoGetter); }
SnmpThresholder implements ServiceThresholder { protected void checkResourceDir(File directory, SnmpThresholdNetworkInterface snmpIface, Date date, Events events) throws IllegalArgumentException { if (directory == null || snmpIface.getNodeId() == null || snmpIface.getInetAddress() == null || date == null || events == null) { throw new IllegalArgumentException("Null parameters not permitted."); } if (log().isDebugEnabled()) { log().debug("checkResourceDir: threshold checking generic resource dir: " + directory.getAbsolutePath()); } String resourceType = directory.getName(); if (!directory.exists()) { log().debug("Aborting check because this node does not support Resource Type " + resourceType); return; } SnmpThresholdConfiguration config = snmpIface.getThresholdConfiguration(); if (log().isDebugEnabled()) { log().debug("checkResourceDir: group=" + config.getGroupName() + ", resourceType=" + resourceType); } ThresholdResourceType thresholdResourceType = config.getGenericResourceTypeMap().get(resourceType); if (thresholdResourceType == null) { log().info("No generic resources for group " + config.getGroupName()); return; } Map<String, Set<ThresholdEntity>> thresholdMap = thresholdResourceType.getThresholdMap(); File[] files = directory.listFiles(); for (File file : files) { String resource = file.getName(); for(String threshKey :thresholdMap.keySet()) { if (log().isDebugEnabled()) { log().debug("checkResourceDir: resource=" + resource); } for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { String dsLabelValue = getDataSourceLabel(file, snmpIface, thresholdEntity); processThresholdForResource(file, snmpIface, date, events, thresholdEntity, dsLabelValue); } } } }  String serviceName(); void initialize(Map<?,?> parameters); void reinitialize(); void release(); void initialize(ThresholdNetworkInterface netIface, Map<?,?> parms); void release(ThresholdNetworkInterface iface); int check(ThresholdNetworkInterface netIface, EventProxy eproxy, Map<?,?> parms); ThresholdsDao getThresholdsDao(); void setThresholdsDao(ThresholdsDao thresholdsDao); IfInfoGetter getIfInfoGetter(); void setIfInfoGetter(IfInfoGetter ifInfoGetter);  }