@SuppressWarnings("deprecation") @Test public void testInterfaces() throws Exception { System.err.println("--------------------------------------------------------"); System.setProperty("org.opennms.rrd.storeByGroup", "true"); ThresholdGroup group = m_thresholdsDao.get("generic-snmp"); File path = m_fileAnticipator.getTempDir(); File nodeDir = m_fileAnticipator.tempDir(path, "1"); long start = System.currentTimeMillis(); List<String> sources = new ArrayList<String>(); sources.add("ifInOctets"); sources.add("ifOutOctets"); sources.add("ifInPackets"); sources.add("ifOutPackets"); File intf1Dir = m_fileAnticipator.tempDir(nodeDir, "eth0"); File rrd1 = m_fileAnticipator.tempFile(intf1Dir, "mib2-stats.jrb"); createDsProperties(intf1Dir, sources, "mib2-stats"); List<String> data1 = new ArrayList<String>(); data1.add("100:200:300:350"); createAndUpdateRrd(rrd1, start, sources, data1); File intf2Dir = m_fileAnticipator.tempDir(nodeDir, "wlan0"); File rrd2 = m_fileAnticipator.tempFile(intf2Dir, "mib2-stats.jrb"); createDsProperties(intf2Dir, sources, "mib2-stats"); 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(); Map<String,String> ifInfoEth0 = new HashMap<String,String>(); ifInfoEth0.put("snmpifindex", "1"); ifInfoEth0.put("snmpifdesc", "eth0"); ifInfoEth0.put("snmpifalias", "ethernet interface"); EasyMock.expect(m_ifInfoGetter.getIfInfoForNodeAndLabel(1, "eth0")).andReturn(ifInfoEth0).times(3); Map<String,String> ifInfoWlan0 = new HashMap<String,String>(); ifInfoWlan0.put("snmpifindex", "2"); ifInfoWlan0.put("snmpifdesc", "wlan0"); ifInfoWlan0.put("snmpifalias", "wireless interface"); EasyMock.expect(m_ifInfoGetter.getIfInfoForNodeAndLabel(1, "wlan0")).andReturn(ifInfoWlan0).times(3); m_mocks.replayAll(); m_snmpThresholder.checkIfDir(intf1Dir, m_thresholdInterface, new Date(start), events); m_snmpThresholder.checkIfDir(intf2Dir, m_thresholdInterface, new Date(start), events); m_mocks.verifyAll(); assertEquals(2, events.getEventCount()); }
protected void checkIfDir(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("checkIfDir: threshold checking interface dir: " + directory.getAbsolutePath()); } String ifLabel = directory.getName(); if (log().isDebugEnabled()) { log().debug("checkIfDir: ifLabel=" + ifLabel); } Map<String, Set<ThresholdEntity>> thresholdMap = snmpIface.getInterfaceThresholdMap(ifLabel); Map<String, String> ifDataMap = new HashMap<String, String>(); for(String threshKey :thresholdMap.keySet()) { for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { processThresholdForInterface(directory, snmpIface, date, events, thresholdEntity, ifLabel, ifDataMap); } } }
SnmpThresholder implements ServiceThresholder { protected void checkIfDir(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("checkIfDir: threshold checking interface dir: " + directory.getAbsolutePath()); } String ifLabel = directory.getName(); if (log().isDebugEnabled()) { log().debug("checkIfDir: ifLabel=" + ifLabel); } Map<String, Set<ThresholdEntity>> thresholdMap = snmpIface.getInterfaceThresholdMap(ifLabel); Map<String, String> ifDataMap = new HashMap<String, String>(); for(String threshKey :thresholdMap.keySet()) { for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { processThresholdForInterface(directory, snmpIface, date, events, thresholdEntity, ifLabel, ifDataMap); } } } }
SnmpThresholder implements ServiceThresholder { protected void checkIfDir(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("checkIfDir: threshold checking interface dir: " + directory.getAbsolutePath()); } String ifLabel = directory.getName(); if (log().isDebugEnabled()) { log().debug("checkIfDir: ifLabel=" + ifLabel); } Map<String, Set<ThresholdEntity>> thresholdMap = snmpIface.getInterfaceThresholdMap(ifLabel); Map<String, String> ifDataMap = new HashMap<String, String>(); for(String threshKey :thresholdMap.keySet()) { for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { processThresholdForInterface(directory, snmpIface, date, events, thresholdEntity, ifLabel, ifDataMap); } } }  }
SnmpThresholder implements ServiceThresholder { protected void checkIfDir(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("checkIfDir: threshold checking interface dir: " + directory.getAbsolutePath()); } String ifLabel = directory.getName(); if (log().isDebugEnabled()) { log().debug("checkIfDir: ifLabel=" + ifLabel); } Map<String, Set<ThresholdEntity>> thresholdMap = snmpIface.getInterfaceThresholdMap(ifLabel); Map<String, String> ifDataMap = new HashMap<String, String>(); for(String threshKey :thresholdMap.keySet()) { for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { processThresholdForInterface(directory, snmpIface, date, events, thresholdEntity, ifLabel, ifDataMap); } } }  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 checkIfDir(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("checkIfDir: threshold checking interface dir: " + directory.getAbsolutePath()); } String ifLabel = directory.getName(); if (log().isDebugEnabled()) { log().debug("checkIfDir: ifLabel=" + ifLabel); } Map<String, Set<ThresholdEntity>> thresholdMap = snmpIface.getInterfaceThresholdMap(ifLabel); Map<String, String> ifDataMap = new HashMap<String, String>(); for(String threshKey :thresholdMap.keySet()) { for (ThresholdEntity thresholdEntity : thresholdMap.get(threshKey)) { processThresholdForInterface(directory, snmpIface, date, events, thresholdEntity, ifLabel, ifDataMap); } } }  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);  }