|
Packit |
fcad23 |
## -*- c -*-
|
|
Packit |
fcad23 |
######################################################################
|
|
Packit |
fcad23 |
## Do the .h file
|
|
Packit |
fcad23 |
######################################################################
|
|
Packit |
fcad23 |
@open -@
|
|
Packit |
fcad23 |
*** Warning: only generating code for nodes of MIB type INTEGER
|
|
Packit |
fcad23 |
@open ${name}.h@
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Note: this file originally auto-generated by mib2c
|
|
Packit |
fcad23 |
* using mib2c.int_watch.conf
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
#ifndef $name.uc_H
|
|
Packit |
fcad23 |
#define $name.uc_H
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/* function declarations */
|
|
Packit |
fcad23 |
void init_$name(void);
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
#endif /* $name.uc_H */
|
|
Packit |
fcad23 |
######################################################################
|
|
Packit |
fcad23 |
## Do the .c file
|
|
Packit |
fcad23 |
######################################################################
|
|
Packit |
fcad23 |
@open ${name}.c@
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Note: this file originally auto-generated by mib2c
|
|
Packit |
fcad23 |
* using mib2c.int_watch.conf
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
#include <net-snmp/net-snmp-config.h>
|
|
Packit |
fcad23 |
#include <net-snmp/net-snmp-includes.h>
|
|
Packit |
fcad23 |
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
|
Packit |
fcad23 |
#include "${name}.h"
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* The variables we want to tie the relevant OIDs to.
|
|
Packit |
fcad23 |
* The agent will handle all GET and (if applicable) SET requests
|
|
Packit |
fcad23 |
* to these variables automatically, changing the values as needed.
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
@foreach $i scalar@
|
|
Packit |
fcad23 |
@if !$i.needlength@
|
|
Packit |
fcad23 |
$i.decl $i = 0; /* XXX: set default value */
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Our initialization routine, called automatically by the agent
|
|
Packit |
fcad23 |
* (Note that the function name must match init_FILENAME())
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
void
|
|
Packit |
fcad23 |
init_${name}(void)
|
|
Packit |
fcad23 |
{
|
|
Packit |
fcad23 |
netsnmp_handler_registration *reg;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
@foreach $i scalar@
|
|
Packit |
fcad23 |
@if !$i.needlength@
|
|
Packit |
fcad23 |
const oid ${i}_oid[] = { $i.commaoid };
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
static netsnmp_watcher_info ${i}_winfo;
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* a debugging statement. Run the agent with -D$name to see
|
|
Packit |
fcad23 |
* the output of this debugging statement.
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
DEBUGMSGTL(("$name", "Initializing the $name module\n"));
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Register scalar watchers for each of the MIB objects.
|
|
Packit |
fcad23 |
* The ASN type and RO/RW status are taken from the MIB definition,
|
|
Packit |
fcad23 |
* but can be adjusted if needed.
|
|
Packit |
fcad23 |
*
|
|
Packit |
fcad23 |
* In most circumstances, the scalar watcher will handle all
|
|
Packit |
fcad23 |
* of the necessary processing. But the NULL parameter in the
|
|
Packit |
fcad23 |
* netsnmp_create_handler_registration() call can be used to
|
|
Packit |
fcad23 |
* supply a user-provided handler if necessary.
|
|
Packit |
fcad23 |
*
|
|
Packit |
fcad23 |
* This approach can also be used to handle Counter64, string-
|
|
Packit |
fcad23 |
* and OID-based watched scalars (although variable-sized writeable
|
|
Packit |
fcad23 |
* objects will need some more specialised initialisation).
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
@foreach $i scalar@
|
|
Packit |
fcad23 |
@if !$i.needlength@
|
|
Packit |
fcad23 |
DEBUGMSGTL(("$name",
|
|
Packit |
fcad23 |
"Initializing $i scalar integer. Default value = %d\n",
|
|
Packit |
fcad23 |
$i));
|
|
Packit |
fcad23 |
reg = netsnmp_create_handler_registration(
|
|
Packit |
fcad23 |
"$i", NULL,
|
|
Packit |
fcad23 |
${i}_oid, OID_LENGTH(${i}_oid),
|
|
Packit |
fcad23 |
@if $i.settable@
|
|
Packit |
fcad23 |
HANDLER_CAN_RWRITE);
|
|
Packit |
fcad23 |
@else@
|
|
Packit |
fcad23 |
HANDLER_CAN_RONLY);
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
netsnmp_init_watcher_info(&${i}_winfo, &$i, sizeof($i.decl),
|
|
Packit |
fcad23 |
$i.type, WATCHER_FIXED_SIZE);
|
|
Packit |
fcad23 |
if (netsnmp_register_watched_scalar( reg, &${i}_winfo ) < 0 ) {
|
|
Packit |
fcad23 |
snmp_log( LOG_ERR, "Failed to register watched $i" );
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
@end@
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSGTL(("$name",
|
|
Packit |
fcad23 |
"Done initalizing $name module\n"));
|
|
Packit |
fcad23 |
}
|