Documentation
¶
Overview ¶
Package query supplies the API for running queries on a goDB database
Index ¶
- Constants
- Variables
- func ParseTimeArgument(timeString string) (int64, error)
- func ParseTimeRange(firstStr, lastStr string) (first, last int64, err error)
- func ParseTimeRangeCollectErrors(firstStr, lastStr string) (first, last int64, details []*huma.ErrorDetail)
- func PermittedFormats() []string
- func PermittedSortBy() []string
- type Args
- func (a *Args) AddOutputs(outputs ...io.Writer) *Args
- func (a *Args) CheckUnboundedQueries() error
- func (a *Args) LogValue() slog.Value
- func (a *Args) Prepare(writers ...io.Writer) (*Statement, error)
- func (args *Args) SetDefaults()
- func (a *Args) String() string
- func (a *Args) ToJSONString() string
- type DNSResolution
- type DetailError
- type Option
- func WithCaller(c string) Option
- func WithCondition(c string) Option
- func WithDirectionIn() Option
- func WithDirectionOut() Option
- func WithDirectionSum() Option
- func WithFirst(f string) Option
- func WithFormat(f string) Option
- func WithLast(l string) Option
- func WithList() Option
- func WithLive() Option
- func WithMaxMemPct(m int) Option
- func WithNumResults(n uint64) Option
- func WithQueryHosts(c string) Option
- func WithResolve() Option
- func WithResolveRows(r int) Option
- func WithResolveTimeout(t time.Duration) Option
- func WithSortAscending() Option
- func WithSortBy(s string) Option
- func WithVersion() Option
- type Runner
- type Statement
- type TimeFormat
Constants ¶
const MaxResults = 9999999999999999
MaxResults stores the maximum number of rows a query will return. This limit is more or less theoretical, since a DB will unlikley feature such an amount of entries
Variables ¶
var ( DefaultDBPath = defaults.DBPath DefaultFormat = types.FormatTXT DefaultMaxMemPct = 60 DefaultNumResults = uint64(1000) DefaultResolveRows = 25 DefaultResolveTimeout = 1 * time.Second DefaultQueryTimeout = defaults.QueryTimeout DefaultSortBy = "bytes" )
Defaults for query arguments
Functions ¶
func ParseTimeArgument ¶
ParseTimeArgument is the entry point for external calls and converts valid formats to a unix timtestamp
func ParseTimeRange ¶
ParseTimeRange will run ParseTimeArgument for a range and validate if the interval is non-zero
func ParseTimeRangeCollectErrors ¶
func ParseTimeRangeCollectErrors(firstStr, lastStr string) (first, last int64, details []*huma.ErrorDetail)
ParseTimeRangeCollectErrors will run ParseTimeArgument for a range and validate if the interval is non-zero. It will append errors encountered during interval validation to the huma.ErrorDetail slice and return them. The error condition will thus be len(details) > 0
func PermittedFormats ¶
func PermittedFormats() []string
PermittedFormats list which formats are supported
func PermittedSortBy ¶
func PermittedSortBy() []string
PermittedSortBy lists which sort by methods are supported
Types ¶
type Args ¶
type Args struct { // required // Query: the query type Query string `` /* 129-byte string literal not displayed */ // Ifaces: the interfaces to query Ifaces string `` /* 169-byte string literal not displayed */ // QueryHosts: the hosts for which data is queried (comma-separated list) QueryHosts string `` /* 160-byte string literal not displayed */ // Hostname: the hostname from which data is queried Hostname string `` /* 143-byte string literal not displayed */ // HostID: the host id from which data is queried HostID uint `` /* 140-byte string literal not displayed */ // data filtering // Condition: the condition to filter data by Condition string `` /* 152-byte string literal not displayed */ // counter addition // In: only show incoming packets/bytes In bool `json:"in,omitempty" yaml:"in,omitempty" query:"in" required:"false" doc:"Only show incoming packets/bytes" example:"false"` // Out: only show outgoing packets/bytes Out bool `` /* 126-byte string literal not displayed */ // Sum: show sum of incoming/outgoing packets/bytes Sum bool `` /* 136-byte string literal not displayed */ // time selection // First: the first timestamp to query First string `` /* 147-byte string literal not displayed */ // Last: the last timestamp to query Last string `json:"last,omitempty" yaml:"last,omitempty" query:"last" required:"false" doc:"The last timestamp to query" example:"-24h"` // formatting // Format: the output format Format string `` /* 134-byte string literal not displayed */ // SortBy: column to sort by SortBy string `` /* 160-byte string literal not displayed */ // NumResults: number of results to return/print NumResults uint64 `` /* 174-byte string literal not displayed */ // SortAscending: sort ascending instead of the default descending SortAscending bool `` /* 162-byte string literal not displayed */ // do-and-exit arguments // List: only list interfaces and return List bool `json:"list,omitempty" yaml:"list,omitempty" query:"list" required:"false" hidden:"true"` // Version: only print version and return Version bool `json:"version,omitempty" yaml:"version,omitempty" query:"version" required:"false" hidden:"true"` // resolution // Note: Nested structures are not supported for form data, see individual parameters in definition of DNSResolution // DNSResolution: guide reverse DNS resolution of sip,dip results DNSResolution DNSResolution `json:"dns_resolution,omitempty" yaml:"dns_resolution,omitempty" doc:"Configures DNS resolution of sip,dip results"` // file system // MaxMemPct: maximum percentage of available host memory to use for query processing MaxMemPct int `` /* 224-byte string literal not displayed */ // LowMem: use less memory for query processing LowMem bool `` /* 141-byte string literal not displayed */ // KeepAlive: keepalive message interval for query processor KeepAlive time.Duration `` /* 175-byte string literal not displayed */ // Caller stores who produced these args (caller) Caller string `` /* 144-byte string literal not displayed */ // Live can be used to request live flow data (in addition to DB results) Live bool `` /* 166-byte string literal not displayed */ // contains filtered or unexported fields }
Args bundles the command line/HTTP parameters required to prepare a query statement
func DefaultArgs ¶
func DefaultArgs() *Args
DefaultArgs creates a basic set of query arguments with only the defaults being set
func (*Args) AddOutputs ¶
AddOutputs allows more control over to which outputs the query results are written
func (*Args) CheckUnboundedQueries ¶
CheckUnboundedQueries qualifies whether a query will load too much data. At the moment, this boils down to raw queries without a condition.
Callers can use this function to protect against long-running queries in order to preserve resources and bandwidth
func (*Args) Prepare ¶
Prepare takes the query Arguments, validates them and creates an executable statement. Optionally, additional writers can be passed to route query results to different destinations.
func (*Args) SetDefaults ¶
func (args *Args) SetDefaults()
SetDefaults sets the default values for all uninitialized fields in the arguments
func (*Args) ToJSONString ¶
ToJSONString marshals the args and puts the result into a string
type DNSResolution ¶
type DNSResolution struct { // Enabled: enable reverse DNS lookups. Example: false Enabled bool `json:"enabled" yaml:"enabled" query:"dns_enabled" doc:"Enable reverse DNS lookups" example:"false"` // Timeout: timeout for reverse DNS lookups Timeout time.Duration `` /* 178-byte string literal not displayed */ // MaxRows: maximum number of rows to resolve MaxRows int `` /* 154-byte string literal not displayed */ // contains filtered or unexported fields }
DNSResolution contains DNS query / resolution related config arguments / parameters
type DetailError ¶
type DetailError struct {
huma.ErrorModel
}
return fmt.Sprintf(str, err.Field, err.Message, errStr)
'}
func NewDetailError ¶
func NewDetailError(code int, err error) *DetailError
NewDetailError creates a new generic DetailError of specific status and providing detailed information based on a generic error
func (*DetailError) Pretty ¶
func (d *DetailError) Pretty() string
Pretty implements the prettier interface for a huma.ErrorModel
type Option ¶
type Option func(*Args)
Option allows to modify an existing Args container
func WithCaller ¶
WithCaller sets the name of the program/tool calling the query
func WithDirectionOut ¶
func WithDirectionOut() Option
WithDirectionOut considers the outgoing flows
func WithMaxMemPct ¶
WithMaxMemPct is an advanced parameter to restrict system memory usage to a fixed percentage of the available memory during query processing
func WithNumResults ¶
WithNumResults sets how many rows are returned
func WithQueryHosts ¶
WithQueryHosts sets the query hosts argument
func WithResolveRows ¶
WithResolveRows sets the amount of rows for which lookups should be attempted
func WithResolveTimeout ¶
WithResolveTimeout sets the timeout for reverse lookups (in seconds)
func WithSortBy ¶
WithSortBy sets by which parameter should be sorted
func WithVersion ¶
func WithVersion() Option
WithVersion sets the version parameter (print version and exit)
type Runner ¶
type Runner interface { // Run takes a query statement, executes the underlying query and returns the result(s) Run(ctx context.Context, args *Args) (*results.Result, error) }
Runner specifies the functionality a query runner must provide
type Statement ¶
type Statement struct { // Ifaces holds the list of all interfaces that should be queried Ifaces []string `json:"ifaces"` LabelSelector types.LabelSelector `json:"label_selector,omitempty"` // needed for feedback to user QueryType string `json:"query_type"` Condition string `json:"condition,omitempty"` // which direction is added Direction types.Direction `json:"direction"` // time selection First int64 `json:"from"` Last int64 `json:"to"` // formatting Format string `json:"format"` NumResults uint64 `json:"limit"` SortBy results.SortOrder `json:"sort_by"` SortAscending bool `json:"sort_ascending,omitempty"` Output io.Writer `json:"-"` // parameters for external calls Caller string `json:"caller,omitempty"` // who called the query // resolution parameters (probably part of table printer) DNSResolution DNSResolution `json:"dns_resolution,omitempty"` // file system MaxMemPct int `json:"max_mem_pct,omitempty"` LowMem bool `json:"low_mem,omitempty"` // query keepalive KeepAliveDuration time.Duration `json:"keepalive,omitempty"` // request live flow data (in addition to DB) Live bool `json:"live,omitempty"` // contains filtered or unexported fields }
Statement bundles all relevant options for running a query and displaying its result
type TimeFormat ¶
TimeFormat denotes a time format with an optional verbose name for display
func TimeFormatsCustom ¶
func TimeFormatsCustom() []TimeFormat
TimeFormatsCustom returns a list of all supported custom time formats
func TimeFormatsDefault ¶
func TimeFormatsDefault() []TimeFormat
TimeFormatsDefault returns a list of all supported default time formats
func TimeFormatsRelative ¶
func TimeFormatsRelative() []TimeFormat
TimeFormatsRelative returns a list of all supported relative time formats