net-snmp 5.7
|
00001 00063 /* 00064 * start be including the appropriate header files 00065 */ 00066 #include <net-snmp/net-snmp-config.h> 00067 #include <net-snmp/net-snmp-includes.h> 00068 #include <net-snmp/net-snmp-features.h> 00069 #include <net-snmp/agent/net-snmp-agent-includes.h> 00070 00071 netsnmp_feature_require(table_set_multi_add_default_row) 00072 netsnmp_feature_require(unregister_auto_data_table) 00073 netsnmp_feature_require(delete_table_data_set) 00074 netsnmp_feature_require(table_dataset) 00075 netsnmp_feature_require(table_set_multi_add_default_row) 00076 netsnmp_feature_require(table_dataset_unregister_auto_data_table) 00077 00078 static netsnmp_table_data_set *table_set; 00079 00080 /* 00081 * our initialization routine, automatically called by the agent 00082 */ 00083 /* 00084 * (to get called, the function name must match init_FILENAME() 00085 */ 00086 void 00087 init_data_set(void) 00088 { 00089 netsnmp_table_row *row; 00090 00091 /* 00092 * the OID we want to register our integer at. This should be the 00093 * * OID node for the entire table. In our case this is the 00094 * * netSnmpIETFWGTable oid definition 00095 */ 00096 oid my_registration_oid[] = 00097 { 1, 3, 6, 1, 4, 1, 8072, 2, 2, 1 }; 00098 00099 /* 00100 * a debugging statement. Run the agent with -Dexample_data_set to see 00101 * * the output of this debugging statement. 00102 */ 00103 DEBUGMSGTL(("example_data_set", 00104 "Initalizing example dataset table\n")); 00105 00106 /* 00107 * It's going to be the "working group chairs" table, since I'm 00108 * * sitting at an IETF convention while I'm writing this. 00109 * * 00110 * * column 1 = index = string = WG name 00111 * * column 2 = string = chair #1 00112 * * column 3 = string = chair #2 (most WGs have 2 chairs now) 00113 */ 00114 00115 table_set = netsnmp_create_table_data_set("netSnmpIETFWGTable"); 00116 00117 /* 00118 * allow the creation of new rows via SNMP SETs 00119 */ 00120 table_set->allow_creation = 1; 00121 00122 /* 00123 * set up what a row "should" look like, starting with the index 00124 */ 00125 netsnmp_table_dataset_add_index(table_set, ASN_OCTET_STR); 00126 00127 /* 00128 * define what the columns should look like. both are octet strings here 00129 */ 00130 netsnmp_table_set_multi_add_default_row(table_set, 00131 /* 00132 * column 2 = OCTET STRING, 00133 * writable = 1, 00134 * default value = NULL, 00135 * default value len = 0 00136 */ 00137 2, ASN_OCTET_STR, 1, NULL, 0, 00138 /* 00139 * similar 00140 */ 00141 3, ASN_OCTET_STR, 1, NULL, 0, 00142 0 /* done */ ); 00143 00144 /* 00145 * register the table 00146 */ 00147 /* 00148 * if we wanted to handle specific data in a specific way, or note 00149 * * when requests came in we could change the NULL below to a valid 00150 * * handler method in which we could over ride the default 00151 * * behaviour of the table_dataset helper 00152 */ 00153 netsnmp_register_table_data_set(netsnmp_create_handler_registration 00154 ("netSnmpIETFWGTable", NULL, 00155 my_registration_oid, 00156 OID_LENGTH(my_registration_oid), 00157 HANDLER_CAN_RWRITE), table_set, NULL); 00158 00159 00160 /* 00161 * create the a row for the table, and add the data 00162 */ 00163 row = netsnmp_create_table_data_row(); 00164 /* 00165 * set the index to the IETF WG name "snmpv3" 00166 */ 00167 netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpv3", 00168 strlen("snmpv3")); 00169 00170 00171 /* 00172 * set column 2 to be the WG chair name "Russ Mundy" 00173 */ 00174 netsnmp_set_row_column(row, 2, ASN_OCTET_STR, 00175 "Russ Mundy", strlen("Russ Mundy")); 00176 netsnmp_mark_row_column_writable(row, 2, 1); /* make writable via SETs */ 00177 00178 /* 00179 * set column 3 to be the WG chair name "David Harrington" 00180 */ 00181 netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "David Harrington", 00182 strlen("David Harrington")); 00183 netsnmp_mark_row_column_writable(row, 3, 1); /* make writable via SETs */ 00184 00185 /* 00186 * add the row to the table 00187 */ 00188 netsnmp_table_dataset_add_row(table_set, row); 00189 00190 #ifdef ADD_MORE_DATA 00191 /* 00192 * add the data, for the second row 00193 */ 00194 row = netsnmp_create_table_data_row(); 00195 netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpconf", 00196 strlen("snmpconf")); 00197 netsnmp_set_row_column(row, 2, ASN_OCTET_STR, "David Partain", 00198 strlen("David Partain")); 00199 netsnmp_mark_row_column_writable(row, 2, 1); /* make writable */ 00200 netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "Jon Saperia", 00201 strlen("Jon Saperia")); 00202 netsnmp_mark_row_column_writable(row, 3, 1); /* make writable */ 00203 netsnmp_table_dataset_add_row(table_set, row); 00204 #endif 00205 00206 /* 00207 * Finally, this actually allows the "add_row" token it the 00208 * * snmpd.conf file to add rows to this table. 00209 * * Example snmpd.conf line: 00210 * * add_row netSnmpIETFWGTable eos "Glenn Waters" "Dale Francisco" 00211 */ 00212 netsnmp_register_auto_data_table(table_set, NULL); 00213 00214 DEBUGMSGTL(("example_data_set", "Done initializing.\n")); 00215 } 00216 00217 void 00218 shutdown_data_set(void) 00219 { 00220 netsnmp_unregister_auto_data_table(table_set, NULL); 00221 netsnmp_delete_table_data_set(table_set); 00222 table_set = NULL; 00223 }