/** Initialize the mteEventTable table by defining its contents and how it's structured */ void initialize_table_mteEventTable(void) { static oid mteEventTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 4, 2 }; size_t mteEventTable_oid_len = OID_LENGTH(mteEventTable_oid); /* * create the table structure itself */ table_set = netsnmp_create_table_data_set("mteEventTable"); /* * comment this out or delete if you don't support creation of new rows */ table_set->allow_creation = 1; /* mark the row status column */ table_set->rowstatus_column = COLUMN_MTEEVENTENTRYSTATUS; /*************************************************** * Adding indexes */ DEBUGMSGTL(("initialize_table_mteEventTable", "adding indexes to table mteEventTable\n")); netsnmp_table_set_add_indexes(table_set, ASN_OCTET_STR, /* index: mteOwner */ ASN_PRIV_IMPLIED_OCTET_STR, /* index: mteEventName */ 0); DEBUGMSGTL(("initialize_table_mteEventTable", "adding column types to table mteEventTable\n")); netsnmp_table_set_multi_add_default_row(table_set, COLUMN_MTEEVENTNAME, ASN_OCTET_STR, 0, NULL, 0, COLUMN_MTEEVENTCOMMENT, ASN_OCTET_STR, 1, NULL, 0, COLUMN_MTEEVENTACTIONS, ASN_OCTET_STR, 1, NULL, 0, COLUMN_MTEEVENTENABLED, ASN_INTEGER, 1, NULL, 0, COLUMN_MTEEVENTENTRYSTATUS, ASN_INTEGER, 1, NULL, 0, 0); /* keep index values around for comparisons later */ table_set->table->store_indexes = 1; /* * registering the table with the master agent */ /* * note: if you don't need a subhandler to deal with any aspects * of the request, change mteEventTable_handler to "NULL" */ netsnmp_register_table_data_set(netsnmp_create_handler_registration ("mteEventTable", mteEventTable_handler, mteEventTable_oid, mteEventTable_oid_len, HANDLER_CAN_RWRITE), table_set, NULL); }
/** Initializes the mgPIDECMTable module */ void init_mgPIDECMTable(void) { /* here we initialize all the tables we're planning on supporting */ /* create the table structure itself */ table_set = netsnmp_create_table_data_set("mgPIDECMTable"); netsnmp_mib_handler *cache_handler; /* comment this out or delete if you don't support creation of new rows */ table_set->allow_creation = 1; /*************************************************** * Adding indexes */ DEBUGMSGTL(("initialize_table_mgPIDECMTable", "adding indexes to table mgPIDECMTable\n")); netsnmp_table_set_add_indexes(table_set, ASN_INTEGER, /* index: mgPIDECMInputNumber */ ASN_INTEGER, /* index: mgPIDECMServiceNumber */ ASN_INTEGER, /* index: mgPIDECMPID */ 0); DEBUGMSGTL(("initialize_table_mgPIDECMTable", "adding column types to table mgPIDECMTable\n")); netsnmp_table_set_multi_add_default_row(table_set, COLUMN_MGPIDECMINPUTNUMBER, ASN_INTEGER, 0, NULL, 0, COLUMN_MGPIDECMSERVICENUMBER, ASN_INTEGER, 0, NULL, 0, COLUMN_MGPIDECMPID, ASN_INTEGER, 0, NULL, 0, COLUMN_MGPIDECMCAPID, ASN_INTEGER, 0, NULL, 0, COLUMN_MGPIDECMCASYSTEMID, ASN_INTEGER, 0, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects of the request, change mgPIDECMTable_handler to "NULL" */ netsnmp_handler_registration *reginfo = netsnmp_create_handler_registration("mgPIDECMTable", NULL, mgPIDECMTable_oid, OID_LENGTH(mgPIDECMTable_oid), HANDLER_CAN_RWRITE); netsnmp_register_table_data_set(reginfo, table_set, NULL); DEBUGMSGTL(("mgPIDECMTable", "Done initalizing mgPIDECMTable module\n")); cache_handler = netsnmp_get_cache_handler(LONGCACHETIMEOUT, /* how long a cache is valid for */ cache_load, /* a pointer to the cache loading function */ cache_free, /* a pointer to the cache freeing function */ mgPIDECMTable_oid, OID_LENGTH(mgPIDECMTable_oid)); /* the OID of the registration point */ netsnmp_inject_handler(reginfo, cache_handler); }
/** Initialize the mytestTable table by defining its contents and how it's structured */ void initialize_table_mytestTable(void) { static oid mytestTable_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 70, 1, 3 }; size_t mytestTable_oid_len = OID_LENGTH(mytestTable_oid); netsnmp_table_data_set *table_set; /* * create the table structure itself */ table_set = netsnmp_create_table_data_set("mytestTable"); /* * comment this out or delete if you don't support creation of new rows */ table_set->allow_creation = 1; table_set->rowstatus_column = COLUMN_MYTESTROWSTATUS; /*************************************************** * Adding indexes */ DEBUGMSGTL(("initialize_table_mytestTable", "adding indexes to table mytestTable\n")); netsnmp_table_set_add_indexes(table_set, ASN_INTEGER, /* index: mytestIndex */ 0); DEBUGMSGTL(("initialize_table_mytestTable", "adding column types to table mytestTable\n")); netsnmp_table_set_multi_add_default_row(table_set, COLUMN_MYTESTINDEX, ASN_INTEGER, 0, NULL, 0, COLUMN_MYTESTCOLUMN1, ASN_INTEGER, 1, NULL, 0, COLUMN_MYTESTROWSTATUS, ASN_INTEGER, 1, NULL, 0, 0); /* * registering the table with the master agent */ /* * note: if you don't need a subhandler to deal with any aspects * of the request, change mytestTable_handler to "NULL" */ netsnmp_register_table_data_set(netsnmp_create_handler_registration ("mytestTable", mytestTable_handler, mytestTable_oid, mytestTable_oid_len, HANDLER_CAN_RWRITE), table_set, NULL); }
/** Initialize the sipProxyCfgTable table by defining it's contents and * how it's structured */ static int initialize_table_sipProxyCfgTable() { static oid sipProxyCfgTable_oid[] = {1,3,6,1,2,1,9991,1,3,1}; size_t sipProxyCfgTable_oid_len = OID_LENGTH(sipProxyCfgTable_oid); const char *func = "snmp_mod"; /* create the table structure itself */ sipProxyCfgTable = netsnmp_create_table_data_set("sipProxyCfgTable"); if(!sipProxyCfgTable) { LOG(L_ERR, "%s: Error creating table\n", func); return -1; } /*************************************************** * Adding indexes */ netsnmp_table_dataset_add_index(sipProxyCfgTable, ASN_INTEGER); netsnmp_table_set_multi_add_default_row( sipProxyCfgTable, COLUMN_SIPREQUESTMAXEXPIRES, ASN_UNSIGNED, 1, NULL, 0, COLUMN_SIPPROXYSTATEFULNESS, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYSENDSCANCEL, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYFORWARDALL1XX, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYRECURSION, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYPROVIDEALTERNATIVES, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYRECORDROUTE, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYSTATETIMEOUT, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYAUTHMETHOD, ASN_OCTET_STR, 1, NULL, 0, COLUMN_SIPPROXYAUTHPGPALGORITHM, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPROXYAUTHREALM, ASN_OCTET_STR, 1, NULL, 0, COLUMN_SIPPROXYNONCELIFETIME, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPPGPPRIVATEKEY, ASN_OCTET_STR, 1, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects * of the request, change sipProxyCfgTable_handler to "NULL" */ netsnmp_register_table_data_set( netsnmp_create_handler_registration( "sipProxyCfgTable", sipProxyCfgTable_handler, sipProxyCfgTable_oid, sipProxyCfgTable_oid_len, HANDLER_CAN_RWRITE), sipProxyCfgTable, NULL); return 0; }
/** Initialize the sipContactTable table by defining it's contents and * how it's structured */ static int initialize_table_sipContactTable() { static oid sipContactTable_oid[] = {1,3,6,1,2,1,9991,1,7,3}; size_t sipContactTable_oid_len = OID_LENGTH(sipContactTable_oid); const char *func = "snmp_mod"; /* create the table structure itself */ sipContactTable = netsnmp_create_table_data_set("sipContactTable"); if(!sipContactTable) { LOG(L_ERR, "%s: Error creating table\n", func); return -1; } /*************************************************** * Adding indexes */ netsnmp_table_dataset_add_index(sipContactTable, ASN_INTEGER); netsnmp_table_dataset_add_index(sipContactTable, ASN_UNSIGNED); netsnmp_table_dataset_add_index(sipContactTable, ASN_UNSIGNED); netsnmp_table_set_multi_add_default_row( sipContactTable, COLUMN_SIPCONTACTINDEX, ASN_UNSIGNED, 0, NULL, 0, COLUMN_SIPCONTACTDISPLAYNAME, ASN_OCTET_STR, 0, NULL, 0, COLUMN_SIPCONTACTURI, ASN_OCTET_STR, 0, NULL, 0, COLUMN_SIPCONTACTLASTUPDATED, ASN_TIMETICKS, 0, NULL, 0, COLUMN_SIPCONTACTEXPIRY, ASN_OCTET_STR, 0, NULL, 0, COLUMN_SIPCONTACTPREFERENCE, ASN_OCTET_STR, 0, NULL, 0, COLUMN_SIPCONTACTACTION, ASN_INTEGER, 0, NULL, 0, COLUMN_SIPCONTACTRETRYAFTER, ASN_OCTET_STR, 0, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects * of the request, change sipContactTable_handler to "NULL" */ netsnmp_register_table_data_set( netsnmp_create_handler_registration( "sipContactTable", sipContactTable_handler, sipContactTable_oid, sipContactTable_oid_len, HANDLER_CAN_RWRITE), sipContactTable, NULL); return 0; }
/** Initialize the sipRegUserTable table by defining it's contents and * how it's structured */ static int initialize_table_sipRegUserTable() { static oid sipRegUserTable_oid[] = {1,3,6,1,2,1,9991,1,7,2}; size_t sipRegUserTable_oid_len = OID_LENGTH(sipRegUserTable_oid); const char *func = "snmp_mod"; /* create the table structure itself */ sipRegUserTable = netsnmp_create_table_data_set("sipRegUserTable"); if(!sipRegUserTable) { LOG(L_ERR, "%s: Error creating table\n", func); return -1; } /*************************************************** * Adding indexes */ netsnmp_table_dataset_add_index(sipRegUserTable, ASN_INTEGER); netsnmp_table_dataset_add_index(sipRegUserTable, ASN_UNSIGNED); netsnmp_table_set_multi_add_default_row( sipRegUserTable, COLUMN_SIPUSERINDEX, ASN_UNSIGNED, 0, NULL, 0, COLUMN_SIPUSERURI, ASN_OCTET_STR, 1, NULL, 0, COLUMN_SIPUSERAUTHENTICATIONFAILURES, ASN_COUNTER, 0, NULL, 0, COLUMN_SIPUSERTABLEROWSTATUS, ASN_INTEGER, 1, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects * of the request, change sipRegUserTable_handler to "NULL" */ netsnmp_register_table_data_set( netsnmp_create_handler_registration( "sipRegUserTable", sipRegUserTable_handler, sipRegUserTable_oid, sipRegUserTable_oid_len, HANDLER_CAN_RWRITE), sipRegUserTable, NULL); return 0; }
/** Initialize the sipRegCfgTable table by defining it's contents and * how it's structured */ static int initialize_table_sipRegCfgTable() { static oid sipRegCfgTable_oid[] = {1,3,6,1,2,1,9991,1,7,1}; size_t sipRegCfgTable_oid_len = OID_LENGTH(sipRegCfgTable_oid); const char *func = "snmp_mod"; /* create the table structure itself */ sipRegCfgTable = netsnmp_create_table_data_set("sipRegCfgTable"); if(!sipRegCfgTable) { LOG(L_ERR, "%s: Error creating table\n", func); return -1; } /*************************************************** * Adding indexes */ netsnmp_table_dataset_add_index(sipRegCfgTable, ASN_INTEGER); netsnmp_table_set_multi_add_default_row( sipRegCfgTable, COLUMN_SIPREGALLOWTHIRDPARTY, ASN_INTEGER, 1, NULL, 0, COLUMN_SIPREGMAXCONTACTEXPIRYDATE, ASN_UNSIGNED, 1, NULL, 0, COLUMN_SIPREGMAXUSERS, ASN_UNSIGNED, 0, NULL, 0, COLUMN_SIPREGCURRENTUSERS, ASN_GAUGE, 0, NULL, 0, COLUMN_SIPREGDFLTREGACTIVEINTERVAL, ASN_UNSIGNED, 1, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects * of the request, change sipRegCfgTable_handler to "NULL" */ netsnmp_register_table_data_set( netsnmp_create_handler_registration( "sipRegCfgTable", sipRegCfgTable_handler, sipRegCfgTable_oid, sipRegCfgTable_oid_len, HANDLER_CAN_RWRITE), sipRegCfgTable, NULL); return 0; }
/** Initialize the sipOtherStatsTable table by defining it's contents and * how it's structured */ static int initialize_table_sipOtherStatsTable() { static oid sipOtherStatsTable_oid[] = {1,3,6,1,2,1,9990,1,10,1}; size_t sipOtherStatsTable_oid_len = OID_LENGTH(sipOtherStatsTable_oid); const char *func = "snmp_mod"; /* create the table structure itself */ sipOtherStatsTable = netsnmp_create_table_data_set("sipOtherStatsTable"); if(!sipOtherStatsTable) { LOG(L_ERR, "%s: Error creating table\n", func); return -1; } /*************************************************** * Adding indexes */ netsnmp_table_dataset_add_index(sipOtherStatsTable, ASN_INTEGER); netsnmp_table_set_multi_add_default_row( sipOtherStatsTable, COLUMN_SIPNUMUNSUPPORTEDURIS, ASN_COUNTER, 0, NULL, 0, 0); /* registering the table with the master agent */ /* note: if you don't need a subhandler to deal with any aspects * of the request, change sipOtherStatsTable_handler to "NULL" */ netsnmp_register_table_data_set( netsnmp_create_handler_registration( "sipOtherStatsTable", sipOtherStatsTable_handler, sipOtherStatsTable_oid, sipOtherStatsTable_oid_len, HANDLER_CAN_RWRITE), sipOtherStatsTable, NULL); return 0; }
/* * (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); */ }