forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
freeipmi_plugin.c
1871 lines (1599 loc) · 63.9 KB
/
freeipmi_plugin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* netdata freeipmi.plugin
* Copyright (C) 2017 Costa Tsaousis
* GPL v3+
*
* Based on:
* ipmimonitoring-sensors.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
* ipmimonitoring-sel.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
*
* Copyright (C) 2007-2015 Lawrence Livermore National Security, LLC.
* Copyright (C) 2006-2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Albert Chu <[email protected]>
* UCRL-CODE-222073
*/
#include "../../libnetdata/libnetdata.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_FREEIPMI
#define IPMI_PARSE_DEVICE_LAN_STR "lan"
#define IPMI_PARSE_DEVICE_LAN_2_0_STR "lan_2_0"
#define IPMI_PARSE_DEVICE_LAN_2_0_STR2 "lan20"
#define IPMI_PARSE_DEVICE_LAN_2_0_STR3 "lan_20"
#define IPMI_PARSE_DEVICE_LAN_2_0_STR4 "lan2_0"
#define IPMI_PARSE_DEVICE_LAN_2_0_STR5 "lanplus"
#define IPMI_PARSE_DEVICE_KCS_STR "kcs"
#define IPMI_PARSE_DEVICE_SSIF_STR "ssif"
#define IPMI_PARSE_DEVICE_OPENIPMI_STR "openipmi"
#define IPMI_PARSE_DEVICE_OPENIPMI_STR2 "open"
#define IPMI_PARSE_DEVICE_SUNBMC_STR "sunbmc"
#define IPMI_PARSE_DEVICE_SUNBMC_STR2 "bmc"
#define IPMI_PARSE_DEVICE_INTELDCMI_STR "inteldcmi"
// ----------------------------------------------------------------------------
// callback required by fatal()
void netdata_cleanup_and_exit(int ret) {
exit(ret);
}
void send_statistics( const char *action, const char *action_result, const char *action_data) {
(void)action;
(void)action_result;
(void)action_data;
return;
}
// callbacks required by popen()
void signals_block(void) {};
void signals_unblock(void) {};
void signals_reset(void) {};
// callback required by eval()
int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
(void)variable;
(void)hash;
(void)rc;
(void)result;
return 0;
};
// required by get_system_cpus()
char *netdata_configured_host_prefix = "";
// ----------------------------------------------------------------------------
#include <ipmi_monitoring.h>
#include <ipmi_monitoring_bitmasks.h>
/* Communication Configuration - Initialize accordingly */
/* Hostname, NULL for In-band communication, non-null for a hostname */
char *hostname = NULL;
/* In-band Communication Configuration */
int driver_type = -1; // IPMI_MONITORING_DRIVER_TYPE_KCS; /* or -1 for default */
int disable_auto_probe = 0; /* probe for in-band device */
unsigned int driver_address = 0; /* not used if probing */
unsigned int register_spacing = 0; /* not used if probing */
char *driver_device = NULL; /* not used if probing */
/* Out-of-band Communication Configuration */
int protocol_version = -1; //IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */
char *username = "foousername";
char *password = "foopassword";
unsigned char *ipmi_k_g = NULL;
unsigned int ipmi_k_g_len = 0;
int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */
int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */
int cipher_suite_id = 0; /* or -1 for default */
int session_timeout = 0; /* 0 for default */
int retransmission_timeout = 0; /* 0 for default */
/* Workarounds - specify workaround flags if necessary */
unsigned int workaround_flags = 0;
/* Initialize w/ record id numbers to only monitor specific record ids */
unsigned int record_ids[] = {0};
unsigned int record_ids_length = 0;
/* Initialize w/ sensor types to only monitor specific sensor types
* see ipmi_monitoring.h sensor types list.
*/
unsigned int sensor_types[] = {0};
unsigned int sensor_types_length = 0;
/* Set to an appropriate alternate if desired */
char *sdr_cache_directory = "/tmp";
char *sensor_config_file = NULL;
/* Set to 1 or 0 to enable these sensor reading flags
* - See ipmi_monitoring.h for descriptions of these flags.
*/
int reread_sdr_cache = 0;
int ignore_non_interpretable_sensors = 0;
int bridge_sensors = 0;
int interpret_oem_data = 0;
int shared_sensors = 0;
int discrete_reading = 1;
int ignore_scanning_disabled = 0;
int assume_bmc_owner = 0;
int entity_sensor_names = 0;
/* Initialization flags
*
* Most commonly bitwise OR IPMI_MONITORING_FLAGS_DEBUG and/or
* IPMI_MONITORING_FLAGS_DEBUG_IPMI_PACKETS for extra debugging
* information.
*/
unsigned int ipmimonitoring_init_flags = 0;
int errnum;
// ----------------------------------------------------------------------------
// SEL only variables
/* Initialize w/ date range to only monitoring specific date range */
char *date_begin = NULL; /* use MM/DD/YYYY format */
char *date_end = NULL; /* use MM/DD/YYYY format */
int assume_system_event_record = 0;
char *sel_config_file = NULL;
// ----------------------------------------------------------------------------
// functions common to sensors and SEL
static void
_init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config)
{
fatal_assert(ipmi_config);
ipmi_config->driver_type = driver_type;
ipmi_config->disable_auto_probe = disable_auto_probe;
ipmi_config->driver_address = driver_address;
ipmi_config->register_spacing = register_spacing;
ipmi_config->driver_device = driver_device;
ipmi_config->protocol_version = protocol_version;
ipmi_config->username = username;
ipmi_config->password = password;
ipmi_config->k_g = ipmi_k_g;
ipmi_config->k_g_len = ipmi_k_g_len;
ipmi_config->privilege_level = privilege_level;
ipmi_config->authentication_type = authentication_type;
ipmi_config->cipher_suite_id = cipher_suite_id;
ipmi_config->session_timeout_len = session_timeout;
ipmi_config->retransmission_timeout_len = retransmission_timeout;
ipmi_config->workaround_flags = workaround_flags;
}
#ifdef NETDATA_COMMENTED
static const char *
_get_sensor_type_string (int sensor_type)
{
switch (sensor_type)
{
case IPMI_MONITORING_SENSOR_TYPE_RESERVED:
return ("Reserved");
case IPMI_MONITORING_SENSOR_TYPE_TEMPERATURE:
return ("Temperature");
case IPMI_MONITORING_SENSOR_TYPE_VOLTAGE:
return ("Voltage");
case IPMI_MONITORING_SENSOR_TYPE_CURRENT:
return ("Current");
case IPMI_MONITORING_SENSOR_TYPE_FAN:
return ("Fan");
case IPMI_MONITORING_SENSOR_TYPE_PHYSICAL_SECURITY:
return ("Physical Security");
case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_SECURITY_VIOLATION_ATTEMPT:
return ("Platform Security Violation Attempt");
case IPMI_MONITORING_SENSOR_TYPE_PROCESSOR:
return ("Processor");
case IPMI_MONITORING_SENSOR_TYPE_POWER_SUPPLY:
return ("Power Supply");
case IPMI_MONITORING_SENSOR_TYPE_POWER_UNIT:
return ("Power Unit");
case IPMI_MONITORING_SENSOR_TYPE_COOLING_DEVICE:
return ("Cooling Device");
case IPMI_MONITORING_SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR:
return ("Other Units Based Sensor");
case IPMI_MONITORING_SENSOR_TYPE_MEMORY:
return ("Memory");
case IPMI_MONITORING_SENSOR_TYPE_DRIVE_SLOT:
return ("Drive Slot");
case IPMI_MONITORING_SENSOR_TYPE_POST_MEMORY_RESIZE:
return ("POST Memory Resize");
case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS:
return ("System Firmware Progress");
case IPMI_MONITORING_SENSOR_TYPE_EVENT_LOGGING_DISABLED:
return ("Event Logging Disabled");
case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG1:
return ("Watchdog 1");
case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_EVENT:
return ("System Event");
case IPMI_MONITORING_SENSOR_TYPE_CRITICAL_INTERRUPT:
return ("Critical Interrupt");
case IPMI_MONITORING_SENSOR_TYPE_BUTTON_SWITCH:
return ("Button/Switch");
case IPMI_MONITORING_SENSOR_TYPE_MODULE_BOARD:
return ("Module/Board");
case IPMI_MONITORING_SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR:
return ("Microcontroller/Coprocessor");
case IPMI_MONITORING_SENSOR_TYPE_ADD_IN_CARD:
return ("Add In Card");
case IPMI_MONITORING_SENSOR_TYPE_CHASSIS:
return ("Chassis");
case IPMI_MONITORING_SENSOR_TYPE_CHIP_SET:
return ("Chip Set");
case IPMI_MONITORING_SENSOR_TYPE_OTHER_FRU:
return ("Other Fru");
case IPMI_MONITORING_SENSOR_TYPE_CABLE_INTERCONNECT:
return ("Cable/Interconnect");
case IPMI_MONITORING_SENSOR_TYPE_TERMINATOR:
return ("Terminator");
case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_BOOT_INITIATED:
return ("System Boot Initiated");
case IPMI_MONITORING_SENSOR_TYPE_BOOT_ERROR:
return ("Boot Error");
case IPMI_MONITORING_SENSOR_TYPE_OS_BOOT:
return ("OS Boot");
case IPMI_MONITORING_SENSOR_TYPE_OS_CRITICAL_STOP:
return ("OS Critical Stop");
case IPMI_MONITORING_SENSOR_TYPE_SLOT_CONNECTOR:
return ("Slot/Connector");
case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE:
return ("System ACPI Power State");
case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG2:
return ("Watchdog 2");
case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_ALERT:
return ("Platform Alert");
case IPMI_MONITORING_SENSOR_TYPE_ENTITY_PRESENCE:
return ("Entity Presence");
case IPMI_MONITORING_SENSOR_TYPE_MONITOR_ASIC_IC:
return ("Monitor ASIC/IC");
case IPMI_MONITORING_SENSOR_TYPE_LAN:
return ("LAN");
case IPMI_MONITORING_SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH:
return ("Management Subsystem Health");
case IPMI_MONITORING_SENSOR_TYPE_BATTERY:
return ("Battery");
case IPMI_MONITORING_SENSOR_TYPE_SESSION_AUDIT:
return ("Session Audit");
case IPMI_MONITORING_SENSOR_TYPE_VERSION_CHANGE:
return ("Version Change");
case IPMI_MONITORING_SENSOR_TYPE_FRU_STATE:
return ("FRU State");
}
return ("Unrecognized");
}
#endif // NETDATA_COMMENTED
// ----------------------------------------------------------------------------
// BEGIN NETDATA CODE
static int debug = 0;
static int netdata_update_every = 5; // this is the minimum update frequency
static int netdata_priority = 90000;
static int netdata_do_sel = 1;
static size_t netdata_sensors_updated = 0;
static size_t netdata_sensors_collected = 0;
static size_t netdata_sel_events = 0;
static size_t netdata_sensors_states_nominal = 0;
static size_t netdata_sensors_states_warning = 0;
static size_t netdata_sensors_states_critical = 0;
struct sensor {
int record_id;
int sensor_number;
int sensor_type;
int sensor_state;
int sensor_units;
char *sensor_name;
int sensor_reading_type;
union {
uint8_t bool_value;
uint32_t uint32_value;
double double_value;
} sensor_reading;
int sent;
int ignore;
int exposed;
int updated;
struct sensor *next;
} *sensors_root = NULL;
static void netdata_mark_as_not_updated() {
struct sensor *sn;
for(sn = sensors_root; sn ;sn = sn->next)
sn->updated = sn->sent = 0;
netdata_sensors_updated = 0;
netdata_sensors_collected = 0;
netdata_sel_events = 0;
netdata_sensors_states_nominal = 0;
netdata_sensors_states_warning = 0;
netdata_sensors_states_critical = 0;
}
static void send_chart_to_netdata_for_units(int units) {
struct sensor *sn, *sn_stored;
int dupfound, multiplier;
switch(units) {
case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
printf("CHART ipmi.temperatures_c '' 'System Celsius Temperatures read by IPMI' 'Celsius' 'temperatures' 'ipmi.temperatures_c' 'line' %d %d\n"
, netdata_priority + 10
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
printf("CHART ipmi.temperatures_f '' 'System Fahrenheit Temperatures read by IPMI' 'Fahrenheit' 'temperatures' 'ipmi.temperatures_f' 'line' %d %d\n"
, netdata_priority + 11
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
printf("CHART ipmi.volts '' 'System Voltages read by IPMI' 'Volts' 'voltages' 'ipmi.voltages' 'line' %d %d\n"
, netdata_priority + 12
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_AMPS:
printf("CHART ipmi.amps '' 'System Current read by IPMI' 'Amps' 'current' 'ipmi.amps' 'line' %d %d\n"
, netdata_priority + 13
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_RPM:
printf("CHART ipmi.rpm '' 'System Fans read by IPMI' 'RPM' 'fans' 'ipmi.rpm' 'line' %d %d\n"
, netdata_priority + 14
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_WATTS:
printf("CHART ipmi.watts '' 'System Power read by IPMI' 'Watts' 'power' 'ipmi.watts' 'line' %d %d\n"
, netdata_priority + 5
, netdata_update_every
);
break;
case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
printf("CHART ipmi.percent '' 'System Metrics read by IPMI' '%%' 'other' 'ipmi.percent' 'line' %d %d\n"
, netdata_priority + 15
, netdata_update_every
);
break;
default:
for(sn = sensors_root; sn; sn = sn->next)
if(sn->sensor_units == units)
sn->ignore = 1;
return;
}
for(sn = sensors_root; sn; sn = sn->next) {
dupfound = 0;
if(sn->sensor_units == units && sn->updated && !sn->ignore) {
sn->exposed = 1;
multiplier = 1;
switch(sn->sensor_reading_type) {
case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
multiplier = 1000;
// fallthrough
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
for (sn_stored = sensors_root; sn_stored; sn_stored = sn_stored->next) {
if (sn_stored == sn) continue;
// If the name is a duplicate, append the sensor number
if ( !strcmp(sn_stored->sensor_name, sn->sensor_name) ) {
dupfound = 1;
printf("DIMENSION i%d_n%d_r%d '%s i%d' absolute 1 %d\n"
, sn->sensor_number
, sn->record_id
, sn->sensor_reading_type
, sn->sensor_name
, sn->sensor_number
, multiplier
);
break;
}
}
// No duplicate name was found, display it just with Name
if (!dupfound) {
// display without ID
printf("DIMENSION i%d_n%d_r%d '%s' absolute 1 %d\n"
, sn->sensor_number
, sn->record_id
, sn->sensor_reading_type
, sn->sensor_name
, multiplier
);
}
break;
default:
sn->ignore = 1;
break;
}
}
}
}
static void send_metrics_to_netdata_for_units(int units) {
struct sensor *sn;
switch(units) {
case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
printf("BEGIN ipmi.temperatures_c\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
printf("BEGIN ipmi.temperatures_f\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
printf("BEGIN ipmi.volts\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_AMPS:
printf("BEGIN ipmi.amps\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_RPM:
printf("BEGIN ipmi.rpm\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_WATTS:
printf("BEGIN ipmi.watts\n");
break;
case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
printf("BEGIN ipmi.percent\n");
break;
default:
for(sn = sensors_root; sn; sn = sn->next)
if(sn->sensor_units == units)
sn->ignore = 1;
return;
}
for(sn = sensors_root; sn; sn = sn->next) {
if(sn->sensor_units == units && sn->updated && !sn->sent && !sn->ignore) {
netdata_sensors_updated++;
sn->sent = 1;
switch(sn->sensor_reading_type) {
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
printf("SET i%d_n%d_r%d = %u\n"
, sn->sensor_number
, sn->record_id
, sn->sensor_reading_type
, sn->sensor_reading.bool_value
);
break;
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
printf("SET i%d_n%d_r%d = %u\n"
, sn->sensor_number
, sn->record_id
, sn->sensor_reading_type
, sn->sensor_reading.uint32_value
);
break;
case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
printf("SET i%d_n%d_r%d = %lld\n"
, sn->sensor_number
, sn->record_id
, sn->sensor_reading_type
, (long long int)(sn->sensor_reading.double_value * 1000)
);
break;
default:
sn->ignore = 1;
break;
}
}
}
printf("END\n");
}
static void send_metrics_to_netdata() {
static int sel_chart_generated = 0, sensors_states_chart_generated = 0;
struct sensor *sn;
if(netdata_do_sel && !sel_chart_generated) {
sel_chart_generated = 1;
printf("CHART ipmi.events '' 'IPMI Events' 'events' 'events' ipmi.sel area %d %d\n"
, netdata_priority + 2
, netdata_update_every
);
printf("DIMENSION events '' absolute 1 1\n");
}
if(!sensors_states_chart_generated) {
sensors_states_chart_generated = 1;
printf("CHART ipmi.sensors_states '' 'IPMI Sensors State' 'sensors' 'states' ipmi.sensors_states line %d %d\n"
, netdata_priority + 1
, netdata_update_every
);
printf("DIMENSION nominal '' absolute 1 1\n");
printf("DIMENSION critical '' absolute 1 1\n");
printf("DIMENSION warning '' absolute 1 1\n");
}
// generate the CHART/DIMENSION lines, if we have to
for(sn = sensors_root; sn; sn = sn->next)
if(sn->updated && !sn->exposed && !sn->ignore)
send_chart_to_netdata_for_units(sn->sensor_units);
if(netdata_do_sel) {
printf(
"BEGIN ipmi.events\n"
"SET events = %zu\n"
"END\n"
, netdata_sel_events
);
}
printf(
"BEGIN ipmi.sensors_states\n"
"SET nominal = %zu\n"
"SET warning = %zu\n"
"SET critical = %zu\n"
"END\n"
, netdata_sensors_states_nominal
, netdata_sensors_states_warning
, netdata_sensors_states_critical
);
// send metrics to netdata
for(sn = sensors_root; sn; sn = sn->next)
if(sn->updated && sn->exposed && !sn->sent && !sn->ignore)
send_metrics_to_netdata_for_units(sn->sensor_units);
}
static int *excluded_record_ids = NULL;
size_t excluded_record_ids_length = 0;
static void excluded_record_ids_parse(const char *s) {
if(!s) return;
while(*s) {
while(*s && !isdigit(*s)) s++;
if(isdigit(*s)) {
char *e;
unsigned long n = strtoul(s, &e, 10);
s = e;
if(n != 0) {
excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int));
if(!excluded_record_ids) {
fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
exit(1);
}
excluded_record_ids[excluded_record_ids_length++] = (int)n;
}
}
}
if(debug) {
fprintf(stderr, "freeipmi.plugin: excluded record ids:");
size_t i;
for(i = 0; i < excluded_record_ids_length; i++) {
fprintf(stderr, " %d", excluded_record_ids[i]);
}
fprintf(stderr, "\n");
}
}
static int *excluded_status_record_ids = NULL;
size_t excluded_status_record_ids_length = 0;
static void excluded_status_record_ids_parse(const char *s) {
if(!s) return;
while(*s) {
while(*s && !isdigit(*s)) s++;
if(isdigit(*s)) {
char *e;
unsigned long n = strtoul(s, &e, 10);
s = e;
if(n != 0) {
excluded_status_record_ids = realloc(excluded_status_record_ids, (excluded_status_record_ids_length + 1) * sizeof(int));
if(!excluded_status_record_ids) {
fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
exit(1);
}
excluded_status_record_ids[excluded_status_record_ids_length++] = (int)n;
}
}
}
if(debug) {
fprintf(stderr, "freeipmi.plugin: excluded status record ids:");
size_t i;
for(i = 0; i < excluded_status_record_ids_length; i++) {
fprintf(stderr, " %d", excluded_status_record_ids[i]);
}
fprintf(stderr, "\n");
}
}
static int excluded_record_ids_check(int record_id) {
size_t i;
for(i = 0; i < excluded_record_ids_length; i++) {
if(excluded_record_ids[i] == record_id)
return 1;
}
return 0;
}
static int excluded_status_record_ids_check(int record_id) {
size_t i;
for(i = 0; i < excluded_status_record_ids_length; i++) {
if(excluded_status_record_ids[i] == record_id)
return 1;
}
return 0;
}
static void netdata_get_sensor(
int record_id
, int sensor_number
, int sensor_type
, int sensor_state
, int sensor_units
, int sensor_reading_type
, char *sensor_name
, void *sensor_reading
) {
// find the sensor record
struct sensor *sn;
for(sn = sensors_root; sn ;sn = sn->next)
if( sn->record_id == record_id &&
sn->sensor_number == sensor_number &&
sn->sensor_reading_type == sensor_reading_type &&
sn->sensor_units == sensor_units &&
!strcmp(sn->sensor_name, sensor_name)
)
break;
if(!sn) {
// not found, create it
// check if it is excluded
if(excluded_record_ids_check(record_id)) {
if(debug) fprintf(stderr, "Sensor '%s' is excluded by excluded_record_ids_check()\n", sensor_name);
return;
}
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);
sn = calloc(1, sizeof(struct sensor));
if(!sn) {
fatal("cannot allocate %zu bytes of memory.", sizeof(struct sensor));
}
sn->record_id = record_id;
sn->sensor_number = sensor_number;
sn->sensor_type = sensor_type;
sn->sensor_state = sensor_state;
sn->sensor_units = sensor_units;
sn->sensor_reading_type = sensor_reading_type;
sn->sensor_name = strdup(sensor_name);
if(!sn->sensor_name) {
fatal("cannot allocate %zu bytes of memory.", strlen(sensor_name));
}
sn->next = sensors_root;
sensors_root = sn;
}
else {
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);
}
switch(sensor_reading_type) {
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER8_BOOL:
sn->sensor_reading.bool_value = *((uint8_t *)sensor_reading);
sn->updated = 1;
netdata_sensors_collected++;
break;
case IPMI_MONITORING_SENSOR_READING_TYPE_UNSIGNED_INTEGER32:
sn->sensor_reading.uint32_value = *((uint32_t *)sensor_reading);
sn->updated = 1;
netdata_sensors_collected++;
break;
case IPMI_MONITORING_SENSOR_READING_TYPE_DOUBLE:
sn->sensor_reading.double_value = *((double *)sensor_reading);
sn->updated = 1;
netdata_sensors_collected++;
break;
default:
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);
sn->ignore = 1;
break;
}
// check if it is excluded
if(excluded_status_record_ids_check(record_id)) {
if(debug) fprintf(stderr, "Sensor '%s' is excluded for status check, by excluded_status_record_ids_check()\n", sensor_name);
return;
}
switch(sensor_state) {
case IPMI_MONITORING_STATE_NOMINAL:
netdata_sensors_states_nominal++;
break;
case IPMI_MONITORING_STATE_WARNING:
netdata_sensors_states_warning++;
break;
case IPMI_MONITORING_STATE_CRITICAL:
netdata_sensors_states_critical++;
break;
default:
break;
}
}
static void netdata_get_sel(
int record_id
, int record_type_class
, int sel_state
) {
(void)record_id;
(void)record_type_class;
(void)sel_state;
netdata_sel_events++;
}
// END NETDATA CODE
// ----------------------------------------------------------------------------
static int
_ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
{
ipmi_monitoring_ctx_t ctx = NULL;
unsigned int sensor_reading_flags = 0;
int i;
int sensor_count;
int rv = -1;
if (!(ctx = ipmi_monitoring_ctx_create ())) {
error("ipmi_monitoring_ctx_create()");
goto cleanup;
}
if (sdr_cache_directory)
{
if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
sdr_cache_directory) < 0)
{
error("ipmi_monitoring_ctx_sdr_cache_directory(): %s\n",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
/* Must call otherwise only default interpretations ever used */
if (sensor_config_file)
{
if (ipmi_monitoring_ctx_sensor_config_file (ctx,
sensor_config_file) < 0)
{
error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
else
{
if (ipmi_monitoring_ctx_sensor_config_file (ctx, NULL) < 0)
{
error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
if (reread_sdr_cache)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE;
if (ignore_non_interpretable_sensors)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_NON_INTERPRETABLE_SENSORS;
if (bridge_sensors)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_BRIDGE_SENSORS;
if (interpret_oem_data)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_INTERPRET_OEM_DATA;
if (shared_sensors)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_SHARED_SENSORS;
if (discrete_reading)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING;
if (ignore_scanning_disabled)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_IGNORE_SCANNING_DISABLED;
if (assume_bmc_owner)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ASSUME_BMC_OWNER;
#ifdef IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
if (entity_sensor_names)
sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES;
#endif // IPMI_MONITORING_SENSOR_READING_FLAGS_ENTITY_SENSOR_NAMES
if (!record_ids_length && !sensor_types_length)
{
if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
hostname,
ipmi_config,
sensor_reading_flags,
NULL,
0,
NULL,
NULL)) < 0)
{
error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
else if (record_ids_length)
{
if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx,
hostname,
ipmi_config,
sensor_reading_flags,
record_ids,
record_ids_length,
NULL,
NULL)) < 0)
{
error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
else
{
if ((sensor_count = ipmi_monitoring_sensor_readings_by_sensor_type (ctx,
hostname,
ipmi_config,
sensor_reading_flags,
sensor_types,
sensor_types_length,
NULL,
NULL)) < 0)
{
error( "ipmi_monitoring_sensor_readings_by_sensor_type(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
}
#ifdef NETDATA_COMMENTED
printf ("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
"Record ID",
"Sensor Name",
"Sensor Number",
"Sensor Type",
"Sensor State",
"Sensor Reading",
"Sensor Units",
"Sensor Event/Reading Type Code",
"Sensor Event Bitmask",
"Sensor Event String");
#endif // NETDATA_COMMENTED
for (i = 0; i < sensor_count; i++, ipmi_monitoring_sensor_iterator_next (ctx))
{
int record_id, sensor_number, sensor_type, sensor_state, sensor_units,
sensor_reading_type;
#ifdef NETDATA_COMMENTED
int sensor_bitmask_type, sensor_bitmask, event_reading_type_code;
char **sensor_bitmask_strings = NULL;
const char *sensor_type_str;
const char *sensor_state_str;
#endif // NETDATA_COMMENTED
char *sensor_name = NULL;
void *sensor_reading;
if ((record_id = ipmi_monitoring_sensor_read_record_id (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_record_id(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
if ((sensor_number = ipmi_monitoring_sensor_read_sensor_number (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_sensor_number(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
if ((sensor_type = ipmi_monitoring_sensor_read_sensor_type (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_sensor_type(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
if (!(sensor_name = ipmi_monitoring_sensor_read_sensor_name (ctx)))
{
error( "ipmi_monitoring_sensor_read_sensor_name(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
if ((sensor_state = ipmi_monitoring_sensor_read_sensor_state (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_sensor_state(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
if ((sensor_units = ipmi_monitoring_sensor_read_sensor_units (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_sensor_units(): %s",
ipmi_monitoring_ctx_errormsg (ctx));
goto cleanup;
}
#ifdef NETDATA_COMMENTED
if ((sensor_bitmask_type = ipmi_monitoring_sensor_read_sensor_bitmask_type (ctx)) < 0)
{
error( "ipmi_monitoring_sensor_read_sensor_bitmask_type(): %s",