Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2017 10:41
Show Gist options
  • Save anonymous/97b0197f9f62d1a6125a247fcfa4cb8e to your computer and use it in GitHub Desktop.
Save anonymous/97b0197f9f62d1a6125a247fcfa4cb8e to your computer and use it in GitHub Desktop.
Post to elasticsearch
import datetime
import json
import settings
def send_to_kibana(data):
headers = {'Content-Type': 'application/json',
'Accept': 'text/plain'}
today = data['out'].strftime('%Y.%m.%d')
type = 'build'
kibana_url = '{}{}/{}'.format(settings.KIBANA_URL, today, type)
kibana_rq = {}
fields = ['hostname', 'status', 'ms', 'service', 'error', 'exception', 'emails_processed']
for field in fields:
kibana_rq[field] = data.get(field)
kibana_rq['ts'] = datetime.datetime.utcnow().isoformat()
requests.post(kibana_url,
data=json.dumps(kibana_rq),
headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment