man tinysnmp-modules (Fonctions bibliothèques) - TinySNMPd module API

NAME

TinySNMPd module API

SYNOPSIS

#include <tinysnmp/agent/module.h>

#include <tinysnmp/agent/odb.h>

static int foo_parse (struct tokens *tokens")

{ ... }

"staticintfoo_open(void)

{ ... }

static int foo_update (struct odb **odb")

{ ... }

"staticintfoo_close(void)

{ ... }

"staticconstuint32_tfoo_oid[]={...};

"staticconstuint32_tbar_oid[]={...};

"structmodulemodule={

.name = "foo"",

.descr = "TheMIBmoduleforFooentities"",

.mod_oid" =foo_oid,

.con_oid" =bar_oid,

.parse" =foo_parse,

.open" =foo_open,

.close" =foo_close, };

DESCRIPTION

Each TinySNMPd modules must define a module structure as above. You have to specify at least the name, description, the module and conformance object identifiers, and an update callback function. All the other callback functions are optional.

The _init() and _fini() functions should not be used.

The module oid (mod_oid) must be the base ObjectID and all ObjectID's exported by the module must be below that base ObjectID. The conformance oid (con_oid) must be the base ObjectID of all the conformance statements of the mib.

The open function is called once when the agent is started. This function should be used to allocate and initialize resources for use by the other functions.

The parse function is called if/when the module section is parsed. This happens after the open function was called.

The close function is called once when the agent is stopped. This function should free all resources allocated by any of the other functions.

The update function is called when the agent is trying to find any ObjectIDs exported by this module. The agent removes all ObjectID's exported by the module before calling this function. If the function fails, it will also remove any ObjectID's afterwards. There is therefore no need to remove any ObjectID's inside the update function.

RETURN VALUES

The open and update callbacks should return 0 if successful, -1 if some error occurred. The parse callback should return 1 a statement was parsed successfully, 0 if an unknown statement is encountered, and -1 if some error occurred.

All errors should be saved using abz_set_error().

SEE ALSO

AUTHOR

Written by Abraham vd Merwe <abz@blio.com>