freeipmi_plugin.c 60 KB

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