/* * Create a new row in the event table */ netsnmp_tdata_row *mteEvent_createEntry (const char *mteOwner, const char *mteEName, int fixed) { struct mteEvent *entry; netsnmp_tdata_row *row; size_t mteOwner_len = (mteOwner) ? strlen (mteOwner) : 0; size_t mteEName_len = (mteEName) ? strlen (mteEName) : 0; DEBUGMSGTL (("disman:event:table", "Create event entry (%s, %s)\n", mteOwner, mteEName)); /* * Create the mteEvent entry, and the * (table-independent) row wrapper structure... */ entry = SNMP_MALLOC_TYPEDEF (struct mteEvent); if (!entry) return NULL; row = netsnmp_tdata_create_row (); if (!row) { SNMP_FREE (entry); return NULL; } row->data = entry; /* * ... initialize this row with the indexes supplied * and the default values for the row... */ if (mteOwner) memcpy (entry->mteOwner, mteOwner, mteOwner_len); netsnmp_table_row_add_index (row, ASN_OCTET_STR, entry->mteOwner, mteOwner_len); if (mteEName) memcpy (entry->mteEName, mteEName, mteEName_len); netsnmp_table_row_add_index (row, ASN_PRIV_IMPLIED_OCTET_STR, entry->mteEName, mteEName_len); entry->mteNotification_len = 2; /* .0.0 */ if (fixed) entry->flags |= MTE_EVENT_FLAG_FIXED; /* * ... and insert the row into the (common) table container */ netsnmp_tdata_add_row (event_table_data, row); DEBUGMSGTL (("disman:event:table", "Event entry created\n")); return row; }
void parse_notificationEvent(const char *token, char *line) { char name_buf[64]; char oid_name_buf[SPRINT_MAX_LEN]; oid oid_buf[MAX_OID_LEN]; size_t oid_buf_len = MAX_OID_LEN; int wild = 1; netsnmp_table_row *row; long tlong; char tc; /* get the owner */ const char *owner = "snmpd.conf"; /* get the name */ char *cp = copy_nword(line, name_buf, SPRINT_MAX_LEN); if (!cp || name_buf[0] == '\0') { config_perror("syntax error."); return; } for(row = table_set->table->first_row; row; row = row->next) { if (strcmp(row->indexes->val.string, owner) == 0 && strcmp(row->indexes->next_variable->val.string, name_buf) == 0) { config_perror("An eventd by that name has already been defined."); return; } } /* now, get all the trap oid */ cp = copy_nword(cp, oid_name_buf, SPRINT_MAX_LEN); if (oid_name_buf[0] == '\0') { config_perror("syntax error."); return; } if (!snmp_parse_oid(oid_name_buf, oid_buf, &oid_buf_len)) { snmp_log(LOG_ERR,"namebuf: %s\n",oid_name_buf); config_perror("unable to parse trap oid"); return; } /* * add to the mteEventNotificationtable to point to the * notification and the objects. */ row = netsnmp_create_table_data_row(); /* indexes */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_table_row_add_index(row, ASN_PRIV_IMPLIED_OCTET_STR, name_buf, strlen(name_buf)); /* columns */ netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATION, ASN_OBJECT_ID, (char *) oid_buf, oid_buf_len * sizeof(oid)); netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATIONOBJECTS, ASN_OCTET_STR, name_buf, strlen(name_buf)); netsnmp_table_data_add_row(mteEventNotif_table_set->table, row); /* * add to the mteEventTable to make it a notification to trigger * notification and the objects. */ row = netsnmp_create_table_data_row(); /* indexes */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_table_row_add_index(row, ASN_PRIV_IMPLIED_OCTET_STR, name_buf, strlen(name_buf)); /* columns */ tc = (u_char)0x80; netsnmp_set_row_column(row, COLUMN_MTEEVENTACTIONS, ASN_OCTET_STR, &tc, 1); tlong = MTETRIGGERENABLED_TRUE; netsnmp_set_row_column(row, COLUMN_MTEEVENTENABLED, ASN_INTEGER, (char *) &tlong, sizeof(tlong)); tlong = RS_ACTIVE; netsnmp_set_row_column(row, COLUMN_MTEEVENTENTRYSTATUS, ASN_INTEGER, (char *) &tlong, sizeof(tlong)); netsnmp_table_data_add_row(table_set->table, row); /* * now all the objects to put into the trap's object row */ while(cp) { cp = copy_nword(cp, oid_name_buf, SPRINT_MAX_LEN); if (strcmp(oid_name_buf, "-w") == 0) { wild = 0; continue; } oid_buf_len = MAX_OID_LEN; if (!snmp_parse_oid(oid_name_buf, oid_buf, &oid_buf_len)) { config_perror("unable to parse an object oid"); return; } mte_add_object_to_table("snmpd.conf", name_buf, oid_buf, oid_buf_len, wild); wild = 1; } }
/* Handles creation of new rows for the table */ static int sipOtherStatsTable_newRow(struct sip_snmp_handler *h) { netsnmp_table_row *row; /* XXX: make sure applIndex is an index for your table */ static int applIndex = -1; const char *func = "snmp_mod"; register struct sip_snmp_handler *c; struct sip_snmp_obj *o; int i, col; /* get applIndex first */ if(applIndex == -1) { applIndex = ser_getApplIndex(); if(applIndex == -1) { LOG(L_ERR,"%s: Couldn't get application index, cannot create " "new row\n", func); return -1; } } /* create the row */ row = netsnmp_create_table_data_row(); if(!row) { LOG(L_ERR, "%s: Couldn't create new row, out of memory?\n", func); return -1; } /* add indexes */ netsnmp_table_row_add_index(row, ASN_INTEGER, &applIndex, sizeof(applIndex)); c = h; for(i=1; i<SIPOTHERSTATSTABLE_INDEXES; i++) { if(!c) { LOG(L_ERR, "%s: Not enought indexes passed, need %d\n", func, SIPOTHERSTATSTABLE_INDEXES); netsnmp_table_data_delete_row(row); return -1; } if(!c->sip_obj || !c->sip_obj->value.voidp) { LOG(L_ERR, "%s: Invalid index passed\n", func); netsnmp_table_data_delete_row(row); return -1; } if(!netsnmp_table_row_add_index(row, ser_types[c->sip_obj->type], c->sip_obj->value.voidp, c->sip_obj->val_len)) { LOG(L_ERR, "%s: Error adding index to row\n", func); netsnmp_table_data_delete_row(row); return -1; } c = c->next; } /* add the data. We start from the last index, all the way to the * end of the linked list */ c = h; for(i=2; i<SIPOTHERSTATSTABLE_INDEXES; i++) c = c->next; col = 1; while(c) { if(col > SIPOTHERSTATSTABLE_COLUMNS) { LOG(L_ERR, "%s: Too many columns for new row\n", func); netsnmp_table_data_delete_row(row); return -1; } o = c->sip_obj; if(!o || !o->value.voidp) { LOG(L_ERR, "%s: Invalid object to add to new row\n", func); netsnmp_table_data_delete_row(row); return -1; } if(netsnmp_set_row_column(row, col, ser_types[o->type], o->value.voidp, o->val_len) != SNMPERR_SUCCESS) { LOG(L_ERR, "%s: Error adding object to row\n", func); netsnmp_table_data_delete_row(row); return -1; } if(c->on_set) netsnmp_mark_row_column_writable(row, col, 1); /* next, please... */ c = c->next; col++; } /* add the row to the table */ if(netsnmp_table_data_add_row(sipOtherStatsTable->table, row) != SNMPERR_SUCCESS) { LOG(L_ERR, "%s: Error adding new row to table\n", func); netsnmp_table_data_delete_row(row); return -1; } return 0; }
/* Adds a new object to the table. If the row doesn't exist is created. * Assumes all objects go to the same row, and all the objects are * new (replacing is done silently) */ static int sipOtherStatsTable_addObj(struct sip_snmp_handler *h, int col) { static netsnmp_table_row *row = NULL; int applIndex; /* Default index for most tables */ int first = 0; const char *func = "snmp_mod"; if(!row) { /* First time. Create row and add indexes */ /* Get index (applIndex). First since we don't need to undo it * but it's still possible that it fails (e.g. if we get called * at the wrong time) */ applIndex = ser_getApplIndex(); if(applIndex == -1) { LOG(L_ERR, "%s: Failed getting table index\n", func); return -1; } /* XXX: If table has more indexes init them here and add * a similar call to row_add_index() as below */ /* Create the row */ row = netsnmp_create_table_data_row(); if(!row) { LOG(L_ERR, "%s: failed creating table row\n", func); return -1; } /* add the index(es) to the table */ if(!netsnmp_table_row_add_index(row, ASN_INTEGER, &applIndex, sizeof(applIndex))) { LOG(L_ERR, "%s: Error adding index to row\n", func); netsnmp_table_data_delete_row(row); row = NULL; return -1; } first = 1; } /* sanity checks */ if(col < 1 || col > SIPOTHERSTATSTABLE_COLUMNS) { LOG(L_ERR, "%s: Invalid column %d to add new object\n", func, col); return -1; } if(!h || !h->sip_obj || !h->sip_obj->value.voidp) { LOG(L_ERR, "%s: Invalid object to add\n", func); return -1; } /* add object to row */ if(netsnmp_set_row_column(row, col, ser_types[h->sip_obj->type], h->sip_obj->value.voidp, h->sip_obj->val_len) != SNMPERR_SUCCESS) { LOG(L_ERR, "%s: Error adding new object to table\n", func); return -1; } /* is it writable? */ if(h->on_set) netsnmp_mark_row_column_writable(row, col, 1); /* If first time, add the row. Subsequent times don't need to do * anything since the table just has a pointer to our local row. * However, if indexes were to change then the row needs to be * replaced */ if(first) { if(netsnmp_table_data_add_row(sipOtherStatsTable->table, row) != SNMPERR_SUCCESS) { LOG(L_ERR, "%s: Error adding new row to table\n",func); return -1; } } /* Fin */ return 0; }
/* * Create a new row in the trigger table */ netsnmp_tdata_row * mteTrigger_createEntry(const char *mteOwner, char *mteTName, int fixed) { struct mteTrigger *entry; netsnmp_tdata_row *row; size_t mteOwner_len = (mteOwner) ? strlen(mteOwner) : 0; size_t mteTName_len = (mteTName) ? strlen(mteTName) : 0; DEBUGMSGTL(("disman:event:table", "Create trigger entry (%s, %s)\n", mteOwner, mteTName)); /* * Create the mteTrigger entry, and the * (table-independent) row wrapper structure... */ entry = SNMP_MALLOC_TYPEDEF(struct mteTrigger); if (!entry) return NULL; row = netsnmp_tdata_create_row(); if (!row) { SNMP_FREE(entry); return NULL; } row->data = entry; /* * ... initialize this row with the indexes supplied * and the default values for the row... */ if (mteOwner) memcpy(entry->mteOwner, mteOwner, mteOwner_len); netsnmp_table_row_add_index(row, ASN_OCTET_STR, entry->mteOwner, mteOwner_len); if (mteTName) memcpy(entry->mteTName, mteTName, mteTName_len); netsnmp_table_row_add_index(row, ASN_PRIV_IMPLIED_OCTET_STR, entry->mteTName, mteTName_len); /* entry->mteTriggerTest = MTE_TRIGGER_BOOLEAN; */ entry->mteTriggerValueID_len = 2; /* .0.0 */ entry->mteTriggerFrequency = 600; memcpy(entry->mteDeltaDiscontID, _sysUpTime_instance, sizeof(_sysUpTime_instance)); entry->mteDeltaDiscontID_len = _sysUpTime_inst_len; entry->mteDeltaDiscontIDType = MTE_DELTAD_TTICKS; entry->flags |= MTE_TRIGGER_FLAG_SYSUPT; entry->mteTExTest = (MTE_EXIST_PRESENT | MTE_EXIST_ABSENT); entry->mteTExStartup = (MTE_EXIST_PRESENT | MTE_EXIST_ABSENT); entry->mteTBoolComparison = MTE_BOOL_UNEQUAL; entry->flags |= MTE_TRIGGER_FLAG_BSTART; entry->mteTThStartup = MTE_THRESH_START_RISEFALL; if (fixed) entry->flags |= MTE_TRIGGER_FLAG_FIXED; /* * ... and insert the row into the (common) table container */ netsnmp_tdata_add_row(trigger_table_data, row); DEBUGMSGTL(("disman:event:table", "Trigger entry created\n")); return row; }
/** @internal */ void netsnmp_config_parse_add_row(const char *token, char *line) { char buf[SNMP_MAXBUF_MEDIUM]; char tname[SNMP_MAXBUF_MEDIUM]; size_t buf_size; int rc; data_set_tables *tables; netsnmp_variable_list *vb; /* containing only types */ netsnmp_table_row *row; netsnmp_table_data_set_storage *dr; line = copy_nword(line, tname, SNMP_MAXBUF_MEDIUM); tables = (data_set_tables *) netsnmp_get_list_data(auto_tables, tname); if (!tables) { config_pwarn("Unknown table trying to add a row"); return; } /* * do the indexes first */ row = netsnmp_create_table_data_row(); for (vb = tables->table_set->table->indexes_template; vb; vb = vb->next_variable) { if (!line) { config_pwarn("missing an index value"); return; } DEBUGMSGTL(("table_set_add_row", "adding index of type %d\n", vb->type)); buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(vb->type, line, buf, &buf_size); netsnmp_table_row_add_index(row, vb->type, buf, buf_size); } /* * then do the data */ for (dr = tables->table_set->default_row; dr; dr = dr->next) { if (!line) { config_pwarn("missing a data value. " "All columns must be specified."); snmp_log(LOG_WARNING," can't find value for column %d\n", dr->column - 1); return; } buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(dr->type, line, buf, &buf_size); DEBUGMSGTL(("table_set_add_row", "adding data at column %d of type %d\n", dr->column, dr->type)); netsnmp_set_row_column(row, dr->column, dr->type, buf, buf_size); if (dr->writable) netsnmp_mark_row_column_writable(row, dr->column, 1); /* make writable */ } rc = netsnmp_table_data_add_row(tables->table_set->table, row); if (SNMPERR_SUCCESS != rc) { config_pwarn("error adding table row"); } }
void init_testhandler(void) { /* * we're registering at .1.2.3.4 */ netsnmp_handler_registration *my_test; netsnmp_table_registration_info *table_info; u_long ind1; netsnmp_table_data *table; netsnmp_table_data_set *table_set; netsnmp_table_row *row; DEBUGMSGTL(("testhandler", "initializing\n")); /* * basic handler test */ netsnmp_register_handler(netsnmp_create_handler_registration ("myTest", my_test_handler, my_test_oid, 4, HANDLER_CAN_RONLY)); /* * instance handler test */ netsnmp_register_instance(netsnmp_create_handler_registration ("myInstance", my_test_instance_handler, my_instance_oid, 5, HANDLER_CAN_RWRITE)); netsnmp_register_ulong_instance("myulong", my_data_ulong_instance, 4, &my_ulong, NULL); /* * table helper test */ my_test = netsnmp_create_handler_registration("myTable", my_test_table_handler, my_table_oid, 4, HANDLER_CAN_RONLY); if (!my_test) return; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (table_info == NULL) return; netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, ASN_INTEGER, 0); table_info->min_column = 3; table_info->max_column = 3; netsnmp_register_table(my_test, table_info); /* * data table helper test */ /* * we'll construct a simple table here with two indexes: an * integer and a string (why not). It'll contain only one * column so the data pointer is merely the data in that * column. */ table = netsnmp_create_table_data("data_table_test"); netsnmp_table_data_add_index(table, ASN_INTEGER); netsnmp_table_data_add_index(table, ASN_OCTET_STR); /* * 1 partridge in a pear tree */ row = netsnmp_create_table_data_row(); ind1 = 1; netsnmp_table_row_add_index(row, ASN_INTEGER, &ind1, sizeof(ind1)); netsnmp_table_row_add_index(row, ASN_OCTET_STR, "partridge", strlen("partridge")); row->data = (void *) "pear tree"; netsnmp_table_data_add_row(table, row); /* * 2 turtle doves */ row = netsnmp_create_table_data_row(); ind1 = 2; netsnmp_table_row_add_index(row, ASN_INTEGER, &ind1, sizeof(ind1)); netsnmp_table_row_add_index(row, ASN_OCTET_STR, "turtle", strlen("turtle")); row->data = (void *) "doves"; netsnmp_table_data_add_row(table, row); /* * we're going to register it as a normal table too, so we get the * automatically parsed column and index information */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (table_info == NULL) return; netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, ASN_OCTET_STR, 0); table_info->min_column = 3; table_info->max_column = 3; netsnmp_register_read_only_table_data (netsnmp_create_handler_registration ("12days", my_data_table_handler, my_data_table_oid, 4, HANDLER_CAN_RONLY), table, table_info); }
/* * (to get called, the function name must match init_FILENAME() */ void init_data_set (void) { netsnmp_table_row *row; /* * the OID we want to register our integer at. This should be the * * OID node for the entire table. In our case this is the * * netSnmpIETFWGTable oid definition */ oid my_registration_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 2, 1 }; /* * a debugging statement. Run the agent with -Dexample_data_set to see * * the output of this debugging statement. */ DEBUGMSGTL (("example_data_set", "Initalizing example dataset table\n")); /* * It's going to be the "working group chairs" table, since I'm * * sitting at an IETF convention while I'm writing this. * * * * column 1 = index = string = WG name * * column 2 = string = chair #1 * * column 3 = string = chair #2 (most WGs have 2 chairs now) */ table_set = netsnmp_create_table_data_set ("netSnmpIETFWGTable"); /* * allow the creation of new rows via SNMP SETs */ table_set->allow_creation = 1; /* * set up what a row "should" look like, starting with the index */ netsnmp_table_dataset_add_index (table_set, ASN_OCTET_STR); /* * define what the columns should look like. both are octet strings here */ netsnmp_table_set_multi_add_default_row (table_set, /* * column 2 = OCTET STRING, * writable = 1, * default value = NULL, * default value len = 0 */ 2, ASN_OCTET_STR, 1, NULL, 0, /* * similar */ 3, ASN_OCTET_STR, 1, NULL, 0, 0 /* done */ ); /* * register the table */ /* * if we wanted to handle specific data in a specific way, or note * * when requests came in we could change the NULL below to a valid * * handler method in which we could over ride the default * * behaviour of the table_dataset helper */ netsnmp_register_table_data_set (netsnmp_create_handler_registration ("netSnmpIETFWGTable", NULL, my_registration_oid, OID_LENGTH (my_registration_oid), HANDLER_CAN_RWRITE), table_set, NULL); /* * create the a row for the table, and add the data */ row = netsnmp_create_table_data_row (); /* * set the index to the IETF WG name "snmpv3" */ netsnmp_table_row_add_index (row, ASN_OCTET_STR, "snmpv3", strlen ("snmpv3")); /* * set column 2 to be the WG chair name "Russ Mundy" */ netsnmp_set_row_column (row, 2, ASN_OCTET_STR, "Russ Mundy", strlen ("Russ Mundy")); netsnmp_mark_row_column_writable (row, 2, 1); /* make writable via SETs */ /* * set column 3 to be the WG chair name "David Harrington" */ netsnmp_set_row_column (row, 3, ASN_OCTET_STR, "David Harrington", strlen ("David Harrington")); netsnmp_mark_row_column_writable (row, 3, 1); /* make writable via SETs */ /* * add the row to the table */ netsnmp_table_dataset_add_row (table_set, row); #ifdef ADD_MORE_DATA /* * add the data, for the second row */ row = netsnmp_create_table_data_row (); netsnmp_table_row_add_index (row, ASN_OCTET_STR, "snmpconf", strlen ("snmpconf")); netsnmp_set_row_column (row, 2, ASN_OCTET_STR, "David Partain", strlen ("David Partain")); netsnmp_mark_row_column_writable (row, 2, 1); /* make writable */ netsnmp_set_row_column (row, 3, ASN_OCTET_STR, "Jon Saperia", strlen ("Jon Saperia")); netsnmp_mark_row_column_writable (row, 3, 1); /* make writable */ netsnmp_table_dataset_add_row (table_set, row); #endif /* * Finally, this actually allows the "add_row" token it the * * snmpd.conf file to add rows to this table. * * Example snmpd.conf line: * * add_row netSnmpIETFWGTable eos "Glenn Waters" "Dale Francisco" */ netsnmp_register_auto_data_table (table_set, NULL); DEBUGMSGTL (("example_data_set", "Done initializing.\n")); }
/** Initialize the lightingTable table by defining its contents and how it's structured */ void initialize_table_lightingTable(void) { const oid lightingTable_oid[] = {1,3,6,1,4,1,12620,5,2}; netsnmp_table_data_set *table_set; /* create the table structure itself */ table_set = netsnmp_create_table_data_set("lightingTable"); /* comment this out or delete if you don't support creation of new rows */ table_set->allow_creation = 1; /*************************************************** * Adding indexes */ DEBUGMSGTL(("initialize_table_lightingTable", "adding indexes to table lightingTable\n")); //netsnmp_table_set_add_indexes(table_set, // ASN_INTEGER, /* index: lightIndex */ // 0); //DEBUGMSGTL(("gpDroneMIB","pt-1\n")); netsnmp_table_dataset_add_index(table_set, ASN_INTEGER); /* index: lightIndex */ DEBUGMSGTL(("initialize_table_lightingTable", "adding column types to table lightingTable\n")); //DEBUGMSGTL(("gpDroneMIB","pt1\n")); /*netsnmp_table_set_multi_add_default_row(table_set, COLUMN_LIGHTDESCRIPTION, ASN_OCTET_STR, 0, NULL, 0, COLUMN_LIGHTTOGGLE, ASN_INTEGER, 1, NULL, 0, COLUMN_LIGHTINDEX, ASN_INTEGER, 0, NULL, 0, 0); */ netsnmp_table_set_multi_add_default_row(table_set, COLUMN_LIGHTINDEX, ASN_INTEGER, 0, NULL, 0, COLUMN_LIGHTDESCRIPTION, ASN_OCTET_STR, 0, NULL, 0, COLUMN_LIGHTTOGGLE, ASN_INTEGER, 1, NULL, 0, 0); //DEBUGMSGTL(("gpDroneMIB","pt2\n")); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects of the request, change lightingTable_handler to "NULL" */ netsnmp_register_table_data_set(netsnmp_create_handler_registration("lightingTable", lightingTable_handler, lightingTable_oid, OID_LENGTH(lightingTable_oid), HANDLER_CAN_RWRITE), table_set, NULL); my_table = (struct tb_entry*)malloc(sizeof(struct tb_entry)*5); int i; for(i = 1; i <= 5; i++){ my_table[i-1].index = (long)i; strncpy(my_table[i-1].descr,l_table[i-1].descr,256); my_table[i-1].toggle = 0;//TODO: initialize int index = i; netsnmp_table_row *row = netsnmp_create_table_data_row(); netsnmp_table_row_add_index(row,ASN_INTEGER,&index,sizeof(index)); netsnmp_set_row_column(row,1,ASN_INTEGER,&index,sizeof(index)); netsnmp_mark_row_column_writable(row,1,0); netsnmp_set_row_column(row,2,ASN_OCTET_STR,l_table[i-1].descr,strlen(l_table[i-1].descr)); netsnmp_mark_row_column_writable(row,2,0); netsnmp_set_row_column(row,3,ASN_INTEGER,&index,sizeof(index)); netsnmp_mark_row_column_writable(row,3,1); netsnmp_table_dataset_add_row(table_set,row); } /*FILE *f = fopen("result.txt","w"); fprintf(f,"Index\t\tDescr\t\tToggle\n"); for(i = 1; i <= 5; i++){ fprintf(f,"%d\t\t%s\t\t%d\n",my_table[i-1].index,my_table[i-1].descr,my_table[i-1].toggle); } fclose(f); */ }
static void parse_table_row( int cpu, char *p, struct snmp_vars *sys, netsnmp_table_data_set *data_set) { netsnmp_table_row *row; row = netsnmp_create_table_data_row(); netsnmp_table_row_add_index(row, ASN_INTEGER, (u_char *)&cpu, sizeof(cpu)); if (sys == cputable) { /* add cpuIndex as column too to break SMIv2 */ netsnmp_set_row_column(row, 1, sys->type, (char *)&cpu, sizeof(cpu)); } for (++sys; p && sys->obj; sys++) { char *val; long long val64; unsigned int uval32; int val32; struct counter64 c64; p += strspn(p, " \t"); val = p; if ((p = strpbrk(p, " \t"))) *p++ = '\0'; if (index(val, '.')) { double d = strtod(val, NULL); val64 = (long long)(d * 100); } else val64 = strtoll(val, NULL, 10); switch (sys->type) { case ASN_OCTET_STR: netsnmp_set_row_column(row, sys->obj, sys->type, (char *)val, strlen(val)); break; case ASN_INTEGER: case ASN_GAUGE: val32 = (int)val64; netsnmp_set_row_column(row, sys->obj, sys->type, (char *)&val32, sizeof(val32)); break; case ASN_COUNTER: uval32 = (unsigned int)val64; netsnmp_set_row_column(row, sys->obj, sys->type, (char *)&uval32, sizeof(uval32)); break; case ASN_COUNTER64: c64.low = (uint32_t)val64; c64.high = val64 >> 32; netsnmp_set_row_column(row, sys->obj, sys->type, (char *)&c64, sizeof(c64)); break; default: netsnmp_table_dataset_delete_row(row); continue; } } netsnmp_table_data_add_row(data_set->table, row); }
int cache_load(netsnmp_cache *cache, void *magic) { DEBUGMSGTL(("mgPIDECMTable", "Load Handler\n")); xmlDocPtr doc; xmlChar *xpath = (xmlChar*) "/dvb/mg/mgSignalCharacteristics/mgSignalCharacteristicsObjects/mgTSStructure/mgPIDECMTable/mgPIDECMEntry"; xmlNodeSetPtr nodeset; xmlXPathObjectPtr result; xmlNodePtr cur; int i; netsnmp_table_row *row; int mgPIDECMInputNumber = -1; int mgPIDECMServiceNumber = -1; int mgPIDECMPID = -1; int mgPIDECMCaPID = -1; int mgPIDECMCASystemID = -1; doc = getXMLDoc(); if (doc == NULL) { DEBUGMSGTL(("mgPIDECMTable", "Problem with loading file %s, keeping old values in table.\n", INPUTXMLDOCUMENTPATH)); return SNMP_ERR_NOERROR; } cleanTableSet(table_set); result = getNodesPtr(doc, xpath); if (result) { nodeset = result->nodesetval; for (i = 0; i < nodeset->nodeNr; i++) { cur = nodeset->nodeTab[i]->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *) "mgPIDECMInputNumber"))) { mgPIDECMInputNumber = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); DEBUGMSGTL(("mgPIDECMTable", "mgPIDECMInputNumber: %d\n", mgPIDECMInputNumber)); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "mgPIDECMServiceNumber"))) { mgPIDECMServiceNumber = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); DEBUGMSGTL(("mgPIDECMTable", " mgPIDECMServiceNumber: %d\n", mgPIDECMServiceNumber)); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "mgPIDECMPID"))) { mgPIDECMPID = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); DEBUGMSGTL(("mgPIDECMTable", "mgPIDECMPID: %d\n", mgPIDECMPID)); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "mgPIDECMCaPID"))) { mgPIDECMCaPID = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); DEBUGMSGTL(("mgPIDECMTable", "mgPIDECMCaPID: %d\n", mgPIDECMCaPID)); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "mgPIDECMCASystemID"))) { mgPIDECMCASystemID = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); DEBUGMSGTL(("mgPIDECMTable", "mgPIDECMCASystemID: %d\n", mgPIDECMCASystemID)); } cur = cur->next; } row = netsnmp_create_table_data_row(); netsnmp_table_row_add_index(row, ASN_INTEGER, &mgPIDECMInputNumber, sizeof (mgPIDECMInputNumber)); netsnmp_table_row_add_index(row, ASN_INTEGER, &mgPIDECMServiceNumber, sizeof (mgPIDECMServiceNumber)); netsnmp_table_row_add_index(row, ASN_INTEGER, &mgPIDECMPID, sizeof (mgPIDECMPID)); netsnmp_set_row_column(row, 4, ASN_INTEGER, &mgPIDECMCaPID, sizeof (mgPIDECMCaPID)); netsnmp_set_row_column(row, 5, ASN_INTEGER, &mgPIDECMCASystemID, sizeof (mgPIDECMCASystemID)); netsnmp_table_dataset_add_row(table_set, row); mgPIDECMInputNumber = -1; mgPIDECMServiceNumber = -1; mgPIDECMPID = -1; mgPIDECMCaPID = -1; mgPIDECMCASystemID = -1; } } else { DEBUGMSGTL(("mgPIDECMTable", "Data loaded from file %s is empty.\n", INPUTXMLDOCUMENTPATH)); } closeXML(doc, result); return SNMP_ERR_NOERROR; }
void log_notification(struct hostent *host, netsnmp_pdu *pdu, netsnmp_transport *transport) { long tmpl; struct timeval now; netsnmp_table_row *row; static oid snmptrapoid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; size_t snmptrapoid_len = OID_LENGTH(snmptrapoid); netsnmp_variable_list *vptr; u_char *logdate; size_t logdate_size; time_t timetnow; u_long vbcount = 0; u_long tmpul; int col; if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_APP_DONT_LOG)) { return; } DEBUGMSGTL(("log_notification", "logging something\n")); row = netsnmp_create_table_data_row(); default_num++; /* * indexes to the table */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, "default", strlen("default")); netsnmp_table_row_add_index(row, ASN_UNSIGNED, &default_num, sizeof(default_num)); /* * add the data */ gettimeofday(&now, NULL); tmpl = netsnmp_timeval_uptime(&now); netsnmp_set_row_column(row, COLUMN_NLMLOGTIME, ASN_TIMETICKS, (u_char *) & tmpl, sizeof(tmpl)); time(&timetnow); logdate = date_n_time(&timetnow, &logdate_size); netsnmp_set_row_column(row, COLUMN_NLMLOGDATEANDTIME, ASN_OCTET_STR, logdate, logdate_size); netsnmp_set_row_column(row, COLUMN_NLMLOGENGINEID, ASN_OCTET_STR, pdu->securityEngineID, pdu->securityEngineIDLen); if (transport && transport->domain == netsnmpUDPDomain) { /* * lame way to check for the udp domain */ /* * no, it is the correct way to do it -- jbpn */ struct sockaddr_in *addr = (struct sockaddr_in *) pdu->transport_data; if (addr) { char buf[sizeof(in_addr_t) + sizeof(addr->sin_port)]; in_addr_t locaddr = htonl(addr->sin_addr.s_addr); u_short portnum = htons(addr->sin_port); memcpy(buf, &locaddr, sizeof(in_addr_t)); memcpy(buf + sizeof(in_addr_t), &portnum, sizeof(addr->sin_port)); netsnmp_set_row_column(row, COLUMN_NLMLOGENGINETADDRESS, ASN_OCTET_STR, buf, sizeof(in_addr_t) + sizeof(addr->sin_port)); } } netsnmp_set_row_column(row, COLUMN_NLMLOGENGINETDOMAIN, ASN_OBJECT_ID, (const u_char *) transport->domain, sizeof(oid) * transport->domain_length); netsnmp_set_row_column(row, COLUMN_NLMLOGCONTEXTENGINEID, ASN_OCTET_STR, pdu->contextEngineID, pdu->contextEngineIDLen); netsnmp_set_row_column(row, COLUMN_NLMLOGCONTEXTNAME, ASN_OCTET_STR, pdu->contextName, pdu->contextNameLen); for (vptr = pdu->variables; vptr; vptr = vptr->next_variable) { if (snmp_oid_compare(snmptrapoid, snmptrapoid_len, vptr->name, vptr->name_length) == 0) { netsnmp_set_row_column(row, COLUMN_NLMLOGNOTIFICATIONID, ASN_OBJECT_ID, vptr->val.string, vptr->val_len); } else { netsnmp_table_row *myrow; myrow = netsnmp_create_table_data_row(); /* * indexes to the table */ netsnmp_table_row_add_index(myrow, ASN_OCTET_STR, "default", strlen("default")); netsnmp_table_row_add_index(myrow, ASN_UNSIGNED, &default_num, sizeof(default_num)); vbcount++; netsnmp_table_row_add_index(myrow, ASN_UNSIGNED, &vbcount, sizeof(vbcount)); /* * OID */ netsnmp_set_row_column(myrow, COLUMN_NLMLOGVARIABLEID, ASN_OBJECT_ID, (u_char *) vptr->name, vptr->name_length * sizeof(oid)); /* * value */ switch (vptr->type) { case ASN_OBJECT_ID: tmpul = 7; col = COLUMN_NLMLOGVARIABLEOIDVAL; break; case ASN_INTEGER: tmpul = 4; col = COLUMN_NLMLOGVARIABLEINTEGER32VAL; break; case ASN_UNSIGNED: tmpul = 2; col = COLUMN_NLMLOGVARIABLEUNSIGNED32VAL; break; case ASN_COUNTER: tmpul = 1; col = COLUMN_NLMLOGVARIABLECOUNTER32VAL; break; case ASN_TIMETICKS: tmpul = 3; col = COLUMN_NLMLOGVARIABLETIMETICKSVAL; break; case ASN_OCTET_STR: tmpul = 6; col = COLUMN_NLMLOGVARIABLEOCTETSTRINGVAL; break; default: /* * unsupported */ DEBUGMSGTL(("log_notification", "skipping type %d\n", vptr->type)); continue; } netsnmp_set_row_column(myrow, COLUMN_NLMLOGVARIABLEVALUETYPE, ASN_INTEGER, (u_char *) & tmpul, sizeof(tmpul)); netsnmp_set_row_column(myrow, col, vptr->type, vptr->val.string, vptr->val_len); DEBUGMSGTL(("log_notification", "adding a row to the variables table\n")); netsnmp_table_dataset_add_row(nlmLogVarTable, myrow); } } /* * store the row */ netsnmp_table_dataset_add_row(nlmLogTable, row); check_log_size(0, NULL); DEBUGMSGTL(("log_notification", "done logging something\n")); }