pduMIB_form.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. /*
  2. * Note: this file originally auto-generated by mib2c
  3. * using mib2c.create-dataset.conf
  4. */
  5. #include <net-snmp/net-snmp-config.h>
  6. #include <net-snmp/net-snmp-includes.h>
  7. #include <net-snmp/agent/net-snmp-agent-includes.h>
  8. #include "pduMIB_form.h"
  9. #include "switch_ctrl.h"
  10. #include "sqlite_handle.h"
  11. #include "common.h"
  12. /** Initialize the pduChannelTable table by defining its contents and how it's structured */
  13. void
  14. initialize_table_pduChannelTable(void)
  15. {
  16. const oid pduChannelTable_oid[] = {1,3,6,1,4,1,2024,1,3,9};
  17. netsnmp_table_data_set *table_set;
  18. /* create the table structure itself */
  19. table_set = netsnmp_create_table_data_set("pduChannelTable");
  20. /* comment this out or delete if you don't support creation of new rows */
  21. table_set->allow_creation = 1;
  22. /***************************************************
  23. * Adding indexes
  24. */
  25. DEBUGMSGTL(("initialize_table_pduChannelTable",
  26. "adding indexes to table pduChannelTable\n"));
  27. netsnmp_table_set_add_indexes(table_set,
  28. ASN_INTEGER, /* index: pduChannelID */
  29. 0);
  30. DEBUGMSGTL(("initialize_table_pduChannelTable",
  31. "adding column types to table pduChannelTable\n"));
  32. netsnmp_table_set_multi_add_default_row(table_set,
  33. COLUMN_PDUCHANNELID, ASN_INTEGER, 0,
  34. NULL, 0,
  35. COLUMN_PDUCHANNELNAME, ASN_OCTET_STR, 0,
  36. NULL, 0,
  37. COLUMN_PDUCHANNELSTATUS, ASN_INTEGER, 1,
  38. NULL, 0,
  39. COLUMN_PDUCHANNELVOLTAGE, ASN_OCTET_STR, 0,
  40. NULL, 0,
  41. COLUMN_PDUCHANNELCURRENT, ASN_OCTET_STR, 0,
  42. NULL, 0,
  43. COLUMN_PDUCHANNELFREQUENCY, ASN_INTEGER, 0,
  44. NULL, 0,
  45. COLUMN_PDUCHANNELCONSUMPTION, ASN_OCTET_STR, 0,
  46. NULL, 0,
  47. COLUMN_PDUCHANNELPOWERFACTOR, ASN_OCTET_STR, 0,
  48. NULL, 0,
  49. COLUMN_PDUCHANNELPACTIVEPOWER, ASN_OCTET_STR, 0,
  50. NULL, 0,
  51. COLUMN_PDUCHANNELREACTIVEPOWER, ASN_OCTET_STR, 0,
  52. NULL, 0,
  53. COLUMN_PDUCHANNELAPPARENTPOWER, ASN_OCTET_STR, 0,
  54. NULL, 0,
  55. 0);
  56. /* registering the table with the master agent */
  57. /* note: if you don't need a subhandler to deal with any aspects
  58. of the request, change pduChannelTable_handler to "NULL" */
  59. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduChannelTable", pduChannelTable_handler,
  60. pduChannelTable_oid,
  61. OID_LENGTH(pduChannelTable_oid),
  62. HANDLER_CAN_RWRITE),
  63. table_set, NULL);
  64. }
  65. /** Initialize the pduGroupTable table by defining its contents and how it's structured */
  66. void
  67. initialize_table_pduGroupTable(void)
  68. {
  69. const oid pduGroupTable_oid[] = {1,3,6,1,4,1,2024,1,3,10};
  70. netsnmp_table_data_set *table_set;
  71. /* create the table structure itself */
  72. table_set = netsnmp_create_table_data_set("pduGroupTable");
  73. /* comment this out or delete if you don't support creation of new rows */
  74. table_set->allow_creation = 1;
  75. /***************************************************
  76. * Adding indexes
  77. */
  78. DEBUGMSGTL(("initialize_table_pduGroupTable",
  79. "adding indexes to table pduGroupTable\n"));
  80. netsnmp_table_set_add_indexes(table_set,
  81. ASN_INTEGER, /* index: pduGroupID */
  82. 0);
  83. DEBUGMSGTL(("initialize_table_pduGroupTable",
  84. "adding column types to table pduGroupTable\n"));
  85. netsnmp_table_set_multi_add_default_row(table_set,
  86. COLUMN_PDUGROUPID, ASN_INTEGER, 0,
  87. NULL, 0,
  88. COLUMN_PDUGROUPNAME, ASN_OCTET_STR, 1,
  89. NULL, 0,
  90. COLUMN_PDUGROUPLIST, ASN_OCTET_STR, 1,
  91. NULL, 0,
  92. COLUMN_PDUGROUPSTATUS, ASN_INTEGER, 1,
  93. NULL, 0,
  94. 0);
  95. /* registering the table with the master agent */
  96. /* note: if you don't need a subhandler to deal with any aspects
  97. of the request, change pduGroupTable_handler to "NULL" */
  98. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduGroupTable", pduGroupTable_handler,
  99. pduGroupTable_oid,
  100. OID_LENGTH(pduGroupTable_oid),
  101. HANDLER_CAN_RWRITE),
  102. table_set, NULL);
  103. }
  104. /** Initialize the pduSensorTable table by defining its contents and how it's structured */
  105. void
  106. initialize_table_pduSensorTable(void)
  107. {
  108. const oid pduSensorTable_oid[] = {1,3,6,1,4,1,2024,1,4,1};
  109. netsnmp_table_data_set *table_set;
  110. /* create the table structure itself */
  111. table_set = netsnmp_create_table_data_set("pduSensorTable");
  112. /* comment this out or delete if you don't support creation of new rows */
  113. table_set->allow_creation = 1;
  114. /***************************************************
  115. * Adding indexes
  116. */
  117. DEBUGMSGTL(("initialize_table_pduSensorTable",
  118. "adding indexes to table pduSensorTable\n"));
  119. netsnmp_table_set_add_indexes(table_set,
  120. ASN_INTEGER, /* index: pduSensorID */
  121. 0);
  122. DEBUGMSGTL(("initialize_table_pduSensorTable",
  123. "adding column types to table pduSensorTable\n"));
  124. netsnmp_table_set_multi_add_default_row(table_set,
  125. COLUMN_PDUSENSORID, ASN_INTEGER, 0,
  126. NULL, 0,
  127. COLUMN_PDUSENSORNAME, ASN_OCTET_STR, 0,
  128. NULL, 0,
  129. COLUMN_PDUSENSORTYPE, ASN_INTEGER, 0,
  130. NULL, 0,
  131. COLUMN_PDUSENSORDATACHENNEL, ASN_OCTET_STR, 0,
  132. NULL, 0,
  133. COLUMN_PDUSENSORMODBUSADDRESS, ASN_INTEGER, 0,
  134. NULL, 0,
  135. COLUMN_PDUSENSORSTATUS, ASN_INTEGER, 1,
  136. NULL, 0,
  137. COLUMN_PDUSENSORVALUENUM, ASN_INTEGER, 0,
  138. NULL, 0,
  139. COLUMN_PDUSENSORVALUE1, ASN_OCTET_STR, 0,
  140. NULL, 0,
  141. COLUMN_PDUSENSORVALUE2, ASN_OCTET_STR, 0,
  142. NULL, 0,
  143. 0);
  144. /* registering the table with the master agent */
  145. /* note: if you don't need a subhandler to deal with any aspects
  146. of the request, change pduSensorTable_handler to "NULL" */
  147. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSensorTable", pduSensorTable_handler,
  148. pduSensorTable_oid,
  149. OID_LENGTH(pduSensorTable_oid),
  150. HANDLER_CAN_RWRITE),
  151. table_set, NULL);
  152. }
  153. /** Initialize the pduSMTPRecMailTable table by defining its contents and how it's structured */
  154. void
  155. initialize_table_pduSMTPRecMailTable(void)
  156. {
  157. const oid pduSMTPRecMailTable_oid[] = {1,3,6,1,4,1,2024,1,5,3,4};
  158. netsnmp_table_data_set *table_set;
  159. /* create the table structure itself */
  160. table_set = netsnmp_create_table_data_set("pduSMTPRecMailTable");
  161. /* comment this out or delete if you don't support creation of new rows */
  162. table_set->allow_creation = 1;
  163. /***************************************************
  164. * Adding indexes
  165. */
  166. DEBUGMSGTL(("initialize_table_pduSMTPRecMailTable",
  167. "adding indexes to table pduSMTPRecMailTable\n"));
  168. netsnmp_table_set_add_indexes(table_set,
  169. ASN_OCTET_STR, /* index: pduSMTPRecMail */
  170. 0);
  171. DEBUGMSGTL(("initialize_table_pduSMTPRecMailTable",
  172. "adding column types to table pduSMTPRecMailTable\n"));
  173. netsnmp_table_set_multi_add_default_row(table_set,
  174. COLUMN_PDUSMTPRECMAIL, ASN_OCTET_STR, 1,
  175. NULL, 0,
  176. 0);
  177. /* registering the table with the master agent */
  178. /* note: if you don't need a subhandler to deal with any aspects
  179. of the request, change pduSMTPRecMailTable_handler to "NULL" */
  180. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSMTPRecMailTable", pduSMTPRecMailTable_handler,
  181. pduSMTPRecMailTable_oid,
  182. OID_LENGTH(pduSMTPRecMailTable_oid),
  183. HANDLER_CAN_RWRITE),
  184. table_set, NULL);
  185. }
  186. /** Initialize the pduMessageNumTable table by defining its contents and how it's structured */
  187. void
  188. initialize_table_pduMessageNumTable(void)
  189. {
  190. const oid pduMessageNumTable_oid[] = {1,3,6,1,4,1,2024,1,5,5,2};
  191. netsnmp_table_data_set *table_set;
  192. /* create the table structure itself */
  193. table_set = netsnmp_create_table_data_set("pduMessageNumTable");
  194. /* comment this out or delete if you don't support creation of new rows */
  195. table_set->allow_creation = 1;
  196. /***************************************************
  197. * Adding indexes
  198. */
  199. DEBUGMSGTL(("initialize_table_pduMessageNumTable",
  200. "adding indexes to table pduMessageNumTable\n"));
  201. netsnmp_table_set_add_indexes(table_set,
  202. ASN_OCTET_STR, /* index: pduMessageRecNum */
  203. 0);
  204. DEBUGMSGTL(("initialize_table_pduMessageNumTable",
  205. "adding column types to table pduMessageNumTable\n"));
  206. netsnmp_table_set_multi_add_default_row(table_set,
  207. COLUMN_PDUMESSAGERECNUM, ASN_OCTET_STR, 1,
  208. NULL, 0,
  209. 0);
  210. /* registering the table with the master agent */
  211. /* note: if you don't need a subhandler to deal with any aspects
  212. of the request, change pduMessageNumTable_handler to "NULL" */
  213. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduMessageNumTable", pduMessageNumTable_handler,
  214. pduMessageNumTable_oid,
  215. OID_LENGTH(pduMessageNumTable_oid),
  216. HANDLER_CAN_RWRITE),
  217. table_set, NULL);
  218. }
  219. /** Initialize the pduMQTTBrokerTable table by defining its contents and how it's structured */
  220. void
  221. initialize_table_pduMQTTBrokerTable(void)
  222. {
  223. const oid pduMQTTBrokerTable_oid[] = {1,3,6,1,4,1,2024,1,5,6,3};
  224. netsnmp_table_data_set *table_set;
  225. /* create the table structure itself */
  226. table_set = netsnmp_create_table_data_set("pduMQTTBrokerTable");
  227. /* comment this out or delete if you don't support creation of new rows */
  228. table_set->allow_creation = 1;
  229. /***************************************************
  230. * Adding indexes
  231. */
  232. DEBUGMSGTL(("initialize_table_pduMQTTBrokerTable",
  233. "adding indexes to table pduMQTTBrokerTable\n"));
  234. netsnmp_table_set_add_indexes(table_set,
  235. ASN_OCTET_STR, /* index: pduMQTTBrokerName */
  236. 0);
  237. DEBUGMSGTL(("initialize_table_pduMQTTBrokerTable",
  238. "adding column types to table pduMQTTBrokerTable\n"));
  239. netsnmp_table_set_multi_add_default_row(table_set,
  240. COLUMN_PDUMQTTBROKERNAME, ASN_OCTET_STR, 1,
  241. NULL, 0,
  242. COLUMN_PDUMQTTBROKERENABLE, ASN_INTEGER, 1,
  243. NULL, 0,
  244. COLUMN_PDUMQTTBROKERIPORDOMAIN, ASN_OCTET_STR, 1,
  245. NULL, 0,
  246. COLUMN_PDUMQTTBROKERPORT, ASN_INTEGER, 1,
  247. NULL, 0,
  248. COLUMN_PDUMQTTBROKERUSERNAME, ASN_OCTET_STR, 1,
  249. NULL, 0,
  250. COLUMN_PDUMQTTBROKERUSERPW, ASN_OCTET_STR, 1,
  251. NULL, 0,
  252. 0);
  253. /* registering the table with the master agent */
  254. /* note: if you don't need a subhandler to deal with any aspects
  255. of the request, change pduMQTTBrokerTable_handler to "NULL" */
  256. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduMQTTBrokerTable", pduMQTTBrokerTable_handler,
  257. pduMQTTBrokerTable_oid,
  258. OID_LENGTH(pduMQTTBrokerTable_oid),
  259. HANDLER_CAN_RWRITE),
  260. table_set, NULL);
  261. }
  262. /** Initialize the pduCloudServerTable table by defining its contents and how it's structured */
  263. void
  264. initialize_table_pduCloudServerTable(void)
  265. {
  266. const oid pduCloudServerTable_oid[] = {1,3,6,1,4,1,2024,1,5,7,3};
  267. netsnmp_table_data_set *table_set;
  268. /* create the table structure itself */
  269. table_set = netsnmp_create_table_data_set("pduCloudServerTable");
  270. /* comment this out or delete if you don't support creation of new rows */
  271. table_set->allow_creation = 1;
  272. /***************************************************
  273. * Adding indexes
  274. */
  275. DEBUGMSGTL(("initialize_table_pduCloudServerTable",
  276. "adding indexes to table pduCloudServerTable\n"));
  277. netsnmp_table_set_add_indexes(table_set,
  278. ASN_OCTET_STR, /* index: pduCloudServerName */
  279. 0);
  280. DEBUGMSGTL(("initialize_table_pduCloudServerTable",
  281. "adding column types to table pduCloudServerTable\n"));
  282. netsnmp_table_set_multi_add_default_row(table_set,
  283. COLUMN_PDUCLOUDSERVERNAME, ASN_OCTET_STR, 1,
  284. NULL, 0,
  285. COLUMN_PDUCLOUDSERVERENABLE, ASN_INTEGER, 1,
  286. NULL, 0,
  287. COLUMN_PDUCLOUDSERVERIPORDOMAIN, ASN_OCTET_STR, 1,
  288. NULL, 0,
  289. COLUMN_PDUCLOUDSERVERPORT, ASN_INTEGER, 1,
  290. NULL, 0,
  291. COLUMN_PDUCLOUDSERVERUSERNAME, ASN_OCTET_STR, 1,
  292. NULL, 0,
  293. COLUMN_PDUCLOUDSERVERUSERPW, ASN_OCTET_STR, 1,
  294. NULL, 0,
  295. 0);
  296. /* registering the table with the master agent */
  297. /* note: if you don't need a subhandler to deal with any aspects
  298. of the request, change pduCloudServerTable_handler to "NULL" */
  299. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduCloudServerTable", pduCloudServerTable_handler,
  300. pduCloudServerTable_oid,
  301. OID_LENGTH(pduCloudServerTable_oid),
  302. HANDLER_CAN_RWRITE),
  303. table_set, NULL);
  304. }
  305. /** Initialize the pduAlarmHistoryTable table by defining its contents and how it's structured */
  306. void
  307. initialize_table_pduAlarmHistoryTable(void)
  308. {
  309. const oid pduAlarmHistoryTable_oid[] = {1,3,6,1,4,1,2024,1,6,1};
  310. netsnmp_table_data_set *table_set;
  311. /* create the table structure itself */
  312. table_set = netsnmp_create_table_data_set("pduAlarmHistoryTable");
  313. /* comment this out or delete if you don't support creation of new rows */
  314. table_set->allow_creation = 1;
  315. /***************************************************
  316. * Adding indexes
  317. */
  318. DEBUGMSGTL(("initialize_table_pduAlarmHistoryTable",
  319. "adding indexes to table pduAlarmHistoryTable\n"));
  320. netsnmp_table_set_add_indexes(table_set,
  321. ASN_INTEGER, /* index: pduAlarmID */
  322. 0);
  323. DEBUGMSGTL(("initialize_table_pduAlarmHistoryTable",
  324. "adding column types to table pduAlarmHistoryTable\n"));
  325. netsnmp_table_set_multi_add_default_row(table_set,
  326. COLUMN_PDUALARMID, ASN_INTEGER, 0,
  327. NULL, 0,
  328. COLUMN_PDUALARMTYPE, ASN_INTEGER, 0,
  329. NULL, 0,
  330. COLUMN_PDUALARMCONTEXT, ASN_OCTET_STR, 0,
  331. NULL, 0,
  332. COLUMN_PDUALARMACTION, ASN_INTEGER, 0,
  333. NULL, 0,
  334. COLUMN_PDUALARMACTIONPARA, ASN_INTEGER, 0,
  335. NULL, 0,
  336. COLUMN_PDUALARMDATE, ASN_OCTET_STR, 0,
  337. NULL, 0,
  338. COLUMN_PDUALARMTIME, ASN_OCTET_STR, 0,
  339. NULL, 0,
  340. 0);
  341. /* registering the table with the master agent */
  342. /* note: if you don't need a subhandler to deal with any aspects
  343. of the request, change pduAlarmHistoryTable_handler to "NULL" */
  344. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduAlarmHistoryTable", pduAlarmHistoryTable_handler,
  345. pduAlarmHistoryTable_oid,
  346. OID_LENGTH(pduAlarmHistoryTable_oid),
  347. HANDLER_CAN_RWRITE),
  348. table_set, NULL);
  349. }
  350. /** Initialize the pduChannelLimitTable table by defining its contents and how it's structured */
  351. void
  352. initialize_table_pduChannelLimitTable(void)
  353. {
  354. const oid pduChannelLimitTable_oid[] = {1,3,6,1,4,1,2024,1,7,2,6};
  355. netsnmp_table_data_set *table_set;
  356. /* create the table structure itself */
  357. table_set = netsnmp_create_table_data_set("pduChannelLimitTable");
  358. /* comment this out or delete if you don't support creation of new rows */
  359. table_set->allow_creation = 1;
  360. /***************************************************
  361. * Adding indexes
  362. */
  363. DEBUGMSGTL(("initialize_table_pduChannelLimitTable",
  364. "adding indexes to table pduChannelLimitTable\n"));
  365. netsnmp_table_set_add_indexes(table_set,
  366. ASN_INTEGER, /* index: pduChannelLimitID */
  367. 0);
  368. DEBUGMSGTL(("initialize_table_pduChannelLimitTable",
  369. "adding column types to table pduChannelLimitTable\n"));
  370. netsnmp_table_set_multi_add_default_row(table_set,
  371. COLUMN_PDUCHANNELLIMITID, ASN_INTEGER, 0,
  372. NULL, 0,
  373. COLUMN_PDUCHANNELLIMITNAME, ASN_OCTET_STR, 1,
  374. NULL, 0,
  375. COLUMN_PDUCHANNELCURRENTLIMITUP, ASN_OCTET_STR, 1,
  376. NULL, 0,
  377. COLUMN_PDUCHANNELVOLTAGELIMITUP, ASN_OCTET_STR, 1,
  378. NULL, 0,
  379. COLUMN_PDUCHANNELVOLTAGELIMITDOWN, ASN_OCTET_STR, 1,
  380. NULL, 0,
  381. COLUMN_PDUCHANNELPOWERLIMITUP, ASN_OCTET_STR, 1,
  382. NULL, 0,
  383. COLUMN_PDUCHANNELCONSUMPTIONLIMITUP, ASN_OCTET_STR, 1,
  384. NULL, 0,
  385. 0);
  386. /* registering the table with the master agent */
  387. /* note: if you don't need a subhandler to deal with any aspects
  388. of the request, change pduChannelLimitTable_handler to "NULL" */
  389. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduChannelLimitTable", pduChannelLimitTable_handler,
  390. pduChannelLimitTable_oid,
  391. OID_LENGTH(pduChannelLimitTable_oid),
  392. HANDLER_CAN_RWRITE),
  393. table_set, NULL);
  394. }
  395. /** Initialize the pduSensorLimitTable table by defining its contents and how it's structured */
  396. void
  397. initialize_table_pduSensorLimitTable(void)
  398. {
  399. const oid pduSensorLimitTable_oid[] = {1,3,6,1,4,1,2024,1,7,3,1};
  400. netsnmp_table_data_set *table_set;
  401. /* create the table structure itself */
  402. table_set = netsnmp_create_table_data_set("pduSensorLimitTable");
  403. /* comment this out or delete if you don't support creation of new rows */
  404. table_set->allow_creation = 1;
  405. /***************************************************
  406. * Adding indexes
  407. */
  408. DEBUGMSGTL(("initialize_table_pduSensorLimitTable",
  409. "adding indexes to table pduSensorLimitTable\n"));
  410. netsnmp_table_set_add_indexes(table_set,
  411. ASN_INTEGER, /* index: pduSensorLimitID */
  412. 0);
  413. DEBUGMSGTL(("initialize_table_pduSensorLimitTable",
  414. "adding column types to table pduSensorLimitTable\n"));
  415. netsnmp_table_set_multi_add_default_row(table_set,
  416. COLUMN_PDUSENSORLIMITID, ASN_INTEGER, 1,
  417. NULL, 0,
  418. COLUMN_PDUSENSORLIMITNAME, ASN_OCTET_STR, 1,
  419. NULL, 0,
  420. COLUMN_PDUSENSORLIMITVALUE1UP, ASN_INTEGER, 1,
  421. NULL, 0,
  422. COLUMN_PDUSENSORLIMITVALUE2UP, ASN_INTEGER, 1,
  423. NULL, 0,
  424. COLUMN_PDUSENSORLIMITVALUE1DOWN, ASN_INTEGER, 1,
  425. NULL, 0,
  426. COLUMN_PDUSENSORLIMITVALUE2DOWN, ASN_INTEGER, 1,
  427. NULL, 0,
  428. 0);
  429. /* registering the table with the master agent */
  430. /* note: if you don't need a subhandler to deal with any aspects
  431. of the request, change pduSensorLimitTable_handler to "NULL" */
  432. netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSensorLimitTable", pduSensorLimitTable_handler,
  433. pduSensorLimitTable_oid,
  434. OID_LENGTH(pduSensorLimitTable_oid),
  435. HANDLER_CAN_RWRITE),
  436. table_set, NULL);
  437. }
  438. /** Initializes the pduMIB module */
  439. void
  440. init_pduMIB_form(void)
  441. {
  442. /* here we initialize all the tables we're planning on supporting */
  443. initialize_table_pduChannelTable();
  444. initialize_table_pduGroupTable();
  445. initialize_table_pduSensorTable();
  446. initialize_table_pduSMTPRecMailTable();
  447. initialize_table_pduMessageNumTable();
  448. initialize_table_pduMQTTBrokerTable();
  449. initialize_table_pduCloudServerTable();
  450. initialize_table_pduAlarmHistoryTable();
  451. initialize_table_pduChannelLimitTable();
  452. initialize_table_pduSensorLimitTable();
  453. }
  454. /** handles requests for the pduChannelTable table, if anything else needs to be done */
  455. int
  456. pduChannelTable_handler(
  457. netsnmp_mib_handler *handler,
  458. netsnmp_handler_registration *reginfo,
  459. netsnmp_agent_request_info *reqinfo,
  460. netsnmp_request_info *requests) {
  461. /* perform anything here that you need to do. The requests have
  462. already been processed by the master table_dataset handler, but
  463. this gives you chance to act on the request in some other way
  464. if need be. */
  465. netsnmp_request_info *request;
  466. netsnmp_table_request_info *table_info;
  467. GlobalPowerManger* iterator;
  468. //GlobalPowerInfo powerInfo;
  469. char buffer[16];
  470. switch(reqinfo->mode)
  471. {
  472. case MODE_GET:
  473. for (request = requests; request; request = request->next)
  474. {
  475. table_info = netsnmp_extract_table_info(request);
  476. int nIndex=1;
  477. list_for_each_entry(iterator, &__globalDeviceManage._globalPowerManger.list, list)
  478. {
  479. //查询数据库总电源信息 传给所申请的参数结构体
  480. //if(dev_search_power_trend_info(__globalDeviceManage.db,iterator->product_id,0,iterator)!=0)
  481. //{
  482. // log_e("search total power consumption err at pduChannelTable_handler from db.");
  483. //}
  484. //传值给总管理结构体
  485. // for(int i=0;i< TOTAL_COUNT;i++)
  486. // {
  487. // strcpy(_over_all_pwr_back_info._Power_Trend_Info.xAxis[i],__PowerTrendInfo._power_trend_info.xAxis[i]);
  488. // _over_all_pwr_back_info._Power_Trend_Info.ydata[POWER_MERITORIOUS_TYPE][i] = __PowerTrendInfo._power_trend_info.ydata[POWER_MERITORIOUS_TYPE][i];
  489. // _over_all_pwr_back_info._Power_Trend_Info.ydata[POWER_REACTIVE_TYPE][i] = __PowerTrendInfo._power_trend_info.ydata[POWER_REACTIVE_TYPE][i];
  490. // _over_all_pwr_back_info._Power_Trend_Info.ydata[POWER_APPARENT_TYPE][i] = __PowerTrendInfo._power_trend_info.ydata[POWER_APPARENT_TYPE][i];
  491. // }
  492. //if(dev_search_latest_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product.id,iterator->product_ch_id,&powerInfo)!=0)
  493. //{
  494. // log_e("search total pwr err at pduChannelTable_handler from db.");
  495. //}
  496. //else
  497. //{
  498. if (nIndex<table_info->index_oid[0])
  499. {
  500. nIndex++;
  501. continue;
  502. }
  503. memset(buffer,0,sizeof(buffer));
  504. switch (table_info->colnum)
  505. {
  506. case COLUMN_PDUCHANNELID:
  507. if (!iterator)
  508. {
  509. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  510. continue;
  511. }
  512. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->product_ch_id);
  513. break;
  514. case COLUMN_PDUCHANNELNAME:
  515. if (!iterator)
  516. {
  517. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  518. continue;
  519. }
  520. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, iterator->product_ch_name, strlen(iterator->product_ch_name));
  521. break;
  522. case COLUMN_PDUCHANNELSTATUS:
  523. if (!iterator)
  524. {
  525. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  526. continue;
  527. }
  528. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerInfo.status);
  529. break;
  530. case COLUMN_PDUCHANNELVOLTAGE:
  531. if (!iterator)
  532. {
  533. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  534. continue;
  535. }
  536. sprintf(buffer,"%0.3f",iterator->_PowerInfo.voltage);
  537. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  538. break;
  539. case COLUMN_PDUCHANNELCURRENT:
  540. if (!iterator)
  541. {
  542. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  543. continue;
  544. }
  545. sprintf(buffer,"%0.3f",iterator->_PowerInfo.current);
  546. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  547. break;
  548. case COLUMN_PDUCHANNELFREQUENCY:
  549. if (!iterator)
  550. {
  551. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  552. continue;
  553. }
  554. sprintf(buffer,"%0.3f",iterator->_PowerInfo.freq);
  555. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  556. break;
  557. case COLUMN_PDUCHANNELCONSUMPTION:
  558. if (!iterator)
  559. {
  560. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  561. continue;
  562. }
  563. sprintf(buffer,"%0.3f",iterator->_PowerInfo.consumption);
  564. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  565. break;
  566. case COLUMN_PDUCHANNELPOWERFACTOR:
  567. if (!iterator)
  568. {
  569. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  570. continue;
  571. }
  572. sprintf(buffer,"%0.3f",iterator->_PowerInfo.factor);
  573. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  574. break;
  575. case COLUMN_PDUCHANNELPACTIVEPOWER:
  576. if (!iterator)
  577. {
  578. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  579. continue;
  580. }
  581. sprintf(buffer,"%0.3f",iterator->_PowerInfo.power);
  582. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  583. break;
  584. case COLUMN_PDUCHANNELREACTIVEPOWER:
  585. if (!iterator)
  586. {
  587. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  588. continue;
  589. }
  590. if (iterator->_PowerInfo.factor>0&&iterator->_PowerInfo.factor<=1)
  591. {
  592. sprintf(buffer,"%0.3f",(iterator->_PowerInfo.power/iterator->_PowerInfo.factor)-iterator->_PowerInfo.power);
  593. }else{
  594. sprintf(buffer,"0");
  595. }
  596. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  597. break;
  598. case COLUMN_PDUCHANNELAPPARENTPOWER:
  599. if (!iterator)
  600. {
  601. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  602. continue;
  603. }
  604. if (iterator->_PowerInfo.factor>0)
  605. {
  606. sprintf(buffer,"%0.3f",iterator->_PowerInfo.power/iterator->_PowerInfo.factor);
  607. }else{
  608. sprintf(buffer,"0");
  609. }
  610. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  611. break;
  612. default:
  613. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  614. break;
  615. }
  616. //}
  617. break;
  618. }
  619. }
  620. break;
  621. case MODE_SET_RESERVE1:
  622. break;
  623. case MODE_SET_RESERVE2:
  624. break;
  625. case MODE_SET_FREE:
  626. break;
  627. case MODE_SET_ACTION:
  628. break;
  629. case MODE_SET_UNDO:
  630. break;
  631. case MODE_SET_COMMIT:
  632. /* XXX: delete temporary storage */
  633. // if (/* XXX: error? */) {
  634. // /* try _really_really_ hard to never get to this point */
  635. // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
  636. // }
  637. for (request = requests; request; request = request->next)
  638. {
  639. table_info = netsnmp_extract_table_info(request);
  640. int nIndex = 1;
  641. list_for_each_entry(iterator, &__globalDeviceManage._globalPowerManger.list, list)
  642. {
  643. if (nIndex < table_info->index_oid[0])
  644. {
  645. nIndex++;
  646. continue;
  647. }
  648. memset(buffer, 0, sizeof(buffer));
  649. switch (table_info->colnum)
  650. {
  651. case COLUMN_PDUCHANNELSTATUS:
  652. if (!iterator)
  653. {
  654. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  655. continue;
  656. }
  657. int nCHOpertype = *request->requestvb->val.integer;
  658. if (nCHOpertype!= iterator->_PowerInfo.status)
  659. {
  660. log_d("SNMP Remote switch ctrl:%d", iterator->product_ch_id);
  661. g_switch_set_all_chn_ctrl(&__globalDeviceManage._globalRelaySampManger,
  662. iterator,
  663. iterator->product_saddr,
  664. iterator->product_ch_addr, // 多版端口余8
  665. nCHOpertype,false);
  666. }
  667. break;
  668. }
  669. break;
  670. }
  671. }
  672. break;
  673. default:
  674. /* we should never get here, so this is a really bad error */
  675. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode );
  676. return SNMP_ERR_GENERR;
  677. }
  678. return SNMP_ERR_NOERROR;
  679. }
  680. /** handles requests for the pduGroupTable table, if anything else needs to be done */
  681. int
  682. pduGroupTable_handler(
  683. netsnmp_mib_handler *handler,
  684. netsnmp_handler_registration *reginfo,
  685. netsnmp_agent_request_info *reqinfo,
  686. netsnmp_request_info *requests) {
  687. /* perform anything here that you need to do. The requests have
  688. already been processed by the master table_dataset handler, but
  689. this gives you chance to act on the request in some other way
  690. if need be. */
  691. netsnmp_request_info *request=NULL;
  692. netsnmp_table_request_info *table_info;
  693. GroupInfo *_GroupInfoTemp = NULL;
  694. GroupInfo group_list;
  695. INIT_LIST_HEAD(&group_list.list);
  696. if (0 != dev_get_group_info(__globalDeviceManage.db, &group_list))
  697. {
  698. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  699. return SNMP_ERR_GENERR;
  700. }
  701. char buffer[16];
  702. switch (reqinfo->mode)
  703. {
  704. case MODE_GET:
  705. for (request = requests; request; request = request->next)
  706. {
  707. table_info = netsnmp_extract_table_info(request);
  708. int nIndex = 1;
  709. list_for_each_entry(_GroupInfoTemp, &group_list.list, list)
  710. {
  711. if (nIndex < table_info->index_oid[0])
  712. {
  713. nIndex++;
  714. continue;
  715. }
  716. memset(buffer, 0, sizeof(buffer));
  717. switch (table_info->colnum)
  718. {
  719. case COLUMN_PDUGROUPID:
  720. if (!_GroupInfoTemp)
  721. {
  722. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  723. continue;
  724. }
  725. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, _GroupInfoTemp->GroupID);
  726. break;
  727. case COLUMN_PDUGROUPNAME:
  728. if (!_GroupInfoTemp)
  729. {
  730. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  731. continue;
  732. }
  733. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, _GroupInfoTemp->GroupName, strlen(_GroupInfoTemp->GroupName));
  734. break;
  735. case COLUMN_PDUGROUPLIST:
  736. if (!_GroupInfoTemp)
  737. {
  738. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  739. continue;
  740. }
  741. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, _GroupInfoTemp->GroupChList, strlen(_GroupInfoTemp->GroupChList));
  742. break;
  743. case COLUMN_PDUGROUPSTATUS:
  744. if (!_GroupInfoTemp)
  745. {
  746. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  747. continue;
  748. }
  749. //判断分组状态
  750. int nStatus = 0;
  751. char *pCHlist;
  752. char *pCHListSave;
  753. pCHlist = strtok_r(_GroupInfoTemp->GroupChList, ",", &pCHListSave);
  754. while(pCHlist!=NULL)
  755. {
  756. GlobalPowerManger *_globalPowerMangerTemp = NULL;
  757. list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
  758. {
  759. if (_globalPowerMangerTemp == NULL)
  760. break;
  761. if (atoi(pCHlist) == _globalPowerMangerTemp->product_ch_id)
  762. {
  763. if (_globalPowerMangerTemp->_PowerInfo.status == 1)
  764. {
  765. nStatus = 1;
  766. break;
  767. }
  768. }
  769. }
  770. pCHlist = strtok_r(NULL, ",",&pCHListSave);
  771. }
  772. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, nStatus);
  773. break;
  774. default:
  775. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  776. break;
  777. }
  778. //}
  779. break;
  780. }
  781. }
  782. break;
  783. case MODE_SET_RESERVE1:
  784. break;
  785. case MODE_SET_RESERVE2:
  786. break;
  787. case MODE_SET_FREE:
  788. break;
  789. case MODE_SET_ACTION:
  790. break;
  791. case MODE_SET_UNDO:
  792. break;
  793. case MODE_SET_COMMIT:
  794. for (request = requests; request; request = request->next)
  795. {
  796. table_info = netsnmp_extract_table_info(request);
  797. int nIndex = 1;
  798. list_for_each_entry(_GroupInfoTemp, &group_list.list, list)
  799. {
  800. if (nIndex < table_info->index_oid[0])
  801. {
  802. nIndex++;
  803. continue;
  804. }
  805. memset(buffer, 0, sizeof(buffer));
  806. switch (table_info->colnum)
  807. {
  808. case COLUMN_PDUGROUPSTATUS:
  809. if (!_GroupInfoTemp)
  810. {
  811. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  812. continue;
  813. }
  814. bool nGroupOpertype = *request->requestvb->val.integer;
  815. char *pCHlist;
  816. char *pCHListSave;
  817. pCHlist = strtok_r(_GroupInfoTemp->GroupChList, ",", &pCHListSave);
  818. if (__globalDeviceManage._globalDevInfo.product.pwr_type == 1)
  819. {
  820. unsigned short pAddrCtrl[50];
  821. memset(pAddrCtrl, 0, sizeof(pAddrCtrl));
  822. int ret = 0;
  823. while(pCHlist!=NULL)
  824. {
  825. GlobalPowerManger *_globalPowerMangerTemp = NULL;
  826. list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
  827. {
  828. if (_globalPowerMangerTemp == NULL)
  829. break;
  830. if (atoi(pCHlist) == _globalPowerMangerTemp->product_ch_id)
  831. {
  832. log_d("SNMP Group switch ctrl:%d", _globalPowerMangerTemp->product_ch_id);
  833. pAddrCtrl[(int)_globalPowerMangerTemp->product_saddr] |= 1 << (_globalPowerMangerTemp->product_ch_addr - 1);
  834. break;
  835. }
  836. }
  837. pCHlist = strtok_r(NULL, ",",&pCHListSave);
  838. }
  839. for (size_t i = 0; i < 50; i++)
  840. {
  841. if (pAddrCtrl[i] != 0)
  842. {
  843. ret = g_switch_set_dcpdu_chns_ctrl(&__globalDeviceManage._globalRelaySampManger,
  844. i,
  845. pAddrCtrl[i],
  846. nGroupOpertype);
  847. if (ret < 0)
  848. {
  849. ret = g_switch_set_dcpdu_chns_ctrl(&__globalDeviceManage._globalRelaySampManger,
  850. i,
  851. pAddrCtrl[i],
  852. nGroupOpertype);
  853. /* code */
  854. }
  855. }
  856. }
  857. }
  858. else
  859. {
  860. while(pCHlist!=NULL)
  861. {
  862. GlobalPowerManger *_globalPowerMangerTemp = NULL;
  863. list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
  864. {
  865. if (_globalPowerMangerTemp == NULL)
  866. break;
  867. if (atoi(pCHlist) == _globalPowerMangerTemp->product_ch_id)
  868. {
  869. log_d("SNMP Group switch ctrl:%d", _globalPowerMangerTemp->product_ch_id);
  870. g_switch_set_all_chn_ctrl(&__globalDeviceManage._globalRelaySampManger,
  871. _globalPowerMangerTemp,
  872. _globalPowerMangerTemp->product_saddr,
  873. _globalPowerMangerTemp->product_ch_addr, // 多版端口余8
  874. nGroupOpertype,true);
  875. break;
  876. }
  877. }
  878. pCHlist = strtok_r(NULL, ",",&pCHListSave);
  879. }
  880. }
  881. }
  882. break;
  883. }
  884. }
  885. break;
  886. default:
  887. /* we should never get here, so this is a really bad error */
  888. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
  889. return SNMP_ERR_GENERR;
  890. }
  891. return SNMP_ERR_NOERROR;
  892. }
  893. /** handles requests for the pduSensorTable table, if anything else needs to be done */
  894. int
  895. pduSensorTable_handler(
  896. netsnmp_mib_handler *handler,
  897. netsnmp_handler_registration *reginfo,
  898. netsnmp_agent_request_info *reqinfo,
  899. netsnmp_request_info *requests) {
  900. /* perform anything here that you need to do. The requests have
  901. already been processed by the master table_dataset handler, but
  902. this gives you chance to act on the request in some other way
  903. if need be. */
  904. netsnmp_request_info *request;
  905. netsnmp_table_request_info *table_info;
  906. GlobalSensorManger *iterator = NULL;
  907. //
  908. char buffer[16];
  909. switch (reqinfo->mode)
  910. {
  911. case MODE_GET:
  912. for (request = requests; request; request = request->next)
  913. {
  914. table_info = netsnmp_extract_table_info(request);
  915. int nIndex = table_info->index_oid[0];
  916. bool findinstance = false;
  917. list_for_each_entry(iterator, &__globalDeviceManage._globalSensorManger.list, list)
  918. {
  919. if (!iterator || nIndex != iterator->sensor_id)
  920. {
  921. continue;
  922. }
  923. findinstance = true;
  924. memset(buffer, 0, sizeof(buffer));
  925. switch (table_info->colnum)
  926. {
  927. case COLUMN_PDUSENSORID:
  928. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_id);
  929. break;
  930. case COLUMN_PDUSENSORNAME:
  931. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, iterator->sensor_name, strlen(iterator->sensor_name));
  932. break;
  933. case COLUMN_PDUSENSORTYPE:
  934. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_type);
  935. break;
  936. case COLUMN_PDUSENSORDATACHENNEL:
  937. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_interface_type);
  938. break;
  939. case COLUMN_PDUSENSORMODBUSADDRESS:
  940. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_addr);
  941. break;
  942. case COLUMN_PDUSENSORSTATUS:
  943. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_status);
  944. break;
  945. case COLUMN_PDUSENSORVALUENUM:
  946. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_val_count);
  947. break;
  948. case COLUMN_PDUSENSORVALUE1:
  949. sprintf(buffer, "%0.3f", iterator->Cur_sensor_info.val1);
  950. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  951. break;
  952. case COLUMN_PDUSENSORVALUE2:
  953. sprintf(buffer, "%0.3f", iterator->Cur_sensor_info.val2);
  954. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  955. break;
  956. default:
  957. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  958. break;
  959. }
  960. //}
  961. break;
  962. }
  963. if (!findinstance)
  964. {
  965. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  966. }
  967. }
  968. break;
  969. case MODE_SET_RESERVE1:
  970. break;
  971. case MODE_SET_RESERVE2:
  972. break;
  973. case MODE_SET_FREE:
  974. break;
  975. case MODE_SET_ACTION:
  976. break;
  977. case MODE_SET_UNDO:
  978. break;
  979. case MODE_SET_COMMIT:
  980. break;
  981. default:
  982. /* we should never get here, so this is a really bad error */
  983. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
  984. return SNMP_ERR_GENERR;
  985. }
  986. return SNMP_ERR_NOERROR;
  987. }
  988. /** handles requests for the pduSMTPRecMailTable table, if anything else needs to be done */
  989. int
  990. pduSMTPRecMailTable_handler(
  991. netsnmp_mib_handler *handler,
  992. netsnmp_handler_registration *reginfo,
  993. netsnmp_agent_request_info *reqinfo,
  994. netsnmp_request_info *requests) {
  995. /* perform anything here that you need to do. The requests have
  996. already been processed by the master table_dataset handler, but
  997. this gives you chance to act on the request in some other way
  998. if need be. */
  999. return SNMP_ERR_NOERROR;
  1000. }
  1001. /** handles requests for the pduMessageNumTable table, if anything else needs to be done */
  1002. int
  1003. pduMessageNumTable_handler(
  1004. netsnmp_mib_handler *handler,
  1005. netsnmp_handler_registration *reginfo,
  1006. netsnmp_agent_request_info *reqinfo,
  1007. netsnmp_request_info *requests) {
  1008. /* perform anything here that you need to do. The requests have
  1009. already been processed by the master table_dataset handler, but
  1010. this gives you chance to act on the request in some other way
  1011. if need be. */
  1012. return SNMP_ERR_NOERROR;
  1013. }
  1014. /** handles requests for the pduMQTTBrokerTable table, if anything else needs to be done */
  1015. int
  1016. pduMQTTBrokerTable_handler(
  1017. netsnmp_mib_handler *handler,
  1018. netsnmp_handler_registration *reginfo,
  1019. netsnmp_agent_request_info *reqinfo,
  1020. netsnmp_request_info *requests) {
  1021. /* perform anything here that you need to do. The requests have
  1022. already been processed by the master table_dataset handler, but
  1023. this gives you chance to act on the request in some other way
  1024. if need be. */
  1025. return SNMP_ERR_NOERROR;
  1026. }
  1027. /** handles requests for the pduCloudServerTable table, if anything else needs to be done */
  1028. int
  1029. pduCloudServerTable_handler(
  1030. netsnmp_mib_handler *handler,
  1031. netsnmp_handler_registration *reginfo,
  1032. netsnmp_agent_request_info *reqinfo,
  1033. netsnmp_request_info *requests) {
  1034. /* perform anything here that you need to do. The requests have
  1035. already been processed by the master table_dataset handler, but
  1036. this gives you chance to act on the request in some other way
  1037. if need be. */
  1038. return SNMP_ERR_NOERROR;
  1039. }
  1040. /** handles requests for the pduAlarmHistoryTable table, if anything else needs to be done */
  1041. int
  1042. pduAlarmHistoryTable_handler(
  1043. netsnmp_mib_handler *handler,
  1044. netsnmp_handler_registration *reginfo,
  1045. netsnmp_agent_request_info *reqinfo,
  1046. netsnmp_request_info *requests) {
  1047. /* perform anything here that you need to do. The requests have
  1048. already been processed by the master table_dataset handler, but
  1049. this gives you chance to act on the request in some other way
  1050. if need be. */
  1051. netsnmp_request_info *request;
  1052. netsnmp_table_request_info *table_info;
  1053. //
  1054. char buffer[16];
  1055. switch (reqinfo->mode)
  1056. {
  1057. case MODE_GET:
  1058. {
  1059. // 初始化表
  1060. int nAlarmNumber = 0;
  1061. _AlarmAckInfo _alarm_ack_info; // 填充数据
  1062. INIT_LIST_HEAD(&_alarm_ack_info.list);
  1063. // 查询数据库,最近的10个报警信息
  1064. char start_time[32] = {0};
  1065. char stop_time[32] = {0};
  1066. struct tm *t;
  1067. struct timeval tv;
  1068. gettimeofday(&tv, NULL);
  1069. t = localtime(&tv.tv_sec);
  1070. sprintf(stop_time, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, 23, 59, 59);
  1071. sprintf(start_time, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, 0, 0, 0);
  1072. int ret = dev_search_alarm_info(__globalDeviceManage.db,
  1073. __globalDeviceManage._globalDevInfo.product.id,
  1074. -1, start_time, stop_time,
  1075. 1, 10,
  1076. &_alarm_ack_info, &nAlarmNumber);
  1077. if (ret != 0)
  1078. {
  1079. log_e("get power alarm error.");
  1080. return SNMP_ERR_GENERR;
  1081. }
  1082. for (request = requests; request; request = request->next)
  1083. {
  1084. table_info = netsnmp_extract_table_info(request);
  1085. int nIndex = 1;
  1086. bool findinstance = false;
  1087. _AlarmAckInfo *_temp;
  1088. list_for_each_entry(_temp, &_alarm_ack_info.list, list)
  1089. {
  1090. if (nIndex < table_info->index_oid[0])
  1091. {
  1092. nIndex++;
  1093. continue;
  1094. }
  1095. if (!_temp)
  1096. {
  1097. break;
  1098. }
  1099. findinstance = true;
  1100. memset(buffer, 0, sizeof(buffer));
  1101. switch (table_info->colnum)
  1102. {
  1103. case COLUMN_PDUALARMID:
  1104. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, nIndex);
  1105. break;
  1106. case COLUMN_PDUALARMTYPE:
  1107. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, _temp->alarmType);
  1108. break;
  1109. case COLUMN_PDUALARMCONTEXT:
  1110. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, _temp->alarmContent, strlen(_temp->alarmContent));
  1111. break;
  1112. case COLUMN_PDUALARMACTION:
  1113. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, -1);
  1114. break;
  1115. case COLUMN_PDUALARMACTIONPARA:
  1116. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, -1);
  1117. break;
  1118. case COLUMN_PDUALARMDATE:
  1119. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, _temp->alarmDate, strlen(_temp->alarmDate));
  1120. break;
  1121. case COLUMN_PDUALARMTIME:
  1122. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, _temp->alarmDate, strlen(_temp->alarmDate));
  1123. break;
  1124. default:
  1125. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  1126. break;
  1127. }
  1128. //}
  1129. break;
  1130. }
  1131. if (!findinstance)
  1132. {
  1133. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  1134. }
  1135. }
  1136. // 释放资源
  1137. if (0 == ret)
  1138. {
  1139. _AlarmAckInfo *node;
  1140. _AlarmAckInfo *next;
  1141. list_for_each_entry_safe(node, next, &_alarm_ack_info.list, list)
  1142. {
  1143. list_del(&node->list);
  1144. free(node);
  1145. }
  1146. }
  1147. }
  1148. break;
  1149. case MODE_SET_RESERVE1:
  1150. break;
  1151. case MODE_SET_RESERVE2:
  1152. break;
  1153. case MODE_SET_FREE:
  1154. break;
  1155. case MODE_SET_ACTION:
  1156. break;
  1157. case MODE_SET_UNDO:
  1158. break;
  1159. case MODE_SET_COMMIT:
  1160. break;
  1161. default:
  1162. /* we should never get here, so this is a really bad error */
  1163. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
  1164. return SNMP_ERR_GENERR;
  1165. }
  1166. return SNMP_ERR_NOERROR;
  1167. }
  1168. /** handles requests for the pduChannelLimitTable table, if anything else needs to be done */
  1169. int
  1170. pduChannelLimitTable_handler(
  1171. netsnmp_mib_handler *handler,
  1172. netsnmp_handler_registration *reginfo,
  1173. netsnmp_agent_request_info *reqinfo,
  1174. netsnmp_request_info *requests) {
  1175. /* perform anything here that you need to do. The requests have
  1176. already been processed by the master table_dataset handler, but
  1177. this gives you chance to act on the request in some other way
  1178. if need be. */
  1179. netsnmp_request_info *request;
  1180. netsnmp_table_request_info *table_info;
  1181. GlobalPowerManger *iterator = NULL;
  1182. //
  1183. char buffer[16];
  1184. switch (reqinfo->mode)
  1185. {
  1186. case MODE_GET:
  1187. for (request = requests; request; request = request->next)
  1188. {
  1189. table_info = netsnmp_extract_table_info(request);
  1190. int nIndex = 1;
  1191. bool findinstance = false;
  1192. list_for_each_entry(iterator, &__globalDeviceManage._globalPowerManger.list, list)
  1193. {
  1194. if (nIndex < table_info->index_oid[0])
  1195. {
  1196. nIndex++;
  1197. continue;
  1198. }
  1199. if (!iterator)
  1200. {
  1201. break;
  1202. }
  1203. findinstance = true;
  1204. memset(buffer, 0, sizeof(buffer));
  1205. switch (table_info->colnum)
  1206. {
  1207. case COLUMN_PDUCHANNELLIMITID:
  1208. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->product_ch_id);
  1209. break;
  1210. case COLUMN_PDUCHANNELLIMITNAME:
  1211. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, iterator->product_ch_name, strlen(iterator->product_ch_name));
  1212. break;
  1213. case COLUMN_PDUCHANNELCURRENTLIMITUP:
  1214. sprintf(buffer, "%0.2f", iterator->global_over_manager.product_cur_upper_threshold);
  1215. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  1216. break;
  1217. case COLUMN_PDUCHANNELVOLTAGELIMITUP:
  1218. sprintf(buffer, "%0.2f", iterator->global_over_manager.product_vol_upper_threshold);
  1219. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  1220. break;
  1221. case COLUMN_PDUCHANNELVOLTAGELIMITDOWN:
  1222. sprintf(buffer, "%0.2f", iterator->global_over_manager.product_vol_lower_threshold);
  1223. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  1224. break;
  1225. case COLUMN_PDUCHANNELPOWERLIMITUP:
  1226. sprintf(buffer, "%0.2f", iterator->global_over_manager.product_pwr_upper_threshold);
  1227. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  1228. break;
  1229. case COLUMN_PDUCHANNELCONSUMPTIONLIMITUP:
  1230. sprintf(buffer, "%0.2f", iterator->global_over_manager.product_pwrcon_upper_threshold);
  1231. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
  1232. break;
  1233. default:
  1234. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  1235. break;
  1236. }
  1237. //}
  1238. break;
  1239. }
  1240. if (!findinstance)
  1241. {
  1242. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  1243. }
  1244. }
  1245. break;
  1246. case MODE_SET_RESERVE1:
  1247. break;
  1248. case MODE_SET_RESERVE2:
  1249. break;
  1250. case MODE_SET_FREE:
  1251. break;
  1252. case MODE_SET_ACTION:
  1253. break;
  1254. case MODE_SET_UNDO:
  1255. break;
  1256. case MODE_SET_COMMIT:
  1257. break;
  1258. default:
  1259. /* we should never get here, so this is a really bad error */
  1260. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
  1261. return SNMP_ERR_GENERR;
  1262. }
  1263. return SNMP_ERR_NOERROR;
  1264. }
  1265. /** handles requests for the pduSensorLimitTable table, if anything else needs to be done */
  1266. int
  1267. pduSensorLimitTable_handler(
  1268. netsnmp_mib_handler *handler,
  1269. netsnmp_handler_registration *reginfo,
  1270. netsnmp_agent_request_info *reqinfo,
  1271. netsnmp_request_info *requests) {
  1272. /* perform anything here that you need to do. The requests have
  1273. already been processed by the master table_dataset handler, but
  1274. this gives you chance to act on the request in some other way
  1275. if need be. */
  1276. netsnmp_request_info *request;
  1277. netsnmp_table_request_info *table_info;
  1278. GlobalSensorManger *iterator = NULL;
  1279. //
  1280. char buffer[16];
  1281. switch (reqinfo->mode)
  1282. {
  1283. case MODE_GET:
  1284. for (request = requests; request; request = request->next)
  1285. {
  1286. table_info = netsnmp_extract_table_info(request);
  1287. int nIndex = table_info->index_oid[0];
  1288. bool findinstance = false;
  1289. list_for_each_entry(iterator, &__globalDeviceManage._globalSensorManger.list, list)
  1290. {
  1291. if (!iterator || nIndex != iterator->sensor_id)
  1292. {
  1293. continue;
  1294. }
  1295. findinstance = true;
  1296. memset(buffer, 0, sizeof(buffer));
  1297. switch (table_info->colnum)
  1298. {
  1299. case COLUMN_PDUSENSORLIMITID:
  1300. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_id);
  1301. break;
  1302. case COLUMN_PDUSENSORLIMITNAME:
  1303. snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, iterator->sensor_name, strlen(iterator->sensor_name));
  1304. break;
  1305. case COLUMN_PDUSENSORLIMITVALUE1UP:
  1306. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->over_manager.sensor_val1_upper_threshold);
  1307. break;
  1308. case COLUMN_PDUSENSORLIMITVALUE2UP:
  1309. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->over_manager.sensor_val2_upper_threshold);
  1310. break;
  1311. case COLUMN_PDUSENSORLIMITVALUE1DOWN:
  1312. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->over_manager.sensor_val1_lower_threshold);
  1313. break;
  1314. case COLUMN_PDUSENSORLIMITVALUE2DOWN:
  1315. snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->over_manager.sensor_val2_lower_threshold);
  1316. break;
  1317. default:
  1318. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  1319. break;
  1320. }
  1321. //}
  1322. break;
  1323. }
  1324. if (!findinstance)
  1325. {
  1326. netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
  1327. }
  1328. }
  1329. break;
  1330. case MODE_SET_RESERVE1:
  1331. break;
  1332. case MODE_SET_RESERVE2:
  1333. break;
  1334. case MODE_SET_FREE:
  1335. break;
  1336. case MODE_SET_ACTION:
  1337. break;
  1338. case MODE_SET_UNDO:
  1339. break;
  1340. case MODE_SET_COMMIT:
  1341. break;
  1342. default:
  1343. /* we should never get here, so this is a really bad error */
  1344. snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
  1345. return SNMP_ERR_GENERR;
  1346. }
  1347. return SNMP_ERR_NOERROR;
  1348. }