int write_exampletrap2(int action, u_char * var_val, u_char var_val_type, size_t var_val_len, u_char * statP, oid * name, size_t name_len) { long intval; /* * these variales will be used when we send the trap */ oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; /* snmpTrapOID.0 */ oid demo_trap[] = { 1, 3, 6, 1, 4, 1, 2021, 13, 990 }; /*demo-trap */ oid example_string_oid[] = { 1, 3, 6, 1, 4, 1, 2021, 254, 1, 0 }; static netsnmp_variable_list var_trap; static netsnmp_variable_list var_obj; DEBUGMSGTL(("example", "write_exampletrap2 entered: action=%d\n", action)); switch (action) { case RESERVE1: /* * The only acceptable value is the integer 1 */ if (var_val_type != ASN_INTEGER) { DEBUGMSGTL(("example", "%x not integer type", var_val_type)); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long)) { DEBUGMSGTL(("example", "wrong length %" NETSNMP_PRIz "u", var_val_len)); return SNMP_ERR_WRONGLENGTH; } intval = *((long *) var_val); if (intval != 1) { DEBUGMSGTL(("example", "wrong value %lx", intval)); return SNMP_ERR_WRONGVALUE; } break; case RESERVE2: /* * No resources are required.... */ break; case FREE: /* * ... so no resources need be freed */ break; case ACTION: /* * Having triggered the sending of a trap, * it would be impossible to revoke this, * so we can't actually invoke the action here. */ break; case UNDO: /* * We haven't done anything yet, * so there's nothing to undo */ break; case COMMIT: /* * Everything else worked, so it's now safe * to trigger the trap. * Note that this is *only* acceptable since * the trap sending routines are "failsafe". * (In fact, they can fail, but they return no * indication of this, which is the next best thing!) */ /* * trap definition objects */ var_trap.next_variable = &var_obj; /* next variable */ var_trap.name = objid_snmptrap; /* snmpTrapOID.0 */ var_trap.name_length = sizeof(objid_snmptrap) / sizeof(oid); /* number of sub-ids */ var_trap.type = ASN_OBJECT_ID; var_trap.val.objid = demo_trap; /* demo-trap objid */ var_trap.val_len = sizeof(demo_trap); /* length in bytes (not number of subids!) */ /* * additional objects */ var_obj.next_variable = NULL; /* No more variables after this one */ var_obj.name = example_string_oid; var_obj.name_length = sizeof(example_string_oid) / sizeof(oid); /* number of sub-ids */ var_obj.type = ASN_OCTET_STR; /* type of variable */ var_obj.val.string = (unsigned char *) example_str; /* value */ var_obj.val_len = strlen(example_str); DEBUGMSGTL(("example", "write_exampletrap2 sending the v2 trap\n")); send_v2trap(&var_trap); DEBUGMSGTL(("example", "write_exampletrap2 v2 trap sent\n")); break; } return SNMP_ERR_NOERROR; }
/* * send trap */ void run_mte_events(struct mteTriggerTable_data *item, oid * name_oid, size_t name_oid_len, const char *eventobjowner, const char *eventobjname) { static oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; /* snmpTrapIOD.0 */ netsnmp_variable_list *var_list = NULL; netsnmp_table_row *row, *notif_row; netsnmp_table_data_set_storage *col1, *tc, *no, *noo; for(row = table_set->table->first_row; row; row = row->next) { if (strcmp(row->indexes->val.string, eventobjowner) == 0 && strcmp(row->indexes->next_variable->val.string, eventobjname) == 0) { /* run this event */ col1 = (netsnmp_table_data_set_storage *) row->data; tc = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTACTIONS); if (!tc->data.bitstring[0] & 0x80) { /* not a notification. next! (XXX: do sets) */ continue; } tc = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTENABLED); if (*(tc->data.integer) != 1) { /* not enabled. next! */ continue; } if (!mteEventNotif_table_set) { /* no notification info */ continue; } /* send the notification */ var_list = NULL; /* XXX: get notif information */ for(notif_row = mteEventNotif_table_set->table->first_row; notif_row; notif_row = notif_row->next) { if (strcmp(notif_row->indexes->val.string, eventobjowner) == 0 && strcmp(notif_row->indexes->next_variable->val.string, eventobjname) == 0) { /* run this event */ col1 = (netsnmp_table_data_set_storage *) notif_row->data; tc = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATION); no = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATIONOBJECTS); noo = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER); if (!tc) continue; /* no notification to be had. XXX: return? */ /* * snmpTrap oid */ snmp_varlist_add_variable(&var_list, objid_snmptrap, sizeof(objid_snmptrap) / sizeof(oid), ASN_OBJECT_ID, (u_char *) tc->data.objid, tc->data_len); /* XXX: add objects from the mteObjectsTable */ DEBUGMSGTL(("mteEventTable:send_events", "no: %x, no->data: %s", no, no->data.string)); DEBUGMSGTL(("mteEventTable:send_events", "noo: %x, noo->data: %s", noo, noo->data.string)); DEBUGMSGTL(("mteEventTable:send_events", "name_oid: %x",name_oid)); if (no && no->data.string && noo && noo->data.string && name_oid) { char *tmpowner = netsnmp_strdup_and_null(noo->data.string, noo->data_len); char *tmpname = netsnmp_strdup_and_null(no->data.string, no->data_len); DEBUGMSGTL(("mteEventTable:send_events", "Adding objects for owner=%s name=%s", tmpowner, tmpname)); mte_add_objects(var_list, item, tmpowner, tmpname, name_oid + item->mteTriggerValueIDLen, name_oid_len - item->mteTriggerValueIDLen); free(tmpowner); free(tmpname); } DEBUGMSGTL(("mteEventTable:send_events", "sending an event ")); DEBUGMSGOID(("mteEventTable:send_events", tc->data.objid, tc->data_len / sizeof(oid))); DEBUGMSG(("mteEventTable:send_events", "\n")); send_v2trap(var_list); snmp_free_varbind(var_list); } } } } }
static void event_send_trap(CRTL_ENTRY_T * evptr, u_char is_rising, u_int alarm_index, u_int value, u_int the_threshold, oid * alarmed_var, size_t alarmed_var_length, u_int sample_type) { static oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; static oid rmon1_trap_oid[] = { 1, 3, 6, 1, 2, 1, 16, 0, 0 }; static oid alarm_index_oid[] = { 1, 3, 6, 1, 2, 1, 16, 3, 1, 1, 1, 0 }; static oid alarmed_var_oid[] = { 1, 3, 6, 1, 2, 1, 16, 3, 1, 1, 3, 0 }; static oid sample_type_oid[] = { 1, 3, 6, 1, 2, 1, 16, 3, 1, 1, 4, 0 }; static oid value_oid[] = { 1, 3, 6, 1, 2, 1, 16, 3, 1, 1, 5, 0 }; static oid threshold_oid[] = { 1, 3, 6, 1, 2, 1, 16, 3, 1, 1, 7, 0 }; /* rising case */ netsnmp_variable_list *var_list = NULL; /* * set the last 'oid' : risingAlarm or fallingAlarm */ if (is_rising) { rmon1_trap_oid[8] = 1; threshold_oid[10] = 7; } else { rmon1_trap_oid[8] = 2; threshold_oid[10] = 8; } alarm_index_oid[11] = alarm_index; alarmed_var_oid[11] = alarm_index; sample_type_oid[11] = alarm_index; value_oid[11] = alarm_index; threshold_oid[11] = alarm_index; /* * build the var list */ snmp_varlist_add_variable(&var_list, objid_snmptrap, OID_LENGTH(objid_snmptrap), ASN_OBJECT_ID, (u_char *) rmon1_trap_oid, sizeof(rmon1_trap_oid)); snmp_varlist_add_variable(&var_list, alarm_index_oid, OID_LENGTH(alarm_index_oid), ASN_INTEGER, (u_char *) &alarm_index, sizeof(u_int)); snmp_varlist_add_variable(&var_list, alarmed_var_oid, OID_LENGTH(alarmed_var_oid), ASN_OBJECT_ID, (u_char *) alarmed_var, alarmed_var_length * sizeof(oid)); snmp_varlist_add_variable(&var_list, sample_type_oid, OID_LENGTH(sample_type_oid), ASN_INTEGER, (u_char *) &sample_type, sizeof(u_int)); snmp_varlist_add_variable(&var_list, value_oid, OID_LENGTH(value_oid), ASN_INTEGER, (u_char *) &value, sizeof(u_int)); snmp_varlist_add_variable(&var_list, threshold_oid, OID_LENGTH(threshold_oid), ASN_INTEGER, (u_char *) &the_threshold, sizeof(u_int)); send_v2trap(var_list); ag_trace("rmon trap has been sent"); snmp_free_varbind(var_list); }
int send_saHpiHotSwapNotification_trap( void ) { netsnmp_variable_list *var_list = NULL; oid saHpiHotSwapNotification_oid[] = { 1,3,6,1,4,1,18568,2,1,1,5,6 }; oid saHpiDomainId_oid[] = { 1,3,6,1,4,1,18568,2,1,1,2,2,1,1, /* insert index here */ }; oid saHpiResourceId_oid[] = { 1,3,6,1,4,1,18568,2,1,1,2,8,1,1, /* insert index here */ }; oid saHpiEventSeverity_oid[] = { 1,3,6,1,4,1,18568,2,1,1,3,1,3,1,3, /* insert index here */ }; oid saHpiHotSwapEventState_oid[] = { 1,3,6,1,4,1,18568,2,1,1,3,1,18,1,3, /* insert index here */ }; oid saHpiHotSwapEventPreviousState_oid[] = { 1,3,6,1,4,1,18568,2,1,1,3,1,18,1,4, /* insert index here */ }; /* * Set the snmpTrapOid.0 value */ snmp_varlist_add_variable(&var_list, snmptrap_oid, OID_LENGTH(snmptrap_oid), ASN_OBJECT_ID, saHpiHotSwapNotification_oid, sizeof(saHpiHotSwapNotification_oid)); /* * Add any objects from the trap definition */ snmp_varlist_add_variable(&var_list, saHpiDomainId_oid, OID_LENGTH(saHpiDomainId_oid), ASN_UNSIGNED, /* Set an appropriate value for saHpiDomainId */ NULL, 0); snmp_varlist_add_variable(&var_list, saHpiResourceId_oid, OID_LENGTH(saHpiResourceId_oid), ASN_UNSIGNED, /* Set an appropriate value for saHpiResourceId */ NULL, 0); snmp_varlist_add_variable(&var_list, saHpiEventSeverity_oid, OID_LENGTH(saHpiEventSeverity_oid), ASN_INTEGER, /* Set an appropriate value for saHpiEventSeverity */ NULL, 0); snmp_varlist_add_variable(&var_list, saHpiHotSwapEventState_oid, OID_LENGTH(saHpiHotSwapEventState_oid), ASN_INTEGER, /* Set an appropriate value for saHpiHotSwapEventState */ NULL, 0); snmp_varlist_add_variable(&var_list, saHpiHotSwapEventPreviousState_oid, OID_LENGTH(saHpiHotSwapEventPreviousState_oid), ASN_INTEGER, /* Set an appropriate value for saHpiHotSwapEventPreviousState */ NULL, 0); /* * Add any extra (optional) objects here */ /* * Send the trap to the list of configured destinations * and clean up */ send_v2trap( var_list ); snmp_free_varbind( var_list ); return SNMP_ERR_NOERROR; }
/* * Populates up to FIVE different rows: * - RDR * - Sensor * - Inventory * - Control * - Watchdog */ int populate_rdr (SaHpiRptEntryT * rpt_entry, oid * rpt_oid, size_t rpt_oid_len, oid * resource_oid, size_t resource_oid_len) { SaErrorT err; SaHpiEntryIdT current_rdr; SaHpiEntryIdT next_rdr; SaHpiRdrT rdr_entry; SaHpiSessionIdT session_id; long backup_count = rdr_count; int rc = AGENT_ERR_NOERROR; oid rdr_oid[RDR_INDEX_NR]; oid full_oid[MAX_OID_LEN]; oid child_oid[MAX_OID_LEN]; size_t child_oid_len; oid column[2]; int column_len = 2; int full_oid_len; unsigned long child_id = 0xDEADBEEF; netsnmp_index rdr_index; saHpiRdrTable_context *rdr_context; oid *trap_oid; trap_vars *trap = NULL; size_t trap_len; netsnmp_variable_list *trap_var; DEBUGMSGTL ((AGENT, "\n\t--- populate_rdr: Entry.\n")); if ((rc = getSaHpiSession (&session_id)) == AGENT_ERR_NOERROR) { rdr_index.len = RDR_INDEX_NR; next_rdr = SAHPI_FIRST_ENTRY; do { current_rdr = next_rdr; memset (&rdr_entry, 0x00, sizeof (SaHpiRdrT)); err = saHpiRdrGet (session_id, rpt_entry->ResourceId, current_rdr, &next_rdr, &rdr_entry); if (err == SA_OK) { rdr_mutex = AGENT_TRUE; // Look at the MIB to find out what the indexs are rdr_oid[0] = rpt_entry->DomainId; rdr_oid[1] = rpt_entry->ResourceId; rdr_oid[2] = rdr_entry.RecordId; // The type is +1 from the SAF HPI SA spec rdr_oid[3] = rdr_entry.RdrType+1; rdr_index.oids = (oid *) & rdr_oid; if (backup_count == 0) { rdr_context = saHpiRdrTable_create_row (&rdr_index); rdr_new_entry_count++; } else { // See if it exists. rdr_context = NULL; rdr_context = CONTAINER_FIND (cb.container, &rdr_index); // If we don't find it - we create it. if (!rdr_context) { // New entry. Add it rdr_context = saHpiRdrTable_create_row (&rdr_index); rdr_new_entry_count++; } if (!rdr_context) { snmp_log (LOG_ERR, "Not enough memory for a RDR row!"); return AGENT_ERR_INTERNAL_ERROR; } } column[0] = 1; column[1] = COLUMN_SAHPIRDRRESOURCEID; build_full_oid (saHpiRdrTable_oid, saHpiRdrTable_oid_len, column, column_len, &rdr_index, full_oid, MAX_OID_LEN, &full_oid_len); child_oid_len = 0; if (rdr_entry.RdrType == SAHPI_SENSOR_RDR) { child_id = rdr_entry.RdrTypeUnion.SensorRec.Num; DEBUGMSGTL ((AGENT, "Calling populate_sensor; RPT: %d, RDR: %d, SensorRec.Num: %d\n", rpt_entry->ResourceId, rdr_entry.RecordId, child_id)); rc = populate_sensor (rdr_entry.RecordId, &rdr_entry.RdrTypeUnion.SensorRec, rpt_entry, full_oid, full_oid_len, child_oid, &child_oid_len); DEBUGMSGTL ((AGENT, "Called populate_sensor(); rc: %d\n", rc)); } if (rdr_entry.RdrType == SAHPI_CTRL_RDR) { child_id = rdr_entry.RdrTypeUnion.CtrlRec.Num; DEBUGMSGTL ((AGENT, "Calling populate_control; RPT: %d, RDR: %d, CtrlRec.Num: %d\n", rpt_entry->ResourceId, rdr_entry.RecordId, child_id)); rc = populate_control (rdr_entry.RecordId,&rdr_entry.RdrTypeUnion.CtrlRec, rpt_entry, full_oid, full_oid_len, child_oid, &child_oid_len); DEBUGMSGTL ((AGENT, "Called populate_control(); rc: %d\n", rc)); } if (rdr_entry.RdrType == SAHPI_INVENTORY_RDR) { child_id = rdr_entry.RdrTypeUnion.InventoryRec.EirId; DEBUGMSGTL ((AGENT, "Calling populate_inventory; RPT: %d, RDR: %d, InventoryRec.EirId: %d\n", rpt_entry->ResourceId, rdr_entry.RecordId, child_id)); rc = populate_inventory (rdr_entry.RecordId,&rdr_entry.RdrTypeUnion.InventoryRec, rpt_entry, full_oid, full_oid_len, child_oid, &child_oid_len); DEBUGMSGTL ((AGENT, "Called populate_inventory(); rc: %d\n", rc)); } if (rdr_entry.RdrType == SAHPI_WATCHDOG_RDR) { child_id = rdr_entry.RdrTypeUnion.WatchdogRec.WatchdogNum; DEBUGMSGTL ((AGENT, "Calling populate_watchdog; RPT: %d, RDR: %d, CtrlRec.Num: %d\n", rpt_entry->ResourceId, rdr_entry.RecordId, child_id)); rc = populate_watchdog (rdr_entry.RecordId,&rdr_entry.RdrTypeUnion.WatchdogRec, rpt_entry, full_oid, full_oid_len, child_oid, &child_oid_len); DEBUGMSGTL ((AGENT, "Called populate_watchdog(); rc: %d\n", rc)); } // Mark this ctx as touched, or cleaned rdr_context->dirty_bit = AGENT_FALSE; // By this stage, rdr_context surely has something in it. // '*_modify_context' does a checksum check to see if // the record needs to be altered, and if so populates with // information from RDR and the OIDs passed. if (saHpiRdrTable_modify_context (rpt_entry, &rdr_entry, rdr_context, rpt_oid, rpt_oid_len, child_oid, child_oid_len, child_id, &trap, &trap_len, &trap_oid) == AGENT_NEW_ENTRY) { CONTAINER_INSERT (cb.container, rdr_context); rdr_count = CONTAINER_SIZE (cb.container); if (send_traps == AGENT_TRUE) { if (trap != NULL) { trap_var = build_notification (&rdr_index, trap, trap_len, saHpiResourceDataRecordNotification_oid, OID_LENGTH (saHpiResourceDataRecordNotification_oid), saHpiRdrTable_oid, saHpiRdrTable_oid_len, rpt_entry->DomainId, rpt_oid, rpt_oid_len, rpt_entry-> ResourceId, resource_oid, resource_oid_len); if (trap_var != NULL) { // Add some more (entryCount, and entryUpdate) snmp_varlist_add_variable (&trap_var, saHpiRdrCount_oid, OID_LENGTH (saHpiRdrCount_oid), ASN_COUNTER, (u_char *) & rdr_count, sizeof (rdr_count)); DEBUGMSGTL ((AGENT, "Sending RDR TRAP/EVENT\n")); send_v2trap (trap_var); snmp_free_varbind (trap_var); } else { snmp_log (LOG_WARNING, "Could not build a RDR TRAP/EVENT message.\n"); rc = AGENT_ERR_BUILD_TRAP; } } } } } else { // Bail out. // This can happend if there are no entries for that Resource rc = AGENT_ERR_OPERATION; break; } } while (next_rdr != SAHPI_LAST_ENTRY); } DEBUGMSGTL ((AGENT, "\n\t--- populate_rdr. Exit\n")); return rc; }
void send_notification(unsigned int clientreg, void *clientarg) { /* * define the OID for the notification we're going to send * NET-SNMP-EXAMPLES-MIB::netSnmpExampleNotification */ oid notification_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 1 }; size_t notification_oid_len = OID_LENGTH(notification_oid); /* * In the notification, we have to assign our notification OID to * the snmpTrapOID.0 object. Here is it's definition. */ oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap); netsnmp_index *index; oid tmp[2]; netSnmpIETFWGTable_context *x; /* * here is where we store the variables to be sent in the trap */ netsnmp_variable_list *notification_vars = NULL; DEBUGMSGTL(("example_notification", "defining the trap\n")); // Lets find the sucker index = SNMP_MALLOC_TYPEDEF(netsnmp_index); tmp[0] = 1; tmp[1] = 'a' + number; index->oids = tmp; index->len = 2; x = CONTAINER_FIND(cb.container, index); free(index); if (x) { DEBUGMSGTL((AGENT,"Found the object! ")); DEBUGMSGOID((AGENT,x->index.oids, x->index.len)); snmp_varlist_add_variable(¬ification_vars, //x->index.oids, x->index.len, objid_snmptrap, objid_snmptrap_len, ASN_OCTET_STR, x->nsIETFWGName, x->nsIETFWGName_len * sizeof(oid)); } /* * add in the trap definition object */ snmp_varlist_add_variable(¬ification_vars, /* * the snmpTrapOID.0 variable */ objid_snmptrap, objid_snmptrap_len, /* * value type is an OID */ ASN_OBJECT_ID, /* * value contents is our notification OID */ (u_char *) notification_oid, /* * size in bytes = oid length * sizeof(oid) */ notification_oid_len * sizeof(oid)); /* * if we wanted to insert additional objects, we'd do it here */ /* * send the trap out. This will send it to all registered * receivers (see the "SETTING UP TRAP AND/OR INFORM DESTINATIONS" * section of the snmpd.conf manual page. */ DEBUGMSGTL(("example_notification", "sending the trap\n")); send_v2trap(notification_vars); /* * free the created notification variable list */ DEBUGMSGTL(("example_notification", "cleaning up\n")); snmp_free_varbind(notification_vars); }
int _mteEvent_fire_notify (struct mteEvent *entry, /* The event to fire */ struct mteTrigger *trigger, /* Trigger that fired */ oid * suffix, size_t sfx_len) /* Matching instance */ { netsnmp_variable_list *var, *v2; extern const oid snmptrap_oid[]; extern const size_t snmptrap_oid_len; netsnmp_session *s; /* * The Event-MIB specification says that objects from the * mteEventTable should come after those from the trigger, * but things actually work better if these come first. * Allow the agent to be configured either way. */ int strictOrdering = netsnmp_ds_get_boolean (NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_STRICT_DISMAN); var = (netsnmp_variable_list *) SNMP_MALLOC_TYPEDEF (netsnmp_variable_list); if (!var) return -1; /* * Set the basic notification OID... */ memset (var, 0, sizeof (netsnmp_variable_list)); snmp_set_var_objid (var, snmptrap_oid, snmptrap_oid_len); snmp_set_var_typed_value (var, ASN_OBJECT_ID, (u_char *) entry->mteNotification, entry->mteNotification_len * sizeof (oid)); /* * ... then add the specified objects from the Objects Table. * * Strictly speaking, the objects from the EventTable are meant * to be listed last (after the various trigger objects). * But logically things actually work better if the event objects * are placed first. So this code handles things either way :-) */ if (!strictOrdering) { DEBUGMSGTL (("disman:event:fire", "Adding event objects (first)\n")); if (strcmp (entry->mteNotifyOwner, "_snmpd") != 0) mteObjects_vblist (var, entry->mteNotifyOwner, entry->mteNotifyObjects, suffix, sfx_len); } DEBUGMSGTL (("disman:event:fire", "Adding trigger objects (general)\n")); mteObjects_vblist (var, trigger->mteTriggerOOwner, trigger->mteTriggerObjects, suffix, sfx_len); DEBUGMSGTL (("disman:event:fire", "Adding trigger objects (specific)\n")); mteObjects_vblist (var, trigger->mteTriggerXOwner, trigger->mteTriggerXObjects, suffix, sfx_len); if (strictOrdering) { DEBUGMSGTL (("disman:event:fire", "Adding event objects (last)\n")); if (strcmp (entry->mteNotifyOwner, "_snmpd") != 0) mteObjects_vblist (var, entry->mteNotifyOwner, entry->mteNotifyObjects, suffix, sfx_len); } /* * Query the agent to retrieve the necessary values... * (skipping the initial snmpTrapOID varbind) */ v2 = var->next_variable; if (entry->session) s = entry->session; else s = trigger->session; netsnmp_query_get (v2, s); /* * ... add any "internal" objects... * (skipped by the processing above, and best handled directly) */ if (strcmp (entry->mteNotifyOwner, "_snmpd") == 0) { DEBUGMSGTL (("disman:event:fire", "Adding event objects (internal)\n")); if (!strictOrdering) { mteObjects_internal_vblist (var, entry->mteNotifyObjects, trigger, s); } else { for (v2 = var; v2 && v2->next_variable; v2 = v2->next_variable) ; mteObjects_internal_vblist (v2, entry->mteNotifyObjects, trigger, s); } } /* * ... and send the resulting varbind list as a notification */ send_v2trap (var); snmp_free_varbind (var); return 0; }
/** here we send a SNMP v2 trap (which can be sent through snmpv3 and * snmpv1 as well) and send it out. */ void send_example_notification(unsigned int clientreg, void *clientarg) { /* * define the OID for the notification we're going to send * NET-SNMP-EXAMPLES-MIB::netSnmpExampleNotification */ oid notification_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 1 }; size_t notification_oid_len = OID_LENGTH(notification_oid); /* * In the notification, we have to assign our notification OID to * the snmpTrapOID.0 object. Here is it's definition. */ oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap); /* * here is where we store the variables to be sent in the trap */ netsnmp_variable_list *notification_vars = NULL; DEBUGMSGTL(("example_notification", "defining the trap\n")); /* * add in the trap definition object */ snmp_varlist_add_variable(¬ification_vars, /* * the snmpTrapOID.0 variable */ objid_snmptrap, objid_snmptrap_len, /* * value type is an OID */ ASN_OBJECT_ID, /* * value contents is our notification OID */ (u_char *) notification_oid, /* * size in bytes = oid length * sizeof(oid) */ notification_oid_len * sizeof(oid)); /* * if we wanted to insert additional objects, we'd do it here */ /* * send the trap out. This will send it to all registered * receivers (see the "SETTING UP TRAP AND/OR INFORM DESTINATIONS" * section of the snmpd.conf manual page. */ DEBUGMSGTL(("example_notification", "sending the trap\n")); send_v2trap(notification_vars); /* * free the created notification variable list */ DEBUGMSGTL(("example_notification", "cleaning up\n")); snmp_free_varbind(notification_vars); }