AnsweredAssumed Answered

Custom Probe Development Questions

Question asked by rrustong.1 on May 10, 2016
Latest reply on May 18, 2016 by Gene_Howard

I have started working on a custom probe using the Java SDK and have a few questions about the best way to handle a few things.  In addition to this being my first foray into probe development, I am also learning Java at the same time, so hopefully my questions make sense.


First, the probe I'm working on is not intended to monitor anything other than the alarm queue so I'm not sure that using the maven template is the best way to build my probe.  In an effort to get something that works and to give me somewhere to start, I did use the template for local monitoring.  The code that I've built thus far works - I'm able to attach to the queue, receive alarms and take action on alarms as intended - but I feel like using that template has added complexity to my probe that is unnecessary.  ie. I don't need any discovery or QOS components.  Is there a better way to get started that will have all of the necessary components of a probe?  Or is the maven archetype the best starting point? 


Second, since I'm not monitoring anything in a traditional manner, I do not expect traditional alerts from breached thresholds to come from my probe.  However, there are a few cases where I've built try/catch blocks or if/then blocks where I would like to be able to create an alert.  According to the documentation, it is not recommended to manually create an alert so I'm trying to figure out how I can actually generate alerts.  The documentation recommends throwing a NimException and allowing the framework to handle the alert, but I'm unable to build anything that actually works in this way.

In the case of an abnormal situation that a probe cannot recover from, a NimException should be thrown by the probe. The framework will catch the NimException and send an associated alarm.

Using the maven local archetype, my probe has a main() method, a basic constructor a doContinuously() method and a runExampleMethod() method.  Within the doContinuously method, I see that NimExceptions are caught and an error is logged.  If I understand how the catch block works, this means that any NimExceptions thrown deeper in my code will be caught by this and will not go any further than being logged.  I don't see how this allows an exception to generate an alert.  The doContinuously method is unchanged from the maven template.  Can someone explain how this is supposed to generate an alert?  Do I need to change something here to allow an alert to be generated?  Any examples of catching (or throwing) an exception that generates an alert in the recommended way?


Here's the doContinuously method that was generated for me:

    @Override     public void doContinuously() throws NimException, InterruptedException {         while (true) {             try {                 runExampleMethod();             } catch (NimException e) {                 Log.error(e.getLocalizedMessage());             } catch (ClassNotFoundException e) {                 e.printStackTrace();             } catch (XPathExpressionException ex) {                 Logger.getLogger(ProbeMain.class.getName()).log(Level.SEVERE, null, ex);             } catch (IOException ex) {                 Logger.getLogger(ProbeMain.class.getName()).log(Level.SEVERE, null, ex);             }             Thread.sleep(interval * 1000);         }     }


I added this simple test to the runExampleMethod() to try forcing an alert:

    private void runExampleMethod() throws NimException, ClassNotFoundException, XPathExpressionException, IOException {          // Set hub and nas address         hubAddress = HubUtil.getHubAddress();         hubProbeAddress = hubAddress + "/hub";         nasAddress = hubAddress + "/nas";         if(nasAddress.contains("nas")){             throw new NimException(E_ERROR, "This is an exeption");         }


This code does post the error message to the probe log as I would expect, but does not generate an alert.  Any hints are welcome.