Hi!

I got absolute zero replies to my message, so I created an isolated test case 
in the mean-time. The test case looks like this:

static  volatile int    stop_requests = 0;      /* count stop requests */

/* main */
int     main(int argc, char *argv[])
{
        int             result  = 0;

        /*BEGIN SNMP*/
        /* prepare for AgentX subagent */
        if ( netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
                                    NETSNMP_DS_AGENT_ROLE, 1)
             != SNMPERR_SUCCESS )
        {
                result = 2;
        }
        SOCK_STARTUP;           /* initialize TCP/IP, if necessary */
        init_agent("testagent");        /* initialize the agent library */
        init_IOTWatchMIB();     /* initialize MIB module */
        while ( stop_requests == 0 ) {
                agent_check_and_process(1); /* 0 == don't block */
        }

        /* at shutdown time */
        snmp_shutdown("testagent");
        SOCK_CLEANUP;
        /*END SNMP*/
quit:   return(result);
}

When running the testagent with ltrace, I see the handlers are registered, and 
the test agent waits for data:

---
SNMP> ltrace ./testagent
__libc_start_main(0x400f40, 1, 0x7ffc0e2bb4e8, 0x4011b0, 0x4011a0 <unfinished 
...>
netsnmp_ds_set_boolean(1, 1, 1, 0, 0x7fd165f0f320) = 0
init_agent(0x4012a4, 0x7fd1663d1f40, 0, 1, 0x7fd165f0f320) = 0
snmp_get_do_debugging(1, 1, 0, 1, 0x2965736c61667c) = 0
netsnmp_create_handler_registration(0x40134d, 0x401040, 0x602120, 13, 1) = 
0x6071a0
netsnmp_register_scalar(0x6071a0, 0x602188, 0, 1, 1000) = 0
netsnmp_create_handler_registration(0x40135f, 0x400fd0, 0x6020a0, 13, 1) = 
0x607d40
netsnmp_register_scalar(0x607d40, 0x602108, 0, 2, 1000) = 0
agent_check_and_process(1, 0x7fd166a33049, 0, 0, 0x608050
---

However If I query the OIDs registered, no data are returned ("There is no such 
variable name in this MIB.")

The init Module looks like this:

/** Initializes the IOTWatchMIB module */
void
init_IOTWatchMIB(void)
{
    static oid      giveItABetterName_oid[] =
        { 1, 3, 6, 1, 4, 1, 8072, 9999, 9999, 1000, 1, 1, 1 };
    static oid      giveThisANameToo_oid[] =
        { 1, 3, 6, 1, 4, 1, 8072, 9999, 9999, 1000, 1, 1, 2 };

    DEBUGMSGTL(("IOTWatchMIB", "Initializing\n"));

    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("giveItABetterName", handle_giveItABetterName,
                             giveItABetterName_oid,
                             OID_LENGTH(giveItABetterName_oid),
                             HANDLER_CAN_RONLY));
    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("giveThisANameToo", handle_giveThisANameToo,
                             giveThisANameToo_oid,
                             OID_LENGTH(giveThisANameToo_oid),
                             HANDLER_CAN_RONLY));
}

(The handlers both should cause an abort if called (to help debugging)):

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *) 0 /* XXX: a pointer to the scalar's 
data */
                                 , 1 /* XXX: the length of the data in bytes */ 
);
        break;

I have absolutely no idea how to debug this. While debugging I'm running snmpd 
in user mode as suggested in the tutorial:
/usr/sbin/snmpd -f -Lo -C --rwcommunity=public --master=agentx \
--agentXSocket=tcp:localhost:1705 udp:1161 -Dagentx

I fail to see where my testagent connects to the SNMP socket, nor do I see that 
my config file is opened. The select() is on a pipe, but I cannot see any other 
process in strace:
---
2819  munmap(0x7f84066bd000, 4096)      = 0
2819  gettimeofday({1439373523, 620867}, NULL) = 0
2819  pipe([3, 4])                      = 0
2819  gettimeofday({1439373523, 621388}, NULL) = 0
2819  pipe([5, 6])                      = 0
2819  select(6, [3 5], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted)
2819  --- SIGINT (Interrupt) @ 0 (0) ---
2819  +++ killed by SIGINT +++
---

Any ideas?

Regards,
Ulrich

>>> Ulrich Windl schrieb am 05.08.2015 um 10:42 in Nachricht <55C1CC7D.CAD : 
>>> 161 :
60728>:
> Hello!
> 
> I had reported problems with registering an AgentX subagent in Perl (no 
> error, but doesn't work). Finally I found the bug that prevented it from 
> working.
> 
> Now I have a C program that uses multiple threads to retrieve and monitor 
> some values. I tried to make this program an AgentX subagent by adding the 
> code from the C coding example. Unfortunately the same things as in Perl 
> happen: The agent does not connect, and there is no error. When trying to 
> access any of the registered OIDs, an error is returned. None of the handlers 
> is ever called.
> 
> What I'd like to have eventually is that one thread takes care of all the 
> SNMP handling.
> 
> From the example I guess that the API is too high-level (init_agent()): It's 
> hard to see which steps are actually executed, and what the results of these 
> steps are.
> 
> What could the problem be, and how could I debug it?
> 
> The essential code fragemnt looks like this:
>                 /*BEGIN SNMP*/
>                 /* prepare for AgentX subagent */
>                 if ( netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
>                                             NETSNMP_DS_AGENT_ROLE, 1)
>                      != SNMPERR_SUCCESS )
>                 {
>                         /* report problem */
>                 }
>                 SOCK_STARTUP;           /* initialize TCP/IP, if necessary 
> */
>                 init_agent("iotwatch"); /* initialize the agent library */
>                 init_IOTWatchMIB();     /* initialize MIB module */
>                 while ( stop_requests == 0 ) {
>                         agent_check_and_process(1); /* 0 == don't block */
>                 }
> 
>                 /* at shutdown time */
>                 snmp_shutdown("iotwatch");
>                 SOCK_CLEANUP;
>                 /*END SNMP*/
> 
> Regards,
> Ulrich
> 
> 




------------------------------------------------------------------------------
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to