Last active
July 27, 2017 07:50
-
-
Save rgolangh/fb724836e92a8d1e7efb845d3afbddac 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
#!/bin/sh -x | |
function usage() { | |
echo " | |
USAGE | |
$0 [IN_FILE] | |
IN_FILE=/path/to/in_file $0 | |
ES_ADDRESS=elasticsearch.example.com IN_FILE=/path/to/in_file $0 | |
This is a loader from fluentd file into elastic-search | |
The IN_FILE contains json events created by fluentd 'out_file' plugin | |
ES_ADDRESS defualts to https://localhost:9200 | |
" | |
exit 1 | |
} | |
IN_FILE=${IN_FILE-$1} | |
ES_ADDRESS=${ES_ADDRESS-localhost} | |
[[ -n ${IN_FILE} ]] || usage | |
# main | |
# openshift only code. If you are authorizred to do this insecure then skip this and change | |
# the 'curl' cmd accordingly | |
oc get secret logging-fluentd --template='{{.data.ca}}' | base64 -d > ca | |
oc get secret logging-fluentd --template='{{.data.key}}' | base64 -d > key | |
oc get secret logging-fluentd --template='{{.data.cert}}' | base64 -d > cert | |
oc port-forward <es pod name> 9200:9200 & | |
cat ${IN_FILE} | gawk -F "\t" '{print "{\"index\": {\"_index\": \"project.ovirt-metrics-lago-engine\", \"_type\": \"metrics\"}}\n" $3}' | \ | |
curl \ | |
-XPOST \ | |
-H "Content-Type: application/x-ndjson" \ | |
${ES_ADDRESS}/_bulk \ | |
--cacert ca --key key --cert ./cert \ | |
--data-binary \ | |
@- \ | |
-v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 20 can be parameterized so the
index
andtype
can be anything and not ovirt specific