sscargal / pmemchk

MIT License
0 stars 1 forks source link

[Collector] Reformat `ipmctl show -a` files to pipe-separated values tables #50

Closed sscargal closed 2 years ago

sscargal commented 2 years ago

The non-all (-a) outputs from ipmctl are displayed in a pipe separated value table format, eg:

$ head -n5 ipmctl_show_-firmware
 DimmID | ActiveFWVersion | StagedFWVersion
============================================
 0x0001 | 01.02.00.5444   | N/A
 0x0011 | 01.02.00.5444   | N/A
 0x0021 | 01.02.00.5444   | N/A

When adding the all (-a) option, the output format is different, eg:

$ head ipmctl_show_-a_-firmware
---DimmID=0x0001---
   ActiveFWVersion=01.02.00.5444
   StagedFWVersion=N/A
   StagedFWActivatable=Not activatable, reboot is required
   FWUpdateStatus=Update loaded successfully
   FWImageMaxSize=266240
   QuiesceRequired=Not required
   ActivationTime=0

To make the rules easier to implement and consistent, the output from the 'all' command should be reformatted into the pipe-separated value table format.

sscargal commented 2 years ago

The following awk script will reformat the data to the requested output format

# AWK rules explanation
# 
# Change the Output Field Separator to the '|' symbol
# BEGIN {OFS="|"}
#
# For all rows that do not begin with '---', remove all leading and trailing white spaces, then print the HdrValue and Fields 1 and 2, then move to the next row
# Performing this row first avoids unnecessary test conditions if we were to place this rule later in the order
# $0 !~ /^---/ {gsub(/^[ \t]+|[ \t]+$/, "", $0);print HdrValue,$1,$2; next}
#
# For rows that begin with '---', replace '---' with blanks, then set HdrStr to Field 1 and HdrValue to Field 2
# $0 ~ /^---/ {gsub(/\-/, "", $0); HdrStr=$1; HdrValue=$2;}
#
# Print the output Header if processing the first row in the input file
# NR == 1 {print HdrStr"|Property|Value";}
awk -F '[=]' 'BEGIN {OFS="|"} 
$0 !~ /^---/ {gsub(/^[ \t]+|[ \t]+$/, "", $0);print HdrValue,$1,$2; next} 
$0 ~ /^---/ {gsub(/\-/, "", $0); HdrStr=$1; HdrValue=$2;} 
NR == 1 {print HdrStr"|Property|Value";} 
' ipmctl_show_-a_-dimm
sscargal commented 2 years ago

Fixed by #51