Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions bin/pd-sensu
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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',
Expand All @@ -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():
Expand All @@ -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:
Expand Down