diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 3ea9bfb3..18456133 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -14,13 +14,19 @@ #Functions############################################################################################################## #move to pihole + +if [ ! -f "/opt/pihole/jq" ] ; then + curl -s http://stedolan.github.io/jq/download/linux64/jq -o /opt/pihole/jq + chmod 755 /opt/pihole/jq +fi + statsUpdateJSON() { if [[ -z "${AdminLink}" ]] ; then AdminLink="http://127.0.0.1/admin" fi local x=$(curl -s ${AdminLink}/api.php?summaryRaw) #check if json is valid - if echo "${x}" | python -m json.tool > /dev/null ; then + if echo "${x}" | /opt/pihole/jq "." > /dev/null ; then echo "${x}" else echo "Error" @@ -33,7 +39,8 @@ statsBlockedDomains() { json=$(statsUpdateJSON) fi if [[ "${json}" != "Error" ]] ; then - local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['domains_being_blocked']") +# local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['domains_being_blocked']") + local x=$(echo "${json}" | /opt/pihole/jq ".domains_being_blocked" | tr -d '"') echo ${x} else echo "Error" @@ -46,7 +53,7 @@ statsQueriesToday() { json=$(statsUpdateJSON) fi if [[ "${json}" != "Error" ]] ; then - local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['dns_queries_today']") + local x=$(echo "${json}" | /opt/pihole/jq ".dns_queries_today" | tr -d '"') echo ${x} else echo "Error" @@ -59,7 +66,7 @@ statsBlockedToday() { json=$(statsUpdateJSON) fi if [[ "${json}" != "Error" ]] ; then - local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['ads_blocked_today']") + local x=$(echo "${json}" | /opt/pihole/jq ".ads_blocked_today" | tr -d '"') echo ${x} else echo "Error" @@ -72,7 +79,7 @@ statsPercentBlockedToday() { json=$(statsUpdateJSON) fi if [[ "${json}" != "Error" ]] ; then - local x=$(echo "${json}" | python -c "import sys, json; print round(float(json.load(sys.stdin)['ads_percentage_today']), 2)") + local x=$(echo "${json}" | /opt/pihole/jq ".ads_percentage_today" | tr -d '"' | xargs printf "%.*f\n" 2) echo ${x} else echo "Error"