get object value in alarm.c

Jeferson Schenkel <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
The  function below in Rmon/alarm.c intends to get a value of an object to
monitoring it, but only objects in internals mibs  can be gotten.
How can I get object of externals mibs that have the handler
_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration
*reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info
*requests)?

static int
fetch_var_val(oid * name, size_t namelen, u_long * new_value)
{
    netsnmp_subtree *tree_ptr;
    size_t          var_len;
    WriteMethod    *write_method;
    struct variable called_var;
    register struct variable *s_var_ptr = NULL;
    register u_char *access;


    tree_ptr = netsnmp_subtree_find(name, namelen, NULL, "");
    if (!tree_ptr) {
        ag_trace("tree_ptr is NULL");
        return SNMP_ERR_NOSUCHNAME;
    }


    memcpy(called_var.name, tree_ptr->name_a,
           tree_ptr->namelen * sizeof(oid));

    if (tree_ptr->reginfo &&
        tree_ptr->reginfo->handler &&
        tree_ptr->reginfo->handler->next &&
        tree_ptr->reginfo->handler->next->myvoid) {
        s_var_ptr = (struct variable
*)tree_ptr->reginfo->handler->next->myvoid;
    }

    if (s_var_ptr) {
        if (s_var_ptr->namelen) {
                called_var.namelen =
                                   tree_ptr->namelen;
                called_var.type = s_var_ptr->type;
                called_var.magic = s_var_ptr->magic;
                called_var.acl = s_var_ptr->acl;
                called_var.findVar = s_var_ptr->findVar;
                access =
                    (*(s_var_ptr->findVar)) (&called_var, name, &namelen,
                                             1, &var_len, &write_method);

                if (access
                    && snmp_oid_compare(name, namelen, tree_ptr->end_a,
                                        tree_ptr->end_len) > 0) {
                    memcpy(name, tree_ptr->end_a, tree_ptr->end_len);
                    access = 0;
                    ag_trace("access := 0");
                }

                if (access) {

                    /*
                     * check 'var_len' ?
                     */

                    /*
                     * check type
                     */
                    switch (called_var.type) {
                    case ASN_INTEGER:
                    case ASN_COUNTER:
                    case ASN_TIMETICKS:
                    case ASN_GAUGE:
                    case ASN_COUNTER64:
                        break;
                    default:
                        ag_trace("invalid type: %d",
                                 (int) called_var.type);
                        return SNMP_ERR_GENERR;
                    }
                    *new_value = *(u_long *) access;
                    return SNMP_ERR_NOERROR;
                }
            }
        }

    return SNMP_ERR_NOSUCHNAME;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.