changes
This commit is contained in:
@ -5,157 +5,110 @@
|
||||
#include <net-snmp/net-snmp-includes.h>
|
||||
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
||||
|
||||
int number1 = 42;
|
||||
int accepted = 43;
|
||||
|
||||
int
|
||||
handle_it(netsnmp_mib_handler *handler,
|
||||
netsnmp_handler_registration *reginfo,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests)
|
||||
handle_counter32(netsnmp_mib_handler *handler,
|
||||
netsnmp_handler_registration *reginfo,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests)
|
||||
{
|
||||
static int the_number = 42;
|
||||
/* We are never called for a GETNEXT if it's registered as a
|
||||
"instance", as it's "magically" handled for us. */
|
||||
|
||||
/*
|
||||
* We are never called for a GETNEXT if it's registered as a
|
||||
* "instance", as it's "magically" handled for us.
|
||||
*/
|
||||
/* a instance handler also only hands us one request at a time, so
|
||||
we don't need to loop over a list of requests; we'll only get one. */
|
||||
|
||||
switch(reqinfo->mode) {
|
||||
|
||||
/*
|
||||
* a instance handler also only hands us one request at a time, so
|
||||
* we don't need to loop over a list of requests; we'll only get one.
|
||||
*/
|
||||
|
||||
switch (reqinfo->mode) {
|
||||
|
||||
case MODE_GET:
|
||||
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
|
||||
(u_char *)
|
||||
/* XXX: a pointer to the scalar's data */
|
||||
&the_number
|
||||
,
|
||||
/*
|
||||
* XXX: the length of the data in bytes
|
||||
*/
|
||||
sizeof(the_number));
|
||||
break;
|
||||
case MODE_GET:
|
||||
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
|
||||
(u_char *) &number1/* XXX: a pointer to the scalar's data */,
|
||||
sizeof(number1) /* XXX: the length of the data in bytes */);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
/*
|
||||
* we should never get here, so this is a really bad error
|
||||
*/
|
||||
return SNMP_ERR_GENERR;
|
||||
default:
|
||||
/* we should never get here, so this is a really bad error */
|
||||
return SNMP_ERR_GENERR;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
init_subagent(void)
|
||||
int
|
||||
handle_dhsAccepted(netsnmp_mib_handler *handler,
|
||||
netsnmp_handler_registration *reginfo,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests)
|
||||
{
|
||||
static oid dhsIllegalInputFailure_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 9 };
|
||||
static oid dhsOKReturned_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 5 };
|
||||
static oid dhsTEMPReturned_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 6 };
|
||||
static oid dhsNetStringFailure_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 12 };
|
||||
static oid dhsRunningNwThreads_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 3 };
|
||||
static oid dhsFailedNwThreads_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 4 };
|
||||
static oid dhsUnknownClassFailure_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 10 };
|
||||
static oid dhsFailed_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 2 };
|
||||
static oid dhsNOTFOUNDReturned_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 8 };
|
||||
static oid dhsAccepted_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 1 };
|
||||
static oid dhsPERMReturned_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 7 };
|
||||
static oid dhsTimeoutFailure_oid[] =
|
||||
{ 1, 3, 6, 1, 4, 1, 9676, 2, 1, 1, 11 };
|
||||
/* We are never called for a GETNEXT if it's registered as a
|
||||
"instance", as it's "magically" handled for us. */
|
||||
|
||||
DEBUGMSGTL(("smmapd_snmp_subagent", "Initializing\n"));
|
||||
/* a instance handler also only hands us one request at a time, so
|
||||
we don't need to loop over a list of requests; we'll only get one. */
|
||||
|
||||
switch(reqinfo->mode) {
|
||||
|
||||
case MODE_GET:
|
||||
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
|
||||
(u_char *) &accepted/* XXX: a pointer to the scalar's data */,
|
||||
sizeof(accepted) /* XXX: the length of the data in bytes */);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
/* we should never get here, so this is a really bad error */
|
||||
return SNMP_ERR_GENERR;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/** Initializes the dhsMIBObjects module */
|
||||
void
|
||||
init_dhsMIBObjects(void)
|
||||
{
|
||||
static oid dhsNumber1_oid[] = { 1,3,6,1,4,1,9676,2,1,1 };
|
||||
static oid dhsAccepted_oid[] = { 1,3,6,1,4,1,9676,2,1,2,1 };
|
||||
|
||||
|
||||
DEBUGMSGTL(("dhsMIBObjects", "Initializing\n"));
|
||||
|
||||
netsnmp_register_scalar(
|
||||
netsnmp_create_handler_registration("dhsNumber1", handle_counter32,
|
||||
dhsNumber1_oid, OID_LENGTH(dhsNumber1_oid),
|
||||
HANDLER_CAN_RONLY
|
||||
));
|
||||
netsnmp_register_scalar(
|
||||
netsnmp_create_handler_registration("dhsAccepted", handle_counter32,
|
||||
dhsAccepted_oid, OID_LENGTH(dhsAccepted_oid),
|
||||
HANDLER_CAN_RONLY
|
||||
));
|
||||
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsIllegalInputFailure",
|
||||
handle_it,
|
||||
dhsIllegalInputFailure_oid,
|
||||
OID_LENGTH(dhsIllegalInputFailure_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsOKReturned", handle_it,
|
||||
dhsOKReturned_oid,
|
||||
OID_LENGTH(dhsOKReturned_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsTEMPReturned", handle_it,
|
||||
dhsTEMPReturned_oid,
|
||||
OID_LENGTH(dhsTEMPReturned_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsNetStringFailure",
|
||||
handle_it,
|
||||
dhsNetStringFailure_oid,
|
||||
OID_LENGTH(dhsNetStringFailure_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsRunningNwThreads",
|
||||
handle_it,
|
||||
dhsRunningNwThreads_oid,
|
||||
OID_LENGTH(dhsRunningNwThreads_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsFailedNwThreads",
|
||||
handle_it,
|
||||
dhsFailedNwThreads_oid,
|
||||
OID_LENGTH(dhsFailedNwThreads_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsUnknownClassFailure",
|
||||
handle_it,
|
||||
dhsUnknownClassFailure_oid,
|
||||
OID_LENGTH(dhsUnknownClassFailure_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsFailed", handle_it, dhsFailed_oid,
|
||||
OID_LENGTH(dhsFailed_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsNOTFOUNDReturned",
|
||||
handle_it,
|
||||
dhsNOTFOUNDReturned_oid,
|
||||
OID_LENGTH(dhsNOTFOUNDReturned_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsAccepted", handle_it,
|
||||
dhsAccepted_oid, OID_LENGTH(dhsAccepted_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsPERMReturned", handle_it,
|
||||
dhsPERMReturned_oid,
|
||||
OID_LENGTH(dhsPERMReturned_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
netsnmp_register_scalar(netsnmp_create_handler_registration
|
||||
("dhsTimeoutFailure", handle_it,
|
||||
dhsTimeoutFailure_oid,
|
||||
OID_LENGTH(dhsTimeoutFailure_oid),
|
||||
HANDLER_CAN_RONLY));
|
||||
}
|
||||
|
||||
void snmp_subagent_main () {
|
||||
int res;
|
||||
|
||||
printf("snmp_subagent_main: 1\n");
|
||||
snmp_enable_stderrlog();
|
||||
printf("snmp_subagent_main: 2\n");
|
||||
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
|
||||
printf("snmp_subagent_main: 3\n");
|
||||
init_agent("smmapd_subagent");
|
||||
init_subagent();
|
||||
printf("snmp_subagent_main: 4\n");
|
||||
init_dhsMIBObjects();
|
||||
printf("snmp_subagent_main: 5\n");
|
||||
init_snmp("smmapd_subagent");
|
||||
printf("snmp_subagent_main: 6\n");
|
||||
|
||||
/* main loop here... */
|
||||
while(1) {
|
||||
agent_check_and_process(1);
|
||||
printf("snmp_subagent_main: main loop\n");
|
||||
res=agent_check_and_process(1);
|
||||
printf("snmp_subagent_main: result in main loop: %d\n",res);
|
||||
}
|
||||
|
||||
/* at shutdown time */
|
||||
|
Reference in New Issue
Block a user