/** Initializes the cpqHost module */ void init_cpqHost(void) { DEBUGMSGTL(("cpqHost", "Initializing\n")); myDistro = getDistroInfo(); cpqHostMibStatusArray[CPQMIB].major = CPQMIBREVMAJOR; cpqHostMibStatusArray[CPQMIB].minor = CPQMIBREVMINOR; netsnmp_register_scalar_group( netsnmp_create_handler_registration("cpqHostMib", cpqHostMib_handler, cpqHostMib_oid, OID_LENGTH(cpqHostMib_oid), HANDLER_CAN_RONLY), CPQHOSTMIBREVMAJOR, CPQHOSTMIBCONDITION); netsnmp_register_scalar_group( netsnmp_create_handler_registration("cpqHostInfo", cpqHostInfo_handler, cpqHostInfo_oid, OID_LENGTH(cpqHostInfo_oid), HANDLER_CAN_RONLY), CPQHOSTNAME, CPQHOSTSYSDESCR); init_cpqHoFileSysTable(); init_cpqHoSwVerTable(); init_cpqHostOsMem(); init_cpqHoSWRunningTable(); /* * register ourselves with the agent to handle our mib tree */ REGISTER_MIB("cpqHostOs", cpqHostOs_variables, variable7, cpqHostOs_variables_oid); /* * place any other initialization junk you need here */ cpqHostMibStatusArray[CPQMIB].stat = MIB_STATUS_AVAILABLE; cpqHostMibStatusArray[CPQMIB].cond = MIB_CONDITION_OK; DEBUGMSGTL(("cpqHost", "Checkinging periodic test trap interval = %d\n", testtrap_interval)); if (testtrap_interval >= 0) { if ((GenericDataStr = getenv(GenericDataEnv)) != (char *) 0) GenericData = GenericDataStr; DEBUGMSGTL(("cpqHost", "Registering periodic test trap alarm\n")); SendcpqHostGenericTrap(); if (testtrap_interval > 0) { if (snmp_alarm_register(testtrap_interval, SA_REPEAT, (SNMPAlarmCallback *) &SendcpqHostGenericTrap, NULL) == 0 ) DEBUGMSGTL(("cpqHost", "Alarm register failed\n")); } } }
/** starts the recurring cache_load callback */ unsigned int netsnmp_cache_timer_start(netsnmp_cache *cache) { if(NULL == cache) return 0; DEBUGMSGTL(( "cache_timer:start", "OID: ")); DEBUGMSGOID(("cache_timer:start", cache->rootoid, cache->rootoid_len)); DEBUGMSG(( "cache_timer:start", "\n")); if(0 != cache->timer_id) { snmp_log(LOG_WARNING, "cache has existing timer id.\n"); return cache->timer_id; } if(! (cache->flags & NETSNMP_CACHE_AUTO_RELOAD)) { snmp_log(LOG_ERR, "cache_timer_start called but auto_reload not set.\n"); return 0; } cache->timer_id = snmp_alarm_register(cache->timeout, SA_REPEAT, _timer_reload, cache); if(0 == cache->timer_id) { snmp_log(LOG_ERR,"could not register alarm\n"); return 0; } cache->flags &= ~NETSNMP_CACHE_AUTO_RELOAD; DEBUGMSGT(("cache_timer:start", "starting timer %lu for cache %p\n", cache->timer_id, cache)); return cache->timer_id; }
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)); }
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_handler(%d)\n", reqinfo->mode); switch (reqinfo->mode) { /* * here we merely mention that we'll answer this request * later. we don't actually care about the mode type in this * example, but for certain cases you may, so I'll leave in the * otherwise useless switch and case statements */ default: /* * mark this variable as something that can't be handled now. * We'll answer it later. */ requests->delegated = 1; /* * register an alarm to update the results at a later * time. Normally, we might have to query something else * (like an external request sent to a different network * or system socket, etc), but for this example we'll do * something really simply and just insert an alarm for a * certain period of time */ snmp_alarm_register(delay_time, /* seconds */ 0, /* dont repeat. */ return_delayed_response, /* the function * to call */ /* * here we create a "cache" of useful * information that we'll want later * on. This argument is passed back * to us in the callback function for * an alarm */ (void *) netsnmp_create_delegated_cache(handler, reginfo, reqinfo, requests, NULL)); break; } return SNMP_ERR_NOERROR; }
void init_pass_persist(void) { snmpd_register_config_handler("pass_persist", pass_persist_parse_config, pass_persist_free_config, "miboid program"); pipe_check_alarm_id = snmp_alarm_register(10, SA_REPEAT, check_persist_pipes, NULL); }
static int subagent_register_ping_alarm(int majorID, int minorID, void *serverarg, void *clientarg) { netsnmp_session *ss = (netsnmp_session *) clientarg; int ping_interval = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL); if (!ping_interval) /* don't do anything if not setup properly */ return 0; /* * register a ping alarm, if desired */ if (ss) { if (ss->securityModel != SNMP_DEFAULT_SECMODEL) { DEBUGMSGTL(("agentx/subagent", "unregister existing alarm %d\n", ss->securityModel)); snmp_alarm_unregister(ss->securityModel); } DEBUGMSGTL(("agentx/subagent", "register ping alarm every %d seconds\n", ping_interval)); /* * we re-use the securityModel parameter for an alarm stash, * since agentx doesn't need it */ ss->securityModel = snmp_alarm_register(ping_interval, SA_REPEAT, agentx_check_session, ss); } else { /* * attempt to open it later instead */ DEBUGMSGTL(("agentx/subagent", "subagent not properly attached, postponing registration till later....\n")); snmp_alarm_register(ping_interval, SA_REPEAT, agentx_reopen_session, NULL); } return 0; }
void init_kernel_sunos5(void) { static int creg = 0; const int period = 30; int alarm_id = 0; if (creg == 0) { alarm_id = snmp_alarm_register(5, NULL, kernel_sunos5_cache_age, NULL); DEBUGMSGTL(("kernel_sunos5", "registered alarm %d with period 5s\n", alarm_id)); alarm_id = snmp_alarm_register(period, SA_REPEAT, kernel_sunos5_cache_age, (void *)period); DEBUGMSGTL(("kernel_sunos5", "registered alarm %d with period %ds\n", alarm_id, period)); ++creg; } }
/* * our initialization routine * (to get called, the function name must match init_FILENAME() */ void init_notification(void) { DEBUGMSGTL(("example_notification", "initializing (setting callback alarm)\n")); snmp_alarm_register(30, /* seconds */ SA_REPEAT, /* repeat (every 30 seconds). */ send_example_notification, /* our callback */ NULL /* no callback data needed */ ); }
int alarm_Activate(RMON_ENTRY_T * eptr) { CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body; int ierr; #if 0 /* KUKU */ kuku_sum = 0; kuku_cnt = 0; #endif ierr = fetch_var_val(body->var_name.objid, body->var_name.length, &body->last_abs_value); if (SNMP_ERR_NOERROR != ierr) { ag_trace("Can't fetch var_name"); return ierr; } if (SAMPLE_TYPE_ABSOLUTE != body->sample_type) { /* * check startup alarm */ if (ALARM_RISING == body->startup_type || ALARM_BOTH == body->startup_type) { if (body->last_abs_value >= body->rising_threshold) { event_api_send_alarm(1, eptr->ctrl_index, body->rising_event_index, body->var_name.objid, body->var_name.length, ALARM_RISING, body->value, body->rising_threshold, "Startup Rising"); } } if (ALARM_FALLING == body->startup_type || ALARM_BOTH == body->startup_type) { if (body->last_abs_value <= body->falling_threshold) { event_api_send_alarm(0, eptr->ctrl_index, body->falling_event_index, body->var_name.objid, body->var_name.length, ALARM_RISING, body->value, body->falling_threshold, "Startup Falling"); } } } body->timer_id = snmp_alarm_register(body->interval, SA_REPEAT, alarm_check_var, eptr); return 0; }
void init_kernel_sunos5(void) { static int creg = 0; const int period = 5; if (creg == 0) { creg = snmp_alarm_register(period, SA_REPEAT, kernel_sunos5_cache_age, (void *)period); DEBUGMSGTL(("kernel_sunos5", "registered alarm %d with period %ds\n", creg, period)); } }
void mteTrigger_enable (struct mteTrigger *entry) { if (!entry) return; if (entry->alarm) { /* XXX - or explicitly call mteTrigger_disable ?? */ snmp_alarm_unregister (entry->alarm); entry->alarm = 0; } if (entry->mteTriggerFrequency) { /* * register once to run ASAP, and another to run * at the trigger frequency */ snmp_alarm_register (0, 0, mteTrigger_run, entry); entry->alarm = snmp_alarm_register (entry->mteTriggerFrequency, SA_REPEAT, mteTrigger_run, entry); } }
void init_alarmService(void) { prop_data properties[KEYS_MAX]; int prop_count=0; char ap_parameter[256]; long int ret ; /* get basic info */ prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties); memset(ap_parameter,0,256); get_prop("ALARM_TIMES",ap_parameter,properties,prop_count); alarmTimes = atoi(ap_parameter); memset(ap_parameter,0,256); get_prop("ALARM_FLAG",ap_parameter,properties,prop_count); if( strcmp(ap_parameter,"")==0 ){ strcpy(ap_parameter,"0"); } alarmFlag= atoi(ap_parameter); free_prop(properties,prop_count); if( alarmFlag != 0 ){ if(alarmTimes>0) alarmId=snmp_alarm_register(alarmTimes, //10 /* seconds */ SA_REPEAT, /* repeat (every 30 seconds). */ register_callback, /* our callback */ NULL ); /* no callback data needed */ else alarmId=snmp_alarm_register(ALARM_TET_FREQUENCY, //10 /* seconds */ SA_REPEAT, /* repeat (every 30 seconds). */ register_callback, /* our callback */ NULL ); /* no callback data needed */ } REGISTER_MIB("autelan-mib/autelan-sourceFile/wapi/alarm", alarm_variables, variable4, alarm_variables_oid); }
static int rowapi_deactivate (TABLE_DEFINTION_T * table_ptr, RMON_ENTRY_T * eptr) { if (RMON1_ENTRY_UNDER_CREATION == eptr->status) { /* * nothing to do */ return SNMP_ERR_NOERROR; } if (table_ptr->ClbkDeactivate) table_ptr->ClbkDeactivate (eptr); eptr->status = RMON1_ENTRY_UNDER_CREATION; eptr->timer_id = snmp_alarm_register (MAX_CREATION_TIME, 0, rowapi_too_long_creation_callback, eptr); ag_trace ("Entry %ld in %s has been deactivated", eptr->ctrl_index, table_ptr->name); return SNMP_ERR_NOERROR; }
//******************************************************************************** // Function: redirect_handler // // Description: Retrieve redirect count from Control Plane. //******************************************************************************** static int redirect_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { syslog(LOG_DEBUG, "Enter: handler, %s.", HANDLER_NAME); syslog(LOG_DEBUG, "handler mode = %d.", reqinfo->mode); requests->delegated = 1; snmp_alarm_register(0, 0, delayed_response, (void *) netsnmp_create_delegated_cache(handler, reginfo, reqinfo, requests, NULL)); syslog(LOG_DEBUG, "Exit: handler, %s.", HANDLER_NAME); return SNMP_ERR_NOERROR; }
/************************************************************ * Initializes the netSnmpIETFWGTable module */ void init_netSnmpIETFWGTable(void) { netsnmp_index *index; netSnmpIETFWGTable_context *x; oid tmp[33]; initialize_table_netSnmpIETFWGTable(); /* * TODO: perform any startup stuff here */ index = SNMP_MALLOC_TYPEDEF(netsnmp_index); tmp[0]=3; tmp[1]='A'; tmp[2] ='B'; tmp[3] ='C'; index->oids = tmp; index->len = 4; x = netSnmpIETFWGTable_create_row(index); CONTAINER_INSERT(cb.container, x); tmp[3]='D'; DEBUGMSGTL((AGENT,"TMP: %s", tmp)); x = netSnmpIETFWGTable_create_row(index); CONTAINER_INSERT(cb.container, x); free(index); index=NULL; //free(x); x=NULL; /* snmp_alarm_register(2, SA_REPEAT, send_notification, index); snmp_alarm_register(5, SA_REPEAT, create_, NULL); */ snmp_alarm_register(10, SA_REPEAT, delete_, NULL); // Do we dealloc x? }
void expExpression_enable( struct expExpression *entry ) { DEBUGMSG(("disman:expr:run", "Enabling %s\n", entry->expName)); if (!entry) return; if (entry->alarm) { /* or explicitly call expExpression_disable ?? */ snmp_alarm_unregister( entry->alarm ); entry->alarm = 0; } if (entry->expDeltaInterval) { entry->alarm = snmp_alarm_register( entry->expDeltaInterval, SA_REPEAT, expExpression_getData, entry ); expExpression_getData( entry->alarm, (void*)entry ); } }
int alarm_Copy (RMON_ENTRY_T * eptr) { CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body; CRTL_ENTRY_T *clone = (CRTL_ENTRY_T *) eptr->tmp; if (RMON1_ENTRY_VALID == eptr->status && clone->rising_threshold <= clone->falling_threshold) { ag_trace ("alarm_Copy failed: invalid thresholds"); return SNMP_ERR_BADVALUE; } if (clone->interval != body->interval) { if (RMON1_ENTRY_VALID == eptr->status) { snmp_alarm_unregister (body->timer_id); body->timer_id = snmp_alarm_register (clone->interval, SA_REPEAT, alarm_check_var, eptr); } body->interval = clone->interval; } if (snmp_oid_compare (clone->var_name.objid, clone->var_name.length, body->var_name.objid, body->var_name.length)) { memcpy (&body->var_name, &clone->var_name, sizeof (VAR_OID_T)); } body->sample_type = clone->sample_type; body->startup_type = clone->startup_type; body->sample_type = clone->sample_type; body->rising_threshold = clone->rising_threshold; body->falling_threshold = clone->falling_threshold; body->rising_event_index = clone->rising_event_index; body->falling_event_index = clone->falling_event_index; /* * ag_trace ("alarm_Copy: rising_threshold=%lu falling_threshold=%lu", * body->rising_threshold, body->falling_threshold); */ return 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)); } }
void vxge_trap_start(struct vxge_trap_info *trap) { /* save a snapshot of current dev info */ if (vxgedev_trap_snapshot(trap) < 0) { /* this is mostly due to driver not loaded */ vxge_log("Error on device info. Trap not enabled\n"); goto out; } /* register the alarm */ trap->alarm_id = snmp_alarm_register(VXGE_TRAP_POLL_INTERVAL, SA_REPEAT, vxge_trap_check, trap); if (!trap->alarm_id) { vxge_log("Alarm registration failed\n"); goto out; } trap->notify = 1; vxge_log("trap handler started...\n"); return; out: /* reset everything */ memset(trap, 0, sizeof(*trap)); }
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)); } }
static int _cache_load( netsnmp_cache *cache ) { int ret = -1; /* * If we've got a valid cache, then release it before reloading */ if (cache->valid && (! (cache->flags & NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD))) _cache_free(cache); if ( cache->load_cache) ret = cache->load_cache(cache, cache->magic); if (ret < 0) { DEBUGMSGT(("helper:cache_handler", " load failed (%d)\n", ret)); cache->valid = 0; return ret; } cache->valid = 1; cache->expired = 0; /* * If we didn't previously have any valid caches outstanding, * then schedule a pass of the auto-release routine. */ if ((!cache_outstanding_valid) && (! (cache->flags & NETSNMP_CACHE_DONT_FREE_EXPIRED))) { snmp_alarm_register(CACHE_RELEASE_FREQUENCY, 0, release_cached_resources, NULL); cache_outstanding_valid = 1; } netsnmp_set_monotonic_marker(&cache->timestampM); DEBUGMSGT(("helper:cache_handler", " loaded (%d)\n", cache->timeout)); return ret; }
/** run regularly to automatically release cached resources. * xxx - method to prevent cache from expiring while a request * is being processed (e.g. delegated request). proposal: * set a flag, which would be cleared when request finished * (which could be acomplished by a dummy data list item in * agent req info & custom free function). */ void release_cached_resources(unsigned int regNo, void *clientargs) { netsnmp_cache *cache = NULL; cache_outstanding_valid = 0; DEBUGMSGTL(("helper:cache_handler", "running auto-release\n")); for (cache = cache_head; cache; cache = cache->next) { DEBUGMSGTL(("helper:cache_handler"," checking %p (flags 0x%x)\n", cache, cache->flags)); if (cache->valid && ! (cache->flags & NETSNMP_CACHE_DONT_AUTO_RELEASE)) { DEBUGMSGTL(("helper:cache_handler"," releasing %p\n", cache)); /* * Check to see if this cache has timed out. * If so, release the cached resources. * Otherwise, note that we still have at * least one active cache. */ if (netsnmp_cache_check_expired(cache)) { if(! (cache->flags & NETSNMP_CACHE_DONT_FREE_EXPIRED)) _cache_free(cache); } else { cache_outstanding_valid = 1; } } } /* * If there are any caches still valid & active, * then schedule another pass. */ if (cache_outstanding_valid) { snmp_alarm_register(CACHE_RELEASE_FREQUENCY, 0, release_cached_resources, NULL); } }
void init_diskio(void) { /* * Define a 'variable' structure that is a representation of our mib. */ /* * first, we have to pick the variable type. They are all defined in * the var_struct.h file in the agent subdirectory. I'm picking the * variable2 structure since the longest sub-component of the oid I * want to load is .2.1 and .2.2 so I need at most 2 spaces in the * last entry. */ struct variable2 diskio_variables[] = { {DISKIO_INDEX, ASN_INTEGER, RONLY, var_diskio, 1, {1}}, {DISKIO_DEVICE, ASN_OCTET_STR, RONLY, var_diskio, 1, {2}}, {DISKIO_NREAD, ASN_COUNTER, RONLY, var_diskio, 1, {3}}, {DISKIO_NWRITTEN, ASN_COUNTER, RONLY, var_diskio, 1, {4}}, {DISKIO_READS, ASN_COUNTER, RONLY, var_diskio, 1, {5}}, {DISKIO_WRITES, ASN_COUNTER, RONLY, var_diskio, 1, {6}}, #if defined(freebsd4) || defined(freebsd5) {DISKIO_LA1, ASN_INTEGER, RONLY, var_diskio, 1, {9}}, {DISKIO_LA5, ASN_INTEGER, RONLY, var_diskio, 1, {10}}, {DISKIO_LA15, ASN_INTEGER, RONLY, var_diskio, 1, {11}}, #endif {DISKIO_NREADX, ASN_COUNTER64, RONLY, var_diskio, 1, {12}}, {DISKIO_NWRITTENX, ASN_COUNTER64, RONLY, var_diskio, 1, {13}}, }; /* * Define the OID pointer to the top of the mib tree that we're * registering underneath. */ oid diskio_variables_oid[] = { 1, 3, 6, 1, 4, 1, 2021, 13, 15, 1, 1 }; /* * register ourselves with the agent to handle our mib tree * * This is a macro defined in ../../snmp_vars.h. The arguments are: * * descr: A short description of the mib group being loaded. * var: The variable structure to load. * vartype: The variable structure used to define it (variable2, variable4, ...) * theoid: A *initialized* *exact length* oid pointer. * (sizeof(theoid) *must* return the number of elements!) */ REGISTER_MIB("diskio", diskio_variables, variable2, diskio_variables_oid); #ifdef solaris2 kc = kstat_open(); if (kc == NULL) snmp_log(LOG_ERR, "diskio: Couldn't open kstat\n"); #endif #ifdef darwin /* * Get the I/O Kit communication handle. */ IOMasterPort(bootstrap_port, &masterPort); #endif #if defined(aix4) || defined(aix5) || defined(aix6) /* * initialize values to gather information on first request */ ps_numdisks = 0; ps_disk = NULL; #endif #if defined (freebsd4) || defined(freebsd5) devla_getstats(0, NULL); /* collect LA data regularly */ snmp_alarm_register(DISKIO_SAMPLE_INTERVAL, SA_REPEAT, devla_getstats, NULL); #endif }
static void logmatch_parse_config(const char *token, char *cptr) { char space_name; char space_path; if (logmatchCount < MAXLOGMATCH) { logmatchTable[logmatchCount].frequency = 30; logmatchTable[logmatchCount].thisIndex = logmatchCount; /* * ------------------------------------ * be careful this counter needs to be * reset from persistent storage * ------------------------------------ */ logmatchTable[logmatchCount].globalMatchCounter = 0; logmatchTable[logmatchCount].currentMatchCounter = 0; logmatchTable[logmatchCount].matchCounter = 0; logmatchTable[logmatchCount].virgin = TRUE; logmatchTable[logmatchCount].currentFilePosition = 0; /* * ------------------------------------ * be careful: the flag 255 must fit to * the size of regEx as definded in * logmatch.h * ------------------------------------ */ sscanf(cptr, "%255s%c%255s%c %d %255c\n", logmatchTable[logmatchCount].name, &space_name, logmatchTable[logmatchCount].filenamePattern, &space_path, &(logmatchTable[logmatchCount].frequency), logmatchTable[logmatchCount].regEx); /* fill in filename with initial data */ strcpy(logmatchTable[logmatchCount].filename, logmatchTable[logmatchCount].filenamePattern); logmatch_update_filename(logmatchTable[logmatchCount].filenamePattern, logmatchTable[logmatchCount].filename); /* * Log an error then return if any of the strings scanned in were * larger then they should have been. */ if (space_name != ' ') { snmp_log(LOG_ERR, "logmatch_parse_config: the name scanned " \ "in from line %s is too large. logmatchCount = %d\n", cptr, logmatchCount); return; } else if (space_path != ' ') { snmp_log(LOG_ERR, "logmatch_parse_config: the file name " \ "scanned in from line %s is too large. logmatchCount = %d\n", cptr, logmatchCount); return; } /* * ------------------------------------ * just to be safe "NULL" the end of * the arary regEx as sscanf won't do * it with the %c modifier * ------------------------------------ */ logmatchTable[logmatchCount].regEx[255] = '\0'; /* * ------------------------------------ * now compile the regular expression * ------------------------------------ */ logmatchTable[logmatchCount].myRegexError = regcomp(&(logmatchTable[logmatchCount].regexBuffer), logmatchTable[logmatchCount].regEx, REG_EXTENDED | REG_NOSUB); if (logmatchTable[logmatchCount].frequency > 0) { snmp_alarm_register(logmatchTable[logmatchCount].frequency, SA_REPEAT, (SNMPAlarmCallback *) updateLogmatch_Scheduled, &(logmatchTable[logmatchCount]) ); } logmatchCount++; } }
/* * creates an entry, locats it in proper sorted order by index * Row is initialized to zero, * except: 'next', 'table_ptr', 'index', * 'timer_id' & 'status'=(RMON1_ENTRY_UNDER_CREATION) * Calls (if need) ClbkCreate. * Schedules for timeout under entry creation (id of this * scheduling is saved in 'timer_id'). * Returns 0: OK, -1:max. number exedes; -2:malloc failed; -3:ClbkCreate failed */ int ROWAPI_new(TABLE_DEFINTION_T * table_ptr, u_long ctrl_index) { register RMON_ENTRY_T *eptr; register RMON_ENTRY_T *prev = NULL; register RMON_ENTRY_T *enew; /* * check on 'max.number' */ if (table_ptr->max_number_of_entries > 0 && table_ptr->current_number_of_entries >= table_ptr->max_number_of_entries) return -1; /* * allocate memory for the header */ enew = (RMON_ENTRY_T *) AGMALLOC(sizeof(RMON_ENTRY_T)); if (!enew) return -2; /* * init the header */ memset(enew, 0, sizeof(RMON_ENTRY_T)); enew->ctrl_index = ctrl_index; enew->table_ptr = (void *) table_ptr; enew->status = RMON1_ENTRY_UNDER_CREATION; enew->only_just_created = 1; /* * create the body: alloc it and set defaults */ if (table_ptr->ClbkCreate) { if (0 != table_ptr->ClbkCreate(enew)) { AGFREE(enew); return -3; } } table_ptr->current_number_of_entries++; /* * find the place : before 'eptr' and after 'prev' */ for (eptr = table_ptr->first; eptr; eptr = eptr->next) { if (ctrl_index < eptr->ctrl_index) break; prev = eptr; } /* * insert it */ enew->next = eptr; if (prev) prev->next = enew; else table_ptr->first = enew; enew->timer_id = snmp_alarm_register(MAX_CREATION_TIME, 0, rowapi_too_long_creation_callback, enew); ag_trace("Entry %ld in %s has been created", enew->ctrl_index, table_ptr->name); return 0; }
void LOG_PROCESSOR_USAGE() { int j = 0; int rc; int num_descript; size_t toc_sz = 0; size_t max_toc_sz = (10 * sizeof(descript)); struct dirent **cpuent; descript *toc; descript *ttoc; /* do something different for VmWare and Solaris */ cpucount = scandir("/sys/class/cpuid", &cpuent, file_select, versionsort); DEBUGMSGTL(("rec:rec_log:rec_log_proc_usage","cpucount = %d\n", cpucount)); if (cpucount == -1) return; if (!rec_init() ) return; /* do Code Descriptor */ if ((rc = doCodeDescriptor(s_ams_rec_handle, s_ams_rec_class, REC_CODE_AMS_PROCESSOR_USAGE, 0, REC_SEV_PERIOD, REC_BINARY_DATA, REC_VIS_CUSTOMER, REC_CODE_AMS_PROCESSOR_USAGE_STR)) != RECORDER_OK) { DEBUGMSGTL(("rec:rec_log_error", "Host Name register descriptor failed %d\n", rc)); return; } num_descript = sizeof(fld)/sizeof(field) * cpucount; DEBUGMSGTL(("rec:rec_log:rec_log_proc_usage","ProcUsage num_descript = %d\n", num_descript)); toc_sz = sizeof(descript) * num_descript; toc = malloc(toc_sz); DEBUGMSGTL(("rec:log","Initial Processor Usage toc_sz = %ld\n", toc_sz)); /* now do the field descriptor */ memset(toc, 0, toc_sz); for (j = 0; j < num_descript; j++ ) { toc[j].flags = REC_FLAGS_DESCRIPTOR | REC_FLAGS_DESC_FIELD; toc[j].classs = s_ams_rec_class; toc[j].code = REC_CODE_AMS_PROCESSOR_USAGE; toc[j].field = j; toc[j].severity_type = REC_SEV_PERIOD | fld[j%2].tp; toc[j].format = fld[j%2].sz; toc[j].visibility = REC_VIS_CUSTOMER; strncpy(toc[j].desc, fld[j%2].nm, sizeof(toc[j].desc) - strlen(toc[j].desc - 1)); strcat(toc[j].desc, cpuent[j/2]->d_name); DEBUGMSGTL(("rec:log", "toc[i] = %p\n", &toc[j])); dump_chunk("rec:rec_log","descriptor", (const u_char *)&toc[j], 96); if (j % 2) free(cpuent[j/2]); } dump_chunk("rec:rec_log", "toc", (const u_char *)toc, toc_sz); free(cpuent); ttoc = toc; while (toc_sz > RECORDER_MAX_BLOB_SIZE) { DEBUGMSGTL(("rec:log","Processor Usage ttoc = %p\n", ttoc)); DEBUGMSGTL(("rec:log","Processor Usage toc_sz = %ld\n", toc_sz)); if ((rc = rec_api4_field(s_ams_rec_handle, max_toc_sz, ttoc)) != RECORDER_OK) { DEBUGMSGTL(("rec:rec_log_error","Proc Usage register descriptor failed %d\n", rc)); return; } toc_sz = toc_sz - max_toc_sz; ttoc = (void *)ttoc + max_toc_sz; } if ((rc = rec_api4_field(s_ams_rec_handle, toc_sz, ttoc)) != RECORDER_OK) { DEBUGMSGTL(("rec:rec_log_error","Proc Usage register descriptor failed %d\n", rc)); return; } free(toc); if (!proc_usage_reinit) switch (log_interval) { case 0: rec_log_proc_usage(0, &cpucount); break; case 1: snmp_alarm_register(60, SA_REPEAT, &rec_log_proc_usage, &cpucount); break; case 2: snmp_alarm_register(600, SA_REPEAT, &rec_log_proc_usage, &cpucount); break; case 3: snmp_alarm_register(3600, SA_REPEAT, &rec_log_proc_usage, &cpucount); break; } else proc_usage_reinit = 0; return; }
void init_diskio(void) { /* * Define a 'variable' structure that is a representation of our mib. */ /* * first, we have to pick the variable type. They are all defined in * the var_struct.h file in the agent subdirectory. I'm picking the * variable2 structure since the longest sub-component of the oid I * want to load is .2.1 and .2.2 so I need at most 2 spaces in the * last entry. */ struct variable2 diskio_variables[] = { {DISKIO_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {1}}, {DISKIO_DEVICE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {2}}, {DISKIO_NREAD, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {3}}, {DISKIO_NWRITTEN, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {4}}, {DISKIO_READS, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {5}}, {DISKIO_WRITES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {6}}, #if defined(HAVE_GETDEVS) || defined(HAVE_DEVSTAT_GETDEVS) || defined(linux) {DISKIO_LA1, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {9}}, {DISKIO_LA5, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {10}}, {DISKIO_LA15, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {11}}, #endif {DISKIO_NREADX, ASN_COUNTER64, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {12}}, {DISKIO_NWRITTENX, ASN_COUNTER64, NETSNMP_OLDAPI_RONLY, var_diskio, 1, {13}}, }; /* * Define the OID pointer to the top of the mib tree that we're * registering underneath. */ oid diskio_variables_oid[] = { 1, 3, 6, 1, 4, 1, 2021, 13, 15, 1, 1 }; /* * register ourselves with the agent to handle our mib tree * * This is a macro defined in ../../snmp_vars.h. The arguments are: * * descr: A short description of the mib group being loaded. * var: The variable structure to load. * vartype: The variable structure used to define it (variable2, variable4, ...) * theoid: A *initialized* *exact length* oid pointer. * (sizeof(theoid) *must* return the number of elements!) */ REGISTER_MIB("diskio", diskio_variables, variable2, diskio_variables_oid); #ifdef solaris2 kc = kstat_open(); if (kc == NULL) snmp_log(LOG_ERR, "diskio: Couldn't open kstat\n"); #endif #ifdef darwin /* * Get the I/O Kit communication handle. */ IOMasterPort(bootstrap_port, &masterPort); #endif #if defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) /* * initialize values to gather information on first request */ ps_numdisks = 0; ps_disk = NULL; #endif #if defined (HAVE_GETDEVS) || defined(HAVE_DEVSTAT_GETDEVS) || defined(linux) devla_getstats(0, NULL); /* collect LA data regularly */ snmp_alarm_register(DISKIO_SAMPLE_INTERVAL, SA_REPEAT, devla_getstats, NULL); #endif #ifdef linux char *app = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE); netsnmp_ds_register_config(ASN_BOOLEAN, app, "diskio_exclude_fd", NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_DISKIO_NO_FD); netsnmp_ds_register_config(ASN_BOOLEAN, app, "diskio_exclude_loop", NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_DISKIO_NO_LOOP); netsnmp_ds_register_config(ASN_BOOLEAN, app, "diskio_exclude_ram", NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_DISKIO_NO_RAM); /* or possible an exclusion pattern? */ snmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_PRE_UPDATE_CONFIG, diskio_free_config, NULL); #endif }
/* * ARGSUSED0 */ static void update_stats(unsigned int registrationNumber, void *clientarg) { /* * The time between the samples we compare */ time_t time_diff; /* * Easier to use these than the snapshots, short hand pointers */ struct cpu_stat_snapshot *css_old, *css_new; /* * The usual stuff to count on, err, by */ int i; /* * The sum of the CPU ticks that have passed on the different CPU states, so we can calculate */ /* * the percentages of each state */ unsigned long long cpu_sum = 0; DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "updating stats\n")); /* * Take the current snapshot */ if (take_snapshot(&snapshot[0]) == -1) { snmp_log(LOG_WARNING, "vmstat_dynix (update_stats): Something went wrong with take_snapshot."); return; } /* * Do we have some data we can use ? An issue right after the start of the agent */ if (number_of_snapshots > 0) { /* * Huh, the number of CPUs changed during run time. That is indeed s.th. worth noting, we */ /* * output a humorous (more or less) syslog message and need to retake the snapshots */ if (snapshot[0].css_cpus != snapshot[1].css_cpus) { if (snapshot[0].css_cpus > snapshot[1].css_cpus) { snmp_log(LOG_NOTICE, "vmstat_dynix (update_stats): Cool ! Number of CPUs increased, must be hot-pluggable."); } else { snmp_log(LOG_NOTICE, "vmstat_dynix (update_stats): Lost at least one CPU, RIP."); } /* * Make all snapshots but the current one invalid */ number_of_snapshots = 1; /* * Move the current one in the "first" [1] slot */ memmove(&snapshot[1], &snapshot[0], sizeof snapshot[0]); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Try to get a new snapshot in five seconds so we can return s.th. useful */ if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) { snmp_log(LOG_WARNING, "vmstat_dynix (update_stats): snmp_alarm_register failed.\n"); } return; } /* * Short hand pointers */ css_new = &snapshot[0]; css_old = &snapshot[number_of_snapshots]; /* * How much time has passed between the snapshots we get the values from ? */ /* * Time is in seconds */ time_diff = snapshot[0].css_time - snapshot[number_of_snapshots].css_time; if (time_diff == 0) DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "time_diff is ZERO... watch for the segfault\n")); DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "time_diff: %lld\n", time_diff)); /* * swapin and swapout are in pages, MIB wants kB/s,so we just need to get kB and seconds */ /* * For the others we need to get value per second */ /* * decided to use sysconf(_SC_PAGESIZE) instead to get around an #ifndef (I don't like those) */ /* * LINTED cast needed, really */ swapin = (uint_t) ((css_new->css_swapin - css_old->css_swapin) * (time_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ swapout = (uint_t) ((css_new->css_swapout - css_old->css_swapout) * (time_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ blocks_read = (uint_t) ((css_new->css_blocks_read - css_old->css_blocks_read) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ blocks_write = (uint_t) ((css_new->css_blocks_write - css_old->css_blocks_write) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ interrupts = (uint_t) ((css_new->css_interrupts - css_old->css_interrupts) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ context_sw = (uint_t) ((css_new->css_context_sw - css_old->css_context_sw) * (time_t) 1000 / time_diff); /* * Loop thru all the V_CPU_STATES and get the differences */ for (i = 0; i < V_CPU_STATES; i++) { cpu_sum += (css_new->css_cpu[i] - css_old->css_cpu[i]); } /* * Now calculate the absolute percentage values */ /* * Looks somewhat complicated sometimes but tries to get around using floats to increase speed */ for (i = 0; i < V_CPU_STATES; i++) { /* * Since we don't return fractions we use + 0.5 to get between 99 and 101 percent adding the values */ /* * together, otherwise we would get less than 100 most of the time */ /* * LINTED has to be 'long' */ cpu_perc[i] = (long) (((css_new->css_cpu[i] - css_old->css_cpu[i]) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * As said before, MIB wants V_CPU_SYSTEM which is V_CPU_KERNEL + V_CPU_STREAM */ /* * LINTED has to be 'long' */ cpu_perc[V_CPU_SYSTEM] = (long) ((((css_new->css_cpu[V_CPU_KERNEL] - css_old->css_cpu[V_CPU_KERNEL]) + (css_new->css_cpu[V_CPU_STREAM] - css_old->css_cpu[V_CPU_STREAM])) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * Make the current one the first one and move the whole thing one place down */ memmove(&snapshot[1], &snapshot[0], (size_t) (((char *) &snapshot[POLL_VALUES]) - ((char *) &snapshot[0]))); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Only important on start up, we keep track of how many snapshots we have taken so far */ if (number_of_snapshots < POLL_VALUES) { number_of_snapshots++; } } /* update_stats ends here */
void init_vmstat_dynix(void) { /* * Which variables do we service ? */ struct variable2 extensible_vmstat_variables[] = { {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {MIBINDEX}}, {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_vmstat, 1, {ERRORNAME}}, {SWAPIN, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SWAPIN}}, {SWAPOUT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SWAPOUT}}, {IOSENT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {IOSENT}}, {IORECEIVE, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {IORECEIVE}}, {SYSINTERRUPTS, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SYSINTERRUPTS}}, {SYSCONTEXT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SYSCONTEXT}}, {CPUUSER, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {CPUUSER}}, {CPUSYSTEM, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {CPUSYSTEM}}, {CPUIDLE, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {CPUIDLE}}, {CPURAWUSER, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {CPURAWUSER}}, {CPURAWSYSTEM, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {CPURAWSYSTEM}}, {CPURAWIDLE, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {CPURAWIDLE}}, {CPURAWWAIT, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {CPURAWWAIT}}, {CPURAWKERNEL, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {CPURAWKERNEL}}, {IORAWSENT, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {IORAWSENT}}, {IORAWRECEIVE, ASN_COUNTER, RONLY, var_extensible_vmstat, 1, {IORAWRECEIVE}}, /* * Future use: */ /* * {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {ERRORFLAG }}, * {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_vmstat, 1, {ERRORMSG }} */ }; /* * Define the OID pointer to the top of the mib tree that we're */ /* * registering underneath */ oid vmstat_variables_oid[] = { NETSNMP_UCDAVIS_MIB, 11 }; /* * register ourselves with the agent to handle our mib tree */ /* * LINTED Trust me, I know what I'm doing */ REGISTER_MIB("ucd-snmp/vmstat", extensible_vmstat_variables, variable2, vmstat_variables_oid); /* * Start with some useful data */ update_stats(0, NULL); /* * update_stats is run every POLL_INTERVAL seconds using this routine */ /* * (see 'man snmp_alarm') */ /* * This is only executed once to get some useful data in the beginning */ if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) { snmp_log(LOG_WARNING, "vmstat_dynix (init): snmp_alarm_register failed.\n"); } /* * This is the one that runs update_stats every POLL_INTERVAL seconds */ if (snmp_alarm_register(POLL_INTERVAL, SA_REPEAT, update_stats, NULL) == 0) { snmp_log(LOG_ERR, "vmstat_dynix (init): snmp_alarm_register failed, cannot service requests.\n"); } } /* init_vmstat_dynix ends here */
/** one-time initialization for mysql */ int netsnmp_mysql_init(void) { int not_argc = 0, i; char *not_args[] = { NULL }; char **not_argv = not_args; netsnmp_trapd_handler *traph; DEBUGMSGTL(("sql:init","called\n")); /** negative or 0 interval disables sql logging */ if (_sql.queue_interval <= 0) { DEBUGMSGTL(("sql:init", "mysql not enabled (sqlSaveInterval is <= 0)\n")); return 0; } /** create queue for storing traps til they are written to the db */ _sql.queue = netsnmp_container_find("fifo"); if (NULL == _sql.queue) { snmp_log(LOG_ERR, "Could not allocate sql buf container\n"); return -1; } #ifdef HAVE_BROKEN_LIBMYSQLCLIENT my_init(); #else MY_INIT("snmptrapd"); #endif /** load .my.cnf values */ load_defaults ("my", _sql.groups, ¬_argc, ¬_argv); for(i=0; i < not_argc; ++i) { if (NULL == not_argv[i]) continue; if (strncmp(not_argv[i],"--password="******"--host=",7) == 0) _sql.host_name = ¬_argv[i][7]; else if (strncmp(not_argv[i],"--user="******"--port=",7) == 0) _sql.port_num = atoi(¬_argv[i][7]); else if (strncmp(not_argv[i],"--socket=",9) == 0) _sql.socket_name = ¬_argv[i][9]; else snmp_log(LOG_WARNING, "unknown argument[%d] %s\n", i, not_argv[i]); } /** init bind structures */ memset(_tbind, 0x0, sizeof(_tbind)); memset(_vbind, 0x0, sizeof(_vbind)); /** trap static bindings */ _tbind[TBIND_HOST].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_HOST].length = &_tbind[TBIND_HOST].buffer_length; _tbind[TBIND_OID].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_OID].length = &_tbind[TBIND_OID].buffer_length; _tbind[TBIND_REQID].buffer_type = MYSQL_TYPE_LONG; _tbind[TBIND_REQID].is_unsigned = 1; _tbind[TBIND_VER].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_VER].is_unsigned = 1; _tbind[TBIND_TYPE].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_TYPE].is_unsigned = 1; _tbind[TBIND_DATE].buffer_type = MYSQL_TYPE_DATETIME; _tbind[TBIND_USER].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_USER].length = &_tbind[TBIND_USER].buffer_length; _tbind[TBIND_TRANSPORT].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_TRANSPORT].length = &_tbind[TBIND_TRANSPORT].buffer_length; _tbind[TBIND_SECURITY_MODEL].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_SECURITY_MODEL].is_unsigned = 1; _tbind[TBIND_v3_MSGID].buffer_type = MYSQL_TYPE_LONG; _tbind[TBIND_v3_MSGID].is_unsigned = 1; _tbind[TBIND_v3_SECURITY_LEVEL].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_v3_SECURITY_LEVEL].is_unsigned = 1; _tbind[TBIND_v3_CONTEXT_NAME].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_CONTEXT_ENGINE].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_NAME].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_NAME].length = &_tbind[TBIND_v3_SECURITY_NAME].buffer_length; _tbind[TBIND_v3_CONTEXT_NAME].length = &_tbind[TBIND_v3_CONTEXT_NAME].buffer_length; _tbind[TBIND_v3_SECURITY_ENGINE].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_ENGINE].length = &_tbind[TBIND_v3_SECURITY_ENGINE].buffer_length; _tbind[TBIND_v3_CONTEXT_ENGINE].length = &_tbind[TBIND_v3_CONTEXT_ENGINE].buffer_length; _tbind[TBIND_v3_MSGID].is_null = _tbind[TBIND_v3_SECURITY_LEVEL].is_null = _tbind[TBIND_v3_CONTEXT_NAME].is_null = _tbind[TBIND_v3_CONTEXT_ENGINE].is_null = _tbind[TBIND_v3_SECURITY_NAME].is_null = _tbind[TBIND_v3_SECURITY_ENGINE].is_null = &_no_v3; /** variable static bindings */ _vbind[VBIND_ID].buffer_type = MYSQL_TYPE_LONG; _vbind[VBIND_ID].is_unsigned = 1; _vbind[VBIND_OID].buffer_type = MYSQL_TYPE_STRING; _vbind[VBIND_OID].length = &_vbind[VBIND_OID].buffer_length; _vbind[VBIND_TYPE].buffer_type = MYSQL_TYPE_SHORT; _vbind[VBIND_TYPE].is_unsigned = 1; #ifdef NETSNMP_MYSQL_TRAP_VALUE_TEXT _vbind[VBIND_VAL].buffer_type = MYSQL_TYPE_STRING; #else _vbind[VBIND_VAL].buffer_type = MYSQL_TYPE_BLOB; #endif _vbind[VBIND_VAL].length = &_vbind[VBIND_VAL].buffer_length; _sql.conn = mysql_init (NULL); if (_sql.conn == NULL) { netsnmp_sql_error("mysql_init() failed (out of memory?)"); return -1; } /** try to connect; we'll try again later if we fail */ (void) netsnmp_mysql_connect(); /** register periodic queue save */ _sql.alarm_id = snmp_alarm_register(_sql.queue_interval, /* seconds */ 1, /* repeat */ _sql_process_queue, /* function */ NULL); /* client args */ /** add handler */ traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER, mysql_handler); if (NULL == traph) { snmp_log(LOG_ERR, "Could not allocate sql trap handler\n"); return -1; } traph->authtypes = TRAP_AUTH_LOG; atexit(netsnmp_mysql_cleanup); return 0; }