Blame man/netsnmp_agent_api.3.def

Packit Service b38f0b
.TH NETSNMP_AGENT_API 3 "13 Aug 2010" VVERSIONINFO "Net-SNMP"
Packit Service b38f0b
.SH NAME
Packit Service b38f0b
netsnmp_agent_api - embedding an agent into a external application
Packit Service b38f0b
.SH SYNOPSIS
Packit Service b38f0b
.nf
Packit Service b38f0b
#include <net\-snmp/net\-snmp\-config.h>
Packit Service b38f0b
#include <net\-snmp/net\-snmp\-includes.h>
Packit Service b38f0b
#include <net\-snmp/agent/net\-snmp\-agent\-includes.h>
Packit Service b38f0b
Packit Service b38f0b
int
Packit Service b38f0b
main (int argc, char *argv[])
Packit Service b38f0b
{
Packit Service b38f0b
  int agentx_subagent = 1;  /* Change this if you're a master agent.  */
Packit Service b38f0b
Packit Service b38f0b
  snmp_enable_stderrlog();
Packit Service b38f0b
Packit Service b38f0b
  /*  If we're an AgentX subagent...  */
Packit Service b38f0b
  if (agentx_subagent) {
Packit Service b38f0b
      /* ...make us an AgentX client.  */
Packit Service b38f0b
      netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                             NETSNMP_DS_AGENT_ROLE, 1);
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  init_agent("yourappname");
Packit Service b38f0b
Packit Service b38f0b
  /*  Initialize your MIB code here.  */
Packit Service b38f0b
  init_my_mib_code();
Packit Service b38f0b
Packit Service b38f0b
  /*  `yourappname' will be used to read yourappname.conf files.  */
Packit Service b38f0b
  init_snmp("yourappname");
Packit Service b38f0b
Packit Service b38f0b
  /*  If we're going to be a SNMP master agent...  */
Packit Service b38f0b
  if (!agentx_subagent)
Packit Service b38f0b
      init_master_agent();  /*  Listen on default port (161).  */
Packit Service b38f0b
Packit Service b38f0b
  /*  Your main loop here...  */
Packit Service b38f0b
  while (whatever) {
Packit Service b38f0b
      /* if you use select(), see snmp_api(3) */
Packit Service b38f0b
      /*     --- OR ---  */
Packit Service b38f0b
      agent_check_and_process(0); /* 0 == don't block */
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  /*  At shutdown time:  */
Packit Service b38f0b
  snmp_shutdown("yourappname");
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
Then:
Packit Service b38f0b
$(CC) ... `net\-snmp\-config \-\-agent\-libs`
Packit Service b38f0b
Packit Service b38f0b
.fi
Packit Service b38f0b
.SH DESCRIPTION
Packit Service b38f0b
.PP
Packit Service b38f0b
Our goal is to create a easy to use interface to the Net-SNMP package
Packit Service b38f0b
such that you can take code that you have written that has been
Packit Service b38f0b
designed to be a Net-SNMP MIB module and embed it into an external
Packit Service b38f0b
application where you can either chose to be a SNMP master agent or an
Packit Service b38f0b
AgentX sub-agent using the same MIB module code.  Our suggestion is
Packit Service b38f0b
that you use our (or another) SNMP agent as the AgentX master agent
Packit Service b38f0b
and chose to become an AgentX subagent which then attaches to the
Packit Service b38f0b
master.
Packit Service b38f0b
.PP
Packit Service b38f0b
The Net-SNMP package provides a pair of libraries that enables easy
Packit Service b38f0b
embedding of an SNMP or AgentX agent into an external software
Packit Service b38f0b
package. AgentX is an extensible protocol designed to allow multiple
Packit Service b38f0b
SNMP sub-agents all run on one machine under a single SNMP master
Packit Service b38f0b
agent.  It is defined in RFC 2741.
Packit Service b38f0b
.PP
Packit Service b38f0b
You will need to perform a few tasks in order to accomplish
Packit Service b38f0b
this. First off, you will need to initialize both the SNMP library and
Packit Service b38f0b
the SNMP agent library. As indicated above, this is done slightly
Packit Service b38f0b
differently depending on whether or not you are going to perform as a
Packit Service b38f0b
master agent or an AgentX sub-agent.
Packit Service b38f0b
.SH CONFIGURATION
Packit Service b38f0b
.PP
Packit Service b38f0b
If you intend to operate as an AgentX sub-agent, you will have to
Packit Service b38f0b
configured the Net-SNMP package with agentx support (which is turned
Packit Service b38f0b
on by default, so just don't turn it off)
Packit Service b38f0b
.PP
Packit Service b38f0b
Additionally, you will need to link against the Net-SNMP libraries
Packit Service b38f0b
(use the output of "net\-snmp\-config \-\-agent\-libs" to get a library
Packit Service b38f0b
list) and call subagent_pre_init() as indicated above.
Packit Service b38f0b
.SH COMPILING
Packit Service b38f0b
.PP
Packit Service b38f0b
In order to make use of any of the above API, you will need to link
Packit Service b38f0b
against at least the four libraries listed above.
Packit Service b38f0b
.SH FUNCTIONS
Packit Service b38f0b
.PP This is a brief description of the functions called above and
Packit Service b38f0b
where to find out more information on them.  It is certainly not a
Packit Service b38f0b
complete list of what is available within all the Net-SNMP libraries. 
Packit Service b38f0b
.IP "snmp_enable_stderrlog()"
Packit Service b38f0b
Logs error output from the SNMP agent to the standard error stream.
Packit Service b38f0b
.IP "netsnmp_ds_set_boolean()"
Packit Service b38f0b
Please see the
Packit Service b38f0b
.IR default_store(3)
Packit Service b38f0b
manual page for more information
Packit Service b38f0b
about this API.
Packit Service b38f0b
.IP "init_agent(char *name)"
Packit Service b38f0b
Initializes the embedded agent.  This should be called before the
Packit Service b38f0b
.BR "init_snmp()"
Packit Service b38f0b
call.  
Packit Service b38f0b
.I name
Packit Service b38f0b
is used to dictate what .conf file to read when
Packit Service b38f0b
.BR "init_snmp()"
Packit Service b38f0b
is called later.
Packit Service b38f0b
.IP "init_snmp(char *name)"
Packit Service b38f0b
Initializes the SNMP library.  Note that one of the things this will
Packit Service b38f0b
do will be to read configuration files in an effort to configure your
Packit Service b38f0b
application. It will attempt to read the configuration files named by
Packit Service b38f0b
the
Packit Service b38f0b
.I name
Packit Service b38f0b
string that you passed in.  It can be used to configure access
Packit Service b38f0b
control, for instance.   Please see the
Packit Service b38f0b
.IR netsnmp_config_api(3) ", " snmp_config(5) ", and " snmpd.conf(5)
Packit Service b38f0b
manual pages for further details on this subject.
Packit Service b38f0b
.IP "init_master_agent(void)"
Packit Service b38f0b
Initializes the master agent and causes it to listen for SNMP requests 
Packit Service b38f0b
on its default UDP port of 161.
Packit Service b38f0b
.IP "agent_check_and_process(int block)"
Packit Service b38f0b
This checks for packets arriving on the SNMP port and processes them
Packit Service b38f0b
if some are found.  If 
Packit Service b38f0b
.I block
Packit Service b38f0b
is non-zero, the function call will block until a packet arrives or an 
Packit Service b38f0b
alarm must be run (see
Packit Service b38f0b
.IR snmp_alarm(3) ).
Packit Service b38f0b
The return value from this function is a positive integer if packets
Packit Service b38f0b
were processed, zero if an alarm occurred and \-1 if an error occured.
Packit Service b38f0b
.IP "snmp_shutdown(char *name);"
Packit Service b38f0b
This shuts down the agent, saving any needed persistent storage, etc.
Packit Service b38f0b
.SH "SEE ALSO"
Packit Service b38f0b
http://www.net\-snmp.org/tutorial\-5/toolkit/ select(2), snmp_api(3),
Packit Service b38f0b
default_store(3), snmp_alarm(3), netsnmp_config_api(3), snmp_config(5),
Packit Service b38f0b
snmpd.conf(5)