ftl

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ReplyTypeUnknown = "UNKNOWN"

Variables

View Source
var DnsSecStatuses = map[uint]DnsSecStatus{
	0: DnsSecStatusUnknown,
	1: "SECURE",
	2: "INSECURE",
	3: "BOGUS",
	4: "ABANDONED",
}
View Source
var QueryTypes = map[uint]QueryType{
	1:  "A",
	2:  "AAAA",
	3:  "ANY",
	4:  "SRV",
	5:  "SOA",
	6:  "PTR",
	7:  "TXT",
	8:  "NAPTR",
	9:  "MX",
	10: "DS",
	11: "RRSIG",
	12: "DNSKEY",
	13: "NS",
	14: "OTHER",
	15: "SVCB",
	16: "HTTPS",
}

QueryTypes see https://docs.pi-hole.net/database/ftl/#supported-query-types

View Source
var ReplyTypes = map[uint]ReplyType{
	0:  ReplyTypeUnknown,
	1:  "NODATA",
	2:  "NXDOMAIN",
	3:  "CNAME",
	4:  "IP",
	5:  "DOMAIN",
	6:  "RRNAME",
	7:  "SERVFAIL",
	8:  "REFUSED",
	9:  "NOTIMP",
	10: "OTHER",
	11: "DNSSEC",
	12: "NONE",
	13: "BLOB",
}

Functions

func DecodeQueryRecord

func DecodeQueryRecord(row scan.RowsScanner, record *QueryRecord) error

func QueryStatusFromOrdinal

func QueryStatusFromOrdinal(ordinal uint) (Decision, Reason)

Types

type Decision

type Decision = string
const (
	DecisionAllowed Decision = "ALLOWED"
	DecisionBlocked Decision = "BLOCKED"
	DecisionUnknown Decision = "UNKNOWN"
)

type DnsSecStatus

type DnsSecStatus = string
const DnsSecStatusUnknown DnsSecStatus = "UNKNOWN"

func DnsSecStatusFromOrdinal

func DnsSecStatusFromOrdinal(ordinal uint) DnsSecStatus

type FtlDb

type FtlDb struct {
	// contains filtered or unexported fields
}

FtlDb represents a time-bounded slice of Pihole FTL database. It exposes methods to query the underlying data without the need to mess with raw SQL

func Open

func Open(path string, start time.Time, end time.Time) (*FtlDb, error)

Open a Pihole FTL long-term database and create an FtlDb instance. The underlying sqlite database is opened in readonly mode.

func (*FtlDb) Close

func (db *FtlDb) Close() error

Close does what it says: releases resources retained by the FtlDb instance

func (*FtlDb) End

func (db *FtlDb) End() time.Time

func (*FtlDb) RecordCount

func (db *FtlDb) RecordCount() int

RecordCount returns the expected number of records in the TimeBounds

func (*FtlDb) Records

func (db *FtlDb) Records(ctx context.Context) <-chan QueryRecord

Records returns a channel of FTL query records that can be read by further processing logic

func (*FtlDb) Start

func (db *FtlDb) Start() time.Time

Start and End return the actual time bounds for the query log slice. These may differ from requested time bounds due to how Pihole caches logs in memory before committing to the database. This behavior is governed by DBINTERVAL configuration. For more details on this behavior, see https://docs.pi-hole.net/ftldns/configfile/#dbinterval

Start time for this interval is the requested start time, but the end time is set to the timestamp of the last entry in the requested interval at the time of FtlDb instance creation. A special case is when there are zero records within the requested interval, in which case Timestamps here are precise to the second.

type QueryRecord

type QueryRecord struct {
	Timestamp    time.Time     `json:"timestamp"`
	Type         QueryType     `json:"type"`
	Decision     Decision      `json:"decision"`
	Reason       Reason        `json:"reason"`
	Domain       string        `json:"domain"`
	Client       string        `json:"client"`
	Forward      string        `json:"forward"`
	ReplyType    ReplyType     `json:"reply_type"`
	ReplyTime    time.Duration `json:"reply_time"`
	DnsSecStatus DnsSecStatus  `json:"dnssec"`
}

QueryRecord /* QueryRecord record logged by FTL

type QueryType

type QueryType = string
const QueryTypeUNKNOWN QueryType = "UNKNOWN"

QueryTypeUNKNOWN is a special default query type to capture unexpected data

func QueryTypeFromOrdinal

func QueryTypeFromOrdinal(ordinal uint) QueryType

QueryTypeFromOrdinal converts the ordinal value read from FTL database into a QueryType value that is more readily consumed by metrics and log aggregation systems

type RawQueryRecord

type RawQueryRecord struct {
	Id        int             `db:"id"`
	Timestamp int             `db:"timestamp"`
	Type      uint            `db:"type"`
	Status    uint            `db:"status"`
	Domain    string          `db:"domain"`
	Client    string          `db:"client"`
	Forward   sql.NullString  `db:"forward"`
	ReplyType uint            `db:"reply_type"`
	ReplyTime sql.NullFloat64 `db:"reply_time"`
	DnsSec    uint            `db:"dnssec"`
}

type Reason

type Reason = string
const (
	ReasonUnknown          Reason = "UNKNOWN"
	ReasonGravity          Reason = "GRAVITY"
	ReasonForwarded        Reason = "FORWARDED"
	ReasonCached           Reason = "CACHED"
	ReasonRegexMatch       Reason = "REGEX_MATCH"
	ReasonExactMatch       Reason = "EXACT_MATCH"
	ReasonByUpstream       Reason = "BY_UPSTREAM"
	ReasonZeroIP           Reason = "ZERO_IP"
	ReasonNxDomain         Reason = "NXDOMAIN"
	ReasonCnameGravity     Reason = "CNAME_GRAVITY"
	ReasonCnameRegexMatch  Reason = "CNAME_REGEX_MATCH"
	ReasonCnameExactMatch  Reason = "CNAME_EXACT_MATCH"
	ReasonRetried          Reason = "RETRIED"
	ReasonRetriedIgnored   Reason = "RETRIED_IGNORED"
	ReasonAlreadyForwarded Reason = "ALREADY_FORWARDED"
	ReasonDatabaseBusy     Reason = "DATABASE_BUSY"
	ReasonSpecialDomain    Reason = "SPECIAL_DOMAIN"
	ReasonCachedStale      Reason = "CACHED_STALE"
)

type ReplyType

type ReplyType = string

func ReplyTypeFromOrdinal

func ReplyTypeFromOrdinal(ordinal uint) ReplyType

Jump to

Keyboard shortcuts

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