Repository navigation
Conversation
Range(0) and Range(0.0) were coerced to Range('') by the falsy check in
Range.__new__, producing 0:inf instead of 0:0, so a threshold such as
critical=0 could never trigger. Numeric specs are now used directly
instead of being round-tripped through str(), which also makes floats
with an exponent in their repr and float('inf') usable as specs.
An empty spec (Range(''), Range(None), or an omitted ScalarContext
threshold) is now unbounded in both directions, equivalent to '~:',
so it never alerts. Previously it meant '0:' and a negative metric
value would unexpectedly produce a WARNING or CRITICAL. The unbounded
range still renders as '' so performance data is unchanged, and
Range('0:') now renders as '0:' so the two stay distinguishable.
Range(False), which worked only by accident of the falsy check, and
Range(True) now both raise TypeError. NaN bounds raise ValueError
instead of silently matching every value.
Fixes #15
Fixes #83
Closes #128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two long-standing
Rangespec bugs, fixed together because they share a root cause (thespec = spec or ''falsy check inRange.__new__) and because the fix for one forces a decision about the other.#83:
Range(0)produced0:infinstead of0:0. The falsy check turned the int0into'', socritical=0could never trigger. The numeric branch in__new__was also dead code: its result was overwritten by the string parse on the next line. Numeric specs are now used directly rather than round-tripped throughstr(), which also makes floats whose repr uses an exponent (e.g.1e20) andfloat('inf')usable as specs.#15: an empty spec meant
0:, so negative values tripped omitted thresholds.Range(''),Range(None), and an omittedScalarContextthreshold are now unbounded in both directions, equivalent to'~:', and never alert. The unbounded range still renders as''so performance data for omitted thresholds is byte-for-byte unchanged.Range('0:')now renders as'0:'rather than''so the two ranges remain distinguishable in perfdata andrepr().Also:
Range(False)(which only worked by accident of the falsy check) andRange(True)now raiseTypeErrorwith a hint to useNone. NaN bounds raiseValueErrorinstead of silently matching every value.This supersedes #128, which patched the
or ''symptom but left the numeric branch dead.Related issue
Fixes #15
Fixes #83
Closes #128
Testing
str(),violationandmatchoutput, exponent-repr floats, infinity, NaN, bools, the''vs'0:'distinction,reprround-tripping for nine specs, and the exact None passed as range defaults to "0:" #15 scenario at theScalarContextlevel including perfdata output.SENSORS OK - sens1 is -3 | sens1=-3;-10:10, exit 0. With an explicitcritical='0:'it still goes CRITICAL.Compatibility and security
Public behaviour changes, all called out in CHANGELOG.txt with an IMPORTANT NOTE at the top of the 1.5.0 section:
Range(0)/Range(0.0):0:infbecomes0:0. Plugins passing an int 0 had a silently disabled threshold and will now alert as intended.None:0:infbecomes-inf:inf. Plugins relying on an omitted threshold to alert on negative values must pass'0:'explicitly.str(Range('0:')):''becomes'0:'. Shows up in perfdata for plugins that pass'0:'explicitly.Range(False): was0:inf, nowTypeError.Range('@'): was@0:, now inverted-unbounded (never matches). Falls out of the parser change; unlikely to be in use.No untrusted input handling or security implications.
Checklist