Created
August 8, 2017 10:41
-
-
Save anonymous/97b0197f9f62d1a6125a247fcfa4cb8e to your computer and use it in GitHub Desktop.
Post to elasticsearch
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
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