/**
 * @internal
 * initialize the iterator container with functions or wrappers
 */
void
_dot11ConfTotalTrapGroupTable_container_init(dot11ConfTotalTrapGroupTable_interface_ctx *if_ctx)
{
    DEBUGMSGTL(("internal:dot11ConfTotalTrapGroupTable:_dot11ConfTotalTrapGroupTable_container_init","called\n"));
    
    /*
     * set up the cache
     */
    if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
                                         _cache_load, _cache_free,
                                         dot11ConfTotalTrapGroupTable_oid,
                                         dot11ConfTotalTrapGroupTable_oid_size);

    if(NULL == if_ctx->cache) {
        snmp_log(LOG_ERR, "error creating cache for dot11ConfTotalTrapGroupTable\n");
        return;
    }

    if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    dot11ConfTotalTrapGroupTable_container_init(&if_ctx->container, if_ctx->cache);
    if(NULL == if_ctx->container)
        if_ctx->container = netsnmp_container_find("dot11ConfTotalTrapGroupTable:table_container");
    if(NULL == if_ctx->container) {
        snmp_log(LOG_ERR,"error creating container in "
                 "dot11ConfTotalTrapGroupTable_container_init\n");
        return;
    }
    if_ctx->cache->magic = (void*)if_ctx->container;
} /* _dot11ConfTotalTrapGroupTable_container_init */
Beispiel #2
0
/** returns a stash_cache handler that can be injected into a given
 *  handler chain (with the specified timeout and root OID values),
 *  but *only* if that handler chain explicitly supports stash cache processing.
 */
netsnmp_mib_handler *
netsnmp_get_timed_bare_stash_cache_handler(int timeout, oid *rootoid, size_t rootoid_len)
{
    netsnmp_mib_handler *handler;
    netsnmp_cache       *cinfo;

    cinfo = netsnmp_cache_create( timeout, _netsnmp_stash_cache_load,
                                 _netsnmp_stash_cache_free, rootoid, rootoid_len );

    if (!cinfo)
        return NULL;

    handler = netsnmp_cache_handler_get( cinfo );
    if (!handler) {
        free(cinfo);
        return NULL;
    }

    handler->next = netsnmp_create_handler("stash_cache", netsnmp_stash_cache_helper);
    if (!handler->next) {
        netsnmp_handler_free(handler);
        free(cinfo);
        return NULL;
    }

    handler->myvoid = cinfo;
    netsnmp_cache_handler_owns_cache(handler);

    return handler;
}
/**
 * @internal
 * initialize the container with functions or wrappers
 */
void
_ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx *
                                     if_ctx)
{
    DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_container_init", "called\n"));

    /*
     * cache init
     */
    if_ctx->cache = netsnmp_cache_create(30,    /* timeout in seconds */
                                         _cache_load, _cache_free,
                                         ipDefaultRouterTable_oid,
                                         ipDefaultRouterTable_oid_size);

    if (NULL == if_ctx->cache) {
        snmp_log(LOG_ERR,
                 "error creating cache for ipDefaultRouterTable\n");
        return;
    }

    if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    ipDefaultRouterTable_container_init(&if_ctx->container, if_ctx->cache);
    if (NULL == if_ctx->container)
        if_ctx->container =
            netsnmp_container_find("ipDefaultRouterTable:table_container");
    if (NULL == if_ctx->container) {
        snmp_log(LOG_ERR, "error creating container in "
                 "ipDefaultRouterTable_container_init\n");
        return;
    }

    if (NULL != if_ctx->cache)
        if_ctx->cache->magic = (void *) if_ctx->container;
}                               /* _ipDefaultRouterTable_container_init */
Beispiel #4
0
void init_cpu( void ) {
    oid nsCPU[] = { 1, 3, 6, 1, 4, 1, 8072, 1, 33 };
    /*
     * If we're sampling the CPU statistics automatically,
     *   then arrange for this to be triggered regularly,
     *   keeping sufficient samples to cover the last minute.
     * If the system-specific code has already initialised
     *   the list of CPU entries, then retrieve the first set
     *   of stats immediately.
     * Otherwise, wait until the regular sampling kicks in.
     *
     * If we're not sampling these statistics regularly,
     *   create a suitable cache handler instead.
     */
    if ( _cpuAutoUpdate ) {
         
        _cpuHistoryLen = 60/_cpuAutoUpdate;
        snmp_alarm_register( _cpuAutoUpdate, SA_REPEAT, _cpu_update_stats,
                             NULL );
        if ( _cpu_head )
            _cpu_update_stats( 0, NULL );
    } else
        _cpu_cache = netsnmp_cache_create( 5, netsnmp_cpu_arch_load, NULL,
                                              nsCPU, OID_LENGTH(nsCPU));
}
Beispiel #5
0
/**
 * create swrun cache
 */
netsnmp_cache *
netsnmp_swrun_cache(void)
{
    oid    hrSWRunTable_oid[]   = { 1, 3, 6, 1, 2, 1, 25, 4, 2 };
    size_t hrSWRunTable_oid_len = OID_LENGTH(hrSWRunTable_oid);

    if ( !swrun_cache ) {
        swrun_cache = netsnmp_cache_create(30,   /* timeout in seconds */
                           _cache_load,  _cache_free,
                           hrSWRunTable_oid, hrSWRunTable_oid_len);
        if (swrun_cache)
            swrun_cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
    }
    return swrun_cache;
}
Beispiel #6
0
/** returns a cache handler that can be injected into a given handler chain.  
 */
netsnmp_mib_handler *
netsnmp_get_cache_handler(int timeout, NetsnmpCacheLoad * load_hook,
                          NetsnmpCacheFree * free_hook,
                          const oid * rootoid, int rootoid_len)
{
    netsnmp_mib_handler *ret = NULL;
    netsnmp_cache  *cache = NULL;

    ret = netsnmp_cache_handler_get(NULL);
    if (ret) {
        cache = netsnmp_cache_create(timeout, load_hook, free_hook,
                                     rootoid, rootoid_len);
        ret->myvoid = (void *) cache;
        netsnmp_cache_handler_owns_cache(ret);
    }
    return ret;
}
Beispiel #7
0
void init_hw_sensors( void ) {

    if ( _sensor_container )
        return;   /* Already initialised */

    DEBUGMSGTL(("sensors", "Initialise Hardware Sensors module\n"));

    /*
     * Define a container to hold the basic list of sensors
     * The four LM-SENSOR-MIB containers will be created in
     *  the relevant initialisation routine(s)
     */
    _sensor_container = netsnmp_container_find("sensorTable:table_container");
    if ( NULL == _sensor_container ) {
        snmp_log( LOG_ERR, "failed to create container for sensorTable");
        return;
    }
    netsnmp_sensor_arch_init( );

    /*
     * If we're sampling the sensor information automatically,
     *   then arrange for this to be triggered regularly.
     *
     * If we're not sampling these values regularly,
     *   create a suitable cache handler instead.
     */
    if ( _sensorAutoUpdate ) {
        DEBUGMSGTL(("sensors", "Reloading Hardware Sensors automatically (%d)\n",
                               _sensorAutoUpdate));
        snmp_alarm_register( _sensorAutoUpdate, SA_REPEAT,
                             _sensor_update_stats, NULL );
    }
    else {
        _sensor_cache = netsnmp_cache_create( 5, netsnmp_sensor_load,
                                                 netsnmp_sensor_free, NULL, 0 );
        DEBUGMSGTL(("sensors", "Reloading Hardware Sensors on-demand (%p)\n",
                               _sensor_cache));
    }
}
Beispiel #8
0
void init_hw_fsys( void ) {

    if ( _fsys_container )
        return;   /* Already initialised */

    DEBUGMSGTL(("fsys", "Initialise Hardware FileSystem module\n"));

    /*
     * Define a container to hold the list of filesystems
     */
    _fsys_container = netsnmp_container_find("fsysTable:table_container");
    if ( NULL == _fsys_container ) {
        snmp_log( LOG_ERR, "failed to create container for fsysTable");
        return;
    }
    netsnmp_fsys_arch_init( );

    /*
     * If we're sampling the file system information automatically,
     *   then arrange for this to be triggered regularly.
     *
     * If we're not sampling these values regularly,
     *   create a suitable cache handler instead.
     */
    if ( _fsysAutoUpdate ) {
        DEBUGMSGTL(("fsys", "Reloading Hardware FileSystems automatically (%d)\n",
                               _fsysAutoUpdate));
        snmp_alarm_register( _fsysAutoUpdate, SA_REPEAT,
                             _fsys_update_stats, NULL );
    }
    else {
        _fsys_cache = netsnmp_cache_create( 5, netsnmp_fsys_load,
                                               netsnmp_fsys_free, NULL, 0 );
        DEBUGMSGTL(("fsys", "Reloading Hardware FileSystems on-demand (%p)\n",
                               _fsys_cache));
    }
}
void
init_snmpTlstmCertToTSNTable_context(const char *contextName)
{
    oid             reg_oid[]   =  { SNMP_TLS_TM_CERT_TABLE };
    const size_t    reg_oid_len =  OID_LENGTH(reg_oid);
    netsnmp_handler_registration    *reg;
    netsnmp_table_registration_info *info;
    netsnmp_cache                   *cache;
    netsnmp_watcher_info            *watcher;
    const char *mib_map_help = 
        MAP_MIB_CONFIG_TOKEN " table persistence (internal use)";

    DEBUGMSGTL(("tlstmCertToSN:init",
                "initializing table tlstmCertToTSNTable\n"));

    reg = netsnmp_create_handler_registration
        ("tlstmCertToTSNTable", tlstmCertToTSNTable_handler,
         reg_oid, reg_oid_len,
         HANDLER_CAN_RWRITE);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for tlstmCertToSN\n");
        return;
    }

    if (NULL != contextName)
        reg->contextName = strdup(contextName);

    _table = netsnmp_tdata_create_table("tlstmCertToTSNTable", 0);
    if (NULL == _table) {
        snmp_log(LOG_ERR,
                 "error creating tdata table for tlstmCertToTSNTable\n");
        return;
    }
    info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == info) {
        snmp_log(LOG_ERR,
                 "error creating table info for tlstmCertToTSNTable\n");
        netsnmp_tdata_delete_table(_table);
        _table = NULL;
        return;
    }
    netsnmp_table_helper_add_indexes(info, 
                                     /* index: tlstmCertToTSNID */
                                     ASN_UNSIGNED,  0);

    info->min_column = SNMPTLSTMCERTTOTSN_TABLE_MIN_COL;
    info->max_column = SNMPTLSTMCERTTOTSN_TABLE_MAX_COL;

    /*
     * cache init
     */
    cache = netsnmp_cache_create(30, (NetsnmpCacheLoad*)_cache_load,
                                 (NetsnmpCacheFree*)_cache_free,
                                 reg_oid,
                                 reg_oid_len);
    if (NULL == cache) {
        snmp_log(LOG_ERR,"error creating cache for tlstmCertToTSNTable\n");
        netsnmp_tdata_delete_table(_table);
        _table = NULL;
        return;
    }
    cache->magic = (void *)_table;
    cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    netsnmp_tdata_register(reg, _table, info);

    if (cache) 
        netsnmp_inject_handler_before( reg, netsnmp_cache_handler_get(cache),
                                       "table_container");

    /*
     * register scalars
     */
    reg_oid[10] = 1;
    reg = netsnmp_create_handler_registration("snmpTlstmCertToTSNCount",
                                              _count_handler, reg_oid,
                                              OID_LENGTH(reg_oid),
                                              HANDLER_CAN_RONLY);
    if (NULL == reg)
        snmp_log(LOG_ERR,
                 "could not create handler for snmpTlstmCertToTSNCount\n");
    else {
        if (NULL != contextName)
            reg->contextName = strdup(contextName);

        netsnmp_register_scalar(reg);
        if (cache) 
            netsnmp_inject_handler_before(reg, netsnmp_cache_handler_get(cache),
                                          "table_container");
    }
    
    reg_oid[10] = 2;
    reg = netsnmp_create_handler_registration(
        "snmpTlstmCertToTSNTableLastChanged", NULL, reg_oid,
        OID_LENGTH(reg_oid), HANDLER_CAN_RONLY);
    watcher = netsnmp_create_watcher_info((void*)&_last_changed,
                                          sizeof(_last_changed),
                                          ASN_TIMETICKS,
                                          WATCHER_FIXED_SIZE);
    if ((NULL == reg) || (NULL == watcher))
        snmp_log(LOG_ERR,
                 "could not create handler for snmpTlstmCertToTSNCount\n");
    else {
        if (NULL != contextName)
            reg->contextName = strdup(contextName);
        netsnmp_register_watched_scalar(reg, watcher);
    }

    /*
     * persistence
     */
    register_config_handler(NULL, MAP_MIB_CONFIG_TOKEN, _parse_mib_maps, NULL,
                            mib_map_help);
    if (snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
                               _save_maps, NULL) != SNMP_ERR_NOERROR)
        snmp_log(LOG_ERR, "error registering for STORE_DATA callback "
                 "for certToTSN\n");

}
Beispiel #10
0
/** Initialize the cpqSasPhyDrvTable table by defining its contents and how it's structured */
void
initialize_table_cpqSasPhyDrvTable(void)
{
    netsnmp_handler_registration *reg = NULL;
    netsnmp_mib_handler *handler = NULL;
    netsnmp_container *container = NULL;
    netsnmp_table_registration_info *table_info = NULL;
    netsnmp_cache  *cache = NULL;

    int reg_tbl_ret = SNMPERR_SUCCESS;

    DEBUGMSGTL(("cpqSasPhyDrvTable:init",
                "initializing table cpqSasPhyDrvTable\n"));

    reg =
        netsnmp_create_handler_registration("cpqSasPhyDrvTable",
                                            cpqSasPhyDrvTable_handler,
                                            cpqSasPhyDrvTable_oid,
                                            cpqSasPhyDrvTable_oid_len,
                                            HANDLER_CAN_RONLY);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for cpqSasPhyDrvTable\n");
        goto bail;
    }

    container =
        netsnmp_container_find("cpqSasPhyDrvTable:table_container");
    if (NULL == container) {
        snmp_log(LOG_ERR,
                 "error creating container for cpqSasPhyDrvTable\n");
        goto bail;
    }

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == table_info) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqSasPhyDrvTable\n");
        goto bail;
    }
    netsnmp_table_helper_add_indexes(table_info, 
                                     ASN_INTEGER,   /* index: cpqSasPhyDrvHbaIndex */
                                     ASN_INTEGER,       /* index: cpqSasPhyDrvIndex */
                                     0);
    table_info->min_column = COLUMN_CPQSASPHYDRVHBAINDEX;
    table_info->max_column = COLUMN_CPQSASPHYDRVTEMPERATURETHRESHOLD;

    /*************************************************
     *
     * inject container_table helper
     */
    handler = netsnmp_container_table_handler_get(table_info, container,
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqSasPhyDrvTable\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting container_table handler for cpqSasPhyDrvTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it, will reuse below */

    /*************************************************
     *
     * inject cache helper
     */
    cache = netsnmp_cache_create(300,    /* timeout in seconds */
                                 _cache_load, _cache_free,
                                 cpqSasPhyDrvTable_oid,
                                 cpqSasPhyDrvTable_oid_len);

    if (NULL == cache) {
        snmp_log(LOG_ERR, "error creating cache for cpqSasPhyDrvTable\n");
        goto bail;
    }
    cache->flags = NETSNMP_CACHE_PRELOAD |
                   NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD |
                   NETSNMP_CACHE_DONT_FREE_EXPIRED |
                   NETSNMP_CACHE_DONT_AUTO_RELEASE |
                   NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    cache->magic = container;

    handler = netsnmp_cache_handler_get(cache);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error creating cache handler for cpqSasPhyDrvTable\n");
        goto bail;
    }

    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting cache handler for cpqSasPhyDrvTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it */

    /*
     * register the table
     */
    reg_tbl_ret = netsnmp_register_table(reg, table_info);
    if (reg_tbl_ret != SNMPERR_SUCCESS) {
        snmp_log(LOG_ERR,
                 "error registering table handler for cpqSasPhyDrvTable\n");
        goto bail;
    }

    /*
     * Initialise the contents of the table here
     */

    return;                     /* ok */

    /*
     * Some error occurred during registration. Clean up and bail.
     */
  bail:                        /* not ok */

    if (handler)
        netsnmp_handler_free(handler);

    if (cache)
        netsnmp_cache_free(cache);

    if (table_info)
        netsnmp_table_registration_info_free(table_info);

    if (container)
        CONTAINER_FREE(container);

    if (reg_tbl_ret == SNMPERR_SUCCESS)
        if (reg)
            netsnmp_handler_registration_free(reg);
}
/** Initialize the hrSWInstalledTable table by defining its contents and how it's structured */
void
initialize_table_hrSWInstalledTable(void)
{
    static oid      hrSWInstalledTable_oid[] =
        { 1, 3, 6, 1, 2, 1, 25, 6, 3 };
    size_t          hrSWInstalledTable_oid_len =
        OID_LENGTH(hrSWInstalledTable_oid);
    netsnmp_handler_registration *reg;
    netsnmp_mib_handler *handler = NULL;
    netsnmp_container *container = NULL;
    netsnmp_cache *cache = NULL;

    DEBUGMSGTL(("hrSWInstalled", "initialize\n"));

    reg =
        netsnmp_create_handler_registration("hrSWInstalledTable",
                                            hrSWInstalledTable_handler,
                                            hrSWInstalledTable_oid,
                                            hrSWInstalledTable_oid_len,
                                            HANDLER_CAN_RONLY);
    if (NULL == reg) {
        snmp_log(LOG_ERR,"error creating handler registration for "
                 MYTABLE "\n");
        goto bail;
    }

    container = netsnmp_container_find("hrSWInstalledTable:table_container");
    if (NULL == container) {
        snmp_log(LOG_ERR,"error creating container for "
                 MYTABLE "\n");
        goto bail;
    }

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == table_info) {
        snmp_log(LOG_ERR,"error allocating table registration for "
                 MYTABLE "\n");
        goto bail;
    }

    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: hrSWInstalledIndex */
                                     0);
    table_info->min_column = COLUMN_HRSWINSTALLEDINDEX;
    table_info->max_column = COLUMN_HRSWINSTALLEDDATE;

    /*************************************************
     *
     * inject container_table helper
     */
    handler = netsnmp_container_table_handler_get(table_info, container,
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    if (NULL == handler) {
        snmp_log(LOG_ERR,"error allocating table registration for "
                 MYTABLE "\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,"error injecting container_table handler for "
                 MYTABLE "\n");
        goto bail;
    }
    handler = NULL; /* reg has it, will reuse below */

    /*************************************************
     *
     * inject cache helper
     */
    cache = netsnmp_cache_create(30,    /* timeout in seconds */
                                 _cache_load, _cache_free,
                                 hrSWInstalledTable_oid,
                                 hrSWInstalledTable_oid_len);

    if (NULL == cache) {
        snmp_log(LOG_ERR, "error creating cache for "
                 MYTABLE "\n");
        goto bail;
    }
    cache->magic = container;

    handler = netsnmp_cache_handler_get(cache);
    if (NULL == handler) {
        snmp_log(LOG_ERR, "error creating cache handler for "
                 MYTABLE "\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,"error injecting cache handler for "
                 MYTABLE "\n");
        goto bail;
    }
    handler = NULL; /* reg has it*/

    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
        snmp_log(LOG_ERR,"error registering table handler for "
                 MYTABLE "\n");
        reg = NULL; /* it was freed inside netsnmp_register_table */
        goto bail;
    }

    return; /* ok */


  bail: /* not ok */
    
    if (handler)
        netsnmp_handler_free(handler);

    if (cache)
        netsnmp_cache_free(cache);

    if (table_info)
        netsnmp_table_registration_info_free(table_info);

    if (container)
        CONTAINER_FREE(container);

    if (reg) 
        netsnmp_handler_registration_free(reg);

}
/** Initialize the cpqLinOsProcessorTable table by defining its contents 
 * and how it's structured 
 */
void
initialize_table_cpqLinOsProcessorTable(void)
{
    netsnmp_handler_registration *reg = NULL;
    netsnmp_mib_handler *handler = NULL;
    netsnmp_container *container = NULL;
    netsnmp_table_registration_info *table_info = NULL;
    netsnmp_cache  *cache = NULL;

    DEBUGMSGTL(("cpqLinOsProcessorTable:init",
                "initializing table cpqLinOsProcessorTable\n"));

    reg =
        netsnmp_create_handler_registration("cpqLinOsProcessorTable",
                                            cpqLinOsProcessorTable_handler,
                                            cpqLinOsProcessorTable_oid,
                                            cpqLinOsProcessorTable_oid_len,
                                            HANDLER_CAN_RONLY);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for cpqLinOsProcessorTable\n");
        goto bail;
    }

    container = netsnmp_container_find("cpqLinOsProcessorTable:table_container");
    if (NULL == container) {
        snmp_log(LOG_ERR, "error creating container for cpqLinOsProcessorTable\n");
        goto bail;
    }
    container->container_name = strdup("cpqLinOsProcessorTable container");

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == table_info) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqLinOsProcessorTable\n");
        goto bail;
    }
    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: cpqLinOsCpuIndex */
                                     0);
    table_info->min_column = COLUMN_CPQLINOSCPUINDEX;
    table_info->max_column = COLUMN_CPQLINOSCPUPRIVILEGEDTIMEPERCENT;

    /*************************************************
     *
     * inject container_table helper
     */
    handler = netsnmp_container_table_handler_get(table_info, container,
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqLinOsProcessorTable\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting container_table handler for cpqLinOsProcessorTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it, will reuse below */

    /*************************************************
     *
     * inject cache helper
     */
    cache = netsnmp_cache_create(5,    /* timeout in seconds */
                                 _cache_load, _cache_free,
                                 cpqLinOsProcessorTable_oid,
                                 cpqLinOsProcessorTable_oid_len);

    if (NULL == cache) {
        snmp_log(LOG_ERR,
                 "error creating cache for cpqLinOsProcessorTable\n");
        goto bail;
    }
    cache->flags = NETSNMP_CACHE_PRELOAD |
                   NETSNMP_CACHE_DONT_FREE_EXPIRED |
                   NETSNMP_CACHE_DONT_AUTO_RELEASE |
                   NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD |
                   NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    cache->magic = container;

    handler = netsnmp_cache_handler_get(cache);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error creating cache handler for cpqLinOsProcessorTable\n");
        goto bail;
    }

    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting cache handler for cpqLinOsProcessorTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it */

    /*
     * register the table
     */
    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
        snmp_log(LOG_ERR,
                 "error registering table handler for cpqLinOsProcessorTable\n");
        reg = NULL;             /* it was freed inside netsnmp_register_table */
        goto bail;
    }

    return;                     /* ok */

    /*
     * Some error occurred during registration. Clean up and bail.
     */
  bail:                        /* not ok */

    if (handler)
        netsnmp_handler_free(handler);

    if (cache)
        netsnmp_cache_free(cache);

    if (table_info)
        netsnmp_table_registration_info_free(table_info);

    if (container)
        CONTAINER_FREE(container);

    if (reg)
        netsnmp_handler_registration_free(reg);
}
Beispiel #13
0
/** Initialize the sctpAssocTable table by defining its contents and how it's structured */
void
initialize_table_sctpAssocTable(void)
{
    static oid      sctpAssocTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 3 };
    size_t          sctpAssocTable_oid_len =
        OID_LENGTH(sctpAssocTable_oid);
    netsnmp_handler_registration *reg = NULL;
    netsnmp_mib_handler *handler = NULL;
    netsnmp_container *container = NULL;
    netsnmp_table_registration_info *table_info = NULL;
    netsnmp_cache  *cache = NULL;

    reg =
        netsnmp_create_handler_registration("sctpAssocTable",
                                            sctpAssocTable_handler,
                                            sctpAssocTable_oid,
                                            sctpAssocTable_oid_len,
                                            HANDLER_CAN_RWRITE);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for sctpAssocTable\n");
        goto bail;
    }
    /** should a set on a non-existent row create a new one? */
    /** reg->modes |= HANDLER_CAN_NOT_CREATE; */

    container = netsnmp_container_find("sctpAssocTable:table_container");
    if (NULL == container) {
        snmp_log(LOG_ERR, "error creating container for sctpAssocTable\n");
        goto bail;
    }
    sctpAssocTable_container = container;

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == table_info) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for sctpAssocTable\n");
        goto bail;
    }
    netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED,  /* index: sctpAssocId */
                                     0);
    table_info->min_column = COLUMN_SCTPASSOCREMHOSTNAME;
    table_info->max_column = COLUMN_SCTPASSOCDISCONTINUITYTIME;

    /*************************************************
     *
     * inject container_table helper
     */
    handler = netsnmp_container_table_handler_get(table_info, container,
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for sctpAssocTable\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting container_table handler for sctpAssocTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it, will reuse below */

    /*************************************************
     *
     * inject cache helper
     */
    cache = netsnmp_cache_create(SCTP_TABLES_CACHE_TIMEOUT,     /* timeout in seconds */
                                 _cache_load, _cache_free,
                                 sctpAssocTable_oid,
                                 sctpAssocTable_oid_len);

    if (NULL == cache) {
        snmp_log(LOG_ERR, "error creating cache for sctpAssocTable\n");
        goto bail;
    }
    cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET
        | NETSNMP_CACHE_AUTO_RELOAD | NETSNMP_CACHE_PRELOAD;
    cache->magic = container;

    handler = netsnmp_cache_handler_get(cache);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error creating cache handler for sctpAssocTable\n");
        goto bail;
    }

    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting cache handler for sctpAssocTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it */

    /*
     * register the table
     */
    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
        snmp_log(LOG_ERR,
                 "error registering table handler for sctpAssocTable\n");
        goto bail;
    }

    /*
     * Initialise the contents of the table here
     */


    return;                     /* ok */

    /*
     * Some error occurred during registration. Clean up and bail.
     */
  bail:                        /* not ok */

    if (handler)
        netsnmp_handler_free(handler);

    if (container)
        CONTAINER_FREE(container);

    if (reg)
        netsnmp_handler_registration_free(reg);
}
Beispiel #14
0
void init_hw_mem( void ) {
    oid nsMemory[] = { 1, 3, 6, 1, 4, 1, 8072, 1, 31 };
    _mem_cache = netsnmp_cache_create( 5, netsnmp_mem_arch_load, NULL,
                                          nsMemory, OID_LENGTH(nsMemory));
}
void init_netflow(void)
{
	netsnmp_handler_registration *reg;
	struct snmp_vars *sys;

	/* snmpd -f -L -Dnetflow,dlmod */
	DEBUGMSGTL(("netflow", "init_netflow\n"));

	netsnmp_register_scalar_group(
	    netsnmp_create_handler_registration(
		    "iptNetflowModule",
		    iptNetflowModule_handler,
		    iptNetflowModule_oid,
		    OID_LENGTH(iptNetflowModule_oid),
		    HANDLER_CAN_RONLY),
	    1, var_max(modinfos));

	netsnmp_register_scalar_group(
	    netsnmp_create_handler_registration(
		    "iptNetflowSysctl",
		    iptNetflowSysctl_handler,
		    iptNetflowSysctl_oid,
		    OID_LENGTH(iptNetflowSysctl_oid),
		    HANDLER_CAN_RWRITE),
	    1, var_max(sysctls));

	netsnmp_register_scalar_group(
	    netsnmp_create_handler_registration(
		    "iptNetflowTotals",
		    iptNetflowTotals_handler,
		    iptNetflowTotals_oid,
		    OID_LENGTH(iptNetflowTotals_oid),
		    HANDLER_CAN_RONLY),
	    1, var_max(totals));

	/* Register first table. */
	reg = netsnmp_create_handler_registration(
	    "iptNetflowCpuTable", /* no handler */ NULL,
	    iptNetflowCpuTable_oid, OID_LENGTH(iptNetflowCpuTable_oid),
	    HANDLER_CAN_RONLY);

	/* set up columns */
	cpu_data_set = netsnmp_create_table_data_set("iptNetflowCpuDataSet");
	netsnmp_table_set_add_indexes(cpu_data_set, ASN_INTEGER, 0);
	/* I include cpuIndex into columns, which is not SMIv2'ish */
	for (sys = cputable; sys->obj; sys++)
		netsnmp_table_set_add_default_row(cpu_data_set, sys->obj, sys->type, 0, NULL, 0);
	netsnmp_register_table_data_set(reg, cpu_data_set, NULL);

	/* cache handler will load actual data, and it needs to be
	 * injected in front of dataset handler to be called first */
	stat_cache = netsnmp_cache_create(
	    /* no timeout */ -1,
	    stat_cache_load, dummy_cache_free,
	    iptNetflowCpuTable_oid, OID_LENGTH(iptNetflowCpuTable_oid));
	netsnmp_inject_handler(reg, netsnmp_cache_handler_get(stat_cache));

	/* Register second table. */
	reg = netsnmp_create_handler_registration(
	    "iptNetflowSockTable", /* no handler */ NULL,
	    iptNetflowSockTable_oid, OID_LENGTH(iptNetflowSockTable_oid),
	    HANDLER_CAN_RONLY);

	/* set up columns */
	sock_data_set = netsnmp_create_table_data_set("iptNetflowSockDataSet");
	/* I don't include sockIndex into columns, which is more SMIv2'ish */
	netsnmp_table_set_add_indexes(sock_data_set, ASN_INTEGER, 0);
	for (sys = &socktable[1]; sys->obj; sys++)
		netsnmp_table_set_add_default_row(sock_data_set, sys->obj, sys->type, 0, NULL, 0);
	netsnmp_register_table_data_set(reg, sock_data_set, NULL);

	/* as before, cache handler will load actual data, and it needs
	 * to be injected in front of dataset handler to be called first */
	stat_cache = netsnmp_cache_create(
	    /* no timeout */ -1,
	    stat_cache_load, dummy_cache_free,
	    iptNetflowSockTable_oid, OID_LENGTH(iptNetflowSockTable_oid));
	netsnmp_inject_handler(reg, netsnmp_cache_handler_get(stat_cache));
}
Beispiel #16
0
/** Initialize the cpqNicIfLogMapTable table by defining its contents and how it's structured */
void
initialize_table_cpqNicIfLogMapTable(void)
{
    const oid       cpqNicIfLogMapTable_oid[] =
        { 1, 3, 6, 1, 4, 1, 232, 18, 2, 2, 1 };
    const size_t    cpqNicIfLogMapTable_oid_len =
        OID_LENGTH(cpqNicIfLogMapTable_oid);
    netsnmp_handler_registration *reg = NULL;
    netsnmp_mib_handler *handler = NULL;
    netsnmp_container *container = NULL;
    netsnmp_table_registration_info *table_info = NULL;
    netsnmp_cache  *cache = NULL;

    int reg_tbl_ret = SNMPERR_SUCCESS;

    DEBUGMSGTL(("cpqNicIfLogMapTable:init",
                "initializing table cpqNicIfLogMapTable\n"));

    reg =
        netsnmp_create_handler_registration("cpqNicIfLogMapTable",
                                            cpqNicIfLogMapTable_handler,
                                            cpqNicIfLogMapTable_oid,
                                            cpqNicIfLogMapTable_oid_len,
                                            HANDLER_CAN_RONLY);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for cpqNicIfLogMapTable\n");
        goto bail;
    }

    container =
        netsnmp_container_find("cpqNicIfLogMapTable:table_container");
    if (NULL == container) {
        snmp_log(LOG_ERR,
                 "error creating container for cpqNicIfLogMapTable\n");
        goto bail;
    }
    container->container_name = strdup("cpqNicIfLogMapTable container");


    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == table_info) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqNicIfLogMapTable\n");
        goto bail;
    }
    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: cpqNicIfLogMapIndex */
                                     0);
    table_info->min_column = COLUMN_CPQNICIFLOGMAPINDEX;
    table_info->max_column = COLUMN_CPQNICIFLOGMAPPCILOCATION;

    /*************************************************
     *
     * inject container_table helper
     */
    handler = netsnmp_container_table_handler_get(table_info, container,
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error allocating table registration for cpqNicIfLogMapTable\n");
        goto bail;
    }
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting container_table handler for cpqNicIfLogMapTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it, will reuse below */

    /*************************************************
     *
     * inject cache helper
     */
    cache = netsnmp_cache_create(30,    /* timeout in seconds */
                                 _cache_load, _cache_free,
                                 cpqNicIfLogMapTable_oid,
                                 cpqNicIfLogMapTable_oid_len);

    if (NULL == cache) {
        snmp_log(LOG_ERR,
                 "error creating cache for cpqNicIfLogMapTable\n");
        goto bail;
    }
    cache->flags = NETSNMP_CACHE_PRELOAD |
                   NETSNMP_CACHE_DONT_FREE_EXPIRED |
                   NETSNMP_CACHE_DONT_AUTO_RELEASE |
                   NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD |
                   NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    cache->magic = container;

    handler = netsnmp_cache_handler_get(cache);
    if (NULL == handler) {
        snmp_log(LOG_ERR,
                 "error creating cache handler for cpqNicIfLogMapTable\n");
        goto bail;
    }

    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
        snmp_log(LOG_ERR,
                 "error injecting cache handler for cpqNicIfLogMapTable\n");
        goto bail;
    }
    handler = NULL;             /* reg has it */

    /*
     * register the table
     */
    reg_tbl_ret = netsnmp_register_table(reg, table_info);
    if (reg_tbl_ret != SNMPERR_SUCCESS) {
        snmp_log(LOG_ERR,
                 "error registering table handler for cpqNicIfLogMapTable\n");
        goto bail;
    }

    return;                     /* ok */

    /*
     * Some error occurred during registration. Clean up and bail.
     */
  bail:                        /* not ok */

    if (handler)
        netsnmp_handler_free(handler);

    if (cache)
        netsnmp_cache_free(cache);

    if (table_info)
        netsnmp_table_registration_info_free(table_info);

    if (container)
        CONTAINER_FREE(container);

    if (reg_tbl_ret == SNMPERR_SUCCESS)
        if (reg)
            netsnmp_handler_registration_free(reg);
}