Advertisement
Guest User

Untitled

a guest
Dec 29th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.22 KB | None | 0 0
  1. /*
  2.  * start be including the appropriate header files
  3.  */
  4. #include <net-snmp/net-snmp-config.h>
  5. #include <net-snmp/net-snmp-includes.h>
  6. #include <net-snmp/net-snmp-features.h>
  7. #include <net-snmp/agent/net-snmp-agent-includes.h>
  8.  
  9. #include "data_set.h"
  10.  
  11. netsnmp_feature_require(table_set_multi_add_default_row)
  12. netsnmp_feature_require(unregister_auto_data_table)
  13. netsnmp_feature_require(delete_table_data_set)
  14. netsnmp_feature_require(table_dataset)
  15. netsnmp_feature_require(table_set_multi_add_default_row)
  16. netsnmp_feature_require(table_dataset_unregister_auto_data_table)
  17.  
  18. static netsnmp_table_data_set *table_set;
  19.  
  20. /*
  21.  * our initialization routine, automatically called by the agent
  22.  */
  23. /*
  24.  * (to get called, the function name must match init_FILENAME()
  25.  */
  26. void
  27. init_data_set(void)
  28. {
  29.     netsnmp_table_row *row;
  30.  
  31.     /*
  32.      * the OID we want to register our integer at.  This should be the
  33.      * * OID node for the entire table.  In our case this is the
  34.      * * netSnmpIETFWGTable oid definition
  35.      */
  36.     oid             my_registration_oid[] =
  37.         { 1, 3, 6, 1, 4, 1, 8072, 2, 2, 1 };
  38.  
  39.     /*
  40.      * a debugging statement.  Run the agent with -Dexample_data_set to see
  41.      * * the output of this debugging statement.
  42.      */
  43.     DEBUGMSGTL(("DATA_SET_MIB_MODULE",
  44.                 "Initalizing example dataset table\n"));
  45.  
  46.     /*
  47.      * It's going to be the "working group chairs" table, since I'm
  48.      * * sitting at an IETF conventwhile I'm writing this.
  49.      * *
  50.      * *  column 1 = index = string = WG name
  51.      * *  column 2 = string = chair #1
  52.      * *  column 3 = string = chair #2  (most WGs have 2 chairs now)
  53.      */
  54.  
  55.     table_set = netsnmp_create_table_data_set("netSnmpIETFWGTable");
  56.  
  57.     /*
  58.      * allow the creation of new rows via SNMP SETs
  59.      */
  60.     table_set->allow_creation = 1;
  61.  
  62.     /*
  63.      * set up what a row "should" look like, starting with the index
  64.      */
  65.     netsnmp_table_dataset_add_index(table_set, ASN_OCTET_STR);
  66.  
  67.     /*
  68.      * define what the columns should look like.  both are octet strings here
  69.      */
  70.     netsnmp_table_set_multi_add_default_row(table_set,
  71.                                             /*
  72.                                              * column 2 = OCTET STRING,
  73.                                              * writable = 1,
  74.                                              * default value = NULL,
  75.                                              * default value len = 0
  76.                                              */
  77.                                             2, ASN_OCTET_STR, 1, NULL, 0,
  78.                                             /*
  79.                                              * similar
  80.                                              */
  81.                                             3, ASN_OCTET_STR, 1, NULL, 0,
  82.                                             0 /* done */ );
  83.  
  84.     /*
  85.      * register the table
  86.      */
  87.     /*
  88.      * if we wanted to handle specific data in a specific way, or note
  89.      * * when requests came in we could change the NULL below to a valid
  90.      * * handler method in which we could over ride the default
  91.      * * behaviour of the table_dataset helper
  92.      */
  93.     netsnmp_register_table_data_set(netsnmp_create_handler_registration
  94.                                     ("netSnmpIETFWGTable", my_handler,
  95.                                      my_registration_oid,
  96.                                      OID_LENGTH(my_registration_oid),
  97.                                      HANDLER_CAN_RWRITE), table_set, NULL);
  98.  
  99.  
  100.     /*
  101.      * create the a row for the table, and add the data
  102.      */
  103.     row = netsnmp_create_table_data_row();
  104.     /*
  105.      * set the index to the IETF WG name "snmpv3"
  106.      */
  107.     netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpv3",
  108.                                 strlen("snmpv3"));
  109.  
  110.  
  111.     /*
  112.      * set column 2 to be the WG chair name "Russ Mundy"
  113.      */
  114.     netsnmp_set_row_column(row, 2, ASN_OCTET_STR,
  115.                            "Russ Mundy", strlen("Russ Mundy"));
  116.     netsnmp_mark_row_column_writable(row, 2, 1);        /* make writable via SETs */
  117.  
  118.     /*
  119.      * set column 3 to be the WG chair name "David Harrington"
  120.      */
  121.     netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "David Harrington",
  122.                            strlen("David Harrington"));
  123.     netsnmp_mark_row_column_writable(row, 3, 1);        /* make writable via SETs */
  124.  
  125.     /*
  126.      * add the row to the table
  127.      */
  128.     netsnmp_table_dataset_add_row(table_set, row);
  129. #define ADD_MORE_DATA
  130. #ifdef ADD_MORE_DATA
  131.     /*
  132.      * add the data, for the second row
  133.      */
  134.     row = netsnmp_create_table_data_row();
  135.     netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpconf",
  136.                                 strlen("snmpconf"));
  137.     netsnmp_set_row_column(row, 2, ASN_OCTET_STR, "David Partain",
  138.                            strlen("David Partain"));
  139.     netsnmp_mark_row_column_writable(row, 2, 1);        /* make writable */
  140.     netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "Jon Saperia",
  141.                            strlen("Jon Saperia"));
  142.     netsnmp_mark_row_column_writable(row, 3, 1);        /* make writable */
  143.     netsnmp_table_dataset_add_row(table_set, row);
  144. #endif
  145.  
  146.     /*
  147.      * Finally, this actually allows the "add_row" token it the
  148.      * * snmpd.conf file to add rows to this table.
  149.      * * Example snmpd.conf line:
  150.      * *   add_row netSnmpIETFWGTable eos "Glenn Waters" "Dale Francisco"
  151.      */
  152.     netsnmp_register_auto_data_table(table_set, NULL);
  153.  
  154.     DEBUGMSGTL(("DATA_SET_MIB_MODULE", "Done initializing.\n"));
  155. }
  156.  
  157. void
  158. shutdown_data_set(void)
  159. {
  160.     netsnmp_unregister_auto_data_table(table_set, NULL);
  161.     netsnmp_delete_table_data_set(table_set);
  162.     table_set = NULL;
  163. }
  164.  
  165. int my_handler(netsnmp_mib_handler *handler,
  166.                netsnmp_handler_registration *reginfo,
  167.                netsnmp_agent_request_info *reqinfo,
  168.                netsnmp_request_info *requests) {
  169.  
  170.   char dialstring[20];
  171.   netsnmp_table_row *row;
  172.   switch (reqinfo->mode) {
  173.     case MODE_GET:
  174.     case MODE_GETNEXT:
  175.     row = netsnmp_extract_table_row(requests);
  176.     DEBUGMSGTL(("DATA_SET_MIB_MODULE","%d\n", requests->requestvb->name[requests->requestvb->name_length-1]));
  177.       break;
  178.  }
  179.   return SNMP_ERR_NOERROR;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement