| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package pihole |
| 4 | |
| 5 | const ( |
| 6 | // Version 6 (https://ftl.pi-hole.net/master/docs/) |
| 7 | urlPathAPIAuth = "/api/auth" |
| 8 | urlPathAPIStatsSummary = "/api/stats/summary" |
| 9 | ) |
| 10 | |
| 11 | type ftlAPIAuthResponse struct { |
| 12 | Session struct { |
| 13 | Valid bool `json:"valid"` |
| 14 | Sid string `json:"sid"` |
| 15 | Csrf string `json:"csrf"` |
| 16 | Validity int64 `json:"validity"` |
| 17 | Message string `json:"message"` |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // https://github.com/pi-hole/FTL/blob/master/src/api/stats.c#L113 |
| 22 | type ftlAPIStatsSummaryResponse struct { |
| 23 | Queries struct { |
| 24 | Total int64 `json:"total" stm:"total"` // Total number of queries |
| 25 | Blocked float64 `json:"blocked" stm:"blocked"` // Number of blocked queries |
| 26 | PercentBlocked float64 `json:"percent_blocked" stm:"percent_blocked,1000,1"` // Percent of blocked queries |
| 27 | UniqueDomains int64 `json:"unique_domains" stm:"unique_domains"` // Number of unique domains FTL knows |
| 28 | Forwarded int64 `json:"forwarded" stm:"forwarded"` // Number of queries that have been forwarded upstream |
| 29 | Cached int64 `json:"cached" stm:"cached"` // Number of queries replied to from cache or local configuration |
| 30 | Frequency float64 `json:"frequency" stm:"frequency,1000,1"` // Average number of queries per second |
| 31 | Types struct { |
| 32 | A int64 `json:"A" stm:"A"` // Type A queries |
| 33 | AAAA int64 `json:"AAAA" stm:"AAAA"` // Type AAAA queries |
| 34 | ANY int64 `json:"ANY" stm:"ANY"` // Type ANY queries |
| 35 | SRV int64 `json:"SRV" stm:"SRV"` // Type SRV queries |
| 36 | SOA int64 `json:"SOA" stm:"SOA"` // Type SOA queries |
| 37 | PTR int64 `json:"PTR" stm:"PTR"` // Type PTR queries |
| 38 | TXT int64 `json:"TXT" stm:"TXT"` // Type TXT queries |
| 39 | NAPTR int64 `json:"NAPTR" stm:"NAPTR"` // Type NAPTR queries |
| 40 | MX int64 `json:"MX" stm:"MX"` // Type MX queries |
| 41 | DS int64 `json:"DS" stm:"DS"` // Type DS queries |
| 42 | RRSIG int64 `json:"RRSIG" stm:"RRSIG"` // Type RRSIG queries |
| 43 | DNSKEY int64 `json:"DNSKEY" stm:"DNSKEY"` // Type DNSKEY queries |
| 44 | NS int64 `json:"NS" stm:"NS"` // Type NS queries |
| 45 | SVCB int64 `json:"SVCB" stm:"SVCB"` // Type SVCB queries |
| 46 | HTTPS int64 `json:"HTTPS" stm:"HTTPS"` // Type HTTPS queries |
| 47 | OTHER int64 `json:"OTHER" stm:"OTHER"` // Queries of remaining types |
| 48 | } `json:"types" stm:"types"` // Number of individual queries |
| 49 | Status struct { |
| 50 | Unknown int64 `json:"UNKNOWN" stm:"UNKNOWN"` // Type UNKNOWN queries |
| 51 | Gravity int64 `json:"GRAVITY" stm:"GRAVITY"` // Type GRAVITY queries |
| 52 | Forwarded int64 `json:"FORWARDED" stm:"FORWARDED"` // Type FORWARDED queries |
| 53 | Cache int64 `json:"CACHE" stm:"CACHE"` // Type CACHE queries |
| 54 | Regex int64 `json:"REGEX" stm:"REGEX"` // Type REGEX queries |
| 55 | DenyList int64 `json:"DENYLIST" stm:"DENYLIST"` // Type DENYLIST queries |
| 56 | ExternalBlockedIP int64 `json:"EXTERNAL_BLOCKED_IP" stm:"EXTERNAL_BLOCKED_IP"` // Type EXTERNAL_BLOCKED_IP queries |
| 57 | ExternalBlockedNull int64 `json:"EXTERNAL_BLOCKED_NULL" stm:"EXTERNAL_BLOCKED_NULL"` // Type EXTERNAL_BLOCKED_NULL queries |
| 58 | ExternalBlockedNxra int64 `json:"EXTERNAL_BLOCKED_NXRA" stm:"EXTERNAL_BLOCKED_NXRA"` // Type EXTERNAL_BLOCKED_NXRA queries |
| 59 | GravityCname int64 `json:"GRAVITY_CNAME" stm:"GRAVITY_CNAME"` // Type GRAVITY_CNAME queries |
| 60 | RegexCname int64 `json:"REGEX_CNAME" stm:"REGEX_CNAME"` // Type REGEX_CNAME queries |
| 61 | DenyListCname int64 `json:"DENYLIST_CNAME" stm:"DENYLIST_CNAME"` // Type DENYLIST_CNAME queries |
| 62 | Retried int64 `json:"RETRIED" stm:"RETRIED"` // Type RETRIED queries |
| 63 | RetriedDnssec int64 `json:"RETRIED_DNSSEC" stm:"RETRIED_DNSSEC"` // Type RETRIED_DNSSEC queries |
| 64 | InProgress int64 `json:"IN_PROGRESS" stm:"IN_PROGRESS"` // Type IN_PROGRESS queries |
| 65 | Dbbusy int64 `json:"DBBUSY" stm:"DBBUSY"` // Type DBBUSY queries |
| 66 | SpecialDomain int64 `json:"SPECIAL_DOMAIN" stm:"SPECIAL_DOMAIN"` // Type SPECIAL_DOMAIN queries |
| 67 | CacheStale int64 `json:"CACHE_STALE" stm:"CACHE_STALE"` // Type CACHE_STALE queries |
| 68 | ExternalBlockedEde15 int64 `json:"EXTERNAL_BLOCKED_EDE15" stm:"EXTERNAL_BLOCKED_EDE15"` // Type EXTERNAL_BLOCKED_EDE15 queries |
| 69 | } `json:"status" stm:"status"` // Number of individual queries (by status) |
| 70 | Replies struct { |
| 71 | UNKNOWN int64 `json:"UNKNOWN" stm:"UNKNOWN"` // Type UNKNOWN replies |
| 72 | NODATA int64 `json:"NODATA" stm:"NODATA"` // Type NODATA replies |
| 73 | NXDOMAIN int64 `json:"NXDOMAIN" stm:"NXDOMAIN"` // Type NXDOMAIN replies |
| 74 | CNAME int64 `json:"CNAME" stm:"CNAME"` // Type CNAME replies |
| 75 | IP int64 `json:"IP" stm:"IP"` // Type IP replies |
| 76 | DOMAIN int64 `json:"DOMAIN" stm:"DOMAIN"` // Type DOMAIN replies |
| 77 | RRNAME int64 `json:"RRNAME" stm:"RRNAME"` // Type RRNAME replies |
| 78 | SERVFAIL int64 `json:"SERVFAIL" stm:"SERVFAIL"` // Type SERVFAIL replies |
| 79 | REFUSED int64 `json:"REFUSED" stm:"REFUSED"` // Type REFUSED replies |
| 80 | NOTIMP int64 `json:"NOTIMP" stm:"NOTIMP"` // Type NOTIMP replies |
| 81 | OTHER int64 `json:"OTHER" stm:"OTHER"` // Type OTHER replies |
| 82 | DNSSEC int64 `json:"DNSSEC" stm:"DNSSEC"` // Type DNSSEC replies |
| 83 | NONE int64 `json:"NONE" stm:"NONE"` // Type NONE replies |
| 84 | BLOB int64 `json:"BLOB" stm:"BLOB"` // Type BLOB replies |
| 85 | } `json:"replies" stm:"replies"` // Number of individual replies |
| 86 | } `json:"queries" stm:"queries"` |
| 87 | Clients struct { |
| 88 | Active int64 `json:"active" stm:"active"` // Number of active clients (seen in the last 24 hours) |
| 89 | Total int64 `json:"total" stm:"total"` // Total number of clients seen by FTL |
| 90 | } `json:"clients" stm:"clients"` |
| 91 | Gravity struct { |
| 92 | DomainsBeingBlocked int64 `json:"domains_being_blocked" stm:"domains_being_blocked"` // Number of domain on your Pi-hole's gravity list |
| 93 | LastUpdate int64 `json:"last_update" stm:"last_update"` // Unix timestamp of last gravity update (may be `0` if unknown) |
| 94 | } `json:"gravity" stm:"gravity"` |
| 95 | Took *float64 `json:"took"` // Time in seconds it took to process the request |
| 96 | } |
| 97 | |
| 98 | type ftlErrorResponse struct { |
| 99 | Error struct { |
| 100 | Key string `json:"key"` |
| 101 | Message string `json:"message"` |
| 102 | } `json:"error"` |
| 103 | Took float64 `json:"took"` |
| 104 | } |