-
Notifications
You must be signed in to change notification settings - Fork 812
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
Checking that attribute retreived by wmi_property is not None #1800
Conversation
@yann could you take a look? |
@@ -109,7 +109,7 @@ def _extract_metrics(self, results, metrics, tag_by, wmi, tag_queries, constant_ | |||
# Special-case metric will just submit 1 for every value | |||
# returned in the result. | |||
val = 1 | |||
else: | |||
elif getattr(res, wmi_property) is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif getattr(res, wmi_property):
is probably enough as we don't want to cast an empty string either.
Also, should we add a log.warning
when we endup in this case ? It could help users or support understanding why some metrics are silenced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
Great, thanks for you reactivity @JohnLZeller. |
8bf787e
to
c864530
Compare
@yannmh how's this? |
val = float(getattr(res, wmi_property)) | ||
elif not getattr(res, wmi_property): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
instead of elif not getattr(res, wmi_property)
as not getattr(res, wmi_property)
will always be True
at this state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, good point.
c864530
to
23c0339
Compare
@yannmh should be good now |
👍 |
Checking that attribute retreived by wmi_property is not None
Sinces #1800, `val` variable is unreferenced when WMI metric is null. Thus, an exception is raised when we try to submit it to Datadog. Ignore null values, and continue, so it does not raise.
Fix regression with #1800, as 0s were not reported anymore. Log a warning when the specified WMI property does not exist among the class, or when the value extracted is not a digit. Keep the crawler running.
Fix regression with #1800, as 0s were not reported anymore. Log a warning when the specified WMI property does not exist among the class, or when the value extracted is not a digit. Keep the crawler running.
Discovered that when wmi_check.py is run, that depending upon the yaml configuration, it can end up pulling attributes that have a value of None, which will throw a TypeError complaining that float() cannot coerce something that is not a string nor an integer. Specifically, this issue came to light with a config that setup grabbing metrics for the
FreeSpace
andSize
properties from theWin32_LogicalDisk
class. This runs for all disks, including CD-ROMs, which will report nothing for either property.The fix is to check tht the attribute retrieved by wmi_property is not None before attempting to coerce to a float.
I'll not for the record as well, in regard to the specific situation that this turned up in, that we are already collecting disk usage statistics in
checks.d/disk.py
, and specificallyFreeSpace
would probably correspond tosystem.disk.free
andSize
tosystem.disk.total
, for each disk.