Summary: Logging Gateway for Administrative alerts.
OverviewThe GigaSpaces Alert interface exposes the XAP environment and the application's health state. It allows users to register listeners on one or more alert types and receive notifications once an alert has been raised or has been resolved. You may use this framework to build a custom integration with a third party monitoring products to leverage the XAP alerting system. The main advantage with this approach is the ability to use an extensive set of out-of-box log appenders that translates log messages into different protocols and APIs to be consumed by third party products. ExampleThe AlertLoggingGateway example project provided with the GigaSpaces distribution using an existing Log4J Appender (SnmpTrapAppender) to convert log messages into SNMP traps, resulting in the alerts propagated to a third party network management solution. AlertsLoggingGatway componentsSnmpTrapTransmitterThe SnmpTrapTransmitter is a XAP PU responsible for the generic Alert-to-Log bridging. It does that by listening to all alerts in its alert filter file. Any incoming alerts are simply writing to commons logging log. Notice that, being generic in nature, the SnmpTrapTransmitter can be reused without any changes in similar projects. <bean id="SnmpTrapTransmitter" class="org.openspaces.example.alert.logging.snmp.SnmpTrapTransmitter" > <property name="alertFileFilter" value="notify-alerts.xml" /> <property name="loggerName" value="org.openspaces.example.alert.logging.AlertLoggingGateway" /> <property name="group" value="group-name-here" /> </bean> Note that if you implement your own variant for this class, for other types of alert interception, you will also have to override the construct() method to register for alerts, the destroy() method to cleanup the registration, and to create your own class implementing the AlertTriggeredEventListener interface in which you will issue the logging calls: public class SnmpTrapTransmitter { private Log logger; @PostConstruct public void construct() throws Exception { registerAlertTrapper(); } @PreDestroy public void destroy() throws Exception { alertManager.getAlertTriggered().remove(atListener); } private void registerAlertTrapper() { atListener = new AlertTriggeredEventListener() { public void alertTriggered(Alert alert) { String loggRecord; loggRecord = alert.toString(); logger.info(loggRecord); } }; XmlAlertConfigurationParser cparse = new XmlAlertConfigurationParser(alertFileFilter); alertManager.configure(cparse.parse()); alertManager.getAlertTriggered().add(atListener); } } SnmpTrapSenderThe SnmpTrapSender is a utility class that implements the SnmpTrapAppender's SnmpTrapSenderFacade interface with an implementation that queues and asynchronously transmits Alerts as SNMP traps. The SNMP transmission method - sendTrap() - uses snmp4j library as its underlying implementation. public class SnmpTrapSender implements SnmpTrapSenderFacade { public void addTrapMessageVariable(String trapOID, String trapValue) { trapQueue.add(trapValue); } public void initialize(SNMPTrapAppender arg0) { trapQueue.clear(); loadRunParams(); } public void sendTrap() { String trapVal = trapQueue.removeFirst(); PDUv1 trapPdu = (PDUv1)DefaultPDUFactory.createPDU(SnmpConstants.version1); trapPdu.setType(PDU.V1TRAP); // pack trapVal into trapPdu snmp.send(trapPdu, target); } commons-logging.properties and log4j.propertiesThe Commons-logging.properties file is a commons logging configuration file which re-directs its calls to a log4j logger. In our example this file contains redirection of commons-logging to log4j as the SNMP trapper we use is on top of log4j. log4j.rootCategory=INFO,TRAP_LOG
log4j.appender.TRAP_LOG=org.apache.log4j.ext.SNMPTrapAppender
log4j.appender.TRAP_LOG.ImplementationClassName=org.openspaces.example.alert.logging.snmp.SnmpTrapSender
log4j.appender.TRAP_LOG.ManagementHost=127.0.0.1
log4j.appender.TRAP_LOG.ManagementHostTrapListenPort=162
log4j.appender.TRAP_LOG.CommunityString=public
log4j.appender.TRAP_LOG.Threshold=INFO
log4j.appender.TRAP_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.TRAP_LOG.layout.ConversionPattern=%d,%p,%t,%c,%m%n
Running the ExampleThe example is located under <GigaSpaces root/tools/alert-integration. To run it you should do the following:
External Dependencies
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |