freeipmi_plugin.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. /*
  3. * netdata freeipmi.plugin
  4. * Copyright (C) 2017 Costa Tsaousis
  5. * GPL v3+
  6. *
  7. * Based on:
  8. * ipmimonitoring-sensors.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
  9. * ipmimonitoring-sel.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
  10. *
  11. * Copyright (C) 2007-2015 Lawrence Livermore National Security, LLC.
  12. * Copyright (C) 2006-2007 The Regents of the University of California.
  13. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  14. * Written by Albert Chu <chu11@llnl.gov>
  15. * UCRL-CODE-222073
  16. */
  17. #include "../../libnetdata/libnetdata.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. #include <errno.h>
  24. #include <unistd.h>
  25. #include <sys/time.h>
  26. #ifdef HAVE_FREEIPMI
  27. #define IPMI_PARSE_DEVICE_LAN_STR "lan"
  28. #define IPMI_PARSE_DEVICE_LAN_2_0_STR "lan_2_0"
  29. #define IPMI_PARSE_DEVICE_LAN_2_0_STR2 "lan20"
  30. #define IPMI_PARSE_DEVICE_LAN_2_0_STR3 "lan_20"
  31. #define IPMI_PARSE_DEVICE_LAN_2_0_STR4 "lan2_0"
  32. #define IPMI_PARSE_DEVICE_LAN_2_0_STR5 "lanplus"
  33. #define IPMI_PARSE_DEVICE_KCS_STR "kcs"
  34. #define IPMI_PARSE_DEVICE_SSIF_STR "ssif"
  35. #define IPMI_PARSE_DEVICE_OPENIPMI_STR "openipmi"
  36. #define IPMI_PARSE_DEVICE_OPENIPMI_STR2 "open"
  37. #define IPMI_PARSE_DEVICE_SUNBMC_STR "sunbmc"
  38. #define IPMI_PARSE_DEVICE_SUNBMC_STR2 "bmc"
  39. #define IPMI_PARSE_DEVICE_INTELDCMI_STR "inteldcmi"
  40. // ----------------------------------------------------------------------------
  41. // callback required by fatal()
  42. void netdata_cleanup_and_exit(int ret) {
  43. exit(ret);
  44. }
  45. void send_statistics( const char *action, const char *action_result, const char *action_data) {
  46. (void)action;
  47. (void)action_result;
  48. (void)action_data;
  49. return;
  50. }
  51. // callbacks required by popen()
  52. void signals_block(void) {};
  53. void signals_unblock(void) {};
  54. void signals_reset(void) {};
  55. // callback required by eval()
  56. int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
  57. (void)variable;
  58. (void)hash;
  59. (void)rc;
  60. (void)result;
  61. return 0;
  62. };
  63. // required by get_system_cpus()
  64. char *netdata_configured_host_prefix = "";
  65. // ----------------------------------------------------------------------------
  66. #include <ipmi_monitoring.h>
  67. #include <ipmi_monitoring_bitmasks.h>
  68. /* Communication Configuration - Initialize accordingly */
  69. /* Hostname, NULL for In-band communication, non-null for a hostname */
  70. char *hostname = NULL;
  71. /* In-band Communication Configuration */
  72. int driver_type = -1; // IPMI_MONITORING_DRIVER_TYPE_KCS; /* or -1 for default */
  73. int disable_auto_probe = 0; /* probe for in-band device */
  74. unsigned int driver_address = 0; /* not used if probing */
  75. unsigned int register_spacing = 0; /* not used if probing */
  76. char *driver_device = NULL; /* not used if probing */
  77. /* Out-of-band Communication Configuration */
  78. int protocol_version = -1; //IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */
  79. char *username = "foousername";
  80. char *password = "foopassword";
  81. unsigned char *ipmi_k_g = NULL;
  82. unsigned int ipmi_k_g_len = 0;
  83. int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */
  84. int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */
  85. int cipher_suite_id = 0; /* or -1 for default */
  86. int session_timeout = 0; /* 0 for default */
  87. int retransmission_timeout = 0; /* 0 for default */
  88. /* Workarounds - specify workaround flags if necessary */
  89. unsigned int workaround_flags = 0;
  90. /* Initialize w/ record id numbers to only monitor specific record ids */
  91. unsigned int record_ids[] = {0};
  92. unsigned int record_ids_length = 0;
  93. /* Initialize w/ sensor types to only monitor specific sensor types
  94. * see ipmi_monitoring.h sensor types list.
  95. */
  96. unsigned int sensor_types[] = {0};
  97. unsigned int sensor_types_length = 0;
  98. /* Set to an appropriate alternate if desired */
  99. char *sdr_cache_directory = "/tmp";
  100. char *sensor_config_file = NULL;
  101. /* Set to 1 or 0 to enable these sensor reading flags
  102. * - See ipmi_monitoring.h for descriptions of these flags.
  103. */
  104. int reread_sdr_cache = 0;
  105. int ignore_non_interpretable_sensors = 0;
  106. int bridge_sensors = 0;
  107. int interpret_oem_data = 0;
  108. int shared_sensors = 0;
  109. int discrete_reading = 1;
  110. int ignore_scanning_disabled = 0;
  111. int assume_bmc_owner = 0;
  112. int entity_sensor_names = 0;
  113. /* Initialization flags
  114. *
  115. * Most commonly bitwise OR IPMI_MONITORING_FLAGS_DEBUG and/or
  116. * IPMI_MONITORING_FLAGS_DEBUG_IPMI_PACKETS for extra debugging
  117. * information.
  118. */
  119. unsigned int ipmimonitoring_init_flags = 0;
  120. int errnum;
  121. // ----------------------------------------------------------------------------
  122. // SEL only variables
  123. /* Initialize w/ date range to only monitoring specific date range */
  124. char *date_begin = NULL; /* use MM/DD/YYYY format */
  125. char *date_end = NULL; /* use MM/DD/YYYY format */
  126. int assume_system_event_record = 0;
  127. char *sel_config_file = NULL;
  128. // ----------------------------------------------------------------------------
  129. // functions common to sensors and SEL
  130. static void
  131. _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config)
  132. {
  133. assert (ipmi_config);
  134. ipmi_config->driver_type = driver_type;
  135. ipmi_config->disable_auto_probe = disable_auto_probe;
  136. ipmi_config->driver_address = driver_address;
  137. ipmi_config->register_spacing = register_spacing;
  138. ipmi_config->driver_device = driver_device;
  139. ipmi_config->protocol_version = protocol_version;
  140. ipmi_config->username = username;
  141. ipmi_config->password = password;
  142. ipmi_config->k_g = ipmi_k_g;
  143. ipmi_config->k_g_len = ipmi_k_g_len;
  144. ipmi_config->privilege_level = privilege_level;
  145. ipmi_config->authentication_type = authentication_type;
  146. ipmi_config->cipher_suite_id = cipher_suite_id;
  147. ipmi_config->session_timeout_len = session_timeout;
  148. ipmi_config->retransmission_timeout_len = retransmission_timeout;
  149. ipmi_config->workaround_flags = workaround_flags;
  150. }
  151. #ifdef NETDATA_COMMENTED
  152. static const char *
  153. _get_sensor_type_string (int sensor_type)
  154. {
  155. switch (sensor_type)
  156. {
  157. case IPMI_MONITORING_SENSOR_TYPE_RESERVED:
  158. return ("Reserved");
  159. case IPMI_MONITORING_SENSOR_TYPE_TEMPERATURE:
  160. return ("Temperature");
  161. case IPMI_MONITORING_SENSOR_TYPE_VOLTAGE:
  162. return ("Voltage");
  163. case IPMI_MONITORING_SENSOR_TYPE_CURRENT:
  164. return ("Current");
  165. case IPMI_MONITORING_SENSOR_TYPE_FAN:
  166. return ("Fan");
  167. case IPMI_MONITORING_SENSOR_TYPE_PHYSICAL_SECURITY:
  168. return ("Physical Security");
  169. case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_SECURITY_VIOLATION_ATTEMPT:
  170. return ("Platform Security Violation Attempt");
  171. case IPMI_MONITORING_SENSOR_TYPE_PROCESSOR:
  172. return ("Processor");
  173. case IPMI_MONITORING_SENSOR_TYPE_POWER_SUPPLY:
  174. return ("Power Supply");
  175. case IPMI_MONITORING_SENSOR_TYPE_POWER_UNIT:
  176. return ("Power Unit");
  177. case IPMI_MONITORING_SENSOR_TYPE_COOLING_DEVICE:
  178. return ("Cooling Device");
  179. case IPMI_MONITORING_SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR:
  180. return ("Other Units Based Sensor");
  181. case IPMI_MONITORING_SENSOR_TYPE_MEMORY:
  182. return ("Memory");
  183. case IPMI_MONITORING_SENSOR_TYPE_DRIVE_SLOT:
  184. return ("Drive Slot");
  185. case IPMI_MONITORING_SENSOR_TYPE_POST_MEMORY_RESIZE:
  186. return ("POST Memory Resize");
  187. case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS:
  188. return ("System Firmware Progress");
  189. case IPMI_MONITORING_SENSOR_TYPE_EVENT_LOGGING_DISABLED:
  190. return ("Event Logging Disabled");
  191. case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG1:
  192. return ("Watchdog 1");
  193. case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_EVENT:
  194. return ("System Event");
  195. case IPMI_MONITORING_SENSOR_TYPE_CRITICAL_INTERRUPT:
  196. return ("Critical Interrupt");
  197. case IPMI_MONITORING_SENSOR_TYPE_BUTTON_SWITCH:
  198. return ("Button/Switch");
  199. case IPMI_MONITORING_SENSOR_TYPE_MODULE_BOARD:
  200. return ("Module/Board");
  201. case IPMI_MONITORING_SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR:
  202. return ("Microcontroller/Coprocessor");
  203. case IPMI_MONITORING_SENSOR_TYPE_ADD_IN_CARD:
  204. return ("Add In Card");
  205. case IPMI_MONITORING_SENSOR_TYPE_CHASSIS:
  206. return ("Chassis");
  207. case IPMI_MONITORING_SENSOR_TYPE_CHIP_SET:
  208. return ("Chip Set");
  209. case IPMI_MONITORING_SENSOR_TYPE_OTHER_FRU:
  210. return ("Other Fru");
  211. case IPMI_MONITORING_SENSOR_TYPE_CABLE_INTERCONNECT:
  212. return ("Cable/Interconnect");
  213. case IPMI_MONITORING_SENSOR_TYPE_TERMINATOR:
  214. return ("Terminator");
  215. case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_BOOT_INITIATED:
  216. return ("System Boot Initiated");
  217. case IPMI_MONITORING_SENSOR_TYPE_BOOT_ERROR:
  218. return ("Boot Error");
  219. case IPMI_MONITORING_SENSOR_TYPE_OS_BOOT:
  220. return ("OS Boot");
  221. case IPMI_MONITORING_SENSOR_TYPE_OS_CRITICAL_STOP:
  222. return ("OS Critical Stop");
  223. case IPMI_MONITORING_SENSOR_TYPE_SLOT_CONNECTOR:
  224. return ("Slot/Connector");
  225. case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE:
  226. return ("System ACPI Power State");
  227. case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG2:
  228. return ("Watchdog 2");
  229. case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_ALERT:
  230. return ("Platform Alert");
  231. case IPMI_MONITORING_SENSOR_TYPE_ENTITY_PRESENCE:
  232. return ("Entity Presence");
  233. case IPMI_MONITORING_SENSOR_TYPE_MONITOR_ASIC_IC:
  234. return ("Monitor ASIC/IC");
  235. case IPMI_MONITORING_SENSOR_TYPE_LAN:
  236. return ("LAN");
  237. case IPMI_MONITORING_SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH:
  238. return ("Management Subsystem Health");
  239. case IPMI_MONITORING_SENSOR_TYPE_BATTERY:
  240. return ("Battery");
  241. case IPMI_MONITORING_SENSOR_TYPE_SESSION_AUDIT:
  242. return ("Session Audit");
  243. case IPMI_MONITORING_SENSOR_TYPE_VERSION_CHANGE:
  244. return ("Version Change");
  245. case IPMI_MONITORING_SENSOR_TYPE_FRU_STATE:
  246. return ("FRU State");
  247. }
  248. return ("Unrecognized");
  249. }
  250. #endif // NETDATA_COMMENTED
  251. // ----------------------------------------------------------------------------
  252. // BEGIN NETDATA CODE
  253. static int debug = 0;
  254. static int netdata_update_every = 5; // this is the minimum update frequency
  255. static int netdata_priority = 90000;
  256. static int netdata_do_sel = 1;
  257. static size_t netdata_sensors_updated = 0;
  258. static size_t netdata_sensors_collected = 0;
  259. static size_t netdata_sel_events = 0;
  260. static size_t netdata_sensors_states_nominal = 0;
  261. static size_t netdata_sensors_states_warning = 0;
  262. static size_t netdata_sensors_states_critical = 0;
  263. struct sensor {
  264. int record_id;
  265. int sensor_number;
  266. int sensor_type;
  267. int sensor_state;
  268. int sensor_units;
  269. char *sensor_name;
  270. int sensor_reading_type;
  271. union {
  272. uint8_t bool_value;
  273. uint32_t uint32_value;
  274. double double_value;
  275. } sensor_reading;
  276. int sent;
  277. int ignore;
  278. int exposed;
  279. int updated;
  280. struct sensor *next;
  281. } *sensors_root = NULL;
  282. static void netdata_mark_as_not_updated() {
  283. struct sensor *sn;
  284. for(sn = sensors_root; sn ;sn = sn->next)
  285. sn->updated = sn->sent = 0;
  286. netdata_sensors_updated = 0;
  287. netdata_sensors_collected = 0;
  288. netdata_sel_events = 0;
  289. netdata_sensors_states_nominal = 0;
  290. netdata_sensors_states_warning = 0;
  291. netdata_sensors_states_critical = 0;
  292. }
  293. static void send_chart_to_netdata_for_units(int units) {
  294. struct sensor *sn;
  295. switch(units) {
  296. case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
  297. printf("CHART ipmi.temperatures_c '' 'System Celsius Temperatures read by IPMI' 'Celsius' 'temperatures' 'ipmi.temperatures_c' 'line' %d %d\n"
  298. , netdata_priority + 10
  299. , netdata_update_every
  300. );
  301. break;
  302. case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
  303. printf("CHART ipmi.temperatures_f '' 'System Fahrenheit Temperatures read by IPMI' 'Fahrenheit' 'temperatures' 'ipmi.temperatures_f' 'line' %d %d\n"
  304. , netdata_priority + 11
  305. , netdata_update_every
  306. );
  307. break;
  308. case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
  309. printf("CHART ipmi.volts '' 'System Voltages read by IPMI' 'Volts' 'voltages' 'ipmi.voltages' 'line' %d %d\n"
  310. , netdata_priority + 12
  311. , netdata_update_every
  312. );
  313. break;
  314. case IPMI_MONITORING_SENSOR_UNITS_AMPS:
  315. printf("CHART ipmi.amps '' 'System Current read by IPMI' 'Amps' 'current' 'ipmi.amps' 'line' %d %d\n"
  316. , netdata_priority + 13
  317. , netdata_update_every
  318. );
  319. break;
  320. case IPMI_MONITORING_SENSOR_UNITS_RPM:
  321. printf("CHART ipmi.rpm '' 'System Fans read by IPMI' 'RPM' 'fans' 'ipmi.rpm' 'line' %d %d\n"
  322. , netdata_priority + 14
  323. , netdata_update_every
  324. );
  325. break;
  326. case IPMI_MONITORING_SENSOR_UNITS_WATTS:
  327. printf("CHART ipmi.watts '' 'System Power read by IPMI' 'Watts' 'power' 'ipmi.watts' 'line' %d %d\n"
  328. , netdata_priority + 5
  329. , netdata_update_every
  330. );
  331. break;
  332. case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
  333. printf("CHART ipmi.percent '' 'System Metrics read by IPMI' '%%' 'other' 'ipmi.percent' 'line' %d %d\n"
  334. , netdata_priority + 15
  335. , netdata_update_every
  336. );
  337. break;
  338. default:
  339. for(sn = sensors_root; sn; sn = sn->next)
  340. if(sn->sensor_units == units)
  341. sn->ignore = 1;
  342. return;
  343. }
  344. for(sn = sensors_root; sn; sn = sn->next) {
  345. if(sn->sensor_units == units && sn->updated && !sn->ignore) {
  346. sn->exposed = 1;
  347. switch(sn->sensor_reading_type) {
  348. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  349. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  350. printf("DIMENSION i%d_n%d_r%d '%s i%d' absolute 1 1\n"
  351. , sn->sensor_number
  352. , sn->record_id
  353. , sn->sensor_reading_type
  354. , sn->sensor_name
  355. , sn->sensor_number
  356. );
  357. break;
  358. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  359. printf("DIMENSION i%d_n%d_r%d '%s i%d' absolute 1 1000\n"
  360. , sn->sensor_number
  361. , sn->record_id
  362. , sn->sensor_reading_type
  363. , sn->sensor_name
  364. , sn->sensor_number
  365. );
  366. break;
  367. default:
  368. sn->ignore = 1;
  369. break;
  370. }
  371. }
  372. }
  373. }
  374. static void send_metrics_to_netdata_for_units(int units) {
  375. struct sensor *sn;
  376. switch(units) {
  377. case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
  378. printf("BEGIN ipmi.temperatures_c\n");
  379. break;
  380. case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
  381. printf("BEGIN ipmi.temperatures_f\n");
  382. break;
  383. case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
  384. printf("BEGIN ipmi.volts\n");
  385. break;
  386. case IPMI_MONITORING_SENSOR_UNITS_AMPS:
  387. printf("BEGIN ipmi.amps\n");
  388. break;
  389. case IPMI_MONITORING_SENSOR_UNITS_RPM:
  390. printf("BEGIN ipmi.rpm\n");
  391. break;
  392. case IPMI_MONITORING_SENSOR_UNITS_WATTS:
  393. printf("BEGIN ipmi.watts\n");
  394. break;
  395. case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
  396. printf("BEGIN ipmi.percent\n");
  397. break;
  398. default:
  399. for(sn = sensors_root; sn; sn = sn->next)
  400. if(sn->sensor_units == units)
  401. sn->ignore = 1;
  402. return;
  403. }
  404. for(sn = sensors_root; sn; sn = sn->next) {
  405. if(sn->sensor_units == units && sn->updated && !sn->sent && !sn->ignore) {
  406. netdata_sensors_updated++;
  407. sn->sent = 1;
  408. switch(sn->sensor_reading_type) {
  409. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  410. printf("SET i%d_n%d_r%d = %u\n"
  411. , sn->sensor_number
  412. , sn->record_id
  413. , sn->sensor_reading_type
  414. , sn->sensor_reading.bool_value
  415. );
  416. break;
  417. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  418. printf("SET i%d_n%d_r%d = %u\n"
  419. , sn->sensor_number
  420. , sn->record_id
  421. , sn->sensor_reading_type
  422. , sn->sensor_reading.uint32_value
  423. );
  424. break;
  425. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  426. printf("SET i%d_n%d_r%d = %lld\n"
  427. , sn->sensor_number
  428. , sn->record_id
  429. , sn->sensor_reading_type
  430. , (long long int)(sn->sensor_reading.double_value * 1000)
  431. );
  432. break;
  433. default:
  434. sn->ignore = 1;
  435. break;
  436. }
  437. }
  438. }
  439. printf("END\n");
  440. }
  441. static void send_metrics_to_netdata() {
  442. static int sel_chart_generated = 0, sensors_states_chart_generated = 0;
  443. struct sensor *sn;
  444. if(netdata_do_sel && !sel_chart_generated) {
  445. sel_chart_generated = 1;
  446. printf("CHART ipmi.events '' 'IPMI Events' 'events' 'events' ipmi.sel area %d %d\n"
  447. , netdata_priority + 2
  448. , netdata_update_every
  449. );
  450. printf("DIMENSION events '' absolute 1 1\n");
  451. }
  452. if(!sensors_states_chart_generated) {
  453. sensors_states_chart_generated = 1;
  454. printf("CHART ipmi.sensors_states '' 'IPMI Sensors State' 'sensors' 'states' ipmi.sensors_states line %d %d\n"
  455. , netdata_priority + 1
  456. , netdata_update_every
  457. );
  458. printf("DIMENSION nominal '' absolute 1 1\n");
  459. printf("DIMENSION critical '' absolute 1 1\n");
  460. printf("DIMENSION warning '' absolute 1 1\n");
  461. }
  462. // generate the CHART/DIMENSION lines, if we have to
  463. for(sn = sensors_root; sn; sn = sn->next)
  464. if(sn->updated && !sn->exposed && !sn->ignore)
  465. send_chart_to_netdata_for_units(sn->sensor_units);
  466. if(netdata_do_sel) {
  467. printf(
  468. "BEGIN ipmi.events\n"
  469. "SET events = %zu\n"
  470. "END\n"
  471. , netdata_sel_events
  472. );
  473. }
  474. printf(
  475. "BEGIN ipmi.sensors_states\n"
  476. "SET nominal = %zu\n"
  477. "SET warning = %zu\n"
  478. "SET critical = %zu\n"
  479. "END\n"
  480. , netdata_sensors_states_nominal
  481. , netdata_sensors_states_warning
  482. , netdata_sensors_states_critical
  483. );
  484. // send metrics to netdata
  485. for(sn = sensors_root; sn; sn = sn->next)
  486. if(sn->updated && sn->exposed && !sn->sent && !sn->ignore)
  487. send_metrics_to_netdata_for_units(sn->sensor_units);
  488. }
  489. static int *excluded_record_ids = NULL;
  490. size_t excluded_record_ids_length = 0;
  491. static void excluded_record_ids_parse(const char *s) {
  492. if(!s) return;
  493. while(*s) {
  494. while(*s && !isdigit(*s)) s++;
  495. if(isdigit(*s)) {
  496. char *e;
  497. unsigned long n = strtoul(s, &e, 10);
  498. s = e;
  499. if(n != 0) {
  500. excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int));
  501. if(!excluded_record_ids) {
  502. fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
  503. exit(1);
  504. }
  505. excluded_record_ids[excluded_record_ids_length++] = (int)n;
  506. }
  507. }
  508. }
  509. if(debug) {
  510. fprintf(stderr, "freeipmi.plugin: excluded record ids:");
  511. size_t i;
  512. for(i = 0; i < excluded_record_ids_length; i++) {
  513. fprintf(stderr, " %d", excluded_record_ids[i]);
  514. }
  515. fprintf(stderr, "\n");
  516. }
  517. }
  518. static int *excluded_status_record_ids = NULL;
  519. size_t excluded_status_record_ids_length = 0;
  520. static void excluded_status_record_ids_parse(const char *s) {
  521. if(!s) return;
  522. while(*s) {
  523. while(*s && !isdigit(*s)) s++;
  524. if(isdigit(*s)) {
  525. char *e;
  526. unsigned long n = strtoul(s, &e, 10);
  527. s = e;
  528. if(n != 0) {
  529. excluded_status_record_ids = realloc(excluded_status_record_ids, (excluded_status_record_ids_length + 1) * sizeof(int));
  530. if(!excluded_status_record_ids) {
  531. fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
  532. exit(1);
  533. }
  534. excluded_status_record_ids[excluded_status_record_ids_length++] = (int)n;
  535. }
  536. }
  537. }
  538. if(debug) {
  539. fprintf(stderr, "freeipmi.plugin: excluded status record ids:");
  540. size_t i;
  541. for(i = 0; i < excluded_status_record_ids_length; i++) {
  542. fprintf(stderr, " %d", excluded_status_record_ids[i]);
  543. }
  544. fprintf(stderr, "\n");
  545. }
  546. }
  547. static int excluded_record_ids_check(int record_id) {
  548. size_t i;
  549. for(i = 0; i < excluded_record_ids_length; i++) {
  550. if(excluded_record_ids[i] == record_id)
  551. return 1;
  552. }
  553. return 0;
  554. }
  555. static int excluded_status_record_ids_check(int record_id) {
  556. size_t i;
  557. for(i = 0; i < excluded_status_record_ids_length; i++) {
  558. if(excluded_status_record_ids[i] == record_id)
  559. return 1;
  560. }
  561. return 0;
  562. }
  563. static void netdata_get_sensor(
  564. int record_id
  565. , int sensor_number
  566. , int sensor_type
  567. , int sensor_state
  568. , int sensor_units
  569. , int sensor_reading_type
  570. , char *sensor_name
  571. , void *sensor_reading
  572. ) {
  573. // find the sensor record
  574. struct sensor *sn;
  575. for(sn = sensors_root; sn ;sn = sn->next)
  576. if( sn->record_id == record_id &&
  577. sn->sensor_number == sensor_number &&
  578. sn->sensor_reading_type == sensor_reading_type &&
  579. sn->sensor_units == sensor_units &&
  580. !strcmp(sn->sensor_name, sensor_name)
  581. )
  582. break;
  583. if(!sn) {
  584. // not found, create it
  585. // check if it is excluded
  586. if(excluded_record_ids_check(record_id)) {
  587. if(debug) fprintf(stderr, "Sensor '%s' is excluded by excluded_record_ids_check()\n", sensor_name);
  588. return;
  589. }
  590. if(debug) fprintf(stderr, "Allocating new sensor data record for sensor '%s', id %d, number %d, type %d, state %d, units %d, reading_type %d\n", sensor_name, record_id, sensor_number, sensor_type, sensor_state, sensor_units, sensor_reading_type);
  591. sn = calloc(1, sizeof(struct sensor));
  592. if(!sn) {
  593. fatal("cannot allocate %zu bytes of memory.", sizeof(struct sensor));
  594. }
  595. sn->record_id = record_id;
  596. sn->sensor_number = sensor_number;
  597. sn->sensor_type = sensor_type;
  598. sn->sensor_state = sensor_state;
  599. sn->sensor_units = sensor_units;
  600. sn->sensor_reading_type = sensor_reading_type;
  601. sn->sensor_name = strdup(sensor_name);
  602. if(!sn->sensor_name) {
  603. fatal("cannot allocate %zu bytes of memory.", strlen(sensor_name));
  604. }
  605. sn->next = sensors_root;
  606. sensors_root = sn;
  607. }
  608. else {
  609. if(debug) fprintf(stderr, "Reusing sensor record for sensor '%s', id %d, number %d, type %d, state %d, units %d, reading_type %d\n", sensor_name, record_id, sensor_number, sensor_type, sensor_state, sensor_units, sensor_reading_type);
  610. }
  611. switch(sensor_reading_type) {
  612. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  613. sn->sensor_reading.bool_value = *((uint8_t *)sensor_reading);
  614. sn->updated = 1;
  615. netdata_sensors_collected++;
  616. break;
  617. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  618. sn->sensor_reading.uint32_value = *((uint32_t *)sensor_reading);
  619. sn->updated = 1;
  620. netdata_sensors_collected++;
  621. break;
  622. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  623. sn->sensor_reading.double_value = *((double *)sensor_reading);
  624. sn->updated = 1;
  625. netdata_sensors_collected++;
  626. break;
  627. default:
  628. if(debug) fprintf(stderr, "Unknown reading type - Ignoring sensor record for sensor '%s', id %d, number %d, type %d, state %d, units %d, reading_type %d\n", sensor_name, record_id, sensor_number, sensor_type, sensor_state, sensor_units, sensor_reading_type);
  629. sn->ignore = 1;
  630. break;
  631. }
  632. // check if it is excluded
  633. if(excluded_status_record_ids_check(record_id)) {
  634. if(debug) fprintf(stderr, "Sensor '%s' is excluded for status check, by excluded_status_record_ids_check()\n", sensor_name);
  635. return;
  636. }
  637. switch(sensor_state) {
  638. case IPMI_MONITORING_STATE_NOMINAL:
  639. netdata_sensors_states_nominal++;
  640. break;
  641. case IPMI_MONITORING_STATE_WARNING:
  642. netdata_sensors_states_warning++;
  643. break;
  644. case IPMI_MONITORING_STATE_CRITICAL:
  645. netdata_sensors_states_critical++;
  646. break;
  647. default:
  648. break;
  649. }
  650. }
  651. static void netdata_get_sel(
  652. int record_id
  653. , int record_type_class
  654. , int sel_state
  655. ) {
  656. (void)record_id;
  657. (void)record_type_class;
  658. (void)sel_state;
  659. netdata_sel_events++;
  660. }
  661. // END NETDATA CODE
  662. // ----------------------------------------------------------------------------
  663. static int
  664. _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
  665. {
  666. ipmi_monitoring_ctx_t ctx = NULL;
  667. unsigned int sensor_reading_flags = 0;
  668. int i;
  669. int sensor_count;
  670. int rv = -1;
  671. if (!(ctx = ipmi_monitoring_ctx_create ())) {
  672. error("ipmi_monitoring_ctx_create()");
  673. goto cleanup;
  674. }
  675. if (sdr_cache_directory)
  676. {
  677. if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
  678. sdr_cache_directory) < 0)
  679. {
  680. error("ipmi_monitoring_ctx_sdr_cache_directory(): %s\n",
  681. ipmi_monitoring_ctx_errormsg (ctx));
  682. goto cleanup;
  683. }
  684. }
  685. /* Must call otherwise only default interpretations ever used */
  686. if (sensor_config_file)
  687. {
  688. if (ipmi_monitoring_ctx_sensor_config_file (ctx,
  689. sensor_config_file) < 0)
  690. {
  691. error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
  692. ipmi_monitoring_ctx_errormsg (ctx));
  693. goto cleanup;
  694. }
  695. }
  696. else
  697. {
  698. if (ipmi_monitoring_ctx_sensor_config_file (ctx, NULL) < 0)
  699. {
  700. error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
  701. ipmi_monitoring_ctx_errormsg (ctx));
  702. goto cleanup;
  703. }
  704. }
  705. if (reread_sdr_cache)
  706. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE;
  707. if (ignore_non_interpretable_sensors)
  708. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_NON_INTERPRETABLE_SENSORS;
  709. if (bridge_sensors)
  710. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_BRIDGE_SENSORS;
  711. if (interpret_oem_data)
  712. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_INTERPRET_OEM_DATA;
  713. if (shared_sensors)
  714. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_SHARED_SENSORS;
  715. if (discrete_reading)
  716. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING;
  717. if (ignore_scanning_disabled)
  718. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_SCANNING_DISABLED;
  719. if (assume_bmc_owner)
  720. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ASSUME_BMC_OWNER;
  721. #ifdef IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
  722. if (entity_sensor_names)
  723. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES;
  724. #endif // IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
  725. if (!record_ids_length && !sensor_types_length)
  726. {
  727. if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
  728. hostname,
  729. ipmi_config,
  730. sensor_reading_flags,
  731. NULL,
  732. 0,
  733. NULL,
  734. NULL)) < 0)
  735. {
  736. error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
  737. ipmi_monitoring_ctx_errormsg (ctx));
  738. goto cleanup;
  739. }
  740. }
  741. else if (record_ids_length)
  742. {
  743. if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
  744. hostname,
  745. ipmi_config,
  746. sensor_reading_flags,
  747. record_ids,
  748. record_ids_length,
  749. NULL,
  750. NULL)) < 0)
  751. {
  752. error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
  753. ipmi_monitoring_ctx_errormsg (ctx));
  754. goto cleanup;
  755. }
  756. }
  757. else
  758. {
  759. if ((sensor_count = ipmi_monitoring_sensor_readings_by_sensor_type (ctx,
  760. hostname,
  761. ipmi_config,
  762. sensor_reading_flags,
  763. sensor_types,
  764. sensor_types_length,
  765. NULL,
  766. NULL)) < 0)
  767. {
  768. error( "ipmi_monitoring_sensor_readings_by_sensor_type(): %s",
  769. ipmi_monitoring_ctx_errormsg (ctx));
  770. goto cleanup;
  771. }
  772. }
  773. #ifdef NETDATA_COMMENTED
  774. printf ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
  775. "Record ID",
  776. "Sensor Name",
  777. "Sensor Number",
  778. "Sensor Type",
  779. "Sensor State",
  780. "Sensor Reading",
  781. "Sensor Units",
  782. "Sensor Event/Reading Type Code",
  783. "Sensor Event Bitmask",
  784. "Sensor Event String");
  785. #endif // NETDATA_COMMENTED
  786. for (i = 0; i < sensor_count; i++, ipmi_monitoring_sensor_iterator_next (ctx))
  787. {
  788. int record_id, sensor_number, sensor_type, sensor_state, sensor_units,
  789. sensor_reading_type;
  790. #ifdef NETDATA_COMMENTED
  791. int sensor_bitmask_type, sensor_bitmask, event_reading_type_code;
  792. char **sensor_bitmask_strings = NULL;
  793. const char *sensor_type_str;
  794. const char *sensor_state_str;
  795. #endif // NETDATA_COMMENTED
  796. char *sensor_name = NULL;
  797. void *sensor_reading;
  798. if ((record_id = ipmi_monitoring_sensor_read_record_id (ctx)) < 0)
  799. {
  800. error( "ipmi_monitoring_sensor_read_record_id(): %s",
  801. ipmi_monitoring_ctx_errormsg (ctx));
  802. goto cleanup;
  803. }
  804. if ((sensor_number = ipmi_monitoring_sensor_read_sensor_number (ctx)) < 0)
  805. {
  806. error( "ipmi_monitoring_sensor_read_sensor_number(): %s",
  807. ipmi_monitoring_ctx_errormsg (ctx));
  808. goto cleanup;
  809. }
  810. if ((sensor_type = ipmi_monitoring_sensor_read_sensor_type (ctx)) < 0)
  811. {
  812. error( "ipmi_monitoring_sensor_read_sensor_type(): %s",
  813. ipmi_monitoring_ctx_errormsg (ctx));
  814. goto cleanup;
  815. }
  816. if (!(sensor_name = ipmi_monitoring_sensor_read_sensor_name (ctx)))
  817. {
  818. error( "ipmi_monitoring_sensor_read_sensor_name(): %s",
  819. ipmi_monitoring_ctx_errormsg (ctx));
  820. goto cleanup;
  821. }
  822. if ((sensor_state = ipmi_monitoring_sensor_read_sensor_state (ctx)) < 0)
  823. {
  824. error( "ipmi_monitoring_sensor_read_sensor_state(): %s",
  825. ipmi_monitoring_ctx_errormsg (ctx));
  826. goto cleanup;
  827. }
  828. if ((sensor_units = ipmi_monitoring_sensor_read_sensor_units (ctx)) < 0)
  829. {
  830. error( "ipmi_monitoring_sensor_read_sensor_units(): %s",
  831. ipmi_monitoring_ctx_errormsg (ctx));
  832. goto cleanup;
  833. }
  834. #ifdef NETDATA_COMMENTED
  835. if ((sensor_bitmask_type = ipmi_monitoring_sensor_read_sensor_bitmask_type (ctx)) < 0)
  836. {
  837. error( "ipmi_monitoring_sensor_read_sensor_bitmask_type(): %s",
  838. ipmi_monitoring_ctx_errormsg (ctx));
  839. goto cleanup;
  840. }
  841. if ((sensor_bitmask = ipmi_monitoring_sensor_read_sensor_bitmask (ctx)) < 0)
  842. {
  843. error(
  844. "ipmi_monitoring_sensor_read_sensor_bitmask(): %s",
  845. ipmi_monitoring_ctx_errormsg (ctx));
  846. goto cleanup;
  847. }
  848. /* it's ok for this to be NULL, i.e. sensor_bitmask ==
  849. * IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN
  850. */
  851. sensor_bitmask_strings = ipmi_monitoring_sensor_read_sensor_bitmask_strings (ctx);
  852. #endif // NETDATA_COMMENTED
  853. if ((sensor_reading_type = ipmi_monitoring_sensor_read_sensor_reading_type (ctx)) < 0)
  854. {
  855. error( "ipmi_monitoring_sensor_read_sensor_reading_type(): %s",
  856. ipmi_monitoring_ctx_errormsg (ctx));
  857. goto cleanup;
  858. }
  859. sensor_reading = ipmi_monitoring_sensor_read_sensor_reading (ctx);
  860. #ifdef NETDATA_COMMENTED
  861. if ((event_reading_type_code = ipmi_monitoring_sensor_read_event_reading_type_code (ctx)) < 0)
  862. {
  863. error( "ipmi_monitoring_sensor_read_event_reading_type_code(): %s",
  864. ipmi_monitoring_ctx_errormsg (ctx));
  865. goto cleanup;
  866. }
  867. #endif // NETDATA_COMMENTED
  868. netdata_get_sensor(
  869. record_id
  870. , sensor_number
  871. , sensor_type
  872. , sensor_state
  873. , sensor_units
  874. , sensor_reading_type
  875. , sensor_name
  876. , sensor_reading
  877. );
  878. #ifdef NETDATA_COMMENTED
  879. if (!strlen (sensor_name))
  880. sensor_name = "N/A";
  881. sensor_type_str = _get_sensor_type_string (sensor_type);
  882. printf ("%d, %s, %d, %s",
  883. record_id,
  884. sensor_name,
  885. sensor_number,
  886. sensor_type_str);
  887. if (sensor_state == IPMI_MONITORING_STATE_NOMINAL)
  888. sensor_state_str = "Nominal";
  889. else if (sensor_state == IPMI_MONITORING_STATE_WARNING)
  890. sensor_state_str = "Warning";
  891. else if (sensor_state == IPMI_MONITORING_STATE_CRITICAL)
  892. sensor_state_str = "Critical";
  893. else
  894. sensor_state_str = "N/A";
  895. printf (", %s", sensor_state_str);
  896. if (sensor_reading)
  897. {
  898. const char *sensor_units_str;
  899. if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL)
  900. printf (", %s",
  901. (*((uint8_t *)sensor_reading) ? "true" : "false"));
  902. else if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32)
  903. printf (", %u",
  904. *((uint32_t *)sensor_reading));
  905. else if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE)
  906. printf (", %.2f",
  907. *((double *)sensor_reading));
  908. else
  909. printf (", N/A");
  910. if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_CELSIUS)
  911. sensor_units_str = "C";
  912. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT)
  913. sensor_units_str = "F";
  914. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_VOLTS)
  915. sensor_units_str = "V";
  916. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_AMPS)
  917. sensor_units_str = "A";
  918. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_RPM)
  919. sensor_units_str = "RPM";
  920. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_WATTS)
  921. sensor_units_str = "W";
  922. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_PERCENT)
  923. sensor_units_str = "%";
  924. else
  925. sensor_units_str = "N/A";
  926. printf (", %s", sensor_units_str);
  927. }
  928. else
  929. printf (", N/A, N/A");
  930. printf (", %Xh", event_reading_type_code);
  931. /* It is possible you may want to monitor specific event
  932. * conditions that may occur. If that is the case, you may want
  933. * to check out what specific bitmask type and bitmask events
  934. * occurred. See ipmi_monitoring_bitmasks.h for a list of
  935. * bitmasks and types.
  936. */
  937. if (sensor_bitmask_type != IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN)
  938. printf (", %Xh", sensor_bitmask);
  939. else
  940. printf (", N/A");
  941. if (sensor_bitmask_type != IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN
  942. && sensor_bitmask_strings)
  943. {
  944. unsigned int i = 0;
  945. printf (",");
  946. while (sensor_bitmask_strings[i])
  947. {
  948. printf (" ");
  949. printf ("'%s'",
  950. sensor_bitmask_strings[i]);
  951. i++;
  952. }
  953. }
  954. else
  955. printf (", N/A");
  956. printf ("\n");
  957. #endif // NETDATA_COMMENTED
  958. }
  959. rv = 0;
  960. cleanup:
  961. if (ctx)
  962. ipmi_monitoring_ctx_destroy (ctx);
  963. return (rv);
  964. }
  965. static int
  966. _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
  967. {
  968. ipmi_monitoring_ctx_t ctx = NULL;
  969. unsigned int sel_flags = 0;
  970. int i;
  971. int sel_count;
  972. int rv = -1;
  973. if (!(ctx = ipmi_monitoring_ctx_create ()))
  974. {
  975. error("ipmi_monitoring_ctx_create()");
  976. goto cleanup;
  977. }
  978. if (sdr_cache_directory)
  979. {
  980. if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
  981. sdr_cache_directory) < 0)
  982. {
  983. error( "ipmi_monitoring_ctx_sdr_cache_directory(): %s",
  984. ipmi_monitoring_ctx_errormsg (ctx));
  985. goto cleanup;
  986. }
  987. }
  988. /* Must call otherwise only default interpretations ever used */
  989. if (sel_config_file)
  990. {
  991. if (ipmi_monitoring_ctx_sel_config_file (ctx,
  992. sel_config_file) < 0)
  993. {
  994. error( "ipmi_monitoring_ctx_sel_config_file(): %s",
  995. ipmi_monitoring_ctx_errormsg (ctx));
  996. goto cleanup;
  997. }
  998. }
  999. else
  1000. {
  1001. if (ipmi_monitoring_ctx_sel_config_file (ctx, NULL) < 0)
  1002. {
  1003. error( "ipmi_monitoring_ctx_sel_config_file(): %s",
  1004. ipmi_monitoring_ctx_errormsg (ctx));
  1005. goto cleanup;
  1006. }
  1007. }
  1008. if (reread_sdr_cache)
  1009. sel_flags |= IPMI_MONITORING_SEL_FLAGS_REREAD_SDR_CACHE;
  1010. if (interpret_oem_data)
  1011. sel_flags |= IPMI_MONITORING_SEL_FLAGS_INTERPRET_OEM_DATA;
  1012. if (assume_system_event_record)
  1013. sel_flags |= IPMI_MONITORING_SEL_FLAGS_ASSUME_SYSTEM_EVENT_RECORD;
  1014. #ifdef IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES
  1015. if (entity_sensor_names)
  1016. sel_flags |= IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES;
  1017. #endif // IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES
  1018. if (record_ids_length)
  1019. {
  1020. if ((sel_count = ipmi_monitoring_sel_by_record_id (ctx,
  1021. hostname,
  1022. ipmi_config,
  1023. sel_flags,
  1024. record_ids,
  1025. record_ids_length,
  1026. NULL,
  1027. NULL)) < 0)
  1028. {
  1029. error( "ipmi_monitoring_sel_by_record_id(): %s",
  1030. ipmi_monitoring_ctx_errormsg (ctx));
  1031. goto cleanup;
  1032. }
  1033. }
  1034. else if (sensor_types_length)
  1035. {
  1036. if ((sel_count = ipmi_monitoring_sel_by_sensor_type (ctx,
  1037. hostname,
  1038. ipmi_config,
  1039. sel_flags,
  1040. sensor_types,
  1041. sensor_types_length,
  1042. NULL,
  1043. NULL)) < 0)
  1044. {
  1045. error( "ipmi_monitoring_sel_by_sensor_type(): %s",
  1046. ipmi_monitoring_ctx_errormsg (ctx));
  1047. goto cleanup;
  1048. }
  1049. }
  1050. else if (date_begin
  1051. || date_end)
  1052. {
  1053. if ((sel_count = ipmi_monitoring_sel_by_date_range (ctx,
  1054. hostname,
  1055. ipmi_config,
  1056. sel_flags,
  1057. date_begin,
  1058. date_end,
  1059. NULL,
  1060. NULL)) < 0)
  1061. {
  1062. error( "ipmi_monitoring_sel_by_sensor_type(): %s",
  1063. ipmi_monitoring_ctx_errormsg (ctx));
  1064. goto cleanup;
  1065. }
  1066. }
  1067. else
  1068. {
  1069. if ((sel_count = ipmi_monitoring_sel_by_record_id (ctx,
  1070. hostname,
  1071. ipmi_config,
  1072. sel_flags,
  1073. NULL,
  1074. 0,
  1075. NULL,
  1076. NULL)) < 0)
  1077. {
  1078. error( "ipmi_monitoring_sel_by_record_id(): %s",
  1079. ipmi_monitoring_ctx_errormsg (ctx));
  1080. goto cleanup;
  1081. }
  1082. }
  1083. #ifdef NETDATA_COMMENTED
  1084. printf ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
  1085. "Record ID",
  1086. "Record Type",
  1087. "SEL State",
  1088. "Timestamp",
  1089. "Sensor Name",
  1090. "Sensor Type",
  1091. "Event Direction",
  1092. "Event Type Code",
  1093. "Event Data",
  1094. "Event Offset",
  1095. "Event Offset String");
  1096. #endif // NETDATA_COMMENTED
  1097. for (i = 0; i < sel_count; i++, ipmi_monitoring_sel_iterator_next (ctx))
  1098. {
  1099. int record_id, record_type, sel_state, record_type_class;
  1100. #ifdef NETDATA_COMMENTED
  1101. int sensor_type, sensor_number, event_direction,
  1102. event_offset_type, event_offset, event_type_code, manufacturer_id;
  1103. unsigned int timestamp, event_data1, event_data2, event_data3;
  1104. char *event_offset_string = NULL;
  1105. const char *sensor_type_str;
  1106. const char *event_direction_str;
  1107. const char *sel_state_str;
  1108. char *sensor_name = NULL;
  1109. unsigned char oem_data[64];
  1110. int oem_data_len;
  1111. unsigned int j;
  1112. #endif // NETDATA_COMMENTED
  1113. if ((record_id = ipmi_monitoring_sel_read_record_id (ctx)) < 0)
  1114. {
  1115. error( "ipmi_monitoring_sel_read_record_id(): %s",
  1116. ipmi_monitoring_ctx_errormsg (ctx));
  1117. goto cleanup;
  1118. }
  1119. if ((record_type = ipmi_monitoring_sel_read_record_type (ctx)) < 0)
  1120. {
  1121. error( "ipmi_monitoring_sel_read_record_type(): %s",
  1122. ipmi_monitoring_ctx_errormsg (ctx));
  1123. goto cleanup;
  1124. }
  1125. if ((record_type_class = ipmi_monitoring_sel_read_record_type_class (ctx)) < 0)
  1126. {
  1127. error( "ipmi_monitoring_sel_read_record_type_class(): %s",
  1128. ipmi_monitoring_ctx_errormsg (ctx));
  1129. goto cleanup;
  1130. }
  1131. if ((sel_state = ipmi_monitoring_sel_read_sel_state (ctx)) < 0)
  1132. {
  1133. error( "ipmi_monitoring_sel_read_sel_state(): %s",
  1134. ipmi_monitoring_ctx_errormsg (ctx));
  1135. goto cleanup;
  1136. }
  1137. netdata_get_sel(
  1138. record_id
  1139. , record_type_class
  1140. , sel_state
  1141. );
  1142. #ifdef NETDATA_COMMENTED
  1143. if (sel_state == IPMI_MONITORING_STATE_NOMINAL)
  1144. sel_state_str = "Nominal";
  1145. else if (sel_state == IPMI_MONITORING_STATE_WARNING)
  1146. sel_state_str = "Warning";
  1147. else if (sel_state == IPMI_MONITORING_STATE_CRITICAL)
  1148. sel_state_str = "Critical";
  1149. else
  1150. sel_state_str = "N/A";
  1151. printf ("%d, %d, %s",
  1152. record_id,
  1153. record_type,
  1154. sel_state_str);
  1155. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD
  1156. || record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
  1157. {
  1158. if (ipmi_monitoring_sel_read_timestamp (ctx, &timestamp) < 0)
  1159. {
  1160. error( "ipmi_monitoring_sel_read_timestamp(): %s",
  1161. ipmi_monitoring_ctx_errormsg (ctx));
  1162. goto cleanup;
  1163. }
  1164. /* XXX: This should be converted to a nice date output using
  1165. * your favorite timestamp -> string conversion functions.
  1166. */
  1167. printf (", %u", timestamp);
  1168. }
  1169. else
  1170. printf (", N/A");
  1171. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD)
  1172. {
  1173. /* If you are integrating ipmimonitoring SEL into a monitoring application,
  1174. * you may wish to count the number of times a specific error occurred
  1175. * and report that to the monitoring application.
  1176. *
  1177. * In this particular case, you'll probably want to check out
  1178. * what sensor type each SEL event is reporting, the
  1179. * event offset type, and the specific event offset that occurred.
  1180. *
  1181. * See ipmi_monitoring_offsets.h for a list of event offsets
  1182. * and types.
  1183. */
  1184. if (!(sensor_name = ipmi_monitoring_sel_read_sensor_name (ctx)))
  1185. {
  1186. error( "ipmi_monitoring_sel_read_sensor_name(): %s",
  1187. ipmi_monitoring_ctx_errormsg (ctx));
  1188. goto cleanup;
  1189. }
  1190. if ((sensor_type = ipmi_monitoring_sel_read_sensor_type (ctx)) < 0)
  1191. {
  1192. error( "ipmi_monitoring_sel_read_sensor_type(): %s",
  1193. ipmi_monitoring_ctx_errormsg (ctx));
  1194. goto cleanup;
  1195. }
  1196. if ((sensor_number = ipmi_monitoring_sel_read_sensor_number (ctx)) < 0)
  1197. {
  1198. error( "ipmi_monitoring_sel_read_sensor_number(): %s",
  1199. ipmi_monitoring_ctx_errormsg (ctx));
  1200. goto cleanup;
  1201. }
  1202. if ((event_direction = ipmi_monitoring_sel_read_event_direction (ctx)) < 0)
  1203. {
  1204. error( "ipmi_monitoring_sel_read_event_direction(): %s",
  1205. ipmi_monitoring_ctx_errormsg (ctx));
  1206. goto cleanup;
  1207. }
  1208. if ((event_type_code = ipmi_monitoring_sel_read_event_type_code (ctx)) < 0)
  1209. {
  1210. error( "ipmi_monitoring_sel_read_event_type_code(): %s",
  1211. ipmi_monitoring_ctx_errormsg (ctx));
  1212. goto cleanup;
  1213. }
  1214. if (ipmi_monitoring_sel_read_event_data (ctx,
  1215. &event_data1,
  1216. &event_data2,
  1217. &event_data3) < 0)
  1218. {
  1219. error( "ipmi_monitoring_sel_read_event_data(): %s",
  1220. ipmi_monitoring_ctx_errormsg (ctx));
  1221. goto cleanup;
  1222. }
  1223. if ((event_offset_type = ipmi_monitoring_sel_read_event_offset_type (ctx)) < 0)
  1224. {
  1225. error( "ipmi_monitoring_sel_read_event_offset_type(): %s",
  1226. ipmi_monitoring_ctx_errormsg (ctx));
  1227. goto cleanup;
  1228. }
  1229. if ((event_offset = ipmi_monitoring_sel_read_event_offset (ctx)) < 0)
  1230. {
  1231. error( "ipmi_monitoring_sel_read_event_offset(): %s",
  1232. ipmi_monitoring_ctx_errormsg (ctx));
  1233. goto cleanup;
  1234. }
  1235. if (!(event_offset_string = ipmi_monitoring_sel_read_event_offset_string (ctx)))
  1236. {
  1237. error( "ipmi_monitoring_sel_read_event_offset_string(): %s",
  1238. ipmi_monitoring_ctx_errormsg (ctx));
  1239. goto cleanup;
  1240. }
  1241. if (!strlen (sensor_name))
  1242. sensor_name = "N/A";
  1243. sensor_type_str = _get_sensor_type_string (sensor_type);
  1244. if (event_direction == IPMI_MONITORING_SEL_EVENT_DIRECTION_ASSERTION)
  1245. event_direction_str = "Assertion";
  1246. else
  1247. event_direction_str = "Deassertion";
  1248. printf (", %s, %s, %d, %s, %Xh, %Xh-%Xh-%Xh",
  1249. sensor_name,
  1250. sensor_type_str,
  1251. sensor_number,
  1252. event_direction_str,
  1253. event_type_code,
  1254. event_data1,
  1255. event_data2,
  1256. event_data3);
  1257. if (event_offset_type != IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN)
  1258. printf (", %Xh", event_offset);
  1259. else
  1260. printf (", N/A");
  1261. if (event_offset_type != IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN)
  1262. printf (", %s", event_offset_string);
  1263. else
  1264. printf (", N/A");
  1265. }
  1266. else if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD
  1267. || record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_NON_TIMESTAMPED_OEM_RECORD)
  1268. {
  1269. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
  1270. {
  1271. if ((manufacturer_id = ipmi_monitoring_sel_read_manufacturer_id (ctx)) < 0)
  1272. {
  1273. error( "ipmi_monitoring_sel_read_manufacturer_id(): %s",
  1274. ipmi_monitoring_ctx_errormsg (ctx));
  1275. goto cleanup;
  1276. }
  1277. printf (", Manufacturer ID = %Xh", manufacturer_id);
  1278. }
  1279. if ((oem_data_len = ipmi_monitoring_sel_read_oem_data (ctx, oem_data, 1024)) < 0)
  1280. {
  1281. error( "ipmi_monitoring_sel_read_oem_data(): %s",
  1282. ipmi_monitoring_ctx_errormsg (ctx));
  1283. goto cleanup;
  1284. }
  1285. printf (", OEM Data = ");
  1286. for (j = 0; j < oem_data_len; j++)
  1287. printf ("%02Xh ", oem_data[j]);
  1288. }
  1289. else
  1290. printf (", N/A, N/A, N/A, N/A, N/A, N/A, N/A");
  1291. printf ("\n");
  1292. #endif // NETDATA_COMMENTED
  1293. }
  1294. rv = 0;
  1295. cleanup:
  1296. if (ctx)
  1297. ipmi_monitoring_ctx_destroy (ctx);
  1298. return (rv);
  1299. }
  1300. // ----------------------------------------------------------------------------
  1301. // MAIN PROGRAM FOR NETDATA PLUGIN
  1302. int ipmi_collect_data(struct ipmi_monitoring_ipmi_config *ipmi_config) {
  1303. errno = 0;
  1304. if (_ipmimonitoring_sensors(ipmi_config) < 0) return -1;
  1305. if(netdata_do_sel) {
  1306. if(_ipmimonitoring_sel(ipmi_config) < 0) return -2;
  1307. }
  1308. return 0;
  1309. }
  1310. int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
  1311. int i, checks = 10;
  1312. unsigned long long total = 0;
  1313. for(i = 0 ; i < checks ; i++) {
  1314. if(debug) fprintf(stderr, "freeipmi.plugin: checking data collection speed iteration %d of %d\n", i+1, checks);
  1315. // measure the time a data collection needs
  1316. unsigned long long start = now_realtime_usec();
  1317. if(ipmi_collect_data(ipmi_config) < 0)
  1318. fatal("freeipmi.plugin: data collection failed.");
  1319. unsigned long long end = now_realtime_usec();
  1320. if(debug) fprintf(stderr, "freeipmi.plugin: data collection speed was %llu usec\n", end - start);
  1321. // add it to our total
  1322. total += end - start;
  1323. // wait the same time
  1324. // to avoid flooding the IPMI processor with requests
  1325. sleep_usec(end - start);
  1326. }
  1327. // so, we assume it needed 2x the time
  1328. // we find the average in microseconds
  1329. // and we round-up to the closest second
  1330. return (int)(( total * 2 / checks / 1000000 ) + 1);
  1331. }
  1332. int parse_inband_driver_type (const char *str)
  1333. {
  1334. assert (str);
  1335. if (strcasecmp (str, IPMI_PARSE_DEVICE_KCS_STR) == 0)
  1336. return (IPMI_MONITORING_DRIVER_TYPE_KCS);
  1337. else if (strcasecmp (str, IPMI_PARSE_DEVICE_SSIF_STR) == 0)
  1338. return (IPMI_MONITORING_DRIVER_TYPE_SSIF);
  1339. /* support "open" for those that might be used to
  1340. * ipmitool.
  1341. */
  1342. else if (strcasecmp (str, IPMI_PARSE_DEVICE_OPENIPMI_STR) == 0
  1343. || strcasecmp (str, IPMI_PARSE_DEVICE_OPENIPMI_STR2) == 0)
  1344. return (IPMI_MONITORING_DRIVER_TYPE_OPENIPMI);
  1345. /* support "bmc" for those that might be used to
  1346. * ipmitool.
  1347. */
  1348. else if (strcasecmp (str, IPMI_PARSE_DEVICE_SUNBMC_STR) == 0
  1349. || strcasecmp (str, IPMI_PARSE_DEVICE_SUNBMC_STR2) == 0)
  1350. return (IPMI_MONITORING_DRIVER_TYPE_SUNBMC);
  1351. return (-1);
  1352. }
  1353. int parse_outofband_driver_type (const char *str)
  1354. {
  1355. assert (str);
  1356. if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_STR) == 0)
  1357. return (IPMI_MONITORING_PROTOCOL_VERSION_1_5);
  1358. /* support "lanplus" for those that might be used to ipmitool.
  1359. * support typo variants to ease.
  1360. */
  1361. else if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR) == 0
  1362. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR2) == 0
  1363. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR3) == 0
  1364. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR4) == 0
  1365. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR5) == 0)
  1366. return (IPMI_MONITORING_PROTOCOL_VERSION_2_0);
  1367. return (-1);
  1368. }
  1369. int main (int argc, char **argv) {
  1370. // ------------------------------------------------------------------------
  1371. // initialization of netdata plugin
  1372. program_name = "freeipmi.plugin";
  1373. // disable syslog
  1374. error_log_syslog = 0;
  1375. // set errors flood protection to 100 logs per hour
  1376. error_log_errors_per_period = 100;
  1377. error_log_throttle_period = 3600;
  1378. // ------------------------------------------------------------------------
  1379. // parse command line parameters
  1380. int i, freq = 0;
  1381. for(i = 1; i < argc ; i++) {
  1382. if(isdigit(*argv[i]) && !freq) {
  1383. int n = str2i(argv[i]);
  1384. if(n > 0 && n < 86400) {
  1385. freq = n;
  1386. continue;
  1387. }
  1388. }
  1389. else if(strcmp("version", argv[i]) == 0 || strcmp("-version", argv[i]) == 0 || strcmp("--version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0 || strcmp("-V", argv[i]) == 0) {
  1390. printf("freeipmi.plugin %s\n", VERSION);
  1391. exit(0);
  1392. }
  1393. else if(strcmp("debug", argv[i]) == 0) {
  1394. debug = 1;
  1395. continue;
  1396. }
  1397. else if(strcmp("sel", argv[i]) == 0) {
  1398. netdata_do_sel = 1;
  1399. continue;
  1400. }
  1401. else if(strcmp("no-sel", argv[i]) == 0) {
  1402. netdata_do_sel = 0;
  1403. continue;
  1404. }
  1405. else if(strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
  1406. fprintf(stderr,
  1407. "\n"
  1408. " netdata freeipmi.plugin %s\n"
  1409. " Copyright (C) 2016-2017 Costa Tsaousis <costa@tsaousis.gr>\n"
  1410. " Released under GNU General Public License v3 or later.\n"
  1411. " All rights reserved.\n"
  1412. "\n"
  1413. " This program is a data collector plugin for netdata.\n"
  1414. "\n"
  1415. " Available command line options:\n"
  1416. "\n"
  1417. " SECONDS data collection frequency\n"
  1418. " minimum: %d\n"
  1419. "\n"
  1420. " debug enable verbose output\n"
  1421. " default: disabled\n"
  1422. "\n"
  1423. " sel\n"
  1424. " no-sel enable/disable SEL collection\n"
  1425. " default: %s\n"
  1426. "\n"
  1427. " hostname HOST\n"
  1428. " username USER\n"
  1429. " password PASS connect to remote IPMI host\n"
  1430. " default: local IPMI processor\n"
  1431. "\n"
  1432. " driver-type IPMIDRIVER\n"
  1433. " Specify the driver type to use instead of doing an auto selection. \n"
  1434. " The currently available outofband drivers are LAN and LAN_2_0,\n"
  1435. " which perform IPMI 1.5 and IPMI 2.0 respectively. \n"
  1436. " The currently available inband drivers are KCS, SSIF, OPENIPMI and SUNBMC.\n"
  1437. "\n"
  1438. " sdr-cache-dir PATH directory for SDR cache files\n"
  1439. " default: %s\n"
  1440. "\n"
  1441. " sensor-config-file FILE filename to read sensor configuration\n"
  1442. " default: %s\n"
  1443. "\n"
  1444. " ignore N1,N2,N3,... sensor IDs to ignore\n"
  1445. " default: none\n"
  1446. "\n"
  1447. " ignore-status N1,N2,N3,... sensor IDs to ignore status (nominal/warning/critical)\n"
  1448. " default: none\n"
  1449. "\n"
  1450. " -v\n"
  1451. " -V\n"
  1452. " version print version and exit\n"
  1453. "\n"
  1454. " Linux kernel module for IPMI is CPU hungry.\n"
  1455. " On Linux run this to lower kipmiN CPU utilization:\n"
  1456. " # echo 10 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us\n"
  1457. "\n"
  1458. " or create: /etc/modprobe.d/ipmi.conf with these contents:\n"
  1459. " options ipmi_si kipmid_max_busy_us=10\n"
  1460. "\n"
  1461. " For more information:\n"
  1462. " https://github.com/netdata/netdata/tree/master/collectors/freeipmi.plugin\n"
  1463. "\n"
  1464. , VERSION
  1465. , netdata_update_every
  1466. , netdata_do_sel?"enabled":"disabled"
  1467. , sdr_cache_directory?sdr_cache_directory:"system default"
  1468. , sensor_config_file?sensor_config_file:"system default"
  1469. );
  1470. exit(1);
  1471. }
  1472. else if(i < argc && strcmp("hostname", argv[i]) == 0) {
  1473. hostname = strdupz(argv[++i]);
  1474. char *s = argv[i];
  1475. // mask it be hidden from the process tree
  1476. while(*s) *s++ = 'x';
  1477. if(debug) fprintf(stderr, "freeipmi.plugin: hostname set to '%s'\n", hostname);
  1478. continue;
  1479. }
  1480. else if(i < argc && strcmp("username", argv[i]) == 0) {
  1481. username = strdupz(argv[++i]);
  1482. char *s = argv[i];
  1483. // mask it be hidden from the process tree
  1484. while(*s) *s++ = 'x';
  1485. if(debug) fprintf(stderr, "freeipmi.plugin: username set to '%s'\n", username);
  1486. continue;
  1487. }
  1488. else if(i < argc && strcmp("password", argv[i]) == 0) {
  1489. password = strdupz(argv[++i]);
  1490. char *s = argv[i];
  1491. // mask it be hidden from the process tree
  1492. while(*s) *s++ = 'x';
  1493. if(debug) fprintf(stderr, "freeipmi.plugin: password set to '%s'\n", password);
  1494. continue;
  1495. }
  1496. else if(strcmp("driver-type", argv[i]) == 0) {
  1497. if (hostname) {
  1498. protocol_version=parse_outofband_driver_type(argv[++i]);
  1499. if(debug) fprintf(stderr, "freeipmi.plugin: outband protocol version set to '%d'\n", protocol_version);
  1500. }
  1501. else {
  1502. driver_type=parse_inband_driver_type(argv[++i]);
  1503. if(debug) fprintf(stderr, "freeipmi.plugin: inband driver type set to '%d'\n", driver_type);
  1504. }
  1505. continue;
  1506. }
  1507. else if(i < argc && strcmp("sdr-cache-dir", argv[i]) == 0) {
  1508. sdr_cache_directory = argv[++i];
  1509. if(debug) fprintf(stderr, "freeipmi.plugin: SDR cache directory set to '%s'\n", sdr_cache_directory);
  1510. continue;
  1511. }
  1512. else if(i < argc && strcmp("sensor-config-file", argv[i]) == 0) {
  1513. sensor_config_file = argv[++i];
  1514. if(debug) fprintf(stderr, "freeipmi.plugin: sensor config file set to '%s'\n", sensor_config_file);
  1515. continue;
  1516. }
  1517. else if(i < argc && strcmp("ignore", argv[i]) == 0) {
  1518. excluded_record_ids_parse(argv[++i]);
  1519. continue;
  1520. }
  1521. else if(i < argc && strcmp("ignore-status", argv[i]) == 0) {
  1522. excluded_status_record_ids_parse(argv[++i]);
  1523. continue;
  1524. }
  1525. error("freeipmi.plugin: ignoring parameter '%s'", argv[i]);
  1526. }
  1527. errno = 0;
  1528. if(freq > netdata_update_every)
  1529. netdata_update_every = freq;
  1530. else if(freq)
  1531. error("update frequency %d seconds is too small for IPMI. Using %d.", freq, netdata_update_every);
  1532. // ------------------------------------------------------------------------
  1533. // initialize IPMI
  1534. struct ipmi_monitoring_ipmi_config ipmi_config;
  1535. if(debug) fprintf(stderr, "freeipmi.plugin: calling _init_ipmi_config()\n");
  1536. _init_ipmi_config(&ipmi_config);
  1537. if(debug) {
  1538. fprintf(stderr, "freeipmi.plugin: calling ipmi_monitoring_init()\n");
  1539. ipmimonitoring_init_flags|=IPMI_MONITORING_FLAGS_DEBUG|IPMI_MONITORING_FLAGS_DEBUG_IPMI_PACKETS;
  1540. }
  1541. if(ipmi_monitoring_init(ipmimonitoring_init_flags, &errnum) < 0)
  1542. fatal("ipmi_monitoring_init: %s", ipmi_monitoring_ctx_strerror(errnum));
  1543. if(debug) fprintf(stderr, "freeipmi.plugin: detecting IPMI minimum update frequency...\n");
  1544. freq = ipmi_detect_speed_secs(&ipmi_config);
  1545. if(debug) fprintf(stderr, "freeipmi.plugin: IPMI minimum update frequency was calculated to %d seconds.\n", freq);
  1546. if(freq > netdata_update_every) {
  1547. info("enforcing minimum data collection frequency, calculated to %d seconds.", freq);
  1548. netdata_update_every = freq;
  1549. }
  1550. // ------------------------------------------------------------------------
  1551. // the main loop
  1552. if(debug) fprintf(stderr, "freeipmi.plugin: starting data collection\n");
  1553. time_t started_t = now_monotonic_sec();
  1554. size_t iteration = 0;
  1555. usec_t step = netdata_update_every * USEC_PER_SEC;
  1556. heartbeat_t hb;
  1557. heartbeat_init(&hb);
  1558. for(iteration = 0; 1 ; iteration++) {
  1559. usec_t dt = heartbeat_next(&hb, step);
  1560. if(debug && iteration)
  1561. fprintf(stderr, "freeipmi.plugin: iteration %zu, dt %llu usec, sensors collected %zu, sensors sent to netdata %zu \n"
  1562. , iteration
  1563. , dt
  1564. , netdata_sensors_collected
  1565. , netdata_sensors_updated
  1566. );
  1567. netdata_mark_as_not_updated();
  1568. if(debug) fprintf(stderr, "freeipmi.plugin: calling ipmi_collect_data()\n");
  1569. if(ipmi_collect_data(&ipmi_config) < 0)
  1570. fatal("data collection failed.");
  1571. if(debug) fprintf(stderr, "freeipmi.plugin: calling send_metrics_to_netdata()\n");
  1572. send_metrics_to_netdata();
  1573. fflush(stdout);
  1574. // restart check (14400 seconds)
  1575. if(now_monotonic_sec() - started_t > 14400) exit(0);
  1576. }
  1577. }
  1578. #else // !HAVE_FREEIPMI
  1579. int main(int argc, char **argv) {
  1580. fatal("freeipmi.plugin is not compiled.");
  1581. }
  1582. #endif // !HAVE_FREEIPMI