Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nhc_common_parse_size doesn't support decimal values #120

Open
kcgthb opened this issue Dec 20, 2022 · 1 comment
Open

nhc_common_parse_size doesn't support decimal values #120

kcgthb opened this issue Dec 20, 2022 · 1 comment
Assignees
Labels
enhancement usability Confusing, strange, misleading, or otherwise problematic UX
Milestone

Comments

@kcgthb
Copy link

kcgthb commented Dec 20, 2022

Using decimal values in checks that use nhc_common_parse_size fail with an arithmetic operator error.

For instance:

$ nhc -d -e 'check_hw_physmem 1.5TB 1.5TB 10%'
DEBUG:  Debugging activated via -d option.
DEBUG:  Evaluating single check line:  check_hw_physmem 1.5TB 1.5TB 10%
[...]
/etc/nhc/scripts/common.nhc: line 508: 1.5*1024*1024*1024: syntax error: invalid arithmetic operator (error token is ".5*1024*1024*1024")
@mej
Copy link
Owner

mej commented Dec 23, 2022

This is a known limitation of Bash; it supports integer arithmetic only.

The "converse" function, nhc_common_unparse_size(), has a block of code to work around the lack of support for fractions and the various challenges that inevitably ensue. 😜 But in truth there are numerous potential "solutions" (mostly workarounds).

One possible workaround that's still readable involves some creative variable naming:

# In /etc/sysconfig/nhc
KB=1024 ; MB=$((1024*KB)) ; GB=$((1024*MB)) ; TB=$((1024*GB)) ; PB=$((1024*TB)) ; EB=$((1024*PB))

This allows for the command-line args or config files to contain something like this:

check_hw_physmem $((15*TB/10)) $((15*TB/10)) 10%

Alternatively, you can employ a similar technique to the code I referenced above, reverting to the next lower size unit:

check_hw_physmem 1536GB 1536GB 10%

That said, if this is actually intended to be a request for adding some level of decimal-parsing support to nhc_common_parse_size()... It would take some creativity, but I think it would be doable, probably using a similar technique to the one shown in the 2nd code block above (i.e., shift decimal right by n, multiply, divide by 10^n). Was that your intent?

@mej mej self-assigned this Dec 23, 2022
@mej mej added enhancement usability Confusing, strange, misleading, or otherwise problematic UX labels Dec 23, 2022
@mej mej added this to the 1.5 Release milestone Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement usability Confusing, strange, misleading, or otherwise problematic UX
Projects
None yet
Development

No branches or pull requests

2 participants