![]() ![]() ![]() |
5.1 Overview
5.2 Creating a New Project
5.3 Loading the MIB in MIB Compiler
5.4 Generating Source Code for the MIB
5.5 Compiling the Generated Code
5.6 Starting and Stopping the Agent
This section will help you develop a simple SNMP agent using WebNMS Agent Toolkit. The basic operations that need to be performed for developing an SNMP Agent are: -
Define MIBs using MIB Editor. To know how to define a MIB, please refer Defining a MIB section . It is not necessary that MIBs should be defined using MIB Editor. If MIBs are defined already, they can also be used.
Create a project and generate source code for the defined MIB using MIB Compiler.
Compile the generated code
Instrument the agent stub files and
Start the agent.
The first step towards creating an agent is Creating a Project for the agent. To create a project in MIB Compiler,
Start the MIB Compiler application. You will be prompted with the following options.
Recent Workspaces
Open Workspace
New Project
Choose New Project here or from the File -> New Project menu bar.
You have to fill in the following details in the wizard for new project : -
Create or Add to Existing Workspace - This will add the project to a new workspace. Use "Browse" option to store the project under an already existing workspace (.wsp).
Project Name - Specify a name for the project. By default it would be as snmpproject01. The project is identified by its .prj extension.
Project Directory - Specify the directory location in which the project should be placed. Use Browse option to navigate the location.
Click OK. The new project gets created and displayed under the workspace area.
5.3 Loading the MIB in MIB Compiler
Now that a project is created, you will have to load the MIB for which the agent has to be created. To load a MIB in the Compiler,
Select MIB -> Load MIB option from the menu bar.
Select a MIB from the list, say AGENT-SAMPLE-MIB. The MIBs in <Agent Toolkit Home>/mibs directory get listed by default. You can make choose these MIBs or from any other location where it is defined and
Click Load MIB. The MIB gets loaded under the Loaded MIB Modules in the MIB View. You can also load Multiple MIBs following the same procedure.
5.4 Generating Source Code for the MIB
Source files can be generated either from MIB compiler or using commandline options. The MIB Compiler generates source files by reading the loaded MIB file. Bulk of effort involved in developing an agent is complete with the generation of source files.
The agent to be developed can be of v1, v2c, or v3 type. The Project -> Settings option in the menu bar can be used to configure the settings for an agent. By default, the version of the agent is v3.
From MIB Compiler UI
To generate source code for a given MIB,
Select Build -> Generate Source from the menu bar.
The files generated are listed in the Debug Window.
On successful generation 'Code generation succeeded for project : snmpproject01.prj' can be seen.
These files get stored under <Agent Toolkit Home>/snmpprojects/projectname/agent/src/com/myCompany/myPackage directory.
They also get listed in the File View frame of MIB Compiler UI.
From CommandLine Tool
Agent Toolkit provides command line options for code generation. This feature is not designed to be used as a standalone utility but intended to add command line control to GUI-assisted agent development process. The project file serves as the input.
Location of Commandline Utilities
The script files responsible for invoking the Command Line Utilities are available under <ATKT_Home>/bin directory where <ATKT_Home> is the working directory of Command Line Utility. The relevant script files are generated under the working directory as SnmpAgentSourceGen.bat / SnmpAgentSourceGen.sh files.
Operating the Commandline Utilities
To accomplish the command line source generation, the following command has to be executed.
//Syntax of the Command in Windows Operating Environment ATKT_Home\bin\XXXAgentSourceGen.bat -x <Project file location>
//Syntax of the Command in Linux/Solaris Operating Environment sh ATKT_Home\bin\XXXAgentSourceGen.sh -x<Project file location>
//A typical input will look like this: ATKT_Home\bin\SnmpAgentSourceGen -x C:\WebNMS\JavaAgent\snmpprojects\TestProject\TestProject.prj |
5.5 Compiling the Generated Code
The MIB Compiler generates a set of source files for each MIB file. Some of the source or stub files need to be instrumented to include the desired function. This section is explained with the notion of developing a simple agent with the default values. Hence the instrumentation part is not covered here. To know more on the same, refer Instrumenting the generated code of a MIB section.
The next step is to compile the generated code to form a complete agent. The agent can be compiled either from MIB Compiler UI or from Command line. For compiling the code,
From MIB Compiler UI
Select Build -> Compile Source from the menu bar.
The files compiled are listed in the Debug Window.
On successful compilation "Compilation succeeded." message can be seen.
From Commandline
Open a command prompt/ terminal.
Go to the <Agent Toolkit Home>/snmpprojects/projectname directory and set the classpath.
Then, execute the
following command:
javac -d
agent\bin agent\src\com\myCompany\myPackage\*.java
The above command will compile all the source files under agent/src directory.
If compilation is successful, the compiled class files will get stored under <Agent Toolkit Home>/snmpprojects/projectname/agent/bin directory.
Now, all the files have been compiled and the simple SNMP agent has been created.
5.6 Starting and Stopping the Agent
Once the agent is developed, it can be started from MIB Compiler UI or from commandline.
From MIB Compiler UI
Select Build -> Start Agent from the menu bar. By default,this would start the agent at port 8001. To stop the agent, use Build -> Stop Agent in the menu bar.
From Commandline
Open a command prompt/ terminal.
Go to <Agent Toolkit Home>/snmpprojects/projectname/agent/bin directory.
Execute the run.bat/ run.sh command.
The agent gets started at the default port 8001.
To stop the agent, use Ctrl + C. This would kill the application.
Now that the agent is developed and started, the next step is to test the agent by sending SNMP requests. To know how to perform Testing on the Agent, please refer to Testing the Agent section.
![]() ![]() ![]() |