Manual Pages for UNIX Darwin command on man snmp_agent_api
MyWebUniversity

Manual Pages for UNIX Darwin command on man snmp_agent_api

SNMPAGENTAPI(3) Net-SNMP SNMPAGENTAPI(3)

NAME

snmpagentapi - embedding an agent into a external application

SYNOPSIS

#include

#include

#include

int main (int argc, char *argv[]) { int agentxsubagent = 1; /* Change this if you're a master agent. */ snmpenablestderrlog(); /* If we're an AgentX subagent... */ if (agentxsubagent) { /* ...make us an AgentX client. */ netsnmpdssetboolean(NETSNMPDSAPPLICATIONID, NETSNMPDSAGENTROLE, 1); } initagent("yourappname"); /* Initialize your MIB code here. */ initmymibcode(); /* `yourappname' will be used to read yourappname.conf files. */ initsnmp("yourappname"); /* If we're going to be a SNMP master agent... */ if (!agentxsubagent) initmasteragent(); /* Listen on default port (161). */ /* Your main loop here... */ while (whatever) { /* if you use select(), see snmpapi(3) */

/* -- OR -- */

agentcheckandprocess(0); /* 0 == don't block */ } /* At shutdown time: */ snmpshutdown("yourappname"); } Then:

$(CC) ... `net-snmp-config -agent-libs`

DESCRIPTION

Our goal is to create a easy to use interface to the Net-SNMP package

such that you can take code that you have written that has been

designed to be a Net-SNMP MIB module and embed it into an external

application where you can either chose to be a SNMP master agent or an

AgentX sub-agent using the same MIB module code. Our suggestion is

that you use our (or another) SNMP agent as the AgentX master agent and chose to become an AgentX subagent which then attaches to the master.

The Net-SNMP package provides a pair of libraries that enables easy

embedding of an SNMP or AgentX agent into an external software package.

AgentX is an extensible protocol designed to allow multiple SNMP sub-

agents all run on one machine under a single SNMP master agent. It is defined in RFC 2741. You will need to perform a few tasks in order to accomplish this. First off, you will need to initialize both the SNMP library and the SNMP agent library. As indicated above, this is done slightly differently depending on whether or not you are going to perform as a master agent

or an AgentX sub-agent.

CCOONNFFIIGGUURRAATTIIOONN

If you intend to operate as an AgentX sub-agent, you will have to con-

figured the Net-SNMP package with agentx support (which is turned on by

default, so just don't turn it off)

Additionally, you will need to link against the net-snmp libraries (use

the output of "net-snmp-config -agent-libs" to get a library list) and

call subagentpreinit() as indicated above. CCOOMMPPIILLIINNGG In order to make use of any of the above API, you will need to link against at least the four libraries listed above. FFUUNNCCTTIIOONNSS

where to find out more information on them. It is certainly not a com-

plete list of what is available within all the net-snmp libraries.

snmpenablestderrlog() Logs error output from the SNMP agent to the standard error stream. netsnmpdssetboolean() Please see the defaultstore(3) manual page for more information about this API. initagent(char *name) Initializes the embedded agent. This should be called before the iinniittssnnmmpp(()) call. name is used to dictate what .conf file to read when iinniittssnnmmpp(()) is called later. initsnmp(char *name) Initializes the SNMP library. Note that one of the things this

will do will be to read configuration files in an effort to con-

figure your application. It will attempt to read the configura-

tion files named by the name string that you passed in. It can be used to configure access control, for instance. Please see the readconfig(3), snmpconfig(5), and snmpd.conf(5) manual pages for further details on this subject. initmasteragent(void) Initializes the master agent and causes it to listen for SNMP requests on its default UDP port of 161. agentcheckandprocess(int block) This checks for packets arriving on the SNMP port and processes

them if some are found. If block is non-zero, the function call

will block until a packet arrives or an alarm must be run (see

snmpalarm(3)). The return value from this function is a posi-

tive integer if packets were processed, zero if an alarm

occurred and -1 if an error occured.

snmpshutdown(char *name); This shuts down the agent, saving any needed persistent storage, etc.

SEE ALSO

http://www.net-snmp.org/tutorial-5/toolkit/, select(2), snmpapi(3),

defaultstore(3), snmpalarm(3), readconfig(3), snmpconfig(5), snmpd.conf(5) 4.2 Berkeley Distribution 02 Apr 2001 SNMPAGENTAPI(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™