From cfb92ec8f6e9938e1ad9b02d45000d5a33c4fd5a Mon Sep 17 00:00:00 2001 From: Brandon Rochon Date: Tue, 31 Oct 2017 17:33:56 -0700 Subject: [PATCH 1/2] optionally truncate sensu output Change-Id: I2d9d2d365798704f6cc9d0c76d247a65216df0c2 --- bin/pd-sensu | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/pd-sensu b/bin/pd-sensu index 4522a8d..e9c83cf 100755 --- a/bin/pd-sensu +++ b/bin/pd-sensu @@ -48,7 +48,7 @@ def log_exception(error, preface="Unexpected error"): class SensuEvent: """Class for enqueueing a Sensu check result as a PD event""" - def __init__(self, integration_key, check_result, given_incident_key=None): + def __init__(self, integration_key, check_result, given_incident_key=None, truncate=None): """Constructor Arguments: @@ -91,7 +91,7 @@ class SensuEvent: self._incident_key = details['id'] self._description = '%s : %s'%( self._incident_key, - details['check']['output'] + details['check']['output'][:truncate] ) def enqueue(self): @@ -129,6 +129,16 @@ def parse_args(): default=None, help="Specifies a custom incident key for deduplication" ) + parser.add_argument( + '-t', + '--truncate', + dest='truncate', + required=False, + default=None, + type=int, + help="Truncates check output in description field to desired character length" + ) + return parser.parse_args() def main(): @@ -137,7 +147,8 @@ def main(): pdevent = SensuEvent( args.integration_key, stdin, - given_incident_key=args.incident_key + given_incident_key=args.incident_key, + truncate=args.truncate ) try: From 040580d42138cf738eff73d7fdecd4deeba06b5b Mon Sep 17 00:00:00 2001 From: Brandon Rochon Date: Tue, 31 Oct 2017 17:37:10 -0700 Subject: [PATCH 2/2] Remove reference to that "other" monitoring system Change-Id: Ia4eab460ac8dd4fd090794d10f89ae5caff5dc5f --- bin/pd-sensu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pd-sensu b/bin/pd-sensu index e9c83cf..f83be4c 100755 --- a/bin/pd-sensu +++ b/bin/pd-sensu @@ -112,7 +112,7 @@ class SensuEvent: ) def parse_args(): - description = "Enqueue an event from Nagios to PagerDuty." + description = "Enqueue an event from Sensu to PagerDuty." parser = argparse.ArgumentParser(description) parser.add_argument( '-k',