pihole

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient added in v1.0.0

type APIClient struct {
	BaseURL string
	Client  *http.Client
	// contains filtered or unexported fields
}

func NewAPIClient added in v1.0.0

func NewAPIClient(baseURL, password string, timeout time.Duration) *APIClient

NewAPIClient initializes and returns a new APIClient.

func (*APIClient) Authenticate added in v1.0.0

func (c *APIClient) Authenticate() error

Authenticate logs in and stores the session ID.

func (*APIClient) FetchData added in v1.0.0

func (c *APIClient) FetchData(endpoint string, result interface{}) error

FetchData makes a GET request to the specified endpoint and parses the response.

type AuthenticationResponse added in v1.0.0

type AuthenticationResponse struct {
	Session struct {
		Valid    bool   `json:"valid"`
		Totp     bool   `json:"totp"`
		Sid      string `json:"sid"`
		Csrf     string `json:"csrf"`
		Validity int    `json:"validity"`
		Message  string `json:"message"`
	} `json:"session"`
}

type BlockingStatus added in v1.0.0

type BlockingStatus struct {
	Blocking string  `json:"blocking"`
	Timer    int     `json:"timer"`
	Took     float64 `json:"took"`
}

type Client

type Client struct {
	Status chan *ClientChannel
	// contains filtered or unexported fields
}

Client struct is a Pi-hole client to request an instance of a Pi-hole ad blocker.

func NewClient

func NewClient(config *config.Config, envConfig *config.EnvConfig) *Client

NewClient method initializes a new Pi-hole client.

func (*Client) CollectMetrics added in v0.1.0

func (c *Client) CollectMetrics(writer http.ResponseWriter, request *http.Request) error

func (*Client) CollectMetricsAsync added in v0.3.0

func (c *Client) CollectMetricsAsync(writer http.ResponseWriter, request *http.Request)

func (*Client) GetHostname added in v0.1.0

func (c *Client) GetHostname() string

func (*Client) String added in v0.1.0

func (c *Client) String() string

type ClientChannel added in v0.3.0

type ClientChannel struct {
	Status ClientStatus
	Err    error
}

func (*ClientChannel) String added in v0.3.0

func (c *ClientChannel) String() string

type ClientStatus added in v0.3.0

type ClientStatus byte
const (
	MetricsCollectionInProgress ClientStatus = iota
	MetricsCollectionSuccess
	MetricsCollectionError
	MetricsCollectionTimeout
)

func (ClientStatus) String added in v0.3.0

func (status ClientStatus) String() string

type PiHoleClient added in v1.0.0

type PiHoleClient struct {
	IP    string `json:"ip"`
	Name  string `json:"name"`
	Count int    `json:"count"`
}

func MergeClients added in v1.0.0

func MergeClients(clients1, clients2 []PiHoleClient) []PiHoleClient

type StatsSummary added in v1.0.0

type StatsSummary struct {
	Queries struct {
		Total          int                `json:"total"`
		Blocked        int                `json:"blocked"`
		PercentBlocked float64            `json:"percent_blocked"`
		UniqueDomains  int                `json:"unique_domains"`
		Forwarded      int                `json:"forwarded"`
		Cached         int                `json:"cached"`
		Frequency      float64            `json:"frequency"`
		Types          map[string]float64 `json:"types"`
		Status         struct {
			UNKNOWN              int `json:"UNKNOWN"`
			GRAVITY              int `json:"GRAVITY"`
			FORWARDED            int `json:"FORWARDED"`
			CACHE                int `json:"CACHE"`
			REGEX                int `json:"REGEX"`
			DENYLIST             int `json:"DENYLIST"`
			EXTERNALBLOCKEDIP    int `json:"EXTERNAL_BLOCKED_IP"`
			EXTERNALBLOCKEDNULL  int `json:"EXTERNAL_BLOCKED_NULL"`
			EXTERNALBLOCKEDNXRA  int `json:"EXTERNAL_BLOCKED_NXRA"`
			GRAVITYCNAME         int `json:"GRAVITY_CNAME"`
			REGEXCNAME           int `json:"REGEX_CNAME"`
			DENYLISTCNAME        int `json:"DENYLIST_CNAME"`
			RETRIED              int `json:"RETRIED"`
			RETRIEDDNSSEC        int `json:"RETRIED_DNSSEC"`
			INPROGRESS           int `json:"IN_PROGRESS"`
			DBBUSY               int `json:"DBBUSY"`
			SPECIALDOMAIN        int `json:"SPECIAL_DOMAIN"`
			CACHESTALE           int `json:"CACHE_STALE"`
			EXTERNALBLOCKEDEDE15 int `json:"EXTERNAL_BLOCKED_EDE15"`
		} `json:"status"`
		Replies struct {
			UNKNOWN  int `json:"UNKNOWN"`
			NODATA   int `json:"NODATA"`
			NXDOMAIN int `json:"NXDOMAIN"`
			CNAME    int `json:"CNAME"`
			IP       int `json:"IP"`
			DOMAIN   int `json:"DOMAIN"`
			RRNAME   int `json:"RRNAME"`
			SERVFAIL int `json:"SERVFAIL"`
			REFUSED  int `json:"REFUSED"`
			NOTIMP   int `json:"NOTIMP"`
			OTHER    int `json:"OTHER"`
			DNSSEC   int `json:"DNSSEC"`
			NONE     int `json:"NONE"`
			BLOB     int `json:"BLOB"`
		} `json:"replies"`
	} `json:"queries"`
	Clients struct {
		Active int `json:"active"`
		Total  int `json:"total"`
	} `json:"clients"`
	Gravity struct {
		DomainsBeingBlocked int `json:"domains_being_blocked"`
		LastUpdate          int `json:"last_update"`
	} `json:"gravity"`
	Took float64 `json:"took"`
}

func (*StatsSummary) String added in v1.0.0

func (s *StatsSummary) String() string

ToString method returns a string of the current statistics struct.

type TopClients added in v1.0.0

type TopClients struct {
	Clients        []PiHoleClient `json:"clients"`
	TotalQueries   int            `json:"total_queries"`
	BlockedQueries int            `json:"blocked_queries"`
	Took           float64        `json:"took"`
}

Response struct represents the full JSON response

type TopDomains added in v1.0.0

type TopDomains struct {
	Domains []struct {
		Domain string `json:"domain"`
		Count  int    `json:"count"`
	} `json:"domains"`
	TotalQueries   int     `json:"total_queries"`
	BlockedQueries int     `json:"blocked_queries"`
	Took           float64 `json:"took"`
}

type Upstreams added in v1.0.0

type Upstreams struct {
	Upstreams []struct {
		IP         string `json:"ip"`
		Name       string `json:"name"`
		Port       int    `json:"port"`
		Count      int    `json:"count"`
		Statistics struct {
			Response float64 `json:"response"`
			Variance float64 `json:"variance"`
		} `json:"statistics"`
	} `json:"upstreams"`
	ForwardedQueries int     `json:"forwarded_queries"`
	TotalQueries     int     `json:"total_queries"`
	Took             float64 `json:"took"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL