mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-07-02 02:33:37 +00:00
add support for verbose sdr output in CSV mode and add some fields,
fix sdr_convert_sensor_reading to properly handle signed values --from Fredrik Ohrn
This commit is contained in:
@ -368,6 +368,19 @@ static const char * unit_desc[] __attribute__((unused)) = {
|
|||||||
"error", "correctable error", "uncorrectable error",
|
"error", "correctable error", "uncorrectable error",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* sensor type codes (IPMI v1.5 table 36.3) */
|
||||||
|
#define SENSOR_TYPE_MAX 0x29
|
||||||
|
static const char * sensor_type_desc[] __attribute__((unused)) = {
|
||||||
|
"reserved",
|
||||||
|
"Temperature", "Voltage", "Current", "Fan", "Physical Security", "Platform Security Violation Attempt",
|
||||||
|
"Processor", "Power Supply", "Power Unit", "Cooling Device", "Other", "Memory", "Drive Slot / Bay",
|
||||||
|
"POST Memory Resize", "System Firmware Progress", "Event Logging Disabled", "Watchdog", "System Event",
|
||||||
|
"Critical Interrupt", "Button", "Module / Board", "Microcontroller / Coprocessor", "Add-in Card",
|
||||||
|
"Chassis", "Chip Set", "Other FRU", "Cable / Interconnect", "Terminator", "System Boot Initiated",
|
||||||
|
"Boot Error", "OS Boot", "OS Critical Stop", "Slot / Connector", "System ACPI Power State", "Watchdog",
|
||||||
|
"Platform Alert", "Entity Presence", "Monitor ASIC / IC", "LAN", "Management Subsystem Health", "Battery"
|
||||||
|
};
|
||||||
|
|
||||||
struct ipmi_sdr_iterator * ipmi_sdr_start(struct ipmi_intf * intf);
|
struct ipmi_sdr_iterator * ipmi_sdr_start(struct ipmi_intf * intf);
|
||||||
struct sdr_get_rs * ipmi_sdr_get_next_header(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i);
|
struct sdr_get_rs * ipmi_sdr_get_next_header(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i);
|
||||||
unsigned char * ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, struct ipmi_sdr_iterator * i);
|
unsigned char * ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, struct ipmi_sdr_iterator * i);
|
||||||
|
@ -65,7 +65,19 @@ sdr_convert_sensor_reading(struct sdr_record_full_sensor * sensor, unsigned char
|
|||||||
k1 = __TO_B_EXP(sensor->bacc);
|
k1 = __TO_B_EXP(sensor->bacc);
|
||||||
k2 = __TO_R_EXP(sensor->bacc);
|
k2 = __TO_R_EXP(sensor->bacc);
|
||||||
|
|
||||||
|
switch (sensor->unit.analog)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
return (float)(((m * val) + (b * pow(10, k1))) * pow(10, k2));
|
return (float)(((m * val) + (b * pow(10, k1))) * pow(10, k2));
|
||||||
|
case 1:
|
||||||
|
if (val & 0x80) val ++;
|
||||||
|
/* Deliberately fall through to case 2. */
|
||||||
|
case 2:
|
||||||
|
return (float)(((m * (signed char)val) + (b * pow(10, k1))) * pow(10, k2));
|
||||||
|
default:
|
||||||
|
/* Ops! This isn't an analog sensor. */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define READING_UNAVAILABLE 0x20
|
#define READING_UNAVAILABLE 0x20
|
||||||
@ -93,6 +105,18 @@ ipmi_sdr_get_sensor_reading(struct ipmi_intf * intf, unsigned char sensor)
|
|||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
ipmi_sdr_get_sensor_type_desc(const unsigned char type)
|
||||||
|
{
|
||||||
|
if (type <= SENSOR_TYPE_MAX)
|
||||||
|
return sensor_type_desc[type];
|
||||||
|
|
||||||
|
if (type < 0xc0)
|
||||||
|
return "reserved";
|
||||||
|
|
||||||
|
return "OEM reserved";
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
ipmi_sdr_get_status(unsigned char stat)
|
ipmi_sdr_get_status(unsigned char stat)
|
||||||
{
|
{
|
||||||
@ -249,55 +273,87 @@ ipmi_sdr_print_sensor_full(struct ipmi_intf * intf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!verbose) {
|
if (csv_output)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* print sensor name, reading, unit, state
|
||||||
|
*/
|
||||||
|
printf("%s,", sensor->id_code ? desc : NULL);
|
||||||
|
|
||||||
|
if (validread)
|
||||||
|
printf("%.*f,", (val==(int)val) ? 0 : 3, val);
|
||||||
|
else
|
||||||
|
printf(",");
|
||||||
|
|
||||||
|
printf("%s,%s",
|
||||||
|
do_unit ? unitstr : "",
|
||||||
|
ipmi_sdr_get_status(rsp->data[2]));
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
printf(",%d.%d,%s,%s,",
|
||||||
|
sensor->entity.id, sensor->entity.instance,
|
||||||
|
val2str(sensor->entity.id, entity_id_vals),
|
||||||
|
ipmi_sdr_get_sensor_type_desc(sensor->sensor.type));
|
||||||
|
|
||||||
|
#define CSV_PRINT_HELPER(flag,value) \
|
||||||
|
if(flag) printf("%.3f,", sdr_convert_sensor_reading(sensor, value)); else printf(",");
|
||||||
|
|
||||||
|
CSV_PRINT_HELPER(sensor->analog_flag.nominal_read, sensor->nominal_read);
|
||||||
|
CSV_PRINT_HELPER(sensor->analog_flag.normal_min, sensor->normal_min);
|
||||||
|
CSV_PRINT_HELPER(sensor->analog_flag.normal_max, sensor->normal_max);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x20, sensor->threshold.upper.non_recover);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x10, sensor->threshold.upper.critical);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x08, sensor->threshold.upper.non_critical);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x04, sensor->threshold.lower.non_recover);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x02, sensor->threshold.lower.critical);
|
||||||
|
CSV_PRINT_HELPER(sensor->mask.threshold.set & 0x01, sensor->threshold.lower.non_critical);
|
||||||
|
|
||||||
|
printf ("%.3f,%.3f",
|
||||||
|
sdr_convert_sensor_reading(sensor, sensor->sensor_min),
|
||||||
|
sdr_convert_sensor_reading(sensor, sensor->sensor_max));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!verbose)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* print sensor name, reading, state
|
* print sensor name, reading, state
|
||||||
*/
|
*/
|
||||||
if (csv_output)
|
|
||||||
printf("%s,",
|
|
||||||
sensor->id_code ? desc : NULL);
|
|
||||||
else
|
|
||||||
printf("%-16s | ",
|
printf("%-16s | ",
|
||||||
sensor->id_code ? desc : NULL);
|
sensor->id_code ? desc : NULL);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
memset(sval, 0, sizeof(sval));
|
memset(sval, 0, sizeof(sval));
|
||||||
if (validread) {
|
if (validread) {
|
||||||
i += snprintf(sval, sizeof(sval), "%.*f",
|
i += snprintf(sval, sizeof(sval), "%.*f %s",
|
||||||
(val==(int)val) ? 0 : 3, val);
|
(val==(int)val) ? 0 : 3, val,
|
||||||
|
do_unit ? unitstr : "");
|
||||||
} else {
|
} else {
|
||||||
i += snprintf(sval, sizeof(sval), "no reading ");
|
i += snprintf(sval, sizeof(sval), "no reading ");
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
printf("%s", sval);
|
printf("%s", sval);
|
||||||
|
|
||||||
if (csv_output)
|
i--;
|
||||||
printf(",");
|
|
||||||
|
|
||||||
if (validread) {
|
|
||||||
if (!csv_output)
|
|
||||||
printf(" ");
|
|
||||||
if (do_unit)
|
|
||||||
printf("%s", unitstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (csv_output)
|
|
||||||
printf(",");
|
|
||||||
else {
|
|
||||||
for (; i<sizeof(sval); i++)
|
for (; i<sizeof(sval); i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf(" | ");
|
printf(" | ");
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s", ipmi_sdr_get_status(rsp->data[2]));
|
printf("%s", ipmi_sdr_get_status(rsp->data[2]));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("Sensor ID : %s (0x%x)\n",
|
printf("Sensor ID : %s (0x%x)\n",
|
||||||
sensor->id_code ? desc : NULL, sensor->keys.sensor_num);
|
sensor->id_code ? desc : NULL, sensor->keys.sensor_num);
|
||||||
printf("Entity ID : %d.%d (%s)\n",
|
printf("Entity ID : %d.%d (%s)\n",
|
||||||
sensor->entity.id, sensor->entity.instance,
|
sensor->entity.id, sensor->entity.instance,
|
||||||
val2str(sensor->entity.id, entity_id_vals));
|
val2str(sensor->entity.id, entity_id_vals));
|
||||||
|
|
||||||
|
printf("Sensor Type : %s\n", ipmi_sdr_get_sensor_type_desc(sensor->sensor.type));
|
||||||
|
|
||||||
printf("Sensor Reading : ");
|
printf("Sensor Reading : ");
|
||||||
if (validread)
|
if (validread)
|
||||||
printf("%.*f %s\n", (val==(int)val) ? 0 : 3, val, unitstr);
|
printf("%.*f %s\n", (val==(int)val) ? 0 : 3, val, unitstr);
|
||||||
@ -326,9 +382,14 @@ ipmi_sdr_print_sensor_full(struct ipmi_intf * intf,
|
|||||||
sdr_convert_sensor_reading(sensor, sensor->threshold.lower.critical));
|
sdr_convert_sensor_reading(sensor, sensor->threshold.lower.critical));
|
||||||
printf("Lower non-critical : %.3f\n",
|
printf("Lower non-critical : %.3f\n",
|
||||||
sdr_convert_sensor_reading(sensor, sensor->threshold.lower.non_critical));
|
sdr_convert_sensor_reading(sensor, sensor->threshold.lower.non_critical));
|
||||||
|
printf("Minimum sensor range : %.3f\n",
|
||||||
|
sdr_convert_sensor_reading(sensor, sensor->sensor_min));
|
||||||
|
printf("Maximum sensor range : %.3f\n",
|
||||||
|
sdr_convert_sensor_reading(sensor, sensor->sensor_max));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf,
|
ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf,
|
||||||
@ -360,8 +421,8 @@ ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf,
|
|||||||
printf("Entity ID : %d.%d (%s)\n",
|
printf("Entity ID : %d.%d (%s)\n",
|
||||||
sensor->entity.id, sensor->entity.instance,
|
sensor->entity.id, sensor->entity.instance,
|
||||||
val2str(sensor->entity.id, entity_id_vals));
|
val2str(sensor->entity.id, entity_id_vals));
|
||||||
|
printf("Sensor Type : %s\n", ipmi_sdr_get_sensor_type_desc(sensor->sensor.type));
|
||||||
if (verbose > 1) {
|
if (verbose > 1) {
|
||||||
printf("Sensor Type Code : 0x%02x\n", sensor->sensor.type);
|
|
||||||
printf("Event Type Code : 0x%02x\n", sensor->event_type);
|
printf("Event Type Code : 0x%02x\n", sensor->event_type);
|
||||||
printbuf(rsp->data, rsp->data_len, "COMPACT SENSOR READING");
|
printbuf(rsp->data, rsp->data_len, "COMPACT SENSOR READING");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user