-
Notifications
You must be signed in to change notification settings - Fork 117
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
Helper method to convert boolean strings to integers #174
Conversation
@Evesy it looks good, can you add a test please? |
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.
overall looks good, some minor enhancements and test will make this mergeable from my perspective though I will check with @cwjohnston since this is closer to the core and I want to check and see if he has any concerns.
lib/sensu-plugin/utils.rb
Outdated
|
||
def cast_bool_values_int(value) | ||
case value | ||
when 'true' |
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.
to make it a bit more generic we should have when 'true', true
as I am sure different implementations will return it differently and we might as well support both.
lib/sensu-plugin/utils.rb
Outdated
case value | ||
when 'true' | ||
1 | ||
when 'false' |
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.
same comment as above when 'false', false
@Evesy thanks for adding those tests which look good to me. |
@cwjohnston his looks good to me, do you have any issues with pushing this logic here? I think it could be helpful to solve the same issue across multiple plugins. |
Seems reasonable and tests look good. Thanks! |
cool, I will cut a release shortly then. |
Apparently the build process is different for this plugin I have opened #175 as I do not see why the process should be different even if the access is. We should figure this out before accepting any more changes. |
Additional helper method
cast_bool_values_int
to convert a provided boolean string to respective integer value.Description
This method accepts a single value, converting a true or false string to 1 or 0 respectively.
Any other values will just be returned.
Motivation and Context
In certain metric collection plugins, metrics are occasionally generated with true/false values rather than integers. Certain TSDB's will not accept boolean values and instead expect integer equivalents (i.e. Graphite, true = 1, false = 0). See sensu-plugins/sensu-plugins-elasticsearch#49 for reference
This helper method allows, where applicable, these values to be converted into integers so they can be successfully ingested by those TSDB's.
How Has This Been Tested?
Tested new method in local environment
Types of changes
Checklist:
Known Caveats