freeipmi_plugin.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  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, *sn_stored;
  295. int dupfound, multiplier;
  296. switch(units) {
  297. case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
  298. printf("CHART ipmi.temperatures_c '' 'System Celsius Temperatures read by IPMI' 'Celsius' 'temperatures' 'ipmi.temperatures_c' 'line' %d %d\n"
  299. , netdata_priority + 10
  300. , netdata_update_every
  301. );
  302. break;
  303. case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
  304. printf("CHART ipmi.temperatures_f '' 'System Fahrenheit Temperatures read by IPMI' 'Fahrenheit' 'temperatures' 'ipmi.temperatures_f' 'line' %d %d\n"
  305. , netdata_priority + 11
  306. , netdata_update_every
  307. );
  308. break;
  309. case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
  310. printf("CHART ipmi.volts '' 'System Voltages read by IPMI' 'Volts' 'voltages' 'ipmi.voltages' 'line' %d %d\n"
  311. , netdata_priority + 12
  312. , netdata_update_every
  313. );
  314. break;
  315. case IPMI_MONITORING_SENSOR_UNITS_AMPS:
  316. printf("CHART ipmi.amps '' 'System Current read by IPMI' 'Amps' 'current' 'ipmi.amps' 'line' %d %d\n"
  317. , netdata_priority + 13
  318. , netdata_update_every
  319. );
  320. break;
  321. case IPMI_MONITORING_SENSOR_UNITS_RPM:
  322. printf("CHART ipmi.rpm '' 'System Fans read by IPMI' 'RPM' 'fans' 'ipmi.rpm' 'line' %d %d\n"
  323. , netdata_priority + 14
  324. , netdata_update_every
  325. );
  326. break;
  327. case IPMI_MONITORING_SENSOR_UNITS_WATTS:
  328. printf("CHART ipmi.watts '' 'System Power read by IPMI' 'Watts' 'power' 'ipmi.watts' 'line' %d %d\n"
  329. , netdata_priority + 5
  330. , netdata_update_every
  331. );
  332. break;
  333. case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
  334. printf("CHART ipmi.percent '' 'System Metrics read by IPMI' '%%' 'other' 'ipmi.percent' 'line' %d %d\n"
  335. , netdata_priority + 15
  336. , netdata_update_every
  337. );
  338. break;
  339. default:
  340. for(sn = sensors_root; sn; sn = sn->next)
  341. if(sn->sensor_units == units)
  342. sn->ignore = 1;
  343. return;
  344. }
  345. for(sn = sensors_root; sn; sn = sn->next) {
  346. dupfound = 0;
  347. if(sn->sensor_units == units && sn->updated && !sn->ignore) {
  348. sn->exposed = 1;
  349. multiplier = 1;
  350. switch(sn->sensor_reading_type) {
  351. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  352. multiplier = 1000;
  353. // fallthrough
  354. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  355. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  356. for (sn_stored = sensors_root; sn_stored; sn_stored = sn_stored->next) {
  357. if (sn_stored == sn) continue;
  358. // If the name is a duplicate, append the sensor number
  359. if ( !strcmp(sn_stored->sensor_name, sn->sensor_name) ) {
  360. dupfound = 1;
  361. printf("DIMENSION i%d_n%d_r%d '%s i%d' absolute 1 %d\n"
  362. , sn->sensor_number
  363. , sn->record_id
  364. , sn->sensor_reading_type
  365. , sn->sensor_name
  366. , sn->sensor_number
  367. , multiplier
  368. );
  369. break;
  370. }
  371. }
  372. // No duplicate name was found, display it just with Name
  373. if (!dupfound) {
  374. // display without ID
  375. printf("DIMENSION i%d_n%d_r%d '%s' absolute 1 %d\n"
  376. , sn->sensor_number
  377. , sn->record_id
  378. , sn->sensor_reading_type
  379. , sn->sensor_name
  380. , multiplier
  381. );
  382. }
  383. break;
  384. default:
  385. sn->ignore = 1;
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. static void send_metrics_to_netdata_for_units(int units) {
  392. struct sensor *sn;
  393. switch(units) {
  394. case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
  395. printf("BEGIN ipmi.temperatures_c\n");
  396. break;
  397. case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
  398. printf("BEGIN ipmi.temperatures_f\n");
  399. break;
  400. case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
  401. printf("BEGIN ipmi.volts\n");
  402. break;
  403. case IPMI_MONITORING_SENSOR_UNITS_AMPS:
  404. printf("BEGIN ipmi.amps\n");
  405. break;
  406. case IPMI_MONITORING_SENSOR_UNITS_RPM:
  407. printf("BEGIN ipmi.rpm\n");
  408. break;
  409. case IPMI_MONITORING_SENSOR_UNITS_WATTS:
  410. printf("BEGIN ipmi.watts\n");
  411. break;
  412. case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
  413. printf("BEGIN ipmi.percent\n");
  414. break;
  415. default:
  416. for(sn = sensors_root; sn; sn = sn->next)
  417. if(sn->sensor_units == units)
  418. sn->ignore = 1;
  419. return;
  420. }
  421. for(sn = sensors_root; sn; sn = sn->next) {
  422. if(sn->sensor_units == units && sn->updated && !sn->sent && !sn->ignore) {
  423. netdata_sensors_updated++;
  424. sn->sent = 1;
  425. switch(sn->sensor_reading_type) {
  426. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  427. printf("SET i%d_n%d_r%d = %u\n"
  428. , sn->sensor_number
  429. , sn->record_id
  430. , sn->sensor_reading_type
  431. , sn->sensor_reading.bool_value
  432. );
  433. break;
  434. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  435. printf("SET i%d_n%d_r%d = %u\n"
  436. , sn->sensor_number
  437. , sn->record_id
  438. , sn->sensor_reading_type
  439. , sn->sensor_reading.uint32_value
  440. );
  441. break;
  442. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  443. printf("SET i%d_n%d_r%d = %lld\n"
  444. , sn->sensor_number
  445. , sn->record_id
  446. , sn->sensor_reading_type
  447. , (long long int)(sn->sensor_reading.double_value * 1000)
  448. );
  449. break;
  450. default:
  451. sn->ignore = 1;
  452. break;
  453. }
  454. }
  455. }
  456. printf("END\n");
  457. }
  458. static void send_metrics_to_netdata() {
  459. static int sel_chart_generated = 0, sensors_states_chart_generated = 0;
  460. struct sensor *sn;
  461. if(netdata_do_sel && !sel_chart_generated) {
  462. sel_chart_generated = 1;
  463. printf("CHART ipmi.events '' 'IPMI Events' 'events' 'events' ipmi.sel area %d %d\n"
  464. , netdata_priority + 2
  465. , netdata_update_every
  466. );
  467. printf("DIMENSION events '' absolute 1 1\n");
  468. }
  469. if(!sensors_states_chart_generated) {
  470. sensors_states_chart_generated = 1;
  471. printf("CHART ipmi.sensors_states '' 'IPMI Sensors State' 'sensors' 'states' ipmi.sensors_states line %d %d\n"
  472. , netdata_priority + 1
  473. , netdata_update_every
  474. );
  475. printf("DIMENSION nominal '' absolute 1 1\n");
  476. printf("DIMENSION critical '' absolute 1 1\n");
  477. printf("DIMENSION warning '' absolute 1 1\n");
  478. }
  479. // generate the CHART/DIMENSION lines, if we have to
  480. for(sn = sensors_root; sn; sn = sn->next)
  481. if(sn->updated && !sn->exposed && !sn->ignore)
  482. send_chart_to_netdata_for_units(sn->sensor_units);
  483. if(netdata_do_sel) {
  484. printf(
  485. "BEGIN ipmi.events\n"
  486. "SET events = %zu\n"
  487. "END\n"
  488. , netdata_sel_events
  489. );
  490. }
  491. printf(
  492. "BEGIN ipmi.sensors_states\n"
  493. "SET nominal = %zu\n"
  494. "SET warning = %zu\n"
  495. "SET critical = %zu\n"
  496. "END\n"
  497. , netdata_sensors_states_nominal
  498. , netdata_sensors_states_warning
  499. , netdata_sensors_states_critical
  500. );
  501. // send metrics to netdata
  502. for(sn = sensors_root; sn; sn = sn->next)
  503. if(sn->updated && sn->exposed && !sn->sent && !sn->ignore)
  504. send_metrics_to_netdata_for_units(sn->sensor_units);
  505. }
  506. static int *excluded_record_ids = NULL;
  507. size_t excluded_record_ids_length = 0;
  508. static void excluded_record_ids_parse(const char *s) {
  509. if(!s) return;
  510. while(*s) {
  511. while(*s && !isdigit(*s)) s++;
  512. if(isdigit(*s)) {
  513. char *e;
  514. unsigned long n = strtoul(s, &e, 10);
  515. s = e;
  516. if(n != 0) {
  517. excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int));
  518. if(!excluded_record_ids) {
  519. fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
  520. exit(1);
  521. }
  522. excluded_record_ids[excluded_record_ids_length++] = (int)n;
  523. }
  524. }
  525. }
  526. if(debug) {
  527. fprintf(stderr, "freeipmi.plugin: excluded record ids:");
  528. size_t i;
  529. for(i = 0; i < excluded_record_ids_length; i++) {
  530. fprintf(stderr, " %d", excluded_record_ids[i]);
  531. }
  532. fprintf(stderr, "\n");
  533. }
  534. }
  535. static int *excluded_status_record_ids = NULL;
  536. size_t excluded_status_record_ids_length = 0;
  537. static void excluded_status_record_ids_parse(const char *s) {
  538. if(!s) return;
  539. while(*s) {
  540. while(*s && !isdigit(*s)) s++;
  541. if(isdigit(*s)) {
  542. char *e;
  543. unsigned long n = strtoul(s, &e, 10);
  544. s = e;
  545. if(n != 0) {
  546. excluded_status_record_ids = realloc(excluded_status_record_ids, (excluded_status_record_ids_length + 1) * sizeof(int));
  547. if(!excluded_status_record_ids) {
  548. fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
  549. exit(1);
  550. }
  551. excluded_status_record_ids[excluded_status_record_ids_length++] = (int)n;
  552. }
  553. }
  554. }
  555. if(debug) {
  556. fprintf(stderr, "freeipmi.plugin: excluded status record ids:");
  557. size_t i;
  558. for(i = 0; i < excluded_status_record_ids_length; i++) {
  559. fprintf(stderr, " %d", excluded_status_record_ids[i]);
  560. }
  561. fprintf(stderr, "\n");
  562. }
  563. }
  564. static int excluded_record_ids_check(int record_id) {
  565. size_t i;
  566. for(i = 0; i < excluded_record_ids_length; i++) {
  567. if(excluded_record_ids[i] == record_id)
  568. return 1;
  569. }
  570. return 0;
  571. }
  572. static int excluded_status_record_ids_check(int record_id) {
  573. size_t i;
  574. for(i = 0; i < excluded_status_record_ids_length; i++) {
  575. if(excluded_status_record_ids[i] == record_id)
  576. return 1;
  577. }
  578. return 0;
  579. }
  580. static void netdata_get_sensor(
  581. int record_id
  582. , int sensor_number
  583. , int sensor_type
  584. , int sensor_state
  585. , int sensor_units
  586. , int sensor_reading_type
  587. , char *sensor_name
  588. , void *sensor_reading
  589. ) {
  590. // find the sensor record
  591. struct sensor *sn;
  592. for(sn = sensors_root; sn ;sn = sn->next)
  593. if( sn->record_id == record_id &&
  594. sn->sensor_number == sensor_number &&
  595. sn->sensor_reading_type == sensor_reading_type &&
  596. sn->sensor_units == sensor_units &&
  597. !strcmp(sn->sensor_name, sensor_name)
  598. )
  599. break;
  600. if(!sn) {
  601. // not found, create it
  602. // check if it is excluded
  603. if(excluded_record_ids_check(record_id)) {
  604. if(debug) fprintf(stderr, "Sensor '%s' is excluded by excluded_record_ids_check()\n", sensor_name);
  605. return;
  606. }
  607. 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);
  608. sn = calloc(1, sizeof(struct sensor));
  609. if(!sn) {
  610. fatal("cannot allocate %zu bytes of memory.", sizeof(struct sensor));
  611. }
  612. sn->record_id = record_id;
  613. sn->sensor_number = sensor_number;
  614. sn->sensor_type = sensor_type;
  615. sn->sensor_state = sensor_state;
  616. sn->sensor_units = sensor_units;
  617. sn->sensor_reading_type = sensor_reading_type;
  618. sn->sensor_name = strdup(sensor_name);
  619. if(!sn->sensor_name) {
  620. fatal("cannot allocate %zu bytes of memory.", strlen(sensor_name));
  621. }
  622. sn->next = sensors_root;
  623. sensors_root = sn;
  624. }
  625. else {
  626. 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);
  627. }
  628. switch(sensor_reading_type) {
  629. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
  630. sn->sensor_reading.bool_value = *((uint8_t *)sensor_reading);
  631. sn->updated = 1;
  632. netdata_sensors_collected++;
  633. break;
  634. case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
  635. sn->sensor_reading.uint32_value = *((uint32_t *)sensor_reading);
  636. sn->updated = 1;
  637. netdata_sensors_collected++;
  638. break;
  639. case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
  640. sn->sensor_reading.double_value = *((double *)sensor_reading);
  641. sn->updated = 1;
  642. netdata_sensors_collected++;
  643. break;
  644. default:
  645. 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);
  646. sn->ignore = 1;
  647. break;
  648. }
  649. // check if it is excluded
  650. if(excluded_status_record_ids_check(record_id)) {
  651. if(debug) fprintf(stderr, "Sensor '%s' is excluded for status check, by excluded_status_record_ids_check()\n", sensor_name);
  652. return;
  653. }
  654. switch(sensor_state) {
  655. case IPMI_MONITORING_STATE_NOMINAL:
  656. netdata_sensors_states_nominal++;
  657. break;
  658. case IPMI_MONITORING_STATE_WARNING:
  659. netdata_sensors_states_warning++;
  660. break;
  661. case IPMI_MONITORING_STATE_CRITICAL:
  662. netdata_sensors_states_critical++;
  663. break;
  664. default:
  665. break;
  666. }
  667. }
  668. static void netdata_get_sel(
  669. int record_id
  670. , int record_type_class
  671. , int sel_state
  672. ) {
  673. (void)record_id;
  674. (void)record_type_class;
  675. (void)sel_state;
  676. netdata_sel_events++;
  677. }
  678. // END NETDATA CODE
  679. // ----------------------------------------------------------------------------
  680. static int
  681. _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
  682. {
  683. ipmi_monitoring_ctx_t ctx = NULL;
  684. unsigned int sensor_reading_flags = 0;
  685. int i;
  686. int sensor_count;
  687. int rv = -1;
  688. if (!(ctx = ipmi_monitoring_ctx_create ())) {
  689. error("ipmi_monitoring_ctx_create()");
  690. goto cleanup;
  691. }
  692. if (sdr_cache_directory)
  693. {
  694. if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
  695. sdr_cache_directory) < 0)
  696. {
  697. error("ipmi_monitoring_ctx_sdr_cache_directory(): %s\n",
  698. ipmi_monitoring_ctx_errormsg (ctx));
  699. goto cleanup;
  700. }
  701. }
  702. /* Must call otherwise only default interpretations ever used */
  703. if (sensor_config_file)
  704. {
  705. if (ipmi_monitoring_ctx_sensor_config_file (ctx,
  706. sensor_config_file) < 0)
  707. {
  708. error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
  709. ipmi_monitoring_ctx_errormsg (ctx));
  710. goto cleanup;
  711. }
  712. }
  713. else
  714. {
  715. if (ipmi_monitoring_ctx_sensor_config_file (ctx, NULL) < 0)
  716. {
  717. error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
  718. ipmi_monitoring_ctx_errormsg (ctx));
  719. goto cleanup;
  720. }
  721. }
  722. if (reread_sdr_cache)
  723. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE;
  724. if (ignore_non_interpretable_sensors)
  725. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_NON_INTERPRETABLE_SENSORS;
  726. if (bridge_sensors)
  727. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_BRIDGE_SENSORS;
  728. if (interpret_oem_data)
  729. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_INTERPRET_OEM_DATA;
  730. if (shared_sensors)
  731. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_SHARED_SENSORS;
  732. if (discrete_reading)
  733. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING;
  734. if (ignore_scanning_disabled)
  735. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_SCANNING_DISABLED;
  736. if (assume_bmc_owner)
  737. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ASSUME_BMC_OWNER;
  738. #ifdef IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
  739. if (entity_sensor_names)
  740. sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES;
  741. #endif // IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
  742. if (!record_ids_length && !sensor_types_length)
  743. {
  744. if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
  745. hostname,
  746. ipmi_config,
  747. sensor_reading_flags,
  748. NULL,
  749. 0,
  750. NULL,
  751. NULL)) < 0)
  752. {
  753. error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
  754. ipmi_monitoring_ctx_errormsg (ctx));
  755. goto cleanup;
  756. }
  757. }
  758. else if (record_ids_length)
  759. {
  760. if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
  761. hostname,
  762. ipmi_config,
  763. sensor_reading_flags,
  764. record_ids,
  765. record_ids_length,
  766. NULL,
  767. NULL)) < 0)
  768. {
  769. error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
  770. ipmi_monitoring_ctx_errormsg (ctx));
  771. goto cleanup;
  772. }
  773. }
  774. else
  775. {
  776. if ((sensor_count = ipmi_monitoring_sensor_readings_by_sensor_type (ctx,
  777. hostname,
  778. ipmi_config,
  779. sensor_reading_flags,
  780. sensor_types,
  781. sensor_types_length,
  782. NULL,
  783. NULL)) < 0)
  784. {
  785. error( "ipmi_monitoring_sensor_readings_by_sensor_type(): %s",
  786. ipmi_monitoring_ctx_errormsg (ctx));
  787. goto cleanup;
  788. }
  789. }
  790. #ifdef NETDATA_COMMENTED
  791. printf ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
  792. "Record ID",
  793. "Sensor Name",
  794. "Sensor Number",
  795. "Sensor Type",
  796. "Sensor State",
  797. "Sensor Reading",
  798. "Sensor Units",
  799. "Sensor Event/Reading Type Code",
  800. "Sensor Event Bitmask",
  801. "Sensor Event String");
  802. #endif // NETDATA_COMMENTED
  803. for (i = 0; i < sensor_count; i++, ipmi_monitoring_sensor_iterator_next (ctx))
  804. {
  805. int record_id, sensor_number, sensor_type, sensor_state, sensor_units,
  806. sensor_reading_type;
  807. #ifdef NETDATA_COMMENTED
  808. int sensor_bitmask_type, sensor_bitmask, event_reading_type_code;
  809. char **sensor_bitmask_strings = NULL;
  810. const char *sensor_type_str;
  811. const char *sensor_state_str;
  812. #endif // NETDATA_COMMENTED
  813. char *sensor_name = NULL;
  814. void *sensor_reading;
  815. if ((record_id = ipmi_monitoring_sensor_read_record_id (ctx)) < 0)
  816. {
  817. error( "ipmi_monitoring_sensor_read_record_id(): %s",
  818. ipmi_monitoring_ctx_errormsg (ctx));
  819. goto cleanup;
  820. }
  821. if ((sensor_number = ipmi_monitoring_sensor_read_sensor_number (ctx)) < 0)
  822. {
  823. error( "ipmi_monitoring_sensor_read_sensor_number(): %s",
  824. ipmi_monitoring_ctx_errormsg (ctx));
  825. goto cleanup;
  826. }
  827. if ((sensor_type = ipmi_monitoring_sensor_read_sensor_type (ctx)) < 0)
  828. {
  829. error( "ipmi_monitoring_sensor_read_sensor_type(): %s",
  830. ipmi_monitoring_ctx_errormsg (ctx));
  831. goto cleanup;
  832. }
  833. if (!(sensor_name = ipmi_monitoring_sensor_read_sensor_name (ctx)))
  834. {
  835. error( "ipmi_monitoring_sensor_read_sensor_name(): %s",
  836. ipmi_monitoring_ctx_errormsg (ctx));
  837. goto cleanup;
  838. }
  839. if ((sensor_state = ipmi_monitoring_sensor_read_sensor_state (ctx)) < 0)
  840. {
  841. error( "ipmi_monitoring_sensor_read_sensor_state(): %s",
  842. ipmi_monitoring_ctx_errormsg (ctx));
  843. goto cleanup;
  844. }
  845. if ((sensor_units = ipmi_monitoring_sensor_read_sensor_units (ctx)) < 0)
  846. {
  847. error( "ipmi_monitoring_sensor_read_sensor_units(): %s",
  848. ipmi_monitoring_ctx_errormsg (ctx));
  849. goto cleanup;
  850. }
  851. #ifdef NETDATA_COMMENTED
  852. if ((sensor_bitmask_type = ipmi_monitoring_sensor_read_sensor_bitmask_type (ctx)) < 0)
  853. {
  854. error( "ipmi_monitoring_sensor_read_sensor_bitmask_type(): %s",
  855. ipmi_monitoring_ctx_errormsg (ctx));
  856. goto cleanup;
  857. }
  858. if ((sensor_bitmask = ipmi_monitoring_sensor_read_sensor_bitmask (ctx)) < 0)
  859. {
  860. error(
  861. "ipmi_monitoring_sensor_read_sensor_bitmask(): %s",
  862. ipmi_monitoring_ctx_errormsg (ctx));
  863. goto cleanup;
  864. }
  865. /* it's ok for this to be NULL, i.e. sensor_bitmask ==
  866. * IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN
  867. */
  868. sensor_bitmask_strings = ipmi_monitoring_sensor_read_sensor_bitmask_strings (ctx);
  869. #endif // NETDATA_COMMENTED
  870. if ((sensor_reading_type = ipmi_monitoring_sensor_read_sensor_reading_type (ctx)) < 0)
  871. {
  872. error( "ipmi_monitoring_sensor_read_sensor_reading_type(): %s",
  873. ipmi_monitoring_ctx_errormsg (ctx));
  874. goto cleanup;
  875. }
  876. sensor_reading = ipmi_monitoring_sensor_read_sensor_reading (ctx);
  877. #ifdef NETDATA_COMMENTED
  878. if ((event_reading_type_code = ipmi_monitoring_sensor_read_event_reading_type_code (ctx)) < 0)
  879. {
  880. error( "ipmi_monitoring_sensor_read_event_reading_type_code(): %s",
  881. ipmi_monitoring_ctx_errormsg (ctx));
  882. goto cleanup;
  883. }
  884. #endif // NETDATA_COMMENTED
  885. netdata_get_sensor(
  886. record_id
  887. , sensor_number
  888. , sensor_type
  889. , sensor_state
  890. , sensor_units
  891. , sensor_reading_type
  892. , sensor_name
  893. , sensor_reading
  894. );
  895. #ifdef NETDATA_COMMENTED
  896. if (!strlen (sensor_name))
  897. sensor_name = "N/A";
  898. sensor_type_str = _get_sensor_type_string (sensor_type);
  899. printf ("%d, %s, %d, %s",
  900. record_id,
  901. sensor_name,
  902. sensor_number,
  903. sensor_type_str);
  904. if (sensor_state == IPMI_MONITORING_STATE_NOMINAL)
  905. sensor_state_str = "Nominal";
  906. else if (sensor_state == IPMI_MONITORING_STATE_WARNING)
  907. sensor_state_str = "Warning";
  908. else if (sensor_state == IPMI_MONITORING_STATE_CRITICAL)
  909. sensor_state_str = "Critical";
  910. else
  911. sensor_state_str = "N/A";
  912. printf (", %s", sensor_state_str);
  913. if (sensor_reading)
  914. {
  915. const char *sensor_units_str;
  916. if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL)
  917. printf (", %s",
  918. (*((uint8_t *)sensor_reading) ? "true" : "false"));
  919. else if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32)
  920. printf (", %u",
  921. *((uint32_t *)sensor_reading));
  922. else if (sensor_reading_type == IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE)
  923. printf (", %.2f",
  924. *((double *)sensor_reading));
  925. else
  926. printf (", N/A");
  927. if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_CELSIUS)
  928. sensor_units_str = "C";
  929. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT)
  930. sensor_units_str = "F";
  931. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_VOLTS)
  932. sensor_units_str = "V";
  933. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_AMPS)
  934. sensor_units_str = "A";
  935. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_RPM)
  936. sensor_units_str = "RPM";
  937. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_WATTS)
  938. sensor_units_str = "W";
  939. else if (sensor_units == IPMI_MONITORING_SENSOR_UNITS_PERCENT)
  940. sensor_units_str = "%";
  941. else
  942. sensor_units_str = "N/A";
  943. printf (", %s", sensor_units_str);
  944. }
  945. else
  946. printf (", N/A, N/A");
  947. printf (", %Xh", event_reading_type_code);
  948. /* It is possible you may want to monitor specific event
  949. * conditions that may occur. If that is the case, you may want
  950. * to check out what specific bitmask type and bitmask events
  951. * occurred. See ipmi_monitoring_bitmasks.h for a list of
  952. * bitmasks and types.
  953. */
  954. if (sensor_bitmask_type != IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN)
  955. printf (", %Xh", sensor_bitmask);
  956. else
  957. printf (", N/A");
  958. if (sensor_bitmask_type != IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN
  959. && sensor_bitmask_strings)
  960. {
  961. unsigned int i = 0;
  962. printf (",");
  963. while (sensor_bitmask_strings[i])
  964. {
  965. printf (" ");
  966. printf ("'%s'",
  967. sensor_bitmask_strings[i]);
  968. i++;
  969. }
  970. }
  971. else
  972. printf (", N/A");
  973. printf ("\n");
  974. #endif // NETDATA_COMMENTED
  975. }
  976. rv = 0;
  977. cleanup:
  978. if (ctx)
  979. ipmi_monitoring_ctx_destroy (ctx);
  980. return (rv);
  981. }
  982. static int
  983. _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
  984. {
  985. ipmi_monitoring_ctx_t ctx = NULL;
  986. unsigned int sel_flags = 0;
  987. int i;
  988. int sel_count;
  989. int rv = -1;
  990. if (!(ctx = ipmi_monitoring_ctx_create ()))
  991. {
  992. error("ipmi_monitoring_ctx_create()");
  993. goto cleanup;
  994. }
  995. if (sdr_cache_directory)
  996. {
  997. if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
  998. sdr_cache_directory) < 0)
  999. {
  1000. error( "ipmi_monitoring_ctx_sdr_cache_directory(): %s",
  1001. ipmi_monitoring_ctx_errormsg (ctx));
  1002. goto cleanup;
  1003. }
  1004. }
  1005. /* Must call otherwise only default interpretations ever used */
  1006. if (sel_config_file)
  1007. {
  1008. if (ipmi_monitoring_ctx_sel_config_file (ctx,
  1009. sel_config_file) < 0)
  1010. {
  1011. error( "ipmi_monitoring_ctx_sel_config_file(): %s",
  1012. ipmi_monitoring_ctx_errormsg (ctx));
  1013. goto cleanup;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. if (ipmi_monitoring_ctx_sel_config_file (ctx, NULL) < 0)
  1019. {
  1020. error( "ipmi_monitoring_ctx_sel_config_file(): %s",
  1021. ipmi_monitoring_ctx_errormsg (ctx));
  1022. goto cleanup;
  1023. }
  1024. }
  1025. if (reread_sdr_cache)
  1026. sel_flags |= IPMI_MONITORING_SEL_FLAGS_REREAD_SDR_CACHE;
  1027. if (interpret_oem_data)
  1028. sel_flags |= IPMI_MONITORING_SEL_FLAGS_INTERPRET_OEM_DATA;
  1029. if (assume_system_event_record)
  1030. sel_flags |= IPMI_MONITORING_SEL_FLAGS_ASSUME_SYSTEM_EVENT_RECORD;
  1031. #ifdef IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES
  1032. if (entity_sensor_names)
  1033. sel_flags |= IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES;
  1034. #endif // IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES
  1035. if (record_ids_length)
  1036. {
  1037. if ((sel_count = ipmi_monitoring_sel_by_record_id (ctx,
  1038. hostname,
  1039. ipmi_config,
  1040. sel_flags,
  1041. record_ids,
  1042. record_ids_length,
  1043. NULL,
  1044. NULL)) < 0)
  1045. {
  1046. error( "ipmi_monitoring_sel_by_record_id(): %s",
  1047. ipmi_monitoring_ctx_errormsg (ctx));
  1048. goto cleanup;
  1049. }
  1050. }
  1051. else if (sensor_types_length)
  1052. {
  1053. if ((sel_count = ipmi_monitoring_sel_by_sensor_type (ctx,
  1054. hostname,
  1055. ipmi_config,
  1056. sel_flags,
  1057. sensor_types,
  1058. sensor_types_length,
  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 if (date_begin
  1068. || date_end)
  1069. {
  1070. if ((sel_count = ipmi_monitoring_sel_by_date_range (ctx,
  1071. hostname,
  1072. ipmi_config,
  1073. sel_flags,
  1074. date_begin,
  1075. date_end,
  1076. NULL,
  1077. NULL)) < 0)
  1078. {
  1079. error( "ipmi_monitoring_sel_by_sensor_type(): %s",
  1080. ipmi_monitoring_ctx_errormsg (ctx));
  1081. goto cleanup;
  1082. }
  1083. }
  1084. else
  1085. {
  1086. if ((sel_count = ipmi_monitoring_sel_by_record_id (ctx,
  1087. hostname,
  1088. ipmi_config,
  1089. sel_flags,
  1090. NULL,
  1091. 0,
  1092. NULL,
  1093. NULL)) < 0)
  1094. {
  1095. error( "ipmi_monitoring_sel_by_record_id(): %s",
  1096. ipmi_monitoring_ctx_errormsg (ctx));
  1097. goto cleanup;
  1098. }
  1099. }
  1100. #ifdef NETDATA_COMMENTED
  1101. printf ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
  1102. "Record ID",
  1103. "Record Type",
  1104. "SEL State",
  1105. "Timestamp",
  1106. "Sensor Name",
  1107. "Sensor Type",
  1108. "Event Direction",
  1109. "Event Type Code",
  1110. "Event Data",
  1111. "Event Offset",
  1112. "Event Offset String");
  1113. #endif // NETDATA_COMMENTED
  1114. for (i = 0; i < sel_count; i++, ipmi_monitoring_sel_iterator_next (ctx))
  1115. {
  1116. int record_id, record_type, sel_state, record_type_class;
  1117. #ifdef NETDATA_COMMENTED
  1118. int sensor_type, sensor_number, event_direction,
  1119. event_offset_type, event_offset, event_type_code, manufacturer_id;
  1120. unsigned int timestamp, event_data1, event_data2, event_data3;
  1121. char *event_offset_string = NULL;
  1122. const char *sensor_type_str;
  1123. const char *event_direction_str;
  1124. const char *sel_state_str;
  1125. char *sensor_name = NULL;
  1126. unsigned char oem_data[64];
  1127. int oem_data_len;
  1128. unsigned int j;
  1129. #endif // NETDATA_COMMENTED
  1130. if ((record_id = ipmi_monitoring_sel_read_record_id (ctx)) < 0)
  1131. {
  1132. error( "ipmi_monitoring_sel_read_record_id(): %s",
  1133. ipmi_monitoring_ctx_errormsg (ctx));
  1134. goto cleanup;
  1135. }
  1136. if ((record_type = ipmi_monitoring_sel_read_record_type (ctx)) < 0)
  1137. {
  1138. error( "ipmi_monitoring_sel_read_record_type(): %s",
  1139. ipmi_monitoring_ctx_errormsg (ctx));
  1140. goto cleanup;
  1141. }
  1142. if ((record_type_class = ipmi_monitoring_sel_read_record_type_class (ctx)) < 0)
  1143. {
  1144. error( "ipmi_monitoring_sel_read_record_type_class(): %s",
  1145. ipmi_monitoring_ctx_errormsg (ctx));
  1146. goto cleanup;
  1147. }
  1148. if ((sel_state = ipmi_monitoring_sel_read_sel_state (ctx)) < 0)
  1149. {
  1150. error( "ipmi_monitoring_sel_read_sel_state(): %s",
  1151. ipmi_monitoring_ctx_errormsg (ctx));
  1152. goto cleanup;
  1153. }
  1154. netdata_get_sel(
  1155. record_id
  1156. , record_type_class
  1157. , sel_state
  1158. );
  1159. #ifdef NETDATA_COMMENTED
  1160. if (sel_state == IPMI_MONITORING_STATE_NOMINAL)
  1161. sel_state_str = "Nominal";
  1162. else if (sel_state == IPMI_MONITORING_STATE_WARNING)
  1163. sel_state_str = "Warning";
  1164. else if (sel_state == IPMI_MONITORING_STATE_CRITICAL)
  1165. sel_state_str = "Critical";
  1166. else
  1167. sel_state_str = "N/A";
  1168. printf ("%d, %d, %s",
  1169. record_id,
  1170. record_type,
  1171. sel_state_str);
  1172. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD
  1173. || record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
  1174. {
  1175. if (ipmi_monitoring_sel_read_timestamp (ctx, &timestamp) < 0)
  1176. {
  1177. error( "ipmi_monitoring_sel_read_timestamp(): %s",
  1178. ipmi_monitoring_ctx_errormsg (ctx));
  1179. goto cleanup;
  1180. }
  1181. /* XXX: This should be converted to a nice date output using
  1182. * your favorite timestamp -> string conversion functions.
  1183. */
  1184. printf (", %u", timestamp);
  1185. }
  1186. else
  1187. printf (", N/A");
  1188. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD)
  1189. {
  1190. /* If you are integrating ipmimonitoring SEL into a monitoring application,
  1191. * you may wish to count the number of times a specific error occurred
  1192. * and report that to the monitoring application.
  1193. *
  1194. * In this particular case, you'll probably want to check out
  1195. * what sensor type each SEL event is reporting, the
  1196. * event offset type, and the specific event offset that occurred.
  1197. *
  1198. * See ipmi_monitoring_offsets.h for a list of event offsets
  1199. * and types.
  1200. */
  1201. if (!(sensor_name = ipmi_monitoring_sel_read_sensor_name (ctx)))
  1202. {
  1203. error( "ipmi_monitoring_sel_read_sensor_name(): %s",
  1204. ipmi_monitoring_ctx_errormsg (ctx));
  1205. goto cleanup;
  1206. }
  1207. if ((sensor_type = ipmi_monitoring_sel_read_sensor_type (ctx)) < 0)
  1208. {
  1209. error( "ipmi_monitoring_sel_read_sensor_type(): %s",
  1210. ipmi_monitoring_ctx_errormsg (ctx));
  1211. goto cleanup;
  1212. }
  1213. if ((sensor_number = ipmi_monitoring_sel_read_sensor_number (ctx)) < 0)
  1214. {
  1215. error( "ipmi_monitoring_sel_read_sensor_number(): %s",
  1216. ipmi_monitoring_ctx_errormsg (ctx));
  1217. goto cleanup;
  1218. }
  1219. if ((event_direction = ipmi_monitoring_sel_read_event_direction (ctx)) < 0)
  1220. {
  1221. error( "ipmi_monitoring_sel_read_event_direction(): %s",
  1222. ipmi_monitoring_ctx_errormsg (ctx));
  1223. goto cleanup;
  1224. }
  1225. if ((event_type_code = ipmi_monitoring_sel_read_event_type_code (ctx)) < 0)
  1226. {
  1227. error( "ipmi_monitoring_sel_read_event_type_code(): %s",
  1228. ipmi_monitoring_ctx_errormsg (ctx));
  1229. goto cleanup;
  1230. }
  1231. if (ipmi_monitoring_sel_read_event_data (ctx,
  1232. &event_data1,
  1233. &event_data2,
  1234. &event_data3) < 0)
  1235. {
  1236. error( "ipmi_monitoring_sel_read_event_data(): %s",
  1237. ipmi_monitoring_ctx_errormsg (ctx));
  1238. goto cleanup;
  1239. }
  1240. if ((event_offset_type = ipmi_monitoring_sel_read_event_offset_type (ctx)) < 0)
  1241. {
  1242. error( "ipmi_monitoring_sel_read_event_offset_type(): %s",
  1243. ipmi_monitoring_ctx_errormsg (ctx));
  1244. goto cleanup;
  1245. }
  1246. if ((event_offset = ipmi_monitoring_sel_read_event_offset (ctx)) < 0)
  1247. {
  1248. error( "ipmi_monitoring_sel_read_event_offset(): %s",
  1249. ipmi_monitoring_ctx_errormsg (ctx));
  1250. goto cleanup;
  1251. }
  1252. if (!(event_offset_string = ipmi_monitoring_sel_read_event_offset_string (ctx)))
  1253. {
  1254. error( "ipmi_monitoring_sel_read_event_offset_string(): %s",
  1255. ipmi_monitoring_ctx_errormsg (ctx));
  1256. goto cleanup;
  1257. }
  1258. if (!strlen (sensor_name))
  1259. sensor_name = "N/A";
  1260. sensor_type_str = _get_sensor_type_string (sensor_type);
  1261. if (event_direction == IPMI_MONITORING_SEL_EVENT_DIRECTION_ASSERTION)
  1262. event_direction_str = "Assertion";
  1263. else
  1264. event_direction_str = "Deassertion";
  1265. printf (", %s, %s, %d, %s, %Xh, %Xh-%Xh-%Xh",
  1266. sensor_name,
  1267. sensor_type_str,
  1268. sensor_number,
  1269. event_direction_str,
  1270. event_type_code,
  1271. event_data1,
  1272. event_data2,
  1273. event_data3);
  1274. if (event_offset_type != IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN)
  1275. printf (", %Xh", event_offset);
  1276. else
  1277. printf (", N/A");
  1278. if (event_offset_type != IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN)
  1279. printf (", %s", event_offset_string);
  1280. else
  1281. printf (", N/A");
  1282. }
  1283. else if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD
  1284. || record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_NON_TIMESTAMPED_OEM_RECORD)
  1285. {
  1286. if (record_type_class == IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
  1287. {
  1288. if ((manufacturer_id = ipmi_monitoring_sel_read_manufacturer_id (ctx)) < 0)
  1289. {
  1290. error( "ipmi_monitoring_sel_read_manufacturer_id(): %s",
  1291. ipmi_monitoring_ctx_errormsg (ctx));
  1292. goto cleanup;
  1293. }
  1294. printf (", Manufacturer ID = %Xh", manufacturer_id);
  1295. }
  1296. if ((oem_data_len = ipmi_monitoring_sel_read_oem_data (ctx, oem_data, 1024)) < 0)
  1297. {
  1298. error( "ipmi_monitoring_sel_read_oem_data(): %s",
  1299. ipmi_monitoring_ctx_errormsg (ctx));
  1300. goto cleanup;
  1301. }
  1302. printf (", OEM Data = ");
  1303. for (j = 0; j < oem_data_len; j++)
  1304. printf ("%02Xh ", oem_data[j]);
  1305. }
  1306. else
  1307. printf (", N/A, N/A, N/A, N/A, N/A, N/A, N/A");
  1308. printf ("\n");
  1309. #endif // NETDATA_COMMENTED
  1310. }
  1311. rv = 0;
  1312. cleanup:
  1313. if (ctx)
  1314. ipmi_monitoring_ctx_destroy (ctx);
  1315. return (rv);
  1316. }
  1317. // ----------------------------------------------------------------------------
  1318. // MAIN PROGRAM FOR NETDATA PLUGIN
  1319. int ipmi_collect_data(struct ipmi_monitoring_ipmi_config *ipmi_config) {
  1320. errno = 0;
  1321. if (_ipmimonitoring_sensors(ipmi_config) < 0) return -1;
  1322. if(netdata_do_sel) {
  1323. if(_ipmimonitoring_sel(ipmi_config) < 0) return -2;
  1324. }
  1325. return 0;
  1326. }
  1327. int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
  1328. int i, checks = 10;
  1329. unsigned long long total = 0;
  1330. for(i = 0 ; i < checks ; i++) {
  1331. if(debug) fprintf(stderr, "freeipmi.plugin: checking data collection speed iteration %d of %d\n", i+1, checks);
  1332. // measure the time a data collection needs
  1333. unsigned long long start = now_realtime_usec();
  1334. if(ipmi_collect_data(ipmi_config) < 0)
  1335. fatal("freeipmi.plugin: data collection failed.");
  1336. unsigned long long end = now_realtime_usec();
  1337. if(debug) fprintf(stderr, "freeipmi.plugin: data collection speed was %llu usec\n", end - start);
  1338. // add it to our total
  1339. total += end - start;
  1340. // wait the same time
  1341. // to avoid flooding the IPMI processor with requests
  1342. sleep_usec(end - start);
  1343. }
  1344. // so, we assume it needed 2x the time
  1345. // we find the average in microseconds
  1346. // and we round-up to the closest second
  1347. return (int)(( total * 2 / checks / 1000000 ) + 1);
  1348. }
  1349. int parse_inband_driver_type (const char *str)
  1350. {
  1351. assert (str);
  1352. if (strcasecmp (str, IPMI_PARSE_DEVICE_KCS_STR) == 0)
  1353. return (IPMI_MONITORING_DRIVER_TYPE_KCS);
  1354. else if (strcasecmp (str, IPMI_PARSE_DEVICE_SSIF_STR) == 0)
  1355. return (IPMI_MONITORING_DRIVER_TYPE_SSIF);
  1356. /* support "open" for those that might be used to
  1357. * ipmitool.
  1358. */
  1359. else if (strcasecmp (str, IPMI_PARSE_DEVICE_OPENIPMI_STR) == 0
  1360. || strcasecmp (str, IPMI_PARSE_DEVICE_OPENIPMI_STR2) == 0)
  1361. return (IPMI_MONITORING_DRIVER_TYPE_OPENIPMI);
  1362. /* support "bmc" for those that might be used to
  1363. * ipmitool.
  1364. */
  1365. else if (strcasecmp (str, IPMI_PARSE_DEVICE_SUNBMC_STR) == 0
  1366. || strcasecmp (str, IPMI_PARSE_DEVICE_SUNBMC_STR2) == 0)
  1367. return (IPMI_MONITORING_DRIVER_TYPE_SUNBMC);
  1368. return (-1);
  1369. }
  1370. int parse_outofband_driver_type (const char *str)
  1371. {
  1372. assert (str);
  1373. if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_STR) == 0)
  1374. return (IPMI_MONITORING_PROTOCOL_VERSION_1_5);
  1375. /* support "lanplus" for those that might be used to ipmitool.
  1376. * support typo variants to ease.
  1377. */
  1378. else if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR) == 0
  1379. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR2) == 0
  1380. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR3) == 0
  1381. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR4) == 0
  1382. || strcasecmp (str, IPMI_PARSE_DEVICE_LAN_2_0_STR5) == 0)
  1383. return (IPMI_MONITORING_PROTOCOL_VERSION_2_0);
  1384. return (-1);
  1385. }
  1386. int main (int argc, char **argv) {
  1387. // ------------------------------------------------------------------------
  1388. // initialization of netdata plugin
  1389. program_name = "freeipmi.plugin";
  1390. // disable syslog
  1391. error_log_syslog = 0;
  1392. // set errors flood protection to 100 logs per hour
  1393. error_log_errors_per_period = 100;
  1394. error_log_throttle_period = 3600;
  1395. // ------------------------------------------------------------------------
  1396. // parse command line parameters
  1397. int i, freq = 0;
  1398. for(i = 1; i < argc ; i++) {
  1399. if(isdigit(*argv[i]) && !freq) {
  1400. int n = str2i(argv[i]);
  1401. if(n > 0 && n < 86400) {
  1402. freq = n;
  1403. continue;
  1404. }
  1405. }
  1406. 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) {
  1407. printf("freeipmi.plugin %s\n", VERSION);
  1408. exit(0);
  1409. }
  1410. else if(strcmp("debug", argv[i]) == 0) {
  1411. debug = 1;
  1412. continue;
  1413. }
  1414. else if(strcmp("sel", argv[i]) == 0) {
  1415. netdata_do_sel = 1;
  1416. continue;
  1417. }
  1418. else if(strcmp("no-sel", argv[i]) == 0) {
  1419. netdata_do_sel = 0;
  1420. continue;
  1421. }
  1422. else if(strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
  1423. fprintf(stderr,
  1424. "\n"
  1425. " netdata freeipmi.plugin %s\n"
  1426. " Copyright (C) 2016-2017 Costa Tsaousis <costa@tsaousis.gr>\n"
  1427. " Released under GNU General Public License v3 or later.\n"
  1428. " All rights reserved.\n"
  1429. "\n"
  1430. " This program is a data collector plugin for netdata.\n"
  1431. "\n"
  1432. " Available command line options:\n"
  1433. "\n"
  1434. " SECONDS data collection frequency\n"
  1435. " minimum: %d\n"
  1436. "\n"
  1437. " debug enable verbose output\n"
  1438. " default: disabled\n"
  1439. "\n"
  1440. " sel\n"
  1441. " no-sel enable/disable SEL collection\n"
  1442. " default: %s\n"
  1443. "\n"
  1444. " hostname HOST\n"
  1445. " username USER\n"
  1446. " password PASS connect to remote IPMI host\n"
  1447. " default: local IPMI processor\n"
  1448. "\n"
  1449. " driver-type IPMIDRIVER\n"
  1450. " Specify the driver type to use instead of doing an auto selection. \n"
  1451. " The currently available outofband drivers are LAN and LAN_2_0,\n"
  1452. " which perform IPMI 1.5 and IPMI 2.0 respectively. \n"
  1453. " The currently available inband drivers are KCS, SSIF, OPENIPMI and SUNBMC.\n"
  1454. "\n"
  1455. " sdr-cache-dir PATH directory for SDR cache files\n"
  1456. " default: %s\n"
  1457. "\n"
  1458. " sensor-config-file FILE filename to read sensor configuration\n"
  1459. " default: %s\n"
  1460. "\n"
  1461. " ignore N1,N2,N3,... sensor IDs to ignore\n"
  1462. " default: none\n"
  1463. "\n"
  1464. " ignore-status N1,N2,N3,... sensor IDs to ignore status (nominal/warning/critical)\n"
  1465. " default: none\n"
  1466. "\n"
  1467. " -v\n"
  1468. " -V\n"
  1469. " version print version and exit\n"
  1470. "\n"
  1471. " Linux kernel module for IPMI is CPU hungry.\n"
  1472. " On Linux run this to lower kipmiN CPU utilization:\n"
  1473. " # echo 10 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us\n"
  1474. "\n"
  1475. " or create: /etc/modprobe.d/ipmi.conf with these contents:\n"
  1476. " options ipmi_si kipmid_max_busy_us=10\n"
  1477. "\n"
  1478. " For more information:\n"
  1479. " https://github.com/netdata/netdata/tree/master/collectors/freeipmi.plugin\n"
  1480. "\n"
  1481. , VERSION
  1482. , netdata_update_every
  1483. , netdata_do_sel?"enabled":"disabled"
  1484. , sdr_cache_directory?sdr_cache_directory:"system default"
  1485. , sensor_config_file?sensor_config_file:"system default"
  1486. );
  1487. exit(1);
  1488. }
  1489. else if(i < argc && strcmp("hostname", argv[i]) == 0) {
  1490. hostname = strdupz(argv[++i]);
  1491. char *s = argv[i];
  1492. // mask it be hidden from the process tree
  1493. while(*s) *s++ = 'x';
  1494. if(debug) fprintf(stderr, "freeipmi.plugin: hostname set to '%s'\n", hostname);
  1495. continue;
  1496. }
  1497. else if(i < argc && strcmp("username", argv[i]) == 0) {
  1498. username = strdupz(argv[++i]);
  1499. char *s = argv[i];
  1500. // mask it be hidden from the process tree
  1501. while(*s) *s++ = 'x';
  1502. if(debug) fprintf(stderr, "freeipmi.plugin: username set to '%s'\n", username);
  1503. continue;
  1504. }
  1505. else if(i < argc && strcmp("password", argv[i]) == 0) {
  1506. password = strdupz(argv[++i]);
  1507. char *s = argv[i];
  1508. // mask it be hidden from the process tree
  1509. while(*s) *s++ = 'x';
  1510. if(debug) fprintf(stderr, "freeipmi.plugin: password set to '%s'\n", password);
  1511. continue;
  1512. }
  1513. else if(strcmp("driver-type", argv[i]) == 0) {
  1514. if (hostname) {
  1515. protocol_version=parse_outofband_driver_type(argv[++i]);
  1516. if(debug) fprintf(stderr, "freeipmi.plugin: outband protocol version set to '%d'\n", protocol_version);
  1517. }
  1518. else {
  1519. driver_type=parse_inband_driver_type(argv[++i]);
  1520. if(debug) fprintf(stderr, "freeipmi.plugin: inband driver type set to '%d'\n", driver_type);
  1521. }
  1522. continue;
  1523. }
  1524. else if(i < argc && strcmp("sdr-cache-dir", argv[i]) == 0) {
  1525. sdr_cache_directory = argv[++i];
  1526. if(debug) fprintf(stderr, "freeipmi.plugin: SDR cache directory set to '%s'\n", sdr_cache_directory);
  1527. continue;
  1528. }
  1529. else if(i < argc && strcmp("sensor-config-file", argv[i]) == 0) {
  1530. sensor_config_file = argv[++i];
  1531. if(debug) fprintf(stderr, "freeipmi.plugin: sensor config file set to '%s'\n", sensor_config_file);
  1532. continue;
  1533. }
  1534. else if(i < argc && strcmp("ignore", argv[i]) == 0) {
  1535. excluded_record_ids_parse(argv[++i]);
  1536. continue;
  1537. }
  1538. else if(i < argc && strcmp("ignore-status", argv[i]) == 0) {
  1539. excluded_status_record_ids_parse(argv[++i]);
  1540. continue;
  1541. }
  1542. error("freeipmi.plugin: ignoring parameter '%s'", argv[i]);
  1543. }
  1544. errno = 0;
  1545. if(freq >= netdata_update_every)
  1546. netdata_update_every = freq;
  1547. else if(freq)
  1548. error("update frequency %d seconds is too small for IPMI. Using %d.", freq, netdata_update_every);
  1549. // ------------------------------------------------------------------------
  1550. // initialize IPMI
  1551. struct ipmi_monitoring_ipmi_config ipmi_config;
  1552. if(debug) fprintf(stderr, "freeipmi.plugin: calling _init_ipmi_config()\n");
  1553. _init_ipmi_config(&ipmi_config);
  1554. if(debug) {
  1555. fprintf(stderr, "freeipmi.plugin: calling ipmi_monitoring_init()\n");
  1556. ipmimonitoring_init_flags|=IPMI_MONITORING_FLAGS_DEBUG|IPMI_MONITORING_FLAGS_DEBUG_IPMI_PACKETS;
  1557. }
  1558. if(ipmi_monitoring_init(ipmimonitoring_init_flags, &errnum) < 0)
  1559. fatal("ipmi_monitoring_init: %s", ipmi_monitoring_ctx_strerror(errnum));
  1560. if(debug) fprintf(stderr, "freeipmi.plugin: detecting IPMI minimum update frequency...\n");
  1561. freq = ipmi_detect_speed_secs(&ipmi_config);
  1562. if(debug) fprintf(stderr, "freeipmi.plugin: IPMI minimum update frequency was calculated to %d seconds.\n", freq);
  1563. if(freq > netdata_update_every) {
  1564. info("enforcing minimum data collection frequency, calculated to %d seconds.", freq);
  1565. netdata_update_every = freq;
  1566. }
  1567. // ------------------------------------------------------------------------
  1568. // the main loop
  1569. if(debug) fprintf(stderr, "freeipmi.plugin: starting data collection\n");
  1570. time_t started_t = now_monotonic_sec();
  1571. size_t iteration = 0;
  1572. usec_t step = netdata_update_every * USEC_PER_SEC;
  1573. heartbeat_t hb;
  1574. heartbeat_init(&hb);
  1575. for(iteration = 0; 1 ; iteration++) {
  1576. usec_t dt = heartbeat_next(&hb, step);
  1577. if(debug && iteration)
  1578. fprintf(stderr, "freeipmi.plugin: iteration %zu, dt %llu usec, sensors collected %zu, sensors sent to netdata %zu \n"
  1579. , iteration
  1580. , dt
  1581. , netdata_sensors_collected
  1582. , netdata_sensors_updated
  1583. );
  1584. netdata_mark_as_not_updated();
  1585. if(debug) fprintf(stderr, "freeipmi.plugin: calling ipmi_collect_data()\n");
  1586. if(ipmi_collect_data(&ipmi_config) < 0)
  1587. fatal("data collection failed.");
  1588. if(debug) fprintf(stderr, "freeipmi.plugin: calling send_metrics_to_netdata()\n");
  1589. send_metrics_to_netdata();
  1590. fflush(stdout);
  1591. // restart check (14400 seconds)
  1592. if(now_monotonic_sec() - started_t > 14400) exit(0);
  1593. }
  1594. }
  1595. #else // !HAVE_FREEIPMI
  1596. int main(int argc, char **argv) {
  1597. fatal("freeipmi.plugin is not compiled.");
  1598. }
  1599. #endif // !HAVE_FREEIPMI