1

I am currently having an application where SNMP ALARMS are raised when my program is not able to reach an external API. I clear the alarm when ever i am successfully getting a response back from the API .

Below is the code for the same .

            // Call Webservice to check the external API is up or not
            logger.debug("Sending trap data Clear Alarm {}" , trapData);
            AlarmTrap.INTERFACE_SMSC_STATUS.clear(trapData);
    }
    catch(CustomException e) 
    {

        AlarmTrap.INTERFACE_SMSC_STATUS.raise(trapData);

        logger.error("Error " + e);
        throw e;
    }

As you can see for every successful response i am clearing the alarm . Though there is no impact on the current execution as SNMP server discard same kind of alarms . I want to know if it is good practice or not . And whether SNMP protocol itself handles duplicate alarms and are not sent across to network .

suvankar bose
  • 291
  • 2
  • 12

1 Answers1

1

If you do not want to send duplicate alarms for consecutive success API responses, you can create a AtomicBoolean class variable - isErrorAlert that only SNMP clear TRAP shall be invoked if the isErrorAlert = true.

AtomicBoolean isErrorAlert = new AtomicBoolean();


try{
  //API Success case
  if(isErrorAlert.compareAndSet(true, false)){
     //send clear trap only if the error case is occured
  }

} catch(Exception e) {
  //Fail case
  isErrorAlert.set(true);
} 

References: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html

neuropaddy
  • 47
  • 1
  • 7
  • Yes, this is the correct solution - your code needs to remember the past result and only send a trap when the result changes. – Jolta Dec 05 '17 at 15:06