tip This documentation is for the old interface of AlertSite. If you use the new interface (AlertSite UXM), please see SNMP Alerts.

SNMP Alert Notifier

Overview

To receive alerts via SNMP traps, a notifier can be configured in the AlertSite Console Notifiers screen. Both snmpv1 and snmpv2c are available. Upon error, an SNMP trap is sent to a specific IP address with a trap listener. A Management Information Base (MIB) has been defined in Abstract Syntax Notation One (ASN1) notation and is available here.

Extensive details about SNMP, snmpv1 and snmpv2c, are available in Request For Comments documents. Please refer to the Internet Engineering Task Force (IETF) web site. Considerable network programming knowledge is advised.

SNMP traps use UDP packets which can be unreliable across public networks. One alternative is to POST the notification to your own web server and then send the trap through your local network, which is more reliable.

Included in Example SNMP Trap below is a sample CGI script written in Perl that takes AlertSite POST notification and forwards it on as an SNMP trap. The task is to grab the data that AlertSite POSTs to the receiving program.

Every web server and language (ASP, Perl, PHP, etc.) has a popular and often-used routine to grab the POST data; in the Perl script, the key line is:

$in = $cgi­->parse_form_data();

This automatically makes all the AlertSite POST fields available to the program, for example:

$in­->{status}   is the test status
$in­->{errcount} is the number of consecutive errors
etc.

Notifications populate the following field/value pairs and send them to the POST location:

source=AlertSite
custid=C00000
company=Boca+Internet+Technologies
device_id=0000
device_name=Test+Notification+Device
device_type=Web+Site
device_typecode=w
errcount=0
http_status=HTTP/1.1+200+OK
location=Fort+Lauderdale,+Florida
location_num=10
status=0
status_text=Site+responded+normally+to+all+tests.
timestamp=2008/09/19+12:47:19
transaction=0

Associated Post Data follows browser/cgi standard format:

CONTENT_LENGTH = 349
CONTENT:
source=AlertSite&custid=C00000&company=Boca+Internet+Technologies&device_id=
0000&device_name=Test+Notification+Device&device_type=Web+Site&device_typeco
de=w&errcount=0&http_status=HTTP/1.1+200+OK&location=Fort+Lauderdale,
+Florida&location_num=10&status=0&status_text=Site+responded+normally+to+all
+tests.&timestamp=2008/09/19+12:47:19&transaction=0&

Example SNMP Trap

#!/usr/bin/perl
############ SET YOUR SITE CONSTANTS HERE #############
BEGIN
{
       ##### destination for your snmp trap #####
       use constant SNMP_HOST => '111.111.11.111';
       ##### versions are snmpv1 or snmpv2c #####
       use constant SNMP_VERSION => 'snmpv1';
}
#######################################################
use Net::SNMP;
use CGI::Lite;
use strict;
my ($cgi, $in);
# get the posted data
$cgi = new CGI::Lite;
$in = $cgi­->parse_form_data();
print "Content­type: text/html\n\n";
print "<html><body>\n";
handle_snmp_trap($in);
print "</body></html>\n";
exit;
sub handle_snmp_trap
{
   if ($in­->{source} eq 'AlertSite')
   {
      my (@oids, $session, $error, $result);
      # setup snmp msg into @oids
      @oids = ();
      push @oids,('1.3.6.1.4.1.20434.1.1.1', OCTET_STRING, $in­->{company});
      push @oids,('1.3.6.1.4.1.20434.1.1.2', OCTET_STRING, $in­->{custid});
      push @oids,('1.3.6.1.4.1.20434.1.1.3', OCTET_STRING, $in­->{device_name});
      push @oids,('1.3.6.1.4.1.20434.1.1.4', OCTET_STRING, $in­->{device_id});
      push @oids,('1.3.6.1.4.1.20434.1.1.5', OCTET_STRING, $in-­>{timestamp});
      push @oids,('1.3.6.1.4.1.20434.1.1.6', OCTET_STRING, $in­->{status});
      push @oids,('1.3.6.1.4.1.20434.1.1.7', OCTET_STRING, $in­->{errcount});
      push @oids,('1.3.6.1.4.1.20434.1.1.8', OCTET_STRING, $in­->{status_text});
      if ($in-­>{step_name})
      {
        push @oids,('1.3.6.1.4.1.20434.1.1.9', OCTET_STRING, $in-­>{step_name});
      }
      if ($in-­>{http_status})
      {
        push @oids,('1.3.6.1.4.1.20434.1.1.10', OCTET_STRING, $in-­>{http_status});
      }
      # open snmp session
      ($session, $error) = Net::SNMP­->session
                      (
                       ­hostname  => SNMP_HOST,
                       ­community => 'public',
                       ­port => 162,
                       ­version => SNMP_VERSION
                      );
      # check for error
      if (!defined($session))
      {
         print "Error ($error) creating SNMP object.\n";
         return;
      }
      $session-­>debug(0xff);  # enable snmp debugging
      # send the trap using correct version
      if (SNMP_VERSION eq 'snmpv2c')
      {
      # add required time and trap id to start of oid list
         unshift @oids,('1.3.6.1.6.3.1.1.4.1.0', OBJECT_IDENTIFIER,
                        '1.3.6.1.4.1.20434.1.2.0.1');
         unshift @oids,('1.3.6.1.2.1.1.3.0', TIMETICKS, 999);
         $result = $session-­>snmpv2_trap(­varbindlist => \@oids);
      }
      else
      {
         $result = $session-­>trap(­enterprise => '1.3.6.1.4.1.20434.1.2',
                                  ­generictrap => 6,
                                  ­specifictrap => 1,
                                  ­varbindlist => \@oids);
      }
      # check for error
      if (!defined($result))
      {
         print "SNMP trap failed (" . $session­->error() .")\n";
      }
      # close the session
      $session-­>close;
   }
   else
   {
      print "Error ­­ invalid or missing POST data\n";
   }
   return;
}

SNMP Packet Example

Here is an example of an SNMP notification packet (note: sensitive information has been modified for this illustration):

SNMP notification


Please Note: The Notification Content packet consists of multiple sets of 3 lines in this order:

  • Message ID
  • Message type
  • Message value

However, the sets themselves are not in any particular order. The packet should be parsed by message ID.

E-Mail Notification Example

Here is the same error message sent to an E-mail notifier:

Email notification


Back to top

© 2016 SmartBear Software --
Syndicate this site RSSATOM