Hi,
I wanted to implement a delay if somebody does snmpget on an oid
1.3.6.1.2.1.1.5.0. So I copied the following code from delayed_instance.c.
I run this code and run snmpget command this oid, I cant see any delay.
Can somebody help me in implementing this?
---------------------------------------------------------------------
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/agent_handler.h>
#include "delayed_instance.h"
static u_long delay_time = 60;
void
init_delayed_instance(void)
{
static oid my_delayed_oid[] = {1, 3, 6, 1, 2, 1, 1, 5, 0};
netsnmp_handler_registration *my_test;
printf("\nInit_start\n");
my_test =
netsnmp_create_handler_registration("delayed_instance_example",
delayed_instance_handler,
my_delayed_oid,
OID_LENGTH(my_delayed_oid),
HANDLER_CAN_RWRITE);
netsnmp_register_instance(my_test);
printf("init_register\n");
sleep(100);
}
#define DELAYED_INSTANCE_SET_NAME "test_delayed"
int
delayed_instance_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
DEBUGMSGTL(("delayed_instance", "Got request, mode = %d:\n",
reqinfo->mode));
printf("delayed_instance, Got request, mode = %d\n", reqinfo->mode);
switch (reqinfo->mode) {
default:
requests->delegated = 1;
snmp_alarm_register(delay_time, /* seconds */
0, /* dont repeat. */
return_delayed_response, /* the function
* to call */
(void *)
netsnmp_create_delegated_cache(handler,
reginfo,
reqinfo,
requests,
NULL));
break;
}
return SNMP_ERR_NOERROR;
}
void
return_delayed_response(unsigned int clientreg, void *clientarg)
{
netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) clientarg;
netsnmp_request_info *requests;
netsnmp_agent_request_info *reqinfo;
u_long *delay_time_cache = NULL;
cache = netsnmp_handler_check_cache(cache);
if (!cache) {
snmp_log(LOG_ERR, "illegal call to return delayed response\n");
return;
}
reqinfo = cache->reqinfo;
requests = cache->requests;
DEBUGMSGTL(("delayed_instance",
"continuing delayed request, mode = %d\n",
cache->reqinfo->mode));
requests->delegated = 0;
switch (cache->reqinfo->mode) {
case MODE_GET:
case MODE_GETNEXT:
{
printf("I'm in get or getnext\n");
snmp_set_var_typed_value(cache->requests->requestvb,
ASN_INTEGER,
(u_char *) & delay_time,
sizeof(delay_time));
break;
}
netsnmp_free_delegated_cache(cache);
}
int main()
{
init_delayed_instance();
return 0;
}
--------------------------------------------------------------------
Regards,
Rav
"SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 2005
conducted by the BUSINESS TODAY - Mercer - TNS India"
SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged
information. In case you are not the original intended Recipient of the
message, you must not, directly or indirectly, use, Disclose, distribute,
print, or copy any part of this message and you are requested to delete it and
inform the sender. Any views expressed in this message are those of the
individual sender unless otherwise stated. Nothing contained in this message
shall be construed as an offer or acceptance of any offer by Sasken
Communication Technologies Limited ("Sasken") unless sent with that express
intent and with due authority of Sasken. Sasken has taken enough precautions to
prevent the spread of viruses. However the company accepts no liability for any
damage caused by any virus transmitted by this email
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders