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

Checking that attribute retreived by wmi_property is not None #1800

Merged
merged 1 commit into from
Aug 7, 2015

Conversation

JohnLZeller
Copy link
Contributor

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 and Size properties from the Win32_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 specifically FreeSpace would probably correspond to system.disk.free and Size to system.disk.total, for each disk.

@JohnLZeller
Copy link
Contributor Author

@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:
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

@yannmh
Copy link
Member

yannmh commented Jul 30, 2015

Great, thanks for you reactivity @JohnLZeller.

@yannmh yannmh added this to the 5.5.0 milestone Jul 30, 2015
@JohnLZeller
Copy link
Contributor Author

@yannmh how's this?

val = float(getattr(res, wmi_property))
elif not getattr(res, wmi_property):
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, good point.

@JohnLZeller
Copy link
Contributor Author

@yannmh should be good now

@yannmh
Copy link
Member

yannmh commented Aug 7, 2015

👍

yannmh added a commit that referenced this pull request Aug 7, 2015
Checking that attribute retreived by wmi_property is not None
@yannmh yannmh merged commit d20b9a3 into master Aug 7, 2015
@yannmh yannmh deleted the zeller/wmi-check-fix branch August 7, 2015 19:29
yannmh added a commit that referenced this pull request Aug 18, 2015
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.
yannmh added a commit that referenced this pull request Aug 19, 2015
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.
@yannmh yannmh mentioned this pull request Aug 19, 2015
yannmh added a commit that referenced this pull request Aug 25, 2015
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants