Ticket #774: add-machine-format.patch

File add-machine-format.patch, 5.9 KB (added by lynxchaus, 7 years ago)
  • smartmontools-6.5

    Description: Add machine-readable output format
    old new static void PrintSmartAttribWithThres(co  
    10141014  bool brief  = !!(format & ata_print_options::FMT_BRIEF);
    10151015  bool hexid  = !!(format & ata_print_options::FMT_HEX_ID);
    10161016  bool hexval = !!(format & ata_print_options::FMT_HEX_VAL);
     1017  bool machine = !!(format & ata_print_options::FMT_MACHINE);
    10171018  bool needheader = true;
    10181019
     1020  if (machine)
     1021        needheader = false;
     1022
    10191023  // step through all vendor attributes
    10201024  for (int i = 0; i < NUMBER_ATA_SMART_ATTRIBUTES; i++) {
    10211025    const ata_smart_attribute & attr = data->vendor_attributes[i];
    static void PrintSmartAttribWithThres(co  
    10491053    }
    10501054
    10511055    // Format value, worst, threshold
    1052     std::string valstr, worstr, threstr;
    1053     if (state > ATTRSTATE_NO_NORMVAL)
    1054       valstr = (!hexval ? strprintf("%.3d",   attr.current)
     1056    std::string idstr, valstr, worstr, threstr;
     1057    if (!machine) {
     1058        if (state > ATTRSTATE_NO_NORMVAL)
     1059            valstr = (!hexval ? strprintf("%.3d",   attr.current)
    10551060                        : strprintf("0x%02x", attr.current));
    1056     else
    1057       valstr = (!hexval ? "---" : "----");
    1058     if (!(defs[attr.id].flags & ATTRFLAG_NO_WORSTVAL))
    1059       worstr = (!hexval ? strprintf("%.3d",   attr.worst)
     1061        else
     1062            valstr = (!hexval ? "---" : "----");
     1063        if (!(defs[attr.id].flags & ATTRFLAG_NO_WORSTVAL))
     1064            worstr = (!hexval ? strprintf("%.3d",   attr.worst)
    10601065                        : strprintf("0x%02x", attr.worst));
    1061     else
    1062       worstr = (!hexval ? "---" : "----");
    1063     if (state > ATTRSTATE_NO_THRESHOLD)
    1064       threstr = (!hexval ? strprintf("%.3d",   threshold)
     1066        else
     1067            worstr = (!hexval ? "---" : "----");
     1068        if (state > ATTRSTATE_NO_THRESHOLD)
     1069            threstr = (!hexval ? strprintf("%.3d",   threshold)
    10651070                         : strprintf("0x%02x", threshold));
    1066     else
    1067       threstr = (!hexval ? "---" : "----");
    1068 
    1069     // Print line for each valid attribute
    1070     std::string idstr = (!hexid ? strprintf("%3d",    attr.id)
    1071                                 : strprintf("0x%02x", attr.id));
     1071        else
     1072            threstr = (!hexval ? "---" : "----");
     1073        // Print line for each valid attribute
     1074        idstr = (!hexid ? strprintf("%3d",    attr.id)
     1075                        : strprintf("0x%02x", attr.id));
     1076    } else {
     1077            valstr  = strprintf("%d", attr.current);
     1078            worstr  = strprintf("%d", attr.worst);
     1079            threstr = strprintf("%d", threshold);
     1080            idstr   = strprintf("%d", attr.id);
     1081    }
    10721082    std::string attrname = ata_get_smart_attr_name(attr.id, defs, rpm);
    10731083    std::string rawstr = ata_format_attr_raw_value(attr, defs);
    10741084
    1075     if (!brief)
     1085    if (machine)
     1086      pout("%s,%s,0x%04x,%s,%s,%s,%s,%s,%s,%s\n",
     1087           idstr.c_str(), attrname.c_str(), attr.flags,
     1088           valstr.c_str(), worstr.c_str(), threstr.c_str(),
     1089           (ATTRIBUTE_FLAGS_PREFAILURE(attr.flags) ? "Pre-fail" : "Old_age"),
     1090           (ATTRIBUTE_FLAGS_ONLINE(attr.flags)     ? "Always"   : "Offline"),
     1091           (state == ATTRSTATE_FAILED_NOW  ? "FAILING_NOW" :
     1092            state == ATTRSTATE_FAILED_PAST ? "In_the_past"
     1093                                           : "-") ,
     1094            rawstr.c_str());
     1095    else if (!brief)
    10761096      pout("%s %-24s0x%04x   %-4s  %-4s  %-4s   %-10s%-9s%-12s%s\n",
    10771097           idstr.c_str(), attrname.c_str(), attr.flags,
    10781098           valstr.c_str(), worstr.c_str(), threstr.c_str(),
    int ataPrintMain (ata_device * device, c  
    30493069    smart_val_ok = false;
    30503070  }
    30513071
    3052   // all this for a newline!
    3053   if (   options.smart_disable           || options.smart_enable
     3072  if (!(options.output_format & ata_print_options::FMT_MACHINE)) {
     3073    // all this for a newline!
     3074    if (   options.smart_disable           || options.smart_enable
    30543075      || options.smart_auto_save_disable || options.smart_auto_save_enable
    30553076      || options.smart_auto_offl_disable || options.smart_auto_offl_enable
    30563077      || options.set_aam || options.set_apm || options.set_lookahead
    int ataPrintMain (ata_device * device, c  
    30583079      || options.sct_wcache_reorder_set)
    30593080    pout("\n");
    30603081
    3061   // START OF READ-ONLY OPTIONS APART FROM -V and -i
    3062   if (   options.smart_check_status  || options.smart_general_values
     3082    // START OF READ-ONLY OPTIONS APART FROM -V and -i
     3083    if (   options.smart_check_status  || options.smart_general_values
    30633084      || options.smart_vendor_attrib || options.smart_error_log
    30643085      || options.smart_selftest_log  || options.smart_selective_selftest_log
    30653086      || options.smart_ext_error_log || options.smart_ext_selftest_log
    30663087      || options.sct_temp_sts        || options.sct_temp_hist               )
    3067     pout("=== START OF READ SMART DATA SECTION ===\n");
    3068  
     3088        pout("=== START OF READ SMART DATA SECTION ===\n");
     3089  }
     3090
    30693091  // Check SMART status
    30703092  if (options.smart_check_status) {
    30713093
  • smartmontools-6.5

    old new struct ata_print_options  
    8181  unsigned sct_temp_int;
    8282  bool sct_temp_int_pers;
    8383
    84   enum { FMT_BRIEF = 0x01, FMT_HEX_ID = 0x02, FMT_HEX_VAL = 0x04 };
     84  enum { FMT_BRIEF = 0x01, FMT_HEX_ID = 0x02, FMT_HEX_VAL = 0x04, FMT_MACHINE = 0x08 };
    8585  unsigned char output_format; // FMT_* flags
    8686
    8787  firmwarebug_defs firmwarebugs; // -F options
  • smartmontools-6.5

    old new static const char * parse_options(int ar  
    825825        ataopts.output_format |= ata_print_options::FMT_HEX_ID;
    826826      else if (!strcmp(optarg, "hex,val"))
    827827        ataopts.output_format |= ata_print_options::FMT_HEX_VAL;
     828      else if (!strcmp(optarg, "machine"))
     829        ataopts.output_format |= ata_print_options::FMT_MACHINE;
    828830      else
    829831        badarg = true;
    830832      break;
    static const char * parse_options(int ar  
    10961098    }
    10971099
    10981100  // From here on, normal operations...
    1099   printslogan();
     1101  if (!(ataopts.output_format & ata_print_options::FMT_MACHINE))
     1102    printslogan();
    11001103 
    11011104  // Warn if the user has provided no device name
    11021105  if (argc-optind<1){