Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/utils/job-utils/ipmi-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function parseSensorsDataFactory(assert, _) {
*/
function parseSdrData(sdrData) {
var sdrArray = sdrData.split('\n\n');

var sdrObjArray = _.transform(sdrArray, function(result, sdr) {
var lines = sdr.trim().split('\n');
var key = '';
Expand Down Expand Up @@ -163,8 +162,11 @@ function parseSensorsDataFactory(assert, _) {
if (key.search(/sensorType/) >= 0) {
var sensorTypeKey = key.slice(0, 'sensorType'.length);
var sdrTypeValue = key.slice('sensorType'.length, key.length);
var match = value.match(/(.+) (\(0x.+\))?/);
key = sensorTypeKey;
value = value.match(/(.+) \(0x.+\)/)[1].trim();
if (match) {
value = match[1].trim();
}
sdrObj.sdrType = sdrTypeValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to change "Analog" to "Threshold" here, since sdr alert job will use this keyword. https://github.com/RackHD/on-tasks/blob/master/lib/jobs/ipmi-sdr-alert-job.js#L186

}
// The sensorReading key requires a bit of additional processing.
Expand Down Expand Up @@ -200,7 +202,6 @@ function parseSensorsDataFactory(assert, _) {

//ipmitool displays states as [state name] so remove the []
value = value.replace('[', '').replace(']', '');

if (key.length > 0) {
if (_.contains(listKeys, key)) {
//The key needs to be mapped to a list.
Expand All @@ -224,6 +225,22 @@ function parseSensorsDataFactory(assert, _) {
}
}
});

// For ipmitool v1.8.11, sensor reading '0h' doesn't exist
// It is presumed that ipmitool v1.8.13 generates '0h' if sensor reading doesn't exit
// To accommodate both v1.8.11 and v1.8.13, sensor reading will be automatically
// generated if it doesn't exist
if (sdrObj.sensorReading === "") {
sdrObj.sensorReading = "0h";
sdrObj.sensorReadingUnits = "";
}

// For ipmitool v1.8.11 sdr type is "Discrete" and "Analog"
// For ipmitool v1.8.13 sdr type is "Discrete" and "Threshold"
// Align sdr type to "Discrete" and "Threshold"
if(sdrObj.sdrType === "Analog") {
sdrObj.sdrType = "Threshold";
}

// if sdrObj has a non-empty value in every required key.
if (_.every(requiredKeys, function(key) {return _.has(sdrObj, key) && sdrObj[key];})) {
Expand Down
1 change: 0 additions & 1 deletion spec/lib/utils/job-utils/pollers/corrupt-ipmi-sdr-v-output
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Sensor ID : PCH Thermal Trip (0xbf)
OEM : 0

Sensor ID : MB Thermal Trip (0xb9)
Entity ID : 7.1 (System Board)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this line here?

Sensor Type (Discrete): Temperature (0x01)
Event Message Control : Per-threshold
Assertions Enabled : Digital State
Expand Down
21 changes: 17 additions & 4 deletions spec/lib/utils/job-utils/pollers/ipmi-parser-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs');
describe("ipmi-parser", function() {
var parser;
var ipmiOutMock;
var ipmiOutMockV11;
var corruptIpmiOutMock;
var ipmiDriveHealthOutMock;

Expand All @@ -22,6 +23,10 @@ describe("ipmi-parser", function() {
.readFileSync(__dirname+'/ipmi-sdr-v-output')
.toString();

ipmiOutMockV11 = fs
.readFileSync(__dirname+'/ipmi-sdr-v1.8.11-output')
.toString();

corruptIpmiOutMock = fs
.readFileSync(__dirname+'/corrupt-ipmi-sdr-v-output')
.toString();
Expand All @@ -32,9 +37,9 @@ describe("ipmi-parser", function() {
});

describe("IPMI extraction", function() {
it("should parse ipmitool -v sdr output", function() {
var sensors = parser.parseSdrData(ipmiOutMock);
sensors.should.have.length(ipmiOutMock.match(/Sensor\ ID/g).length);
function testSdrParser(sdr){
var sensors = parser.parseSdrData(sdr);
sensors.should.have.length(sdr.match(/Sensor\ ID/g).length);

var expectedAssertions = {
'PSU1 Status (0xe0)': ['Power Supply AC lost'],
Expand Down Expand Up @@ -69,7 +74,7 @@ describe("ipmi-parser", function() {
if (sensor.sdrType === 'Discrete') {
if (_.has(expectedAssertions, sensor.sensorId)) {
expect(sensor).to.have.property('statesAsserted');
_.forEach(expectedAssertions[sensor.sensorId],
_.forEach(expectedAssertions[sensor.sensorId],
function(assertion) {
expect(sensor.statesAsserted).to.include(assertion);
expect(sensor.statesAsserted)
Expand All @@ -82,6 +87,14 @@ describe("ipmi-parser", function() {
expect(sensor.status).to.equal(expectedValue);
}
});
}

it("should parse ipmitool -v sdr output", function() {
testSdrParser(ipmiOutMock);
});

it("should parse ipmitool -v sdr output for v1.8.11", function() {
testSdrParser(ipmiOutMockV11);
});

it("should omit corrupt sdr entries", function() {
Expand Down
Loading