Documentation
¶
Overview ¶
The reporter package provides a simple interface to generating Geneos dataviews, with headlines and a data table, either though the XML-RPC API, as Toolkit compatible CSV, XLSX workbooks or a number of other formats.
The reporter package provides a simple interface to generating Geneos dataviews, with headlines and a data table, either though the XML-RPC API, as Toolkit compatible CSV, XLSX workbooks or a number of other formats.
Index ¶
- Constants
- func CollectOptions[T any](options ...any) (opts []T)
- type APIReporter
- func (a *APIReporter) AddHeadline(name, value string)
- func (a *APIReporter) AddHeadlines(headlines map[string]string)
- func (a *APIReporter) Close()
- func (a *APIReporter) Extension() string
- func (a *APIReporter) Prepare(report Report) (err error)
- func (a *APIReporter) Render()
- func (a *APIReporter) Reset(report Report) error
- func (a *APIReporter) UpdateTable(columns []string, rows [][]string)
- type APIReporterOption
- func APIEntity(entity string) APIReporterOption
- func APIHostname(hostname string) APIReporterOption
- func APIMaxRows(n int) APIReporterOption
- func APIPort(port int) APIReporterOption
- func APISampler(sampler string) APIReporterOption
- func APISecure(secure bool) APIReporterOption
- func APISkipVerify(skip bool) APIReporterOption
- func DataviewCreateDelay(delay time.Duration) APIReporterOption
- func ResetDataviews(reset bool) APIReporterOption
- type ConditionalFormat
- type ConditionalFormatSet
- type ConditionalFormatTest
- type FormattedReporter
- func (fr *FormattedReporter) AddHeadline(name, value string)
- func (fr *FormattedReporter) AddHeadlines(headlines map[string]string)
- func (fr *FormattedReporter) Close()
- func (fr *FormattedReporter) Extension() string
- func (fr *FormattedReporter) Prepare(report Report) (err error)
- func (fr *FormattedReporter) Render()
- func (fr *FormattedReporter) Reset(report Report) (err error)
- func (fr *FormattedReporter) UpdateTable(columns []string, data [][]string)
- type FormattedReporterOption
- func DataviewCSSClass(cssclass string) FormattedReporterOption
- func HTMLPostscript(postscript string) FormattedReporterOption
- func HTMLPreamble(preamble string) FormattedReporterOption
- func HeadlineCSSClass(cssclass string) FormattedReporterOption
- func OrderByColumns(cols ...int) FormattedReporterOption
- func Writer(w io.Writer) FormattedReporterOption
- func ZipWriter(z *zip.Writer) FormattedReporterOption
- type Report
- type Reporter
- type ReporterOption
- type TabWriterReporter
- func (t *TabWriterReporter) AddHeadline(name, value string)
- func (t *TabWriterReporter) AddHeadlines(headlines map[string]string)
- func (t *TabWriterReporter) Close()
- func (t *TabWriterReporter) Extension() string
- func (t *TabWriterReporter) Prepare(report Report) error
- func (t *TabWriterReporter) Render()
- func (t *TabWriterReporter) Reset(report Report) error
- func (t *TabWriterReporter) UpdateTable(columns []string, rows [][]string)
- type ToolkitReporter
- func (t *ToolkitReporter) AddHeadline(name, value string)
- func (t *ToolkitReporter) AddHeadlines(headlines map[string]string)
- func (t *ToolkitReporter) Close()
- func (t *ToolkitReporter) Extension() string
- func (t *ToolkitReporter) Prepare(report Report) error
- func (t *ToolkitReporter) Render()
- func (t *ToolkitReporter) Reset(report Report) (err error)
- func (t *ToolkitReporter) UpdateTable(columns []string, rows [][]string)
- type XLSXReporter
- func (x *XLSXReporter) AddHeadline(name, value string)
- func (x *XLSXReporter) AddHeadlines(headlines map[string]string)
- func (x *XLSXReporter) Close()
- func (x *XLSXReporter) Extension() string
- func (x *XLSXReporter) Prepare(report Report) (err error)
- func (x *XLSXReporter) Render()
- func (x *XLSXReporter) Reset(report Report) (err error)
- func (x *XLSXReporter) UpdateTable(columns []string, rows [][]string)
- type XLSXReporterOption
- func DateFormat(dateFormat string) XLSXReporterOption
- func IntFormat(format int) XLSXReporterOption
- func MaxColumnWidth(n float64) XLSXReporterOption
- func MinColumnWidth(n float64) XLSXReporterOption
- func PercentFormat(format int) XLSXReporterOption
- func SeverityColours(undefined, ok, warning, critical string) XLSXReporterOption
- func SummarySheetName(name string) XLSXReporterOption
- func XLSXHeadlines(headlines int) XLSXReporterOption
- func XLSXPassword(password config.Secret) XLSXReporterOption
- func XLSXScramble(scramble bool) XLSXReporterOption
Constants ¶
const ( XLSXHeadlinesNone = iota XLSXHeadlinesVertical XLSXHeadlinesHorizontal )
Variables ¶
This section is empty.
Functions ¶
func CollectOptions ¶ added in v1.27.0
Types ¶
type APIReporter ¶
type APIReporter struct {
// contains filtered or unexported fields
}
An APIReporter connects to a Geneos Netprobe using the XML-RPC API and publishes Dataview with optional Headlines
func (*APIReporter) AddHeadline ¶
func (a *APIReporter) AddHeadline(name, value string)
func (*APIReporter) AddHeadlines ¶ added in v1.27.0
func (a *APIReporter) AddHeadlines(headlines map[string]string)
func (*APIReporter) Close ¶
func (a *APIReporter) Close()
func (*APIReporter) Extension ¶
func (a *APIReporter) Extension() string
func (*APIReporter) Prepare ¶
func (a *APIReporter) Prepare(report Report) (err error)
Prepare sets the Dataview group and title from the report structure passed. err is returned if the connection fails or the name is invalid. Note that in the Geneos api sampler the group and title must be different.
func (*APIReporter) Render ¶
func (a *APIReporter) Render()
func (*APIReporter) Reset ¶ added in v1.27.0
func (a *APIReporter) Reset(report Report) error
func (*APIReporter) UpdateTable ¶
func (a *APIReporter) UpdateTable(columns []string, rows [][]string)
UpdateTable takes a table of data in the form of a slice of slices of strings and writes them to the configured APIReporter. The first slice must be the column names. UpdateTable replaces all existing data in the Dataview.
type APIReporterOption ¶ added in v1.27.0
type APIReporterOption func(*apiReportOptions)
func APIEntity ¶
func APIEntity(entity string) APIReporterOption
func APIHostname ¶
func APIHostname(hostname string) APIReporterOption
func APIMaxRows ¶
func APIMaxRows(n int) APIReporterOption
func APIPort ¶
func APIPort(port int) APIReporterOption
func APISampler ¶
func APISampler(sampler string) APIReporterOption
func APISecure ¶
func APISecure(secure bool) APIReporterOption
func APISkipVerify ¶
func APISkipVerify(skip bool) APIReporterOption
func DataviewCreateDelay ¶
func DataviewCreateDelay(delay time.Duration) APIReporterOption
func ResetDataviews ¶
func ResetDataviews(reset bool) APIReporterOption
type ConditionalFormat ¶
type ConditionalFormat struct {
Test ConditionalFormatTest `mapstructure:"test,omitempty"`
Set []ConditionalFormatSet `mapstructure:"set,omitempty"`
}
type ConditionalFormatSet ¶
type ConditionalFormatTest ¶
type ConditionalFormatTest struct {
Columns []string `mapstructure:"columns,omitempty"`
Logical string `mapstructure:"logical,omitempty"` // "and", "all" or "or", "any"
Condition string `mapstructure:"condition,omitempty"`
Type string `mapstructure:"type,omitempty"`
Value string `mapstructure:"value,omitempty"`
}
type FormattedReporter ¶
type FormattedReporter struct {
// contains filtered or unexported fields
}
FormattedReporter implements a Reporter that outputs in various formatted text formats, including plain text tables, Markdown and HTML.
func (*FormattedReporter) AddHeadline ¶
func (fr *FormattedReporter) AddHeadline(name, value string)
AddHeadline adds a headline to the reporter. The order of headlines is preserved, and the headlines are rendered in the order they were added.
func (*FormattedReporter) AddHeadlines ¶ added in v1.27.0
func (fr *FormattedReporter) AddHeadlines(headlines map[string]string)
AddHeadlines adds multiple headlines to the reporter. The order of headlines is NOT preserved.
func (*FormattedReporter) Close ¶
func (fr *FormattedReporter) Close()
func (*FormattedReporter) Extension ¶
func (fr *FormattedReporter) Extension() string
func (*FormattedReporter) Prepare ¶
func (fr *FormattedReporter) Prepare(report Report) (err error)
func (*FormattedReporter) Render ¶
func (fr *FormattedReporter) Render()
Render sends the collected report data to the underlying table.Writer as on table of headlines and another or table data
func (*FormattedReporter) Reset ¶ added in v1.27.0
func (fr *FormattedReporter) Reset(report Report) (err error)
func (*FormattedReporter) UpdateTable ¶
func (fr *FormattedReporter) UpdateTable(columns []string, data [][]string)
type FormattedReporterOption ¶ added in v1.27.0
type FormattedReporterOption func(*formattedReporterOptions)
func DataviewCSSClass ¶
func DataviewCSSClass(cssclass string) FormattedReporterOption
func HTMLPostscript ¶
func HTMLPostscript(postscript string) FormattedReporterOption
func HTMLPreamble ¶
func HTMLPreamble(preamble string) FormattedReporterOption
func HeadlineCSSClass ¶
func HeadlineCSSClass(cssclass string) FormattedReporterOption
func OrderByColumns ¶ added in v1.26.0
func OrderByColumns(cols ...int) FormattedReporterOption
OrderByColumns sets the column indices to order the table by, in order of precedence. The default is to order by the first column only.
func Writer ¶
func Writer(w io.Writer) FormattedReporterOption
func ZipWriter ¶
func ZipWriter(z *zip.Writer) FormattedReporterOption
type Report ¶
type Report struct {
Name string `mapstructure:"report"`
Title string `mapstructure:"name"`
Columns []string `mapstructure:"columns,omitempty"`
ScrambleColumns []string `mapstructure:"scramble-columns,omitempty"`
// FilePath is the pattern used to generate a file path for reports
// when being written to a directory or a zip archive. It may
// contain placeholders that will be replaced with report-specific
// values.
//
// When not set the file path is generated from the report name,
// lowercased and with spaces replaced by '-' (dash) and an extension
// appropriate to the report format.
//
// Example: "reports/${value}_report.${extension}"
// The ${value} placeholder is replaced with the split value
// (e.g. gateway name) and ${extension} with the appropriate file
// extension for the report format (e.g. "csv" or "xlsx").
//
// ${value} is only replaced when the report is being split by a
// column value, e.g. gateway name. If the report is not split,
// then ${value} is unset.
//
// The ${extension} placeholder is always replaced.
FilePath string `mapstructure:"file-path,omitempty"`
Dataview struct {
Group string `mapstructure:"group,omitempty"`
Enable *bool `mapstructure:"enable,omitempty"`
} `mapstructure:"dataview,omitempty"`
XLSX struct {
// xlsx specific
Enable *bool `mapstructure:"enable,omitempty"`
FreezeColumn string `mapstructure:"freeze-to-column"`
ConditionalFormat []ConditionalFormat `mapstructure:"conditional-format,omitempty"`
} `mapstructure:"xlsx,omitempty"`
}
type Reporter ¶
type Reporter interface {
// Prepare initialises the current report and must be called before AddHeadline() or UpdateTable()
Prepare(report Report) error
// AddHeadline adds a single headline to the current report dataview / sheet etc.
AddHeadline(name, value string)
// AddHeadlines adds multiple headlines to the current report dataview / sheet etc.
AddHeadlines(headlines map[string]string)
// UpdateTable sets the main data table to the rows given. The first row must be the column names.
UpdateTable(columns []string, rows [][]string)
// Reset deletes an existing report, e.g. an existing Dataview from a previous run
Reset(report Report) error
// Render writes the current report to the destination selected with Prepare()
Render()
// Close releases any resources for the whole reporter
Close()
// Extension returns the file extension appropriate for this reporter type
Extension() string
}
func NewReporter ¶
NewReporter returns a reporter for type format, which must be one of "toolkit", "csv", "tsv", "api", "dataview", "xlsx", "table" or "html". If a destination writer is required for the reporter type, then w should be the io.Writer to use. options are a list of options of either ReporterOptions or the options for the selected reporter type.
TODO: add "column" output format, based on tabwriter.
type ReporterOption ¶ added in v1.27.0
type ReporterOption func(*reporterOptions)
func Scramble ¶
func Scramble(scramble bool) ReporterOption
func ScrambleColumns ¶
func ScrambleColumns(columns []string) ReporterOption
func ScrambleFunc ¶
func ScrambleFunc(fn func(in string) string) ReporterOption
type TabWriterReporter ¶ added in v1.26.0
type TabWriterReporter struct {
// contains filtered or unexported fields
}
TabWriterReporter implements a Reporter using tabwriter to format output in columns.
func (*TabWriterReporter) AddHeadline ¶ added in v1.26.0
func (t *TabWriterReporter) AddHeadline(name, value string)
AddHeadline adds a headline (not used in tabwriter).
func (*TabWriterReporter) AddHeadlines ¶ added in v1.27.0
func (t *TabWriterReporter) AddHeadlines(headlines map[string]string)
func (*TabWriterReporter) Close ¶ added in v1.26.0
func (t *TabWriterReporter) Close()
Close releases resources for TabWriterReporter.
func (*TabWriterReporter) Extension ¶ added in v1.26.0
func (t *TabWriterReporter) Extension() string
Extension returns the file extension for TabWriterReporter.
func (*TabWriterReporter) Prepare ¶ added in v1.26.0
func (t *TabWriterReporter) Prepare(report Report) error
Prepare initialises the TabWriterReporter.
func (*TabWriterReporter) Render ¶ added in v1.26.0
func (t *TabWriterReporter) Render()
Render writes the table to the tabwriter.
func (*TabWriterReporter) Reset ¶ added in v1.27.0
func (t *TabWriterReporter) Reset(report Report) error
Reset is a no-op for TabWriterReporter.
func (*TabWriterReporter) UpdateTable ¶ added in v1.26.0
func (t *TabWriterReporter) UpdateTable(columns []string, rows [][]string)
UpdateTable sets the main data table to the rows given. The first row must be the column names. It overwrites any existing table data. Data is output as-is and no quoting takes place
type ToolkitReporter ¶
type ToolkitReporter struct {
// contains filtered or unexported fields
}
func (*ToolkitReporter) AddHeadline ¶
func (t *ToolkitReporter) AddHeadline(name, value string)
AddHeadline adds a headline to the reporter.
func (*ToolkitReporter) AddHeadlines ¶ added in v1.27.0
func (t *ToolkitReporter) AddHeadlines(headlines map[string]string)
AddHeadlines adds multiple headlines to the reporter.
func (*ToolkitReporter) Close ¶
func (t *ToolkitReporter) Close()
Close will call Close on the writer if it has a Close method
func (*ToolkitReporter) Extension ¶
func (t *ToolkitReporter) Extension() string
func (*ToolkitReporter) Prepare ¶
func (t *ToolkitReporter) Prepare(report Report) error
func (*ToolkitReporter) Render ¶
func (t *ToolkitReporter) Render()
func (*ToolkitReporter) Reset ¶ added in v1.27.0
func (t *ToolkitReporter) Reset(report Report) (err error)
func (*ToolkitReporter) UpdateTable ¶
func (t *ToolkitReporter) UpdateTable(columns []string, rows [][]string)
UpdateTable sets the main data table to the rows given. The first row must be the column names. It overwrites any existing table data.
type XLSXReporter ¶
type XLSXReporter struct {
// contains filtered or unexported fields
}
func (*XLSXReporter) AddHeadline ¶
func (x *XLSXReporter) AddHeadline(name, value string)
AddHeadline adds a headline to the reporter. The order of headlines is preserved, and the headlines are rendered in the order they were added.
func (*XLSXReporter) AddHeadlines ¶ added in v1.27.0
func (x *XLSXReporter) AddHeadlines(headlines map[string]string)
AddHeadlines adds multiple headlines to the reporter. The order of headlines is NOT preserved.
func (*XLSXReporter) Close ¶
func (x *XLSXReporter) Close()
func (*XLSXReporter) Extension ¶
func (x *XLSXReporter) Extension() string
func (*XLSXReporter) Prepare ¶
func (x *XLSXReporter) Prepare(report Report) (err error)
func (*XLSXReporter) Render ¶
func (x *XLSXReporter) Render()
func (*XLSXReporter) Reset ¶ added in v1.27.0
func (x *XLSXReporter) Reset(report Report) (err error)
func (*XLSXReporter) UpdateTable ¶
func (x *XLSXReporter) UpdateTable(columns []string, rows [][]string)
UpdateTable takes a table of data in the form of a slice of slices of strings and writes them to the configured XLSXReporter. The first slice must be the column names. UpdateTable replaces all existing data in the sheet.
type XLSXReporterOption ¶ added in v1.27.0
type XLSXReporterOption func(*xlsxReportOptions)
func DateFormat ¶
func DateFormat(dateFormat string) XLSXReporterOption
func IntFormat ¶
func IntFormat(format int) XLSXReporterOption
func MaxColumnWidth ¶
func MaxColumnWidth(n float64) XLSXReporterOption
func MinColumnWidth ¶
func MinColumnWidth(n float64) XLSXReporterOption
func PercentFormat ¶
func PercentFormat(format int) XLSXReporterOption
func SeverityColours ¶
func SeverityColours(undefined, ok, warning, critical string) XLSXReporterOption
func SummarySheetName ¶
func SummarySheetName(name string) XLSXReporterOption
func XLSXHeadlines ¶
func XLSXHeadlines(headlines int) XLSXReporterOption
XLSXHeadlines sets visibility and the direction of headlines in a sheet. The default is not to include headlines. If passed XLSXHeadlinesVertical then the headlines are added as a two column list of name/value pairs. If passed XLSXHeadlinesHorizontal then headlines are added as two rows with each headlines added as a single column, name above value.
func XLSXPassword ¶
func XLSXPassword(password config.Secret) XLSXReporterOption
XLSXPassword sets the workbook password
func XLSXScramble ¶
func XLSXScramble(scramble bool) XLSXReporterOption