ActiveSocket is compliant with SNMP versions v1 and v2c. Several SNMP data types are supported, including:
ActiveSocket supports the following SNMP trap features:
ActiveSocket can be well integrated into JavaScript environments. This document describes how ActiveSocket can be integrated into JavaScript projects.
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.
When using HTML, there are two ways to install the ActiveSocket Toolkit on a client PC:
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/network-component/asocket.dll"
classid="CLSID:634320AF-A7F3-4048-8A52-D1387F44B8CC" ></object>
<object id="SnmpTrap" codebase="http://www.activexperts.com/files/network-component/asocket.dll"
classid="CLSID:E00A6261-0E7E-46FD-AEFF-36995D4F202A" ></object>
<object id="SnmpObject" codebase="http://www.activexperts.com/files/network-component/asocket.dll"
classid="CLSID:A6174470-3F28-4350-8621-BD0A20A5E0B6" ></object>
<object id="Constants" codebase="http://www.activexperts.com/files/network-component/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:
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.
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.
To send SNMP traps using JavaScript, you need to declare and create the following ActiveSocket objects:
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" );
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/network-component/asocket.dll"
classid="CLSID:634320AF-A7F3-4048-8A52-D1387F44B8CC" ></object>
<object id="SnmpTrap" codebase="http://www.activexperts.com/files/network-component/asocket.dll"
classid="CLSID:E00A6261-0E7E-46FD-AEFF-36995D4F202A" ></object>
<object id="SnmpObject" codebase="http://www.activexperts.com/files/network-component/asocket.dll"
classid="CLSID:A6174470-3F28-4350-8621-BD0A20A5E0B6" ></object>
<object id="Constants" codebase="http://www.activexperts.com/files/network-component/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/network-component/#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.