| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package pihole |
| 4 | |
| 5 | type piholeMetrics struct { |
| 6 | summary *summaryRawMetrics // ?summary |
| 7 | queryTypes *queryTypesMetrics // ?getQueryTypes |
| 8 | forwarders *forwardDestinations // ?getForwardedDestinations |
| 9 | } |
| 10 | |
| 11 | func (p piholeMetrics) hasSummary() bool { |
| 12 | return p.summary != nil |
| 13 | } |
| 14 | func (p piholeMetrics) hasQueryTypes() bool { |
| 15 | return p.queryTypes != nil |
| 16 | } |
| 17 | func (p piholeMetrics) hasForwarders() bool { |
| 18 | return p.forwarders != nil && len(p.forwarders.Destinations) > 0 |
| 19 | } |
| 20 | |
| 21 | type piholeAPIVersion struct { |
| 22 | Version int |
| 23 | } |
| 24 | |
| 25 | type summaryRawMetrics struct { |
| 26 | DomainsBeingBlocked int64 `json:"domains_being_blocked"` |
| 27 | DNSQueriesToday int64 `json:"dns_queries_today"` |
| 28 | AdsBlockedToday int64 `json:"ads_blocked_today"` |
| 29 | AdsPercentageToday float64 `json:"ads_percentage_today"` |
| 30 | UniqueDomains int64 `json:"unique_domains"` |
| 31 | QueriesForwarded int64 `json:"queries_forwarded"` |
| 32 | QueriesCached int64 `json:"queries_cached"` |
| 33 | ClientsEverSeen int64 `json:"clients_ever_seen"` |
| 34 | UniqueClients int64 `json:"unique_clients"` |
| 35 | DNSQueriesAllTypes int64 `json:"dns_queries_all_types"` |
| 36 | ReplyNODATA int64 `json:"reply_NODATA"` |
| 37 | ReplyNXDOMAIN int64 `json:"reply_NXDOMAIN"` |
| 38 | ReplyCNAME int64 `json:"reply_CNAME"` |
| 39 | ReplyIP int64 `json:"reply_IP"` |
| 40 | PrivacyLevel int64 `json:"privacy_level"` |
| 41 | Status string `json:"status"` |
| 42 | GravityLastUpdated struct { |
| 43 | // gravity.list has been removed (https://github.com/pi-hole/pi-hole/pull/2871#issuecomment-520251509) |
| 44 | FileExists bool `json:"file_exists"` |
| 45 | Absolute *int64 |
| 46 | } `json:"gravity_last_updated"` |
| 47 | } |
| 48 | |
| 49 | type queryTypesMetrics struct { |
| 50 | Types struct { |
| 51 | A float64 `json:"A (IPv4)"` |
| 52 | AAAA float64 `json:"AAAA (IPv6)"` |
| 53 | ANY float64 |
| 54 | SRV float64 |
| 55 | SOA float64 |
| 56 | PTR float64 |
| 57 | TXT float64 |
| 58 | } `json:"querytypes"` |
| 59 | } |
| 60 | |
| 61 | // https://github.com/pi-hole/FTL/blob/6f69dd5b4ca60f925d68bfff3869350e934a7240/src/api/api.c#L474 |
| 62 | type forwardDestinations struct { |
| 63 | Destinations map[string]float64 `json:"forward_destinations"` |
| 64 | } |
| 65 | |
| 66 | //type ( |
| 67 | // item map[string]int64 |
| 68 | // |
| 69 | // topClients struct { |
| 70 | // Sources item `json:"top_sources"` |
| 71 | // } |
| 72 | // topItems struct { |
| 73 | // TopQueries item `json:"top_queries"` |
| 74 | // TopAds item `json:"top_ads"` |
| 75 | // } |
| 76 | //) |
| 77 | // |
| 78 | //func (i *item) UnmarshalJSON(data []byte) error { |
| 79 | // if isEmptyArray(data) { |
| 80 | // return nil |
| 81 | // } |
| 82 | // type plain *item |
| 83 | // return json.Unmarshal(data, (plain)(i)) |
| 84 | //} |