ActiveSocket

 Product Overview

 ActiveSocket Objects:
 
 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 Tutorials

 Tools


  Download ActiveSocket Network Communications Toolkit 4.1  (7643 KB - .exe file)
  Download Manual  (556 KB - .htm file)


Send SNMP Traps from an HTML/JavaScript webpage


ActiveSocket provides an easy-to-use development interface (SDK) to a variety of IP protocols.
By using ActiveSocket, you can very easily create or enhance applications with network features.

ActiveSocket features the following protocols: ICMP, HTTP and HTTPs with support for proxy servers, Telnet, NTP time protocol,
RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets (TCP and UDP), WOL (Wake-On-LAN), and more.

ActiveSocket is compliant with SNMP versions v1 and v2c. Several SNMP data types are supported, including:
  • ASN_INTEGER; Numeric values;
  • ASN_INTEGER32; Numeric values;
  • ASN_BITS; Bit values, for instance: one bit per port to see if a port is connected;
  • ASN_OCTETSTRING; Byte string;
  • ASN_NULL; Null value;
  • ASN_OBJECTIDENTIFIER; Object identifier (OID);
  • ASN_SEQUENCE; Text string;
  • ASN_IPADDRESS; IP address;
  • ASN_COUNTER32; 32 bit counter;
  • ASN_GAUGE32; 32 bit gauge;
  • ASN_TIMETICKS; Timestamps or uptime;
  • ASN_OPAQUE; Byte string;
  • ASN_COUNTER64; 64 bit counter;
  • ASN_UNSIGNED32; unsigned 32 bit numeric value.
ActiveSocket supports the following SNMP trap features:
  • SNMP v1 and SNMP v2c support;
  • Support for alphanumeric OID's (object identifier) and numeric OID's;
  • Multithreading architecture: send and/or receive SNMP traps simultaneously from one process using multiple threads;
  • Support for ports other than the default 161 and 162 ports;
  • Support for enterprise specific traps;
  • Support for SNMP v1 generic traps such as coldstart, warmstart, linkup, linkdown, authfailure and neighbourloss;
  • Send multiple data objects (variable bindings) using a single SNMP trap message.

ActiveSocket can be well integrated into JavaScript environments.
This document describes how ActiveSocket can be integrated into JavaScript projects.

Prerequisites

IMPORTANT: Make sure that the SNMP Service is installed and running on the machine where ActiveSocket is installed. For more details, please read FAQ items Q1200010 and Q1200015.



Step 1: Installation of ActiveSocket

When using HTML, there are two ways to install the ActiveSocket Toolkit on a client PC:
  • Automatically using HTML code;
  • Using the ActiveSocket Toolkit InstallShield installation.
Automatic installation using HTML code

You can install the ActiveSocket Toolkit automatically using the following HTML code on top of the HTML page:
<head>
  <object id="SnmpTrapManager" codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
                               classid="CLSID:634320AF-A7F3-4048-8A52-D1387F44B8CC" ></object>
  <object id="SnmpTrap"        codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
                               classid="CLSID:E00A6261-0E7E-46FD-AEFF-36995D4F202A" ></object>
  <object id="SnmpObject"      codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
                               classid="CLSID:A6174470-3F28-4350-8621-BD0A20A5E0B6" ></object>
  <object id="Constants"       codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
                               classid="CLSID:EC4937DE-1B46-4AB4-BE3B-2CEF007F0D36" ></object>
</head>
The ActiveSocket Toolkit will be installated automatically. The user will be asked to confirm the installation, because the DLL is coming from an untrusted site (www.activexperts.com).
There are two ways to avoid prompting:

  • Add the ActiveX/COM location to the user's trusted sites.
    You can manage trusted manually (by using the Internet Explorer), through a logon script (by appyling the registry change from the logon script)
    or by using Active Directory Group Policies;

  • OR use a trusted location for the DLL.
    For instance your Intranet site, because most probably this site has already been added to the list of trusted sites for all users.
Manual installation using the ActiveSocket Toolkit installation procedure

On each client PC, download the ActiveSocket Toolkit from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.



Step 2: Create a new webpage

Create a new script using your favorite editor. You can simply use notepad.
However, a JavaScript editor is recommended, so you can browse through objects, objects properties and object functions.
Add the following HTML code to the header section of your HTML code:
   <script type="text/javascript" >
   </script>

You're now able to write a more advanced scripts to communicate using the ActiveSocket Toolkit.



Step 3: Create the ActiveSocket objects in JavaScript


To send SNMP traps using JavaScript, you need to declare and create the following ActiveSocket objects:

  • SnmpTrapManager; The SNMP manager which allows you to send and/or receive SNMP traps in the form of SnmpTrap objects;
  • SnmpTrap; The actual SNMP trap, this object holds some SNMP trap properties like: destination host, port and community, specific and generic trap and a timestamp;
  • SnmpObject; This object is used to hold the data to be send with the SNMP trap. These data objects are also called variable bindings.

To create the ActiveSocket objects, add the following lines of codes on top of your JavaScript code (directly after the script tag) :
   var objSnmpTrapManager = new ActiveXObject ( "ActiveXperts.SnmpTrapManager" );
   var objSnmpObject      = new ActiveXObject ( "ActiveXperts.SnmpObject" );
   var objSnmpTrap        = new ActiveXObject ( "ActiveXperts.SnmpTrap" );
   var objConstants       = new ActiveXObject ( "ActiveXperts.ASConstants" );
   


Step 4: Send an SNMP trap message to a remote SNMP management station

You can now send SNMP trap messages to any SNMP management station or device.
The following HTML/JavaScript code shows how to send an SNMP trap from a website:
<html>
  <head>
    <title>ActiveSocket HTML/JavaScript Sample (Send SNMP Traps)</title>

    <object id="SnmpTrapManager" codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
	                             classid="CLSID:634320AF-A7F3-4048-8A52-D1387F44B8CC"  ></object>
    <object id="SnmpTrap"        codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
	                             classid="CLSID:E00A6261-0E7E-46FD-AEFF-36995D4F202A"  ></object>
    <object id="SnmpObject"      codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
	                             classid="CLSID:A6174470-3F28-4350-8621-BD0A20A5E0B6"  ></object>
    <object id="Constants"       codebase="http://www.activexperts.com/files/activsocket/asocket.dll" 
	                             classid="CLSID:EC4937DE-1B46-4AB4-BE3B-2CEF007F0D36"  ></object>	
     
    <script type="text/javascript" >
    
      var objSnmpTrapManager = new ActiveXObject ( "ActiveXperts.SnmpTrapManager" );
      var objSnmpObject      = new ActiveXObject ( "ActiveXperts.SnmpObject" );
      var objSnmpTrap        = new ActiveXObject ( "ActiveXperts.SnmpTrap" );
      var objConstants       = new ActiveXObject ( "ActiveXperts.ASConstants" );
        	 
      function Init ()
      {
        objSnmpTrapManager.Initialize ();
      }
		
      function UnInit ()
      {
        objSnmpTrapManager.Shutdown ();
      }
		
      function SendTrap ()
      {
        objSnmpObject.Clear ();
	
        objSnmpObject.Value   = textTrapValue.value;
        objSnmpObject.OID     = textTrapOid.value;
		    
        if ( textTrapType.value == "string"    ) objSnmpObject.Type = objConstants.asSNMP_TYPE_OCTETSTRING;
        if ( textTrapType.value == "number"    ) objSnmpObject.Type = objConstants.asSNMP_TYPE_UNSIGNED32;
        if ( textTrapType.value == "ipaddress" ) objSnmpObject.Type = objConstants.asSNMP_TYPE_IPADDRESS;
		    
        objSnmpTrap.Clear ();
		    
        objSnmpTrap.Host      = textSnmpManager.value;
        objSnmpTrap.Community = textSnmpCommunity.value;
        objSnmpTrap.AddObject ( objSnmpObject );
		    
        objSnmpTrapManager.Send ( objSnmpTrap );
		    
        textResult.value = "ERROR #" + objSnmpTrapManager.LastError + " (" + objSnmpTrapManager.GetErrorDescription ( objSnmpTrapManager.LastError );
      }
     
    </script>
  </head>
	
  <body OnLoad="Init()" OnUnload="UnInit" >
    <font face="sans-serif" size="2">
    <hr size="1" color="#707070">
    <b><font size="4">ActiveXperts ActiveSocket HTML/JavaScript Sample</font></b>
    <br>
    <br>
    Send a SNMP Trap to a SNMP Manager.
    <br>
    <br>
    IMPORTANT: For more details about using ActiveSocket with HTML: 
    <a href="http://www.activexperts.com/support/activsocket/#html" target="_blank">ActiveSocket HTML/Javascript FAQ</a>.
    <br>
    <hr size="1" color="#707070">
    <br>
    <table border="0" bgcolor="#f0f0f0" ID="table1" >
      <tr>
        <td width="120" valign="top">SNMP Manager:</td>
        <td width="450">
          <input size="50" type="text" id="textSnmpManager" value="DELL09" >
          </select>
        </td>
      </tr>
      <tr>
        <td valign="top">SNMP Community:</td>
        <td>
          <input size="50" type="text" id="textSnmpCommunity" value="public" >
          <br>
          <br>
        </td>
      </tr>
      <tr>
        <td valign="top">Trap OID:<br>
        </td>
        <td>
          <input size="50" type="text" id="textTrapOid" value="system.sysDescr.0" >
        </td>
      </tr>
      <tr>
        <td vAlign="top">Trap Value:</td>
        <td>
          <input size="50" type="text"" id="textTrapValue" value="A System Description" >
        </td>
      </tr>
      <tr>
        <td vAlign="top">Trap Type:</td>
        <td>
          <select id="textTrapType">
          <option value="string">String</option>							
          <option value="number">Number</option>
          <option value="ipaddress">IP Address</option>										
          </select>
          <br>
          <br>
        </td>
      </tr>
      <tr>
        <td vAlign="top">Result:</td>
        <td>
          <input size="50" type="text" id="textResult" value="N/A" >							
        </td>
      </tr>
    </table>
    <br>
    <input type="button" onclick="SendTrap()" value="Send Trap">
    <br>
    <hr size="1" color="#707070">
    <font size="1" face="Verdana">
	  This demo uses the ActiveXperts ActiveSocket Toolkit, an <a href="http://www.activexperts.com">ActiveXperts Software</a> product.
    </font></b>
  </body>
</html>
There are many working samples included with the product.
You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.





The ActiveSocket tool is a Network Communications ActiveX software component (SDK). This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform, including Visual Basic .NET, Visual CSharp .NET, ASP .NET (VB,CS), ASP, Visual Basic, Visual Studio/Visual C++, Delphi, PHP, ColdFusion, HTML, VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.

©2009 ActiveXperts Software B.V. All rights reserved.  Contact Us | Terms of Use | Privacy Policy