Created
February 28, 2016 15:14
-
-
Save dmsimard/bd49f7ec459e66ec7b94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# This script is a Sensu mutator meant to accept data from Sensu as stdin in | |
# order to merge data from the event and check 'occurrences' fields in order | |
# to make them usable together in a filter. | |
import sys | |
try: | |
import simplejson as json | |
except ImportError: | |
import json | |
if __name__ == '__main__': | |
try: | |
data = json.load(sys.stdin) | |
except Exception as e: | |
print("Unable to parse JSON: {0}".format(str(e))) | |
sys.exit(1) | |
if 'occurrences' in data and 'occurrences' in data['check']: | |
data['merged-occurrences'] = { | |
'event': data['occurrences'], | |
'check': data['check']['occurrences'] | |
} | |
data['mutated'] = True | |
with open('/tmp/merged', 'w+') as file: | |
file.write(json.dumps(data, indent=2)) | |
file.close() | |
try: | |
print(json.dumps(data)) | |
sys.exit(0) | |
except Exception as e: | |
print("Unable to print mutated json: {0}".format(str(e))) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment