import { Integer } from "../../../peg-number" import { HexInteger } from "../../../peg-hex-number" import { Newline } from "../../../peg-newline" import { SameLine as _ } from "../../../peg-whitespace" import { RestOfLine } from "../../../peg-rest-of-line" import { IdentifierValue } from "../primitives" import { Header } from "../shared" { const matchValue = require("match-value"); const mapAttributeFlags = require("../../map-attribute-flags"); } RootAttributes = header:Header attributesSection:AttributesSection Newline* { return { ...header, attributes: attributesSection } }; AttributesSection = AttributesSectionSATA / AttributesSectionNVMe AttributesSectionSATA = "=== START OF READ SMART DATA SECTION ===" Newline "SMART Attributes Data Structure revision number:" _ Integer Newline "Vendor Specific SMART Attributes with Thresholds:" Newline "ID#" _ "ATTRIBUTE_NAME" _ "FLAG" _ "VALUE" _ "WORST" _ "THRESH" _ "TYPE" _ "UPDATED" _ "WHEN_FAILED" _ "RAW_VALUE" Newline attributes:AttributeFieldSATA+ { return attributes; } AttributesSectionNVMe = "=== START OF SMART DATA SECTION ===" Newline "SMART/Health Information (NVMe Log 0x02)" Newline attributes:AttributeFieldNVMe+ { return attributes; } AttributeFlags = "0x" number:HexInteger { return mapAttributeFlags(number); } AttributeUpdatedWhen = "Always" / "Offline" AttributeFailedWhen = "FAILING_NOW" / "In_the_past" / "-" AttributeFieldType = "Pre-fail" / "Old_age" AttributeFieldSATA = _? id:Integer _ attributeName:IdentifierValue _ flags:AttributeFlags _ value:Integer _ worstValue:Integer _ threshold:Integer _ type:AttributeFieldType _ updatedWhen:AttributeUpdatedWhen _ failedWhen:AttributeFailedWhen _ rawValue:RestOfLine { return { id, attributeName, flags, value, worstValue, threshold, rawValue, updatedWhen: matchValue(updatedWhen, { "Always": "always", "Offline": "offline" }), type: matchValue(type, { "Pre-fail": "preFail", "Old_age": "oldAge" }), failingNow: (failedWhen === "FAILING_NOW"), /* TODO: Should the below include the FAILING_NOW state? */ failedBefore: (failedWhen === "In_the_past") }; } AttributeFieldNVMe = label:$[^:]+ ":" _ value:RestOfLine { return { label: label, value }; }