-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpihole_temperature_query
44 lines (36 loc) · 1.3 KB
/
pihole_temperature_query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Script to read temperature on the Raspberry Pi running Pi-hole and perform
# a safe domain query to get that temperature into the Query log
# Created 2022-10-08 version 1.0
# Run manually or via cron as frequently as required, eg every 1 minute
# Temperatures are in C by default
# Uncomment line below to use F
#usef=1
# Read RPi SoC temperature from VideoCore GPU
# Note script user should be in video group (default pi is)
get_temperature() {
temperature=$(vcgencmd measure_temp)
}
# Sanitise the temperature to make it domain-friendly
# eg temp=52.6'C --> 52.6
clean_temperature() {
temperature=$(echo $temperature | sed -e "s/temp=//" -e "s/'C//")
}
# Convert C to F
convert_c_to_f() {
temperature=$(echo "1.8 * $temperature + 32" | bc)
}
# Run a query against the sanitised temperature
# IMPORTANT Blacklist regex ^.*temperature\.home\.arpa$ to prevent these from leaving
# Using home.arpa further protects in case of accidental upstream exposure
# RR type 66 is IANA unassigned and will appear in the Query Log as TYPE66 and in the Dashboard Query Types as OTHER
query_temperature() {
dig @127.0.0.1 pihole-temp-$temperature.temperature.home.arpa type66 &>/dev/null
}
# Create a temperature entry
get_temperature
clean_temperature
if [ -n "$usef" ]; then
convert_c_to_f
fi
query_temperature