Suppress nagios_wrapper valueMeta for empty detail

Checks processed by the nagios_wrapper typically contain a text string
and return code.  The text string is submitted to the API as valueMeta
'detail'.  However, if the Nagios check does not return a text string,
the 'detail' field is empty, this condition has been known to cause an
UNPROCESSABLE_ENTITY error in the API ("valueMeta detail cannot have an
empty value").

This change prevents valueMeta 'detail' from being submitted to the API
if the Nagios check outputs no text string along with its return code.

Change-Id: Ic6b584d6f988323d25676ebbdbdbe3edd06c4c3a
This commit is contained in:
David Schroeder
2015-04-17 15:47:32 -06:00
parent 395f5ac28a
commit e35af0e8e9

View File

@@ -104,10 +104,12 @@ class WrapNagios(ServicesCheck):
status_code = proc.poll()
last_run_data[instance['name']] = time.time()
self.gauge(metric_name,
status_code,
dimensions=dimensions,
value_meta={'detail': detail})
if detail:
self.gauge(metric_name, status_code,
dimensions=dimensions,
value_meta={'detail': detail})
else:
self.gauge(metric_name, status_code, dimensions=dimensions)
# Return DOWN on critical, UP otherwise
if status_code == "2":
return Status.DOWN, "DOWN: {0}".format(detail)