wrider | 0db762a | 2019-09-04 17:05:29 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | MR_HOSTPORT="$_MR_HOSTPORT" |
| 4 | MR_TOPIC="$_MR_TOPIC" |
| 5 | LOGSTASH_URL="$_LOGSTASH_URL" |
| 6 | |
| 7 | if ! jq --version > /dev/null 2&>1 ; then |
| 8 | apt-get update |
| 9 | apt-get install -y jq curl |
| 10 | fi |
| 11 | |
| 12 | echo "IN SCRIPT" |
| 13 | echo "$MR_HOSTPORT $MR_TOPIC $LOGSTASH_URL" |
| 14 | |
| 15 | while true; do |
| 16 | # if dmaap returns single JSON structure |
| 17 | DATA=$(curl -s -H "Accept: application/json" -X GET http://${MR_HOSTPORT}/events/${MR_TOPIC}/elk-plotter/elk-plotter?timeout=60000) |
| 18 | DATA=$(echo $DATA| sed -e 's/\\"/"/g' -e 's/"{/{/g' -e 's/}"/}/g') |
| 19 | echo "Getting data: $DATA" |
| 20 | |
| 21 | #VESEVENT=$(echo $DATA |jq -r '((.event.commonEventHeader.lastEpochMicrosec)|tostring) + "," + ((.event.measurementsForVfScalingFields.vNicUsageArray[0].receivedTotalPacketsDelta) | tostring)') |
| 22 | #curl -i -XPUT 'http://127.0.0.1:8080/onenumber/onenumebr' -d "${VESEVENT}" |
| 23 | |
| 24 | # dmaap returns json array |
| 25 | # echo "Reading source: $.event.commonEventHeader.reportingEntityName" |
| 26 | source=$(echo $DATA |jq -r '.[] | ((.event.commonEventHeader.reportingEntityName) | tostring)') |
| 27 | echo "Source name: $source" |
| 28 | if [ "$source" == "GS_LITE MC" ] |
| 29 | then |
| 30 | DATA=$(echo $DATA |jq -r --arg source "$source" '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[1].value) | tostring)+ ","+ ((.event.measurementsForVfScalingFields.additionalFields[2].value) | tostring)') |
| 31 | #EVENTS=$(echo $DATA |jq -r '.event.measurementFields.additionalFields.SgNBRequestRate') |
| 32 | #for EVENT in $EVENTS; do |
| 33 | elif [ "$source" == "AC xAPP" ] |
| 34 | then |
| 35 | DATA=$(echo $DATA |jq -r --arg source "$source" '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[0].value) | tostring)') |
| 36 | else |
| 37 | DATA="No supportive reporting entity provided" |
| 38 | fi |
| 39 | echo "Injecting VES event: $DATA" |
| 40 | curl -i -XPUT "${LOGSTASH_URL}" -d "${DATA}" |
| 41 | #done |
| 42 | done |
| 43 | |