sensu-plugins / sensu-plugin

A framework for writing Sensu plugins & handlers with Ruby.
http://sensuapp.org
MIT License
126 stars 117 forks source link

Helper method to convert boolean strings to integers #174

Closed Evesy closed 7 years ago

Evesy commented 7 years ago

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 https://github.com/sensu-plugins/sensu-plugins-elasticsearch/issues/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

majormoses commented 7 years ago

@Evesy it looks good, can you add a test please?

majormoses commented 7 years ago

@Evesy thanks for adding those tests which look good to me.

majormoses commented 7 years ago

@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.

cwjohnston commented 7 years ago

Seems reasonable and tests look good. Thanks!

majormoses commented 7 years ago

cool, I will cut a release shortly then.

majormoses commented 7 years ago

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.

majormoses commented 7 years ago

released: https://rubygems.org/gems/sensu-plugin/versions/2.1.0