diff --git a/common/toolcommon/tool-config-file-common.c b/common/toolcommon/tool-config-file-common.c index 27974ea..7ba77ee 100644 --- a/common/toolcommon/tool-config-file-common.c +++ b/common/toolcommon/tool-config-file-common.c @@ -3592,7 +3592,6 @@ config_file_parse (const char *filename, &(ipmi_sensors_data.sensor_state_config_file), 0 }, - { "ipmi-sensors-entity-sensor-names", CONFFILE_OPTION_BOOL, @@ -3605,6 +3604,17 @@ config_file_parse (const char *filename, 0, }, { + "ipmi-sensors-output-sensor-thresholds", + CONFFILE_OPTION_BOOL, + -1, + _config_file_bool, + 1, + 0, + &(ipmi_sensors_data.output_sensor_thresholds_count), + &(ipmi_sensors_data.output_sensor_thresholds), + 0, + }, + { "ipmi-sensors-no-sensor-type-output", CONFFILE_OPTION_BOOL, -1, diff --git a/common/toolcommon/tool-config-file-common.h b/common/toolcommon/tool-config-file-common.h index 219ff2a..06ec454 100644 --- a/common/toolcommon/tool-config-file-common.h +++ b/common/toolcommon/tool-config-file-common.h @@ -229,6 +229,8 @@ struct config_file_data_ipmi_sensors int output_sensor_state_count; char *sensor_state_config_file; int sensor_state_config_file_count; + int output_sensor_thresholds; + int output_sensor_thresholds_count; int no_sensor_type_output; int no_sensor_type_output_count; int comma_separated_output_count; diff --git a/etc/freeipmi.conf b/etc/freeipmi.conf index eafe147..9d99116 100644 --- a/etc/freeipmi.conf +++ b/etc/freeipmi.conf @@ -472,6 +472,8 @@ # # ipmi-sensors-entity-sensor-names DISABLE # +# ipmi-sensors-output-sensor-thresholds DISABLE +# # ipmi-sensors-no-sensor-type-output DISABLE # # ipmi-sensors-comma-separated-output DISABLE diff --git a/ipmi-sensors/ipmi-sensors-argp.c b/ipmi-sensors/ipmi-sensors-argp.c index 455f316..28836e0 100644 --- a/ipmi-sensors/ipmi-sensors-argp.c +++ b/ipmi-sensors/ipmi-sensors-argp.c @@ -127,19 +127,21 @@ static struct argp_option cmdline_options[] = "Specify an alternate sensor state configuration file.", 52}, { "entity-sensor-names", ENTITY_SENSOR_NAMES_KEY, NULL, 0, "Output sensor names with entity ids and instances.", 53}, + { "output-sensor-thresholds", OUTPUT_SENSOR_THRESHOLDS_KEY, NULL, 0, + "Output sensor thresholds in output.", 54}, { "no-sensor-type-output", NO_SENSOR_TYPE_OUTPUT_KEY, 0, 0, - "Do not show sensor type output.", 54}, + "Do not show sensor type output.", 55}, { "comma-separated-output", COMMA_SEPARATED_OUTPUT_KEY, 0, 0, - "Output fields in comma separated format.", 55}, + "Output fields in comma separated format.", 56}, { "no-header-output", NO_HEADER_OUTPUT_KEY, 0, 0, - "Do not output column headers.", 56}, + "Do not output column headers.", 57}, { "non-abbreviated-units", NON_ABBREVIATED_UNITS_KEY, 0, 0, - "Output non-abbreviated units (e.g. 'Amps' insetead of 'A').", 57}, + "Output non-abbreviated units (e.g. 'Amps' insetead of 'A').", 58}, { "legacy-output", LEGACY_OUTPUT_KEY, 0, 0, - "Output in legacy format.", 58}, + "Output in legacy format.", 59}, /* ipmimonitoring legacy support */ { "ipmimonitoring-legacy-output", IPMIMONITORING_LEGACY_OUTPUT_KEY, 0, 0, - "Output in ipmimonitoring legacy format.", 58}, + "Output in ipmimonitoring legacy format.", 60}, { NULL, 0, NULL, 0, NULL, 0} }; @@ -294,6 +296,9 @@ cmdline_parse (int key, char *arg, struct argp_state *state) case ENTITY_SENSOR_NAMES_KEY: cmd_args->entity_sensor_names = 1; break; + case OUTPUT_SENSOR_THRESHOLDS_KEY: + cmd_args->output_sensor_thresholds = 1; + break; case NO_SENSOR_TYPE_OUTPUT_KEY: cmd_args->no_sensor_type_output = 1; break; @@ -415,6 +420,8 @@ _ipmi_sensors_config_file_parse (struct ipmi_sensors_arguments *cmd_args) cmd_args->sensor_state_config_file = config_file_data.sensor_state_config_file; if (config_file_data.entity_sensor_names_count) cmd_args->entity_sensor_names = config_file_data.entity_sensor_names; + if (config_file_data.output_sensor_thresholds_count) + cmd_args->output_sensor_thresholds = config_file_data.output_sensor_thresholds; if (config_file_data.no_sensor_type_output_count) cmd_args->no_sensor_type_output = config_file_data.no_sensor_type_output; if (config_file_data.comma_separated_output_count) @@ -497,6 +504,7 @@ ipmi_sensors_argp_parse (int argc, char **argv, struct ipmi_sensors_arguments *c cmd_args->output_sensor_state = 0; cmd_args->sensor_state_config_file = NULL; cmd_args->entity_sensor_names = 0; + cmd_args->output_sensor_thresholds = 0; cmd_args->no_sensor_type_output = 0; cmd_args->comma_separated_output = 0; cmd_args->no_header_output = 0; diff --git a/ipmi-sensors/ipmi-sensors-simple-output.c b/ipmi-sensors/ipmi-sensors-simple-output.c index 07ef472..8314b18 100644 --- a/ipmi-sensors/ipmi-sensors-simple-output.c +++ b/ipmi-sensors/ipmi-sensors-simple-output.c @@ -683,6 +683,12 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, { char fmt[IPMI_SENSORS_FMT_BUFLEN + 1]; uint8_t event_reading_type_code; + double *lower_non_critical_threshold = NULL; + double *upper_non_critical_threshold = NULL; + double *lower_critical_threshold = NULL; + double *upper_critical_threshold = NULL; + double *lower_non_recoverable_threshold = NULL; + double *upper_non_recoverable_threshold = NULL; int rv = -1; assert (state_data); @@ -760,6 +766,100 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, } } + if (state_data->prog_data->args->output_sensor_thresholds) + { + char thresholdfmt[IPMI_SENSORS_FMT_BUFLEN + 1]; + char nafmt[IPMI_SENSORS_FMT_BUFLEN + 1]; + + if (ipmi_sensors_get_thresholds (state_data, + sdr_record, + sdr_record_len, + &lower_non_critical_threshold, + &lower_critical_threshold, + &lower_non_recoverable_threshold, + &upper_non_critical_threshold, + &upper_critical_threshold, + &upper_non_recoverable_threshold) < 0) + goto cleanup; + + memset (fmt, '\0', IPMI_SENSORS_FMT_BUFLEN + 1); + + if (state_data->prog_data->args->comma_separated_output) + { + snprintf (thresholdfmt, + IPMI_SENSORS_FMT_BUFLEN, + ",%%.2f"); + + snprintf (nafmt, + IPMI_SENSORS_FMT_BUFLEN, + ",%%s"); + } + else + { + snprintf (thresholdfmt, + IPMI_SENSORS_FMT_BUFLEN, + " | %%-10.2f"); + + snprintf (nafmt, + IPMI_SENSORS_FMT_BUFLEN, + " | %%-10s"); + } + + if (lower_non_recoverable_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *lower_non_recoverable_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + + if (lower_critical_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *lower_critical_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + + if (lower_non_critical_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *lower_non_critical_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + + if (upper_non_critical_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *upper_non_critical_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + + if (upper_critical_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *upper_critical_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + + if (upper_non_recoverable_threshold) + pstdout_printf (state_data->pstate, + thresholdfmt, + *upper_non_recoverable_threshold); + else + pstdout_printf (state_data->pstate, + nafmt, + IPMI_SENSORS_NA_STRING); + } + if (state_data->prog_data->args->comma_separated_output) pstdout_printf (state_data->pstate, ","); else @@ -799,11 +897,11 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, if (state_data->prog_data->args->comma_separated_output) snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - ",%%.2f,%%s,"); + ",%%.2f,%%s"); else snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - " | %%-10.2f | %%-%ds | ", + " | %%-10.2f | %%-%ds", state_data->column_width.sensor_units); pstdout_printf (state_data->pstate, @@ -818,11 +916,11 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, if (state_data->prog_data->args->comma_separated_output) snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - ",%%s,%%s,"); + ",%%s,%%s"); else snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - " | %%-10s | %%-%ds | ", + " | %%-10s | %%-%ds", state_data->column_width.sensor_units); pstdout_printf (state_data->pstate, @@ -831,13 +929,33 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, IPMI_SENSORS_NA_STRING); } } - else + + if (state_data->prog_data->args->output_sensor_thresholds) { if (state_data->prog_data->args->comma_separated_output) + pstdout_printf (state_data->pstate, + ",%s,%s,%s,%s,%s,%s", + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING); + else + pstdout_printf (state_data->pstate, + " | %-10s | %-10s | %-10s | %-10s | %-10s | %-10s", + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING); + } + + if (state_data->prog_data->args->comma_separated_output) pstdout_printf (state_data->pstate, ","); else pstdout_printf (state_data->pstate, " | "); - } if (ipmi_sensors_output_event_message_list (state_data, event_message_output_type, @@ -852,6 +970,12 @@ _simple_output_full_record (ipmi_sensors_state_data_t *state_data, rv = 0; cleanup: + free (lower_non_critical_threshold); + free (upper_non_critical_threshold); + free (lower_critical_threshold); + free (upper_critical_threshold); + free (lower_non_recoverable_threshold); + free (upper_non_recoverable_threshold); return (rv); } @@ -883,11 +1007,11 @@ _simple_output_compact_record (ipmi_sensors_state_data_t *state_data, if (state_data->prog_data->args->comma_separated_output) snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - ",%%s,%%s,"); + ",%%s,%%s"); else snprintf (fmt, IPMI_SENSORS_FMT_BUFLEN, - " | %%-10s | %%-%ds | ", + " | %%-10s | %%-%ds", state_data->column_width.sensor_units); pstdout_printf (state_data->pstate, @@ -895,13 +1019,33 @@ _simple_output_compact_record (ipmi_sensors_state_data_t *state_data, IPMI_SENSORS_NA_STRING, IPMI_SENSORS_NA_STRING); } - else + + if (state_data->prog_data->args->output_sensor_thresholds) { if (state_data->prog_data->args->comma_separated_output) + pstdout_printf (state_data->pstate, + ",%s,%s,%s,%s,%s,%s", + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING); + else + pstdout_printf (state_data->pstate, + " | %-10s | %-10s | %-10s | %-10s | %-10s | %-10s", + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING, + IPMI_SENSORS_NA_STRING); + } + + if (state_data->prog_data->args->comma_separated_output) pstdout_printf (state_data->pstate, ","); else pstdout_printf (state_data->pstate, " | "); - } if (ipmi_sensors_output_event_message_list (state_data, event_message_output_type, @@ -1027,6 +1171,16 @@ _output_headers (ipmi_sensors_state_data_t *state_data) SENSORS_HEADER_UNITS_STR); } + if (state_data->prog_data->args->output_sensor_thresholds) + { + if (state_data->prog_data->args->comma_separated_output) + pstdout_printf (state_data->pstate, + ",Lower NR,Lower C,Lower NC,Upper NC,Upper C,Upper NR"); + else + pstdout_printf (state_data->pstate, + " | Lower NR | Lower C | Lower NC | Upper NC | Upper C | Upper NR "); + } + if (state_data->prog_data->args->comma_separated_output) pstdout_printf (state_data->pstate, ",%s\n", diff --git a/ipmi-sensors/ipmi-sensors.h b/ipmi-sensors/ipmi-sensors.h index bfc246e..e385510 100644 --- a/ipmi-sensors/ipmi-sensors.h +++ b/ipmi-sensors/ipmi-sensors.h @@ -51,12 +51,13 @@ enum ipmi_sensors_argp_option_keys OUTPUT_SENSOR_STATE_KEY = 169, SENSOR_STATE_CONFIG_FILE_KEY = 170, ENTITY_SENSOR_NAMES_KEY = 171, - NO_SENSOR_TYPE_OUTPUT_KEY = 172, - COMMA_SEPARATED_OUTPUT_KEY = 173, - NO_HEADER_OUTPUT_KEY = 174, - NON_ABBREVIATED_UNITS_KEY = 175, - LEGACY_OUTPUT_KEY = 176, - IPMIMONITORING_LEGACY_OUTPUT_KEY = 177, + OUTPUT_SENSOR_THRESHOLDS_KEY = 172, + NO_SENSOR_TYPE_OUTPUT_KEY = 173, + COMMA_SEPARATED_OUTPUT_KEY = 174, + NO_HEADER_OUTPUT_KEY = 175, + NON_ABBREVIATED_UNITS_KEY = 176, + LEGACY_OUTPUT_KEY = 177, + IPMIMONITORING_LEGACY_OUTPUT_KEY = 178, }; struct ipmi_sensors_arguments @@ -83,6 +84,7 @@ struct ipmi_sensors_arguments int output_sensor_state; char *sensor_state_config_file; int entity_sensor_names; + int output_sensor_thresholds; int no_sensor_type_output; int comma_separated_output; int no_header_output; diff --git a/man/freeipmi.conf.5.pre.in b/man/freeipmi.conf.5.pre.in index 9b4bf96..af1047f 100644 --- a/man/freeipmi.conf.5.pre.in +++ b/man/freeipmi.conf.5.pre.in @@ -1184,6 +1184,11 @@ Specify the default sensor state configuration file. Specify if output of sensor names should include entity ids and instances by default or not. .TP +\fBipmi\-sensors\-output\-sensor\-thresholds\fR \fIENABLE|DISABLE\fR +Specify if +.B ipmi-sensors +should output sensor thresholds by default. +.TP \fBipmi\-sensors\-no\-sensor\-type\-output\fR \fIENABLE|DISABLE\fR Specify if output of the sensor type should be output by default or not. diff --git a/man/ipmi-sensors.8.pre.in b/man/ipmi-sensors.8.pre.in index d0950d0..bcd13f7 100644 --- a/man/ipmi-sensors.8.pre.in +++ b/man/ipmi-sensors.8.pre.in @@ -156,6 +156,12 @@ previously output by Specify an alternate sensor state configuration file. Option ignored if \fB\-\-output\-sensor\-state\fR not specified. #include <@top_srcdir@/man/manpage-common-entity-sensor-names.man> +.TP +\fB\-\-output\-sensor\-thresholds\fR +Output sensor thresholds in output. This will add columns to the +default output for lower non-recoverable, lower critical, lower +non-critical, upper non-critical, upper critical, and upper +non-recoverable thresholds. #include <@top_srcdir@/man/manpage-common-no-sensor-type-output.man> #include <@top_srcdir@/man/manpage-common-comma-separated-output.man> #include <@top_srcdir@/man/manpage-common-no-header-output.man>