Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ssoto/55b910c1b6e1dca29721b00467d9a350 to your computer and use it in GitHub Desktop.
Save ssoto/55b910c1b6e1dca29721b00467d9a350 to your computer and use it in GitHub Desktop.
Post to elasticsearch
import datetime
import json
PROJECT = 'sparta'
KIBANA_URL = 'http://elastic:9200/{}-'.format(PROJECT)
def send_to_kibana():
headers = {'Content-Type': 'application/json',
'Accept': 'text/plain'}
today = data['out'].strftime('%Y.%m.%d')
type = 'build'
  kibana_url = '{}{}/{}'.format(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