mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-01 10:33:18 +00:00
try with jq
This commit is contained in:
parent
5894a0e9c5
commit
33285d8d8c
1 changed files with 12 additions and 5 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue