Skip to content

Commit

Permalink
Some collect in probe desc can now be marked as optional, to prevent …
Browse files Browse the repository at this point in the history
…useless log
  • Loading branch information
fbacchella committed Apr 23, 2015
1 parent e8aa005 commit 6d98e1c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
5 changes: 4 additions & 1 deletion dtd/probedesc.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@
<!ELEMENT probeClass (#PCDATA)>
<!ELEMENT probeName (#PCDATA)>
<!ELEMENT snmpRequester (#PCDATA)>
<!ELEMENT collect (#PCDATA)>
<!ELEMENT collect (#PCDATA)>
<!ATTLIST collect
optional (true|false) "false"
>
27 changes: 25 additions & 2 deletions junit/jrds/configuration/TestProbeDescBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@ public void testFullConfigpath() throws Exception {
PropertiesManager localpm = Tools.makePm();
ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader);
conf.getNodeMap(ConfigType.PROBEDESC).put("name", Tools.parseRessource("httpxmlprobedesc.xml"));
Assert.assertNotNull("Probedesc not build", conf.setProbeDescMap().get("name"));

ProbeDesc pd = conf.setProbeDescMap().get("name");
Assert.assertNotNull("Probedesc not build", pd);
}

@Test
public void testOptional() throws Exception {
PropertiesManager localpm = Tools.makePm();
ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader);
JrdsDocument pddoc = Tools.parseRessource("httpxmlprobedesc.xml");
pddoc.getRootElement().getElementbyName("probeClass").setTextContent("jrds.mockobjects.MokeProbeBean");

conf.getNodeMap(ConfigType.PROBEDESC).put("name", pddoc);

ProbeDesc pd = conf.setProbeDescMap().get("name");
Assert.assertNotNull("Probedesc not build", pd);

@SuppressWarnings("unchecked")
Probe<String, String> p = (Probe<String, String>) pd.getProbeClass().getConstructor().newInstance();
p.setPd(pd);
p.setLabel("goodlabel");
Assert.assertTrue("optional resolution broken", p.isOptional("goodlabel"));
}

@Test
Expand All @@ -60,7 +81,8 @@ public void testCustomBeans() throws Exception {
Assert.assertNotNull("custom bean customattr1 not found", pd.getBean("customattr1"));
Assert.assertNotNull("custom bean customattr2 not found", pd.getBean("customattr2"));

Probe<?,?> p = pd.getProbeClass().getConstructor().newInstance();
@SuppressWarnings("unchecked")
Probe<String, String> p = (Probe<String, String>) pd.getProbeClass().getConstructor().newInstance();
p.setPd(pd);
pd.getBean("customattr1").set(p, "value1");
pd.getBean("customattr2").set(p, "value2");
Expand All @@ -70,5 +92,6 @@ public void testCustomBeans() throws Exception {

Assert.assertEquals("value1", Util.parseTemplate("${attr.customattr1}", p));
Assert.assertEquals("value2", Util.parseTemplate("${attr.customattr2}", p));

}
}
7 changes: 6 additions & 1 deletion junit/ressources/httpxmlprobedesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
<ds>
<dsName>d</dsName>
<dsType>counter</dsType>
<collect>%2$s</collect>
<collect optional="false">%2$s</collect>
</ds>
<ds>
<dsName>e</dsName>
<dsType>counter</dsType>
<collect optional="true">${label}</collect>
</ds>
<graphs>
</graphs>
</probedesc>
10 changes: 10 additions & 0 deletions src/jrds/Probe.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ public Map<KeyType, String> getCollectMapping() {
}
return retValues;
}

/**
* Return true if is collect key was marked optionnal in the probe description
*
* @param collect
* @return
*/
public boolean isOptional(KeyType collect ) {
return getPd().isOptional(getCollectMapping().get(collect));
}

/**
* Return an new sample with collected values
Expand Down
9 changes: 7 additions & 2 deletions src/jrds/ProbeDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static class DefaultBean {
private float uptimefactor = (float) 1.0;
private Map<String, Double> defaultValues = new HashMap<String,Double>(0);
private Map<String, GenericBean> beans = new HashMap<String, GenericBean>(0);
private final Set<Object> optionals = new HashSet<Object>(0);
private final Set<String> optionals = new HashSet<String>(0);

private static final class DsDesc {
public DsType dsType;
Expand Down Expand Up @@ -504,7 +504,12 @@ public Object clone() throws CloneNotSupportedException {
return newpd;
}

public boolean isOptional(Object dsName){
/**
* Return true if the given datasource was associated with an optional collect string
* @param dsName
* @return
*/
boolean isOptional(String dsName){
return optionals.contains(dsName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/jrds/probe/JMX.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Map<String, Double> getNewSampleValuesConnected(JMXConnection cnx) {
log(Level.ERROR, e1, "Invalide JMX attribue %s", attributeName);
} catch (InstanceNotFoundException e1) {
Level l = Level.ERROR;
if (getPd().isOptional(getCollectMapping().get(collect))) {
if(isOptional(collect)) {
l = Level.DEBUG;
}
log(l, "JMX instance not found: %s", e1.getMessage());
Expand Down

0 comments on commit 6d98e1c

Please sign in to comment.