Skip to content

check_dmi_data_match fails because of whitespaces #49

@rpabel

Description

@rpabel

The autogenerated nhc.conf on some of our nodes contains spaces in check_dmi_data_match tests like this:

check_dmi_data_match -h 0x0400 -t 4 "Processor Information: Version: Intel(R) Xeon(R) CPU           X5550  @ 2.67GHz"

The string is later read in and passed around and when it is fed to eval, the whitespaces are collapsed:

1510827263] - DEBUG:  Glob match check:  Processor Information: Version: Intel(R) Xeon(R) CPU           X5550  @ 2.67GHz does not match Processor Information: Version: Intel(R) Xeon(R) CPU X5550 @ 2.67GHz

The easiest workaround I found is escaping all whitespaces twice:

check_dmi_data_match -h 0x0401 -t 4 "Processor\\ Information:\\ Version:\\ Intel(R)\\ Xeon(R)\\ CPU\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ X5550\\ \\ @\\ 2.67GHz"

Now the tests run just fine:

Running check:  "check_dmi_data_match -h 0x0400 -t 4 "Processor\ Information:\ Version:\ Intel(R)\ Xeon(R)\ CPU\ \ \ \ \ \ \ \ \ \ \ X5550\ \ @\ 2.67GHz"

I've adapted nhc-genconf to change the output if two consecutive whitespaces are found:

diff -ruN nhc.orig/nhc-genconf nhc/nhc-genconf
--- nhc.orig/nhc-genconf        2017-11-16 11:38:10.872479034 +0100
+++ nhc/nhc-genconf     2017-11-16 11:37:43.041458469 +0100
@@ -248,7 +248,12 @@
             IFS=$' \t\n'
             for ((i=0; i<${#LINES[*]}; i++)); do
                 if mcheck "${LINES[$i]}" "$DMI_MATCH"; then
-                    echo "# $HOSTNAME || check_dmi_data_match -h $HANDLE ${DMI_TYPE_IDS[$HANDLE]:+-t ${DMI_TYPE_IDS[$HANDLE]}} \"${LINES[i]}\""
+                    if [[ "${LINES[$i]}" == *"  "* ]]; then
+                        ESCAPED=$(echo "${LINES[i]}" | sed 's/\([ ]\)/\\\\\1/g')
+                        echo "# $HOSTNAME || check_dmi_data_match -h $HANDLE ${DMI_TYPE_IDS[$HANDLE]:+-t ${DMI_TYPE_IDS[$HANDLE]}} \"${ESCAPED}\""
+                    else
+                        echo "# $HOSTNAME || check_dmi_data_match -h $HANDLE ${DMI_TYPE_IDS[$HANDLE]:+-t ${DMI_TYPE_IDS[$HANDLE]}} \"${LINES[i]}\""
+                    fi
                 fi
             done
         done

But maybe this should be fixed at the point where the whitespaces are collapsed due to missing quotation marks?

Roland

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions