SNMP Alerts


The GigaSpaces data grid Alert interface exposes the data grid 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 data grid alerting system. A recommended approach for this type of integration is to construct a listener that writes the selected alert types into the logger mechanism. Examples of this are the log4j and commons-logging frameworks.

The main advantage to this approach is the ability to use an extensive set of out-of-the-box log appenders that translate log messages into different protocols and APIs to be consumed by third-party products.


AlertsLoggingGatway Example

The AlertLoggingGateway example provided with the GigaSpaces distribution uses an existing Log4J Appender (SnmpTrapAppender) to convert log messages into SNMP traps, resulting in the alerts being propagated to a third-party network management solution.




The SnmpTrapTransmitter is a Processing UnitClosed This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity. that is responsible for the generic Alert-to-Log bridging, and listens to all alerts in its alert filter file. Any incoming alerts are written to the commons log. The SnmpTrapTransmitter is generic and can therefore be reused in similar projects without any changes. The SnmpTrapTransmitter exposes the following configuration parameters:

  • AlertFileFilter - the name of Alert filter xml file used to filter Alerts to be logged.
    loggerName - the name of the logger to be created.
    group - the data grid group for which the Alert listener will be configured.
  <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" />

If you implement your own variant for this class, then for other types of alert interceptions you also have to do the following:

  • Override the construct() method to register for alerts
  • Override the destroy() method to clean up the registration
  • Create your own class implementing the AlertTriggeredEventListener interface in which you will issue the logging calls.

See the following example:

public class SnmpTrapTransmitter {

    private Log logger;

    public void construct() throws Exception {

    public void destroy() throws Exception {

    private void registerAlertTrapper() {
        atListener = new AlertTriggeredEventListener() {
            public void alertTriggered(Alert alert) {
                String loggRecord;
                loggRecord = alert.toString();

        XmlAlertConfigurationParser cparse = new XmlAlertConfigurationParser(alertFileFilter);


The 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 the snmp4j library as its underlying implementation.

public class SnmpTrapSender implements SnmpTrapSenderFacade {

    public void addTrapMessageVariable(String trapOID, String trapValue) {

    public void initialize(SNMPTrapAppender arg0) {

    public void sendTrap() {
        String trapVal = trapQueue.removeFirst();
                PDUv1 trapPdu = (PDUv1)DefaultPDUFactory.createPDU(SnmpConstants.version1);
                // pack trapVal into trapPdu
        snmp.send(trapPdu, target);


The Commons-logging.properties file is a commons logging configuration file that redirects its calls to a log4j logger. In our example, this file contains a redirection of commons-logging to log4j because the SNMP trapper used is on top of log4j. log4j.properties is a log4j configuration file that delegates log writes to the SNMPTrapAppender, resulting in SNMP traps.


Using the AlertsLoggingGatway Example

External Dependencies

  • Minimum log4j version is 1.2.14

  • Minimum snmpTrapAppender version is 1.2.9

  • Minimum snmp4j version is 1.11.2

  • To build the example, you must have Apache Maven installed.

Running the Example

The AlertsLoggingGatway example is located under <product>/tools/alert-integration.

To run the example:

  1. Set the group value in the puClosed This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity..xml file to your own data grid group. (Optionally, you can edit the function registerAlertTrapper() in SnmpTrapTransmitter.java to create your own Admin object in any way you see fit.)

  2. (Optional) Edit the notify-alerts.xml file to set your own alerts and alert conditions that will be listened to by this example.

  3. (Optional) Edit log4j.properties to set the IP address and port used by your SNMP server software (if any).

  4. If you don't have SNMP server software, download one in order to run and test this example. For example, the iReasoning MIB browser (mibbrowser) provides good basic SNMP trap viewing capabilities with a free personal edition. Make sure to configure log4j.properties to use the same IPaddress and port used by the server.

  5. Install GigaSpaces's Maven dependencies to the local Maven repository by running the <product>/bin/gs maven install script.
  6. Build and pack the sample project into a JAR file. This can be done by executing the command mvn from the project's root directory, or by performing an equivalent action within your UI. A successful build should result in the creation of the example JAR file in target/AlertLoggingGateway.jar.

  7. If needed, start the data grid with at least one running LUSClosed Lookup Service. This service provides a mechanism for services to discover each other. Each service can query the lookup service for other services, and register itself in the lookup service so other services may find it., GSMClosed Grid Service Manager. This is is a service grid component that manages a set of Grid Service Containers (GSCs). A GSM has an API for deploying/undeploying Processing Units. When a GSM is instructed to deploy a Processing Unit, it finds an appropriate, available GSC and tells that GSC to run an instance of that Processing Unit. It then continuously monitors that Processing Unit instance to verify that it is alive, and that the SLA is not breached. and GSCClosed Grid Service Container. This provides an isolated runtime for one (or more) processing unit (PU) instance and exposes its state to the GSM. belonging to the data grid group declared in step 1.

  8. Deploy the sample JAR to the GSC.

  9. If needed, perform data grid actions that will trigger one or more of the defined alerts. Creating a new GSC is usually a good way to creating a multitude of different alerts.

  10. Start up your SNMP server to intercept and view incoming traps. If you're using a MIB browser, enter the Trap Receiver (Ctrl-I) and make sure it is configured to listen on the correct IP address and port.