protected Document makeDocument(XmlProvider xmlstarter) { Document ribclQ = xmlstarter.getDocument(); Element LOCFG = ribclQ.createElement("LOCFG"); LOCFG.setAttribute("version", "2.21"); ribclQ.appendChild(LOCFG); Element RIBCL = ribclQ.createElement("RIBCL"); LOCFG.appendChild(RIBCL); RIBCL.setAttribute("VERSION", "2.0"); Element LOGIN = ribclQ.createElement("LOGIN"); LOGIN.setAttribute("USER_LOGIN", user); LOGIN.setAttribute("PASSWORD", passwd); RIBCL.appendChild(LOGIN); Element command = ribclQ.createElement(getPd().getSpecific("command")); command.setAttribute("MODE", "read"); LOGIN.appendChild(command); Element subcommand = ribclQ.createElement(getPd().getSpecific("subcommand")); command.appendChild(subcommand); return ribclQ; }
public Boolean configure() { if(cmd == null) return false; String cmdargs = getPd().getSpecific("arguments"); if(cmdargs != null && !cmdargs.trim().isEmpty()) { cmd = cmd + " " + Util.parseTemplate(cmdargs, this); } return true; }
@Override public Boolean configure() { if("true".equalsIgnoreCase(getPd().getSpecific("mandatorySession"))) { mandatorySession = true; } return super.configure(); }
protected String resolvCmdPath(String path) { List<String> pathelements = new ArrayList<String>(); pathelements.addAll(Arrays.asList(path.split(";"))); String envPath = System.getenv("PATH"); if(envPath != null && !envPath.isEmpty()) { pathelements.addAll(Arrays.asList(envPath.split(System.getProperty("path.separator")))); } String cmdname = getPd().getSpecific("command"); log(Level.DEBUG, "will look for %s in %s", cmdname, pathelements); for(String pathdir: pathelements) { File tryfile = new File(pathdir, cmdname); log(Level.TRACE, "trying if %s can execute", tryfile); if(tryfile.canExecute()) { log(Level.DEBUG, "will use %s as a command", tryfile.getAbsolutePath()); cmd = tryfile.getAbsolutePath(); break; } } if(cmd == null) { log(Level.ERROR, "command %s not found", cmdname); } return cmd; }
private String oneLine(Probe<?, ?> p) { ProbeDesc<?> pd = p.getPd(); String description = pd.getSpecific("description"); if(description == null) description = ""; return "| " + getSourceTypeLink(p, true) + " | " + description + " | " + classToLink(p.getClass()) + " | "; }
@Override public void setParent(StarterNode parent) { super.setParent(parent); if(listener == null) { String listenerClassName = this.getPd().getSpecific("listener"); try { @SuppressWarnings("unchecked") Class<Listener<?, KeyType>> listenerClass = (Class<Listener<?, KeyType>>) this.getClass().getClassLoader().loadClass(listenerClassName); listener = parent.find(listenerClass); } catch (ClassNotFoundException e) { log(Level.ERROR, e, "Can't find listener class: %s", e.getMessage()); } } }
/** * Extract the the uptime from the XML document, reusing the XML provider * utilites * * @param xmlstarter * @param d * @return */ protected long findUptime(XmlProvider xmlstarter, Document d) { String upTimePath = getPd().getSpecific("upTimePath"); if(upTimePath != null) { return xmlstarter.findUptime(d, upTimePath); } else if(getPd().getSpecific("nouptime") != null) { return Long.MAX_VALUE; } else { String startTimePath = getPd().getSpecific("startTimePath"); String currentTimePath = getPd().getSpecific("currentTimePath"); String timePattern = getPd().getSpecific("timePattern"); if(startTimePath != null && currentTimePath != null && timePattern != null) { DateFormat df = new SimpleDateFormat(timePattern); return xmlstarter.findUptimeByDate(d, startTimePath, currentTimePath, df); } else { log(Level.ERROR, "No xpath for the uptime"); return 0; } } }
protected long findUptime(LdapConnection cnx) { Set<String> collectPaths = new HashSet<String>(upTimeSpecifics.length); for(String s: upTimeSpecifics) { String v = getPd().getSpecific(s); if(v != null && !"".equals(v.trim())) collectPaths.add(v.trim()); return jrds.Util.parseStringNumber(retValues.get("upTimePath").toString(), -1L); } else { Object startTimePath = retValues.get(getPd().getSpecific("startTimePath")); Object currentTimePath = retValues.get(getPd().getSpecific("currentTimePath")); Object timePattern = getPd().getSpecific("timePattern"); if(startTimePath != null && timePattern != null) { DateFormat df = new SimpleDateFormat(timePattern.toString());
String fetchList = getPd().getSpecific("fetch"); if (fetchList == null) { log(Level.ERROR, "no fetch list defined");
@Override public boolean readSpecific() { getPd().addSpecific(REQUESTERNAME, "RAW"); String oidString = getPd().getSpecific(INDEXOIDNAME); if(oidString != null && oidString.length() > 0) { indexOid = new OID(oidString); } return super.readSpecific(); }
/** * * @see jrds.ProbeConnected#configure() */ public Boolean configure(List<?> args) { if(super.configure()) { ProbeDesc<String> pd = getPd(); query = jrds.Util.parseTemplate(pd.getSpecific("query"), getHost(), args); keyColumn = jrds.Util.parseTemplate(pd.getSpecific("key"), getHost(), args); uptimeQuery = jrds.Util.parseTemplate(pd.getSpecific("uptimeQuery"), getHost(), args); uptimeRow = jrds.Util.parseTemplate(pd.getSpecific("uptimeRow"), getHost(), args); String indexTemplate = pd.getSpecific("index"); if(indexTemplate != null && !"".equals(indexTemplate)) index = jrds.Util.parseTemplate(indexTemplate, getHost(), args); setName(jrds.Util.parseTemplate(pd.getProbeName(), args)); return true; } return false; }
BufferedReader statsbuffer = getAnswer(inputSocket, outputSocket, getPd().getSpecific("command")); Number uptime = vars.remove(getPd().getSpecific("uptime")); if(uptime != null) { setUptime(uptime.longValue());
if (getPd().getSpecific("nouptime") == null) { String upTimePointer = getPd().getSpecific("upTimePath"); if (upTimePointer != null && !upTimePointer.isEmpty()) { uptimePointer = JsonPath.compile(Util.parseTemplate(upTimePointer, this)); } else { String startTimePath = getPd().getSpecific("startTimePath"); String currentTimePath = getPd().getSpecific("currentTimePath"); timePattern = getPd().getSpecific("timePattern"); if(startTimePath != null && currentTimePath != null && timePattern != null) { startPointer = JsonPath.compile(Util.parseTemplate(startTimePath, this));
@Override public boolean readSpecific() { nameMap = getPd().getCollectMapping(); boolean readOK = false; try { String requesterName = getPd().getSpecific(REQUESTERNAME); if(requesterName != null) { log(Level.TRACE, "Setting requester to %s", requesterName); requester = SnmpRequester.valueOf(requesterName.toUpperCase()); readOK = true; } else { log(Level.ERROR, "No requester found"); } String uptimeOidName = getPd().getSpecific(UPTIMEOIDNAME); if(uptimeOidName != null) { log(Level.TRACE, "Setting uptime OID to %s", uptimeOidName); uptimeoid = new OID(uptimeOidName); } } catch (Exception e) { log(Level.ERROR, e, "Unable to read specific: %s", e.getMessage()); } return readOK && super.readSpecific(); }
@Test public void loadProbeDesc() throws Exception { JrdsDocument d = Tools.parseRessource("fulldesc.xml"); PropertiesManager pm = new PropertiesManager(); ProbeDescBuilder builder = new ProbeDescBuilder(); builder.setPm(new PropertiesManager()); ProbeDesc<?> pd = builder.makeProbeDesc(d); Assert.assertEquals("name", pd.getName()); Assert.assertEquals("probename", pd.getProbeName()); Assert.assertEquals(jrds.mockobjects.MokeProbe.class, pd.getProbeClass()); Assert.assertEquals("specificvalue1", pd.getSpecific("specificname1")); Assert.assertEquals("specificvalue2", pd.getSpecific("specificname2")); Assert.assertEquals(0.5, pd.getUptimefactor(), 0); Assert.assertEquals((long) pm.step * 2, pd.getHeartBeatDefault()); logger.trace(pd.getCollectMapping()); logger.trace(pd.getDefaultBeans()); // An empty collect string should not be collected Assert.assertEquals(5, pd.getCollectMapping().size()); }