Skip to content

Instantly share code, notes, and snippets.

@dmsimard
Created February 28, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmsimard/bd49f7ec459e66ec7b94 to your computer and use it in GitHub Desktop.
Save dmsimard/bd49f7ec459e66ec7b94 to your computer and use it in GitHub Desktop.
#!/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