DX Infrastructure Manager

Expand all | Collapse all

Custom Probe Development Questions

Jump to Best Answer
  • 1.  Custom Probe Development Questions

    Posted 05-10-2016 03:26 PM

    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.

     

    Thanks!



  • 2.  Re: Custom Probe Development Questions
    Best Answer

    Posted 05-18-2016 01:21 PM

    Hi,

     

    When I am looking for a quick example I usually go to the old codewizard for very basic examples:

     

    http://support.nimsoft.com/Files%5CArchive%5C00057%5Ccode_wizard-1_70.zip

     

    I know this has not been updated in a LONG time but the basic are the same.

     

    I used to do quickly generate the java code below.


    hope this helps

    //#################################################################

    //# CodeWizard:  Java

    //# This code was generated with the Nimsoft CodeWizard version 1.70

    //# Date: Wednesday, May 18, 2016

    //

    package example;

    import java.io.IOException;

    import com.nimsoft.nimbus.*;

    import com.nimsoft.nimbus.ci.ConfigurationItem;

     

    public class example_probe {

        static NimLog logger = NimLog.getLogger(example_probe.class);

     

        public static void main(String[] args) {

            try {

                example_probe exampleprobe = new example_probe();

                exampleprobe.doit(args);

            }catch(Exception e) {

                e.printStackTrace();

            }

        }

     

        public void doit(String[] args) throws Exception {

            NimProbe  probe = null;

     

            // Loop to handle restart (_restart) command

            // Stop (_stop) command terminates the loop

            do {

     

                // Construct the probe

                probe = new NimProbe("example_probe","1.00","My company",args);

     

                logger.log(0," - ---STARTING - ----");

                logger.setLogLevel(NimLog.WARN);

     

                // Subscribe to message from the hub, register the "hubpost" callback method

                probe.setSubscribeSubject("alarm");

                probe.registerHubpostCallback(this,"hubpostCallback");

     

                // Define and send a warning alarm

                 try {

                     ConfigurationItem ConfItem = new ConfigurationItem("citype", "ciname","Hostname");

                     NimAlarm alarm = new NimAlarm(NimAlarm.NIML_WARNING, "Alarm generated from Java","2","JAVA","JAVA",ConfItem,"ciMetricId");

                     alarm.send();

                     alarm.disconnect();

                 } catch (IOException e) {

                     e.printStackTrace();

                  }

                // Run until a stop signal is received from the manager.

                // Restart initiates re-creation of the probe.

                // The doForever() method returns true or false

                //   true  - a restart command (_restart) is received

                //   false - a stop command (_stop) is received

            } while (probe.doForever());

     

            logger.log(NimLog.WARN," - ---STOPPING - ----");

        }

     

        /**

         * The "hubpost" callback that receives a PDS with some userdata

         * @param session The callback session

         * @param pdsuserdata The PDS user data

         */

        public static void hubpostCallback(NimSession session, PDS pdsuserdata) throws NimException {

            session.sendReply(NimException.OK,null); // OK return

        }

     

    }