snmp4az
Programmer
- Apr 6, 2008
- 2
Hi,
I'm new to snmp ... I'm using unix environment ... I went through net-snmp site tutorial ... I have a manager to issue get and set commant, agent and server which I'm monitoring its cpu, mem usage and other stuff ( I provide a code example at the end of the message) ... I have some general questions please:
1- I have MIB and then I Use mib2c tool ( mib2c -c mib2c.int_watch.conf MIB) to get .c and .h C codes for agent ... how can I manipulate the variable (e.g: example1: in the provided code) in other ways outside of SNMP gets/sets ?
2- using mib2c -c mib2c.scalar.conf MIB, it doesn't declare the variable it provide a handler to do what ever I want to do in case of get,set .. again how can I manipulate variable if it is not declared? how can I ulter the stub code?
3- In general I define cpuusage, memoryusage, diskusage as integer variable in MIB and I use mib2c -c mib2c.int_watch.conf MIB .. and I want to monitor those variable on server and provide the information to the maneger through agent using snmpget?
4- Is their any good coding references for coding snmp in Unix?
Appreciate your help ..
Thanks in advance ..
Zainab
--------------------------------------------------------------------
Code Example:
This example creates some scalar registrations that allows some simple variables to be accessed via SNMP. In a more realistic example, it is likely that these variables would also be manipulated in other ways outside of SNMP gets/sets.
If this module is compiled into an agent, you should be able to issue snmp commands that look something like (authentication information not shown in these commands):
snmpget localhost netSnmpExampleInteger.0
netSnmpExampleScalars = 42
snmpset localhost netSnmpExampleInteger.0 = 1234
netSnmpExampleScalars = 1234
snmpget localhost netSnmpExampleInteger.0
netSnmpExampleScalars = 1234
/*
* start be including the appropriate header files
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/*
* Then, we declare the variables we want to be accessed
*/
static int example1 = 42; /* default value */
/*
* our initialization routine, automatically called by the agent
* (to get called, the function name must match init_FILENAME())
*/
void
init_scalar_int(void)
{
/*
* the OID we want to register our integer at. This should be a
* fully qualified instance. In our case, it's a scalar at:
* NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
* trailing 0 which is required for any instantiation of any
* scalar object)
*/
oid my_registration_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
/*
* a debugging statement. Run the agent with -Dexample_scalar_int to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("example_scalar_int",
"Initalizing example scalar int. Default value = %d\n",
example1));
/*
* the line below registers our "example1" variable above as
* accessible and makes it writable. A read only version of the
* same registration would merely call
* register_read_only_int_instance() instead.
*
* If we wanted a callback when the value was retrieved or set
* (even though the details of doing this are handled for you),
* you could change the NULL pointer below to a valid handler
* function.
*/
netsnmp_register_int_instance("my example int variable",
my_registration_oid,
OID_LENGTH(my_registration_oid),
&example1, NULL);
DEBUGMSGTL(("example_scalar_int",
"Done initalizing example scalar int\n"));
}
I'm new to snmp ... I'm using unix environment ... I went through net-snmp site tutorial ... I have a manager to issue get and set commant, agent and server which I'm monitoring its cpu, mem usage and other stuff ( I provide a code example at the end of the message) ... I have some general questions please:
1- I have MIB and then I Use mib2c tool ( mib2c -c mib2c.int_watch.conf MIB) to get .c and .h C codes for agent ... how can I manipulate the variable (e.g: example1: in the provided code) in other ways outside of SNMP gets/sets ?
2- using mib2c -c mib2c.scalar.conf MIB, it doesn't declare the variable it provide a handler to do what ever I want to do in case of get,set .. again how can I manipulate variable if it is not declared? how can I ulter the stub code?
3- In general I define cpuusage, memoryusage, diskusage as integer variable in MIB and I use mib2c -c mib2c.int_watch.conf MIB .. and I want to monitor those variable on server and provide the information to the maneger through agent using snmpget?
4- Is their any good coding references for coding snmp in Unix?
Appreciate your help ..
Thanks in advance ..
Zainab
--------------------------------------------------------------------
Code Example:
This example creates some scalar registrations that allows some simple variables to be accessed via SNMP. In a more realistic example, it is likely that these variables would also be manipulated in other ways outside of SNMP gets/sets.
If this module is compiled into an agent, you should be able to issue snmp commands that look something like (authentication information not shown in these commands):
snmpget localhost netSnmpExampleInteger.0
netSnmpExampleScalars = 42
snmpset localhost netSnmpExampleInteger.0 = 1234
netSnmpExampleScalars = 1234
snmpget localhost netSnmpExampleInteger.0
netSnmpExampleScalars = 1234
/*
* start be including the appropriate header files
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/*
* Then, we declare the variables we want to be accessed
*/
static int example1 = 42; /* default value */
/*
* our initialization routine, automatically called by the agent
* (to get called, the function name must match init_FILENAME())
*/
void
init_scalar_int(void)
{
/*
* the OID we want to register our integer at. This should be a
* fully qualified instance. In our case, it's a scalar at:
* NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
* trailing 0 which is required for any instantiation of any
* scalar object)
*/
oid my_registration_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
/*
* a debugging statement. Run the agent with -Dexample_scalar_int to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("example_scalar_int",
"Initalizing example scalar int. Default value = %d\n",
example1));
/*
* the line below registers our "example1" variable above as
* accessible and makes it writable. A read only version of the
* same registration would merely call
* register_read_only_int_instance() instead.
*
* If we wanted a callback when the value was retrieved or set
* (even though the details of doing this are handled for you),
* you could change the NULL pointer below to a valid handler
* function.
*/
netsnmp_register_int_instance("my example int variable",
my_registration_oid,
OID_LENGTH(my_registration_oid),
&example1, NULL);
DEBUGMSGTL(("example_scalar_int",
"Done initalizing example scalar int\n"));
}