/** * This function registers an int helper handler to a specified OID. * * @param name the name used for registration pruposes. * * @param reg_oid the OID where you want to register your integer at * * @param reg_oid_len the length of the OID * * @param it the integer value to be registered during initialization * * @param subhandler a handler to do whatever you want to do, otherwise use * NULL to use the default int handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_int_instance(const char *name, const oid * reg_oid, size_t reg_oid_len, int *it, Netsnmp_Node_Handler * subhandler) { return netsnmp_register_watched_instance( netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RWRITE), netsnmp_create_watcher_info( (void *)it, sizeof(int), ASN_INTEGER, WATCHER_FIXED_SIZE)); }
int netsnmp_register_ulong_instance(const char *name, const oid * reg_oid, size_t reg_oid_len, u_long * it, Netsnmp_Node_Handler * subhandler) { return netsnmp_register_watched_instance2( netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RWRITE), netsnmp_create_watcher_info( (void *)it, sizeof(u_long), ASN_UNSIGNED, WATCHER_FIXED_SIZE)); }
int netsnmp_register_read_only_uint_instance(const char *name, const oid * reg_oid, size_t reg_oid_len, unsigned int *it, Netsnmp_Node_Handler * subhandler) { return netsnmp_register_watched_instance( netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RONLY), netsnmp_create_watcher_info( (void *)it, sizeof(unsigned int), ASN_UNSIGNED, WATCHER_FIXED_SIZE)); }
int netsnmp_register_watched_spinlock(netsnmp_handler_registration *reginfo, int *spinlock) { netsnmp_mib_handler *whandler; netsnmp_watcher_info *winfo; whandler = netsnmp_get_watched_spinlock_handler(); whandler->myvoid = (void *)spinlock; winfo = netsnmp_create_watcher_info((void *)spinlock, sizeof(int), ASN_INTEGER, WATCHER_FIXED_SIZE); netsnmp_inject_handler(reginfo, whandler); return netsnmp_register_watched_scalar(reginfo, winfo); }
/* * our initialization routine, automatically called by the agent * (to get called, the function name must match init_FILENAME()) */ void init_serverName(void) { static oid serverName_oid[] = { MOD_SNMP_OID 1 , 1}; /*strcpy(serverName_str, "myString Value" );*/ /* * a debugging statement. Run the agent with -DserverName to see * the output of this debugging statement. */ DEBUGMSGTL(("serverName", "Initializing the serverName module\n")); /* * the line below registers our variables defined above as * accessible and makes them writable. A read only version of any * of these registrations would merely call * register_read_only_int_instance() instead. The functions * called below should be consistent with your MIB, however. * * If you wanted a callback when the value was retrieved or set * (even though the details of doing this are handled for you), * you could change the NULL pointer below to a valid handler * function. */ /* netsnmp_register_int_instance("serverName", serverName_oid, OID_LENGTH(serverName_oid), &serverName, NULL); */ netsnmp_register_watched_scalar( netsnmp_create_handler_registration( "serverName", NULL, serverName_oid, OID_LENGTH(serverName_oid), HANDLER_CAN_RWRITE), netsnmp_create_watcher_info( &serverName_str, sizeof(serverName_str), ASN_OCTET_STR, WATCHER_MAX_SIZE) ); DEBUGMSGTL(("serverName", "Done initalizing serverName module\n")); }
int netsnmp_register_read_only_counter32_instance(const char *name, const oid * reg_oid, size_t reg_oid_len, u_long * it, Netsnmp_Node_Handler * subhandler) { return netsnmp_register_watched_instance( netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RONLY), netsnmp_create_watcher_info( (void *)it, sizeof(u_long), ASN_COUNTER, WATCHER_FIXED_SIZE)); }
int netsnmp_register_read_only_long_scalar(const char *name, const oid * reg_oid, size_t reg_oid_len, long * it, Netsnmp_Node_Handler * subhandler) { return netsnmp_register_watched_scalar( netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RONLY ), netsnmp_create_watcher_info( (void *)it, sizeof( long ), ASN_INTEGER, WATCHER_FIXED_SIZE )); }
int netsnmp_register_long_instance_context(const char *name, const oid * reg_oid, size_t reg_oid_len, long *it, Netsnmp_Node_Handler * subhandler, const char *contextName) { netsnmp_handler_registration *myreg = netsnmp_create_handler_registration( name, subhandler, reg_oid, reg_oid_len, HANDLER_CAN_RWRITE); if (myreg && contextName) myreg->contextName = strdup(contextName); return netsnmp_register_watched_instance( myreg, netsnmp_create_watcher_info( (void *)it, sizeof(long), ASN_INTEGER, WATCHER_FIXED_SIZE)); }
void init_agentHttpAccess(void) { static oid agentHttpAccess_oid[] = {MOD_SNMP_OID 2, 7 }; DEBUGMSGTL(("agentHttpAccess", "Initializing\n")); netsnmp_register_watched_scalar( netsnmp_create_handler_registration( "agentHttpAccess", NULL, agentHttpAccess_oid, OID_LENGTH(agentHttpAccess_oid), HANDLER_CAN_RWRITE), netsnmp_create_watcher_info( &agentHttpAccess, sizeof(agentHttpAccess), ASN_COUNTER, WATCHER_MAX_SIZE) ); }
/* * our initialization routine, automatically called by the agent * (to get called, the function name must match init_FILENAME()) */ void init_serverRestart(void) { static oid serverRestart_oid[] = { MOD_SNMP_OID 1 , 4}; DEBUGMSGTL(("serverRestart","Initializing the serverRestart module\n")); netsnmp_register_watched_scalar( netsnmp_create_handler_registration( "serverRestart", handle_serverRestart, serverRestart_oid, OID_LENGTH(serverRestart_oid), HANDLER_CAN_RWRITE), netsnmp_create_watcher_info( &serverRestart_str, sizeof(serverRestart_str), ASN_OCTET_STR, WATCHER_MAX_SIZE) ); DEBUGMSGTL(("serverRestart", "Done initalizing serverRestart module\n")); }
static void platform_string_register(int index, const char* desc, char* value) { oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1}; tree[11] = index; if(!value || !value[0]) { return; } char* s = aim_strdup(value); netsnmp_handler_registration *reg = netsnmp_create_handler_registration( desc, NULL, tree, OID_LENGTH(tree), HANDLER_CAN_RONLY); netsnmp_watcher_info *winfo = netsnmp_create_watcher_info( s, strlen(s), ASN_OCTET_STR, WATCHER_FIXED_SIZE); netsnmp_register_watched_scalar( reg, winfo ); }
/** * @internal * Initialize the table ipv4InterfaceTable * (Define its contents and how it's structured) */ void _ipv4InterfaceTable_initialize_interface(ipv4InterfaceTable_registration * reg_ptr, u_long flags) { netsnmp_baby_steps_access_methods *access_multiplexer = &ipv4InterfaceTable_if_ctx.access_multiplexer; netsnmp_table_registration_info *tbl_info = &ipv4InterfaceTable_if_ctx.tbl_info; netsnmp_handler_registration *reginfo; netsnmp_mib_handler *handler; int mfd_modes = 0; DEBUGMSGTL(("internal:ipv4InterfaceTable:_ipv4InterfaceTable_initialize_interface", "called\n")); /************************************************* * * save interface context for ipv4InterfaceTable */ /* * Setting up the table's definition */ netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER, /** index: ipv4InterfaceIfIndex */ 0); /* * Define the minimum and maximum accessible columns. This * optimizes retrival. */ tbl_info->min_column = IPV4INTERFACETABLE_MIN_COL; tbl_info->max_column = IPV4INTERFACETABLE_MAX_COL; /* * save users context */ ipv4InterfaceTable_if_ctx.user_ctx = reg_ptr; /* * call data access initialization code */ ipv4InterfaceTable_init_data(reg_ptr); /* * set up the container */ _ipv4InterfaceTable_container_init(&ipv4InterfaceTable_if_ctx); if (NULL == ipv4InterfaceTable_if_ctx.container) { snmp_log(LOG_ERR, "could not initialize container for ipv4InterfaceTable\n"); return; } /* * access_multiplexer: REQUIRED wrapper for get request handling */ access_multiplexer->object_lookup = _mfd_ipv4InterfaceTable_object_lookup; access_multiplexer->get_values = _mfd_ipv4InterfaceTable_get_values; /* * no wrappers yet */ access_multiplexer->pre_request = _mfd_ipv4InterfaceTable_pre_request; access_multiplexer->post_request = _mfd_ipv4InterfaceTable_post_request; /* * REQUIRED wrappers for set request handling */ access_multiplexer->object_syntax_checks = _mfd_ipv4InterfaceTable_check_objects; access_multiplexer->undo_setup = _mfd_ipv4InterfaceTable_undo_setup; access_multiplexer->undo_cleanup = _mfd_ipv4InterfaceTable_undo_cleanup; access_multiplexer->set_values = _mfd_ipv4InterfaceTable_set_values; access_multiplexer->undo_sets = _mfd_ipv4InterfaceTable_undo_values; /* * no wrappers yet */ access_multiplexer->commit = _mfd_ipv4InterfaceTable_commit; access_multiplexer->undo_commit = _mfd_ipv4InterfaceTable_undo_commit; access_multiplexer->irreversible_commit = _mfd_ipv4InterfaceTable_irreversible_commit; /************************************************* * * Create a registration, save our reg data, register table. */ DEBUGMSGTL(("ipv4InterfaceTable:init_ipv4InterfaceTable", "Registering ipv4InterfaceTable as a mibs-for-dummies table.\n")); handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); reginfo = netsnmp_handler_registration_create("ipv4InterfaceTable", handler, ipv4InterfaceTable_oid, ipv4InterfaceTable_oid_size, HANDLER_CAN_BABY_STEP | HANDLER_CAN_RWRITE); if (NULL == reginfo) { snmp_log(LOG_ERR, "error registering table ipv4InterfaceTable\n"); return; } reginfo->my_reg_void = &ipv4InterfaceTable_if_ctx; /************************************************* * * set up baby steps handler, create it and inject it */ if (access_multiplexer->object_lookup) mfd_modes |= BABY_STEP_OBJECT_LOOKUP; if (access_multiplexer->set_values) mfd_modes |= BABY_STEP_SET_VALUES; if (access_multiplexer->irreversible_commit) mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; if (access_multiplexer->object_syntax_checks) mfd_modes |= BABY_STEP_CHECK_OBJECT; if (access_multiplexer->pre_request) mfd_modes |= BABY_STEP_PRE_REQUEST; if (access_multiplexer->post_request) mfd_modes |= BABY_STEP_POST_REQUEST; if (access_multiplexer->undo_setup) mfd_modes |= BABY_STEP_UNDO_SETUP; if (access_multiplexer->undo_cleanup) mfd_modes |= BABY_STEP_UNDO_CLEANUP; if (access_multiplexer->undo_sets) mfd_modes |= BABY_STEP_UNDO_SETS; if (access_multiplexer->row_creation) mfd_modes |= BABY_STEP_ROW_CREATE; if (access_multiplexer->consistency_checks) mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; if (access_multiplexer->commit) mfd_modes |= BABY_STEP_COMMIT; if (access_multiplexer->undo_commit) mfd_modes |= BABY_STEP_UNDO_COMMIT; handler = netsnmp_baby_steps_handler_get(mfd_modes); netsnmp_inject_handler(reginfo, handler); /************************************************* * * inject row_merge helper with prefix rootoid_len + 2 (entry.col) */ handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); netsnmp_inject_handler(reginfo, handler); /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(tbl_info, ipv4InterfaceTable_if_ctx. container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); netsnmp_inject_handler(reginfo, handler); /* * register table */ netsnmp_register_table(reginfo, tbl_info); /* * register LastChanged */ { oid lc_oid[] = { IPV4INTERFACETABLELASTCHANGE_OID }; netsnmp_register_watched_scalar(netsnmp_create_handler_registration ("ipv4TableLastChanged", NULL, lc_oid, OID_LENGTH(lc_oid), HANDLER_CAN_RONLY), netsnmp_create_watcher_info((void *) &ipv4InterfaceTable_if_ctx. last_changed, sizeof (u_long), ASN_TIMETICKS, WATCHER_FIXED_SIZE)); } } /* _ipv4InterfaceTable_initialize_interface */
/* * Our initialization routine, called automatically by the agent * (Note that the function name must match init_FILENAME()) */ void init_statPPTP(void) { netsnmp_handler_registration *reg; netsnmp_watcher_info *winfo; static oid statPPTPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,3,1 }; static oid statPPTPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,3,2 }; /* * a debugging statement. Run the agent with -DstatPPTP to see * the output of this debugging statement. */ DEBUGMSGTL(("statPPTP", "Initializing the statPPTP module\n")); if (!triton_module_loaded("pptp")) return; pptp_get_stat(&stat_starting, &stat_active); /* * Register scalar watchers for each of the MIB objects. * The ASN type and RO/RW status are taken from the MIB definition, * but can be adjusted if needed. * * In most circumstances, the scalar watcher will handle all * of the necessary processing. But the NULL parameter in the * netsnmp_create_handler_registration() call can be used to * supply a user-provided handler if necessary. * * This approach can also be used to handle Counter64, string- * and OID-based watched scalars (although variable-sized writeable * objects will need some more specialised initialisation). */ DEBUGMSGTL(("statPPTP", "Initializing statPPTPStarting scalar integer. Default value = %d\n", 0)); reg = netsnmp_create_handler_registration( "statPPTPStarting", NULL, statPPTPStarting_oid, OID_LENGTH(statPPTPStarting_oid), HANDLER_CAN_RONLY); winfo = netsnmp_create_watcher_info( stat_starting, sizeof(*stat_starting), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched statPPTPStarting" ); } DEBUGMSGTL(("statPPTP", "Initializing statPPTPActive scalar integer. Default value = %d\n", 0)); reg = netsnmp_create_handler_registration( "statPPTPActive", NULL, statPPTPActive_oid, OID_LENGTH(statPPTPActive_oid), HANDLER_CAN_RONLY); winfo = netsnmp_create_watcher_info( stat_active, sizeof(*stat_active), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched statPPTPActive" ); } DEBUGMSGTL(("statPPTP", "Done initalizing statPPTP module\n")); }
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"); }