Last active
May 16, 2017 18:54
-
-
Save theeye-io/b0c6d0b47e39960347fbe65f485f9e27 to your computer and use it in GitHub Desktop.
Based on a query from oracle database, remove unused and malformed lines and return pretty output
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/bash | |
limit=$1 | |
file=$2 | |
echo "Checking $file . Limit $limit" | |
echo | |
# remove trash lines and apply format | |
# output get out in two columns NAME > VALUE | |
# NOTE: this part of the script | |
# awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' | |
# join together every two consecutive lines | |
data=$(cat $file | sed '/^$/d' | sed '/^-[- ]*/d' | sed '/^DISPONIBLE.*$/d' | sed '1,5d;/^TABLESPACE.*$/d' | tac | sed '1,4d' | tac | awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' | awk '{n=split($0,a," "); print a[1],a[3]}') | |
alert='no' | |
while read line; do | |
val="$(echo $line | cut -d" " -f2)" | |
if [[ $val > $limit ]]; then | |
# alert | |
alert='yes' | |
fi | |
done <<< "$(echo -e "$data")" | |
echo "DATA DUMP" | |
echo "$data" | |
# THEEYE parses the data as JSON. | |
json=$(echo "$data" | awk '{split($0,a," "); print "\"" a[1] "\":" a[2]}' | sed 's/$/,/' | sed '1s/^/{/' | sed '$s/,/}/') | |
if [ $alert == 'yes' ]; then | |
echo "{\"state\":\"failure\",\"data\":$json}" | tr '\n' ' ' | |
else | |
echo "{\"state\":\"success\",\"data\":$json}" | tr '\n' ' ' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment