I need to know every day a specific client queried a specific domain.
I know from a search in the UI that the client performed multiple queries every day that it queried the domain, but I only want one result per day. I need the output in a format I can put in a spreadsheet, so had been trying to find a good sqllite3 query but I'm struggling. Could someone please help?
Thank you!
PS: I've read the documentation at Redirecting... If you're strong on this stuff it would be awesome if you could please add some examples to that page please!
pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db "Select domain, count(domain) from queries where client='IP' and domain='DOMAIN' and timestamp > strftime('%s','now','-1 days');"
nice pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db "SELECT timestamp, domain FROM queries where client='10.10.10.10' and domain='domain.i.am.looking.for.com' and timestamp > strftime('%s','now','-9999 days');"
...and I can then use a simple shell script with date -d @<date string> to convert those in to time and date strings. I'll then dedupe them so I get a list of each day the domain was queried at least once.
pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db "SELECT date(timestamp,'unixepoch', 'localtime'), domain FROM queries where client='IP' and domain='DOMAIN' and timestamp > strftime('%s','now',' -999 days') group by date(timestamp,'unixepoch','localtime');"
I think you could even remove the timestamp selection as it seems you try to just get "all".
You can avoid a script with date if you change your SQL query to use the SQLite3 datetime() function or strftime() if you need a different format:
-- Old query:
SELECT timestamp, domain FROM queries WHERE ...
-- New query using datetime() function
SELECT datetime(timestamp,'unixepoch', 'localtime'), domain FROM queries WHERE ...