1 /** @example scalar_int.c
2 * This example creates some scalar registrations that allows
3 * some simple variables to be accessed via SNMP. In a more
4 * realistic example, it is likely that these variables would also be
5 * manipulated in other ways outside of SNMP gets/sets.
7 * If this module is compiled into an agent, you should be able to
8 * issue snmp commands that look something like (authentication
9 * information not shown in these commands):
11 * - snmpget localhost netSnmpExampleInteger.0
12 * - netSnmpExampleScalars = 42
14 * - snmpset localhost netSnmpExampleInteger.0 = 1234
15 * - netSnmpExampleScalars = 1234
17 * - snmpget localhost netSnmpExampleInteger.0
18 * - netSnmpExampleScalars = 1234
23 * start be including the appropriate header files
25 #include <net-snmp/net-snmp-config.h>
26 #include <net-snmp/net-snmp-includes.h>
27 #include <net-snmp/agent/net-snmp-agent-includes.h>
30 * Then, we declare the variables we want to be accessed
32 static int example1 = 42; /* default value */
35 * our initialization routine, automatically called by the agent
36 * (to get called, the function name must match init_FILENAME())
42 * the OID we want to register our integer at. This should be a
43 * fully qualified instance. In our case, it's a scalar at:
44 * NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
45 * trailing 0 which is required for any instantiation of any
48 oid my_registration_oid[] =
49 { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
52 * a debugging statement. Run the agent with -Dexample_scalar_int to see
53 * the output of this debugging statement.
55 DEBUGMSGTL(("example_scalar_int",
56 "Initalizing example scalar int. Default value = %d\n",
60 * the line below registers our "example1" variable above as
61 * accessible and makes it writable. A read only version of the
62 * same registration would merely call
63 * register_read_only_int_instance() instead.
65 * If we wanted a callback when the value was retrieved or set
66 * (even though the details of doing this are handled for you),
67 * you could change the NULL pointer below to a valid handler
70 netsnmp_register_int_instance("my example int variable",
72 OID_LENGTH(my_registration_oid),
75 DEBUGMSGTL(("example_scalar_int",
76 "Done initalizing example scalar int\n"));