public void start(String[] args) throws Exception { ProbeDesc<OID> pd = new ProbeDesc<>(); pd.setProbeClass(jrds.probe.snmp.RdsSnmpSimple.class); boolean indexed = false;
static public <KeyType> ProbeDesc<KeyType> getPd() { ProbeDesc<KeyType> pd = new ProbeDesc<KeyType>(); Map<String, Object> dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "sun"); dsMap.put("dsType", DsType.GAUGE); pd.add(dsMap); dsMap.clear(); dsMap.put("dsName", "shade"); dsMap.put("dsType", DsType.GAUGE); pd.add(dsMap); pd.setName(FILE); pd.setProbeName(FILE); return pd; }
protected <KeyType> ProbeDesc<KeyType> generateProbeDesc(String type) { ProbeDesc<KeyType> pd = new ProbeDesc<>(); pd.setName(type); pd.setProbeName("dummyprobe"); Map<String, Object> dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds0"); dsMap.put("dsType", DsType.COUNTER); dsMap.put("collectKey", "/jrdsstats/stat[@key='a']/@value"); pd.add(dsMap); dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds1"); dsMap.put("dsType", DsType.COUNTER); dsMap.put("collectKey", "/jrdsstats/stat[@key='b']/@value"); pd.add(dsMap); dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds2"); dsMap.put("dsType", DsType.COUNTER); pd.add(dsMap); return pd; }
public void start(String[] args) throws Exception { ProbeDesc<OID> pd = new ProbeDesc<>(); pd.setProbeClass(jrds.probe.snmp.RdsSnmpSimple.class); List<String> xmlPaths = new ArrayList<>();
public TestHttpProbe() { ProbeDesc<String> pd = new ProbeDesc<>(); pd.setName("ApacheHttpClientTester"); pd.add("test", DsType.COUNTER); setPd(pd); }
static public ProbeDesc<String> getPd() { ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setName("MokeProbeDesc"); pd.setProbeName("mokeprobedesc"); pd.add("MokeDs", DsType.COUNTER); return pd; }
public void configure() throws InvocationTargetException { Map<String, String> empty = Collections.emptyMap(); setMainStore(new RrdDbStoreFactory(), empty); ProbeDesc<String> pd = new ProbeDesc<>(); pd.setName("DummyProbe"); pd.setProbeName("dummyprobe"); setPd(pd); if(getHost() == null) { HostInfo host = new HostInfo("DummyHost"); host.setHostDir(new File("tmp")); setHost(new HostStarter(host)); } Map<String, Object> dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds0"); dsMap.put("dsType", DsType.COUNTER); dsMap.put("collectKey", "/jrdsstats/stat[@key='a']/@value"); pd.add(dsMap); dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds1"); dsMap.put("dsType", DsType.COUNTER); dsMap.put("collectKey", "/jrdsstats/stat[@key='b']/@value"); pd.add(dsMap); dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds2"); dsMap.put("dsType", DsType.COUNTER); pd.add(dsMap); }
@Test public void enumerateProbe() throws IOException { PropertiesManager pm = Tools.makePm(testFolder, "autocreate=false", "strictparsing=true"); pm.update(); pm.libspath.clear(); File descpath = new File("desc"); if(descpath.exists()) pm.libspath.add(descpath.toURI()); ConfigObjectFactory conf = new ConfigObjectFactory(pm); Set<String> failed = new HashSet<String>(); for(JrdsDocument n: conf.getNodeMap(ConfigType.PROBEDESC).values()) { JrdsElement root = n.getRootElement(); JrdsElement classElem = root.getElementbyName("probeClass"); ProbeDesc<String> pd = new ProbeDesc<>(); String name = ""; try { String className = classElem.getTextContent().trim(); name = root.getElementbyName("name").getTextContent(); @SuppressWarnings("unchecked") Class<? extends Probe<String, ?>> c = (Class<? extends Probe<String, ?>>) pm.extensionClassLoader.loadClass(className); pd.setProbeClass(c); } catch (Exception e) { logger.error("Failed probedesc " + name + ": " + e.getMessage()); failed.add(name); } } if(!failed.isEmpty()) { Assert.fail("Invalid class:" + failed); } }
ProbeDesc<A> pd = getPd(); if(pd == null) { pd = new ProbeDesc<A>(); pd.setName(probeType); pd.setProbeName("dummyprobe");
@SuppressWarnings("unchecked") public <KeyType> ProbeDesc<KeyType> makeProbeDesc(JrdsDocument n) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException { ProbeDesc<KeyType> pd = new ProbeDesc<KeyType>();
@Test public void testDefault() throws Exception { ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setName("empty"); pd.setProbeName("empty");
@Test public void testHighLow() throws Exception { ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setName("empty"); pd.setProbeName("empty"); Map<String, Object> dsMap = new HashMap<String, Object>(); dsMap.put("dsName", "ds0"); dsMap.put("dsType", DsType.COUNTER); dsMap.put("collecthigh", "high"); dsMap.put("collectlow", "low"); pd.add(dsMap); GenerateProbe.ChainedMap<Object> args = GenerateProbe.ChainedMap.start(); args.set(ProbeDesc.class, pd).set(Probe.class, DummyProbe.class); @SuppressWarnings("unchecked") MokeProbe<String, Number> p = (MokeProbe<String, Number>) GenerateProbe.quickProbe(testFolder, args); HostStarter host = new HostStarter(new HostInfo("DummyHost")); host.setParent(Tools.getDefaultTimer()); host.getHost().setHostDir(testFolder.newFolder("testDefault")); p.setHost(host); p.configure(); Assert.assertTrue("Failed to create storage", p.checkStore()); Map<String, Number> val = new HashMap<String, Number>(); long high = 255L; long low = 64L; val.put("high", high); val.put("low", low); p.injectValues(val); p.collect(); Assert.assertEquals("32 + 32 to 64 failed", (high << 32) + low, p.getLastValues().get("ds0").doubleValue(), 0.1); }
@SuppressWarnings("unchecked") @Test public void build5() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { HttpProbe<String> p = new HttpProbe<String>() { @Override protected Map<String, Number> parseStream(InputStream stream) { return null; } }; ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setProbeClass((Class<? extends Probe<String, ?>>) p.getClass()); p.setHost(webserver); p.setPd(pd); p.setFile("/${1}"); p.setPort(80); List<Object> args = Arrays.asList((Object) "file"); Assert.assertTrue(p.configure(args)); Assert.assertEquals("http://" + HOST + ":80/file", p.getUrlAsString()); validateBean(p); }
@SuppressWarnings("unchecked") @Test public void build3() throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { HttpProbe<String> p = new HttpProbe<String>() { @Override protected Map<String, Number> parseStream(InputStream stream) { return null; } }; p.setHost(webserver); ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setProbeClass((Class<? extends Probe<String, ?>>) p.getClass()); p.setPd(pd); p.setFile("/file"); p.setPort(81); Assert.assertTrue(p.configure()); Assert.assertEquals("http://" + HOST + ":81/file", p.getUrlAsString()); Assert.assertEquals("http://" + HOST + ":81/file", pd.getBean("url").get(p).toString()); validateBean(p); }
@SuppressWarnings("unchecked") @Test public void build2() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { HttpProbe<String> p = new HttpProbe<String>() { @Override protected Map<String, Number> parseStream(InputStream stream) { return null; } }; p.setHost(webserver); ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setProbeClass((Class<? extends Probe<String, ?>>) p.getClass()); p.setPd(pd); p.setFile("/file"); p.setPort(80); Assert.assertTrue(p.configure("/file")); Assert.assertEquals("http://" + HOST + ":80/file", p.getUrlAsString()); validateBean(p); }
@SuppressWarnings("unchecked") @Test public void build1() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { HttpProbe<String> p = new HttpProbe<String>() { @Override protected Map<String, Number> parseStream(InputStream stream) { return null; } }; ProbeDesc<String> pd = new ProbeDesc<>(); pd.setProbeClass((Class<? extends Probe<String, ?>>) p.getClass()); p.setHost(webserver); p.setPd(pd); p.setFile("/"); p.setPort(80); Assert.assertTrue(p.configure()); Assert.assertEquals("http://" + HOST + ":80/", p.getUrlAsString()); validateBean(p); }
@Test public void testBean() throws IOException, InvocationTargetException, IllegalArgumentException, IllegalAccessException { RRDToolProbe p = new RRDToolProbe(); p.setHost(new HostStarter(new HostInfo("toto"))); ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setProbeClass(p.getClass()); pd.setName("Rrdtool"); pd.setProbeName("rrdtool"); p.setPd(pd); p.setRrdfile(rrdfile); Assert.assertEquals("invalid rrdfile bean", p.getRrdfile(), pd.getBean("rrdfile").get(p)); Assert.assertEquals("invalid rrdfile bean template ", p.getRrdfile().toString(), Util.parseTemplate("${attr.rrdfile}", p)); }
@Test public void test1() throws IOException, InvocationTargetException { RRDToolProbe p = new RRDToolProbe(); p.setHost(new HostStarter(new HostInfo("toto"))); ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setName("Rrdtool"); pd.setProbeName("rrdtool"); p.setPd(pd); Map<String, String> empty = Collections.emptyMap(); p.setMainStore(new RrdDbStoreFactory(), empty); Assert.assertTrue("rrd native file can't be read", rrdfile.canRead()); Assert.assertTrue("Configuration of the probe failed", p.configure(rrdfile)); Assert.assertTrue("Check of the probe failed", p.checkStore()); GraphDesc gd = new GraphDesc(); gd.setGraphName("rrdtool"); gd.setName("rrdtool"); gd.add("speed", "speed", null, GraphDesc.LINE, Color.BLUE, "speed", GraphDesc.DEFAULTCF, false, null, null, null); gd.add("weight", "weight", null, GraphDesc.LINE, Color.GREEN, "weight", GraphDesc.DEFAULTCF, false, null, null, null); p.addGraph(gd); for(GraphNode gn: p.getGraphList()) { Graph g = gn.getGraph(); g.setEnd(new Date(end * 1000)); g.setStart(new Date(start * 1000)); File outputFile = new File(testFolder.getRoot(), "rrdtool.png"); OutputStream out = new FileOutputStream(outputFile); g.writePng(out); Assert.assertTrue("graph not created", outputFile.canRead()); } }
ProbeDesc<String> pd = (ProbeDesc<String>) args.get(ProbeDesc.class.getCanonicalName()); if(pd == null) { pd = new ProbeDesc<String>();
@SuppressWarnings("unchecked") @Test public void build4() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { HttpProbe<String> p = new HttpProbe<String>() { @Override protected Map<String, Number> parseStream(InputStream stream) { return null; } }; ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setProbeClass((Class<? extends Probe<String, ?>>) p.getClass()); p.setHost(webserver); p.setPd(pd); p.setFile("/"); p.setPort(80); p.setLogin("login@domain"); p.setPassword("password"); Assert.assertTrue(p.configure()); Assert.assertEquals("http://login%40domain:password@" + HOST + ":80/", p.getUrlAsString()); validateBean(p); }