Documentation
¶
Index ¶
- Variables
- func FormatClockAgo(val interface{}) string
- func FormatClockRelative(val interface{}) string
- func FormatDefaultCell(key string, val interface{}, resource string) string
- func FormatDuration(d time.Duration) string
- func FormatSeverity(val interface{}) string
- func IsTerminal() bool
- func ParseEpoch(val interface{}) (int64, bool)
- func PrintErrorEnvelope(w io.Writer, errObj interface{})
- func ValidateFields(data interface{}, resource string, fields []string) error
- func ValidateFieldsFromRowMaps(rowMaps []map[string]interface{}, resource string, fields []string) error
- type ColumnDefinition
- type Formatter
- type PrintOptions
Constants ¶
This section is empty.
Variables ¶
var KnownResourceAttributes = map[string][]string{
"host": {"hostid", "host", "name", "status", "description", "proxy_hostid", "ip", "dns", "port", "available", "error", "tls_connect", "tls_accept", "inventory_mode"},
"inventory": {"hostid", "host", "name", "inventory_mode", "type", "type_full", "vendor", "model", "hardware", "macaddress_a", "macaddress_b", "serialno_a", "serialno_b", "tag", "asset_tag", "os", "os_full", "os_short", "location", "location_lat", "location_lon", "poc_1_name", "poc_1_email", "poc_1_phone_a", "poc_1_cell", "poc_1_notes", "notes", "chassis", "deployment_status", "date_hw_purchase", "date_hw_install", "date_hw_expiry", "date_hw_decomm", "site_rack", "site_notes", "host_networks", "alias"},
"template": {"templateid", "name", "host", "description", "uuid", "vendor_name", "vendor_version"},
"problem": {"eventid", "source", "object", "objectid", "clock", "ns", "r_eventid", "r_clock", "r_ns", "correlationid", "userid", "name", "acknowledged", "severity", "cause_eventid", "opdata", "suppressed", "status", "host", "hostname", "age"},
"item": {"itemid", "type", "snmp_oid", "hostid", "name", "key_", "delay", "history", "trends", "status", "value_type", "trapper_hosts", "units", "description", "lastvalue", "prevvalue", "lastclock", "error", "host"},
"trigger": {"triggerid", "expression", "description", "url", "status", "value", "priority", "lastchange", "comments", "error", "templateid", "type", "state", "flags", "recovery_mode", "recovery_expression", "correlation_mode", "correlation_tag", "manual_close", "opdata", "event_name"},
"hostgroup": {"groupid", "name", "flags", "uuid"},
"maintenance": {"maintenanceid", "name", "maintenance_type", "description", "active_since", "active_till", "tags_evaltype"},
"event": {"eventid", "source", "object", "objectid", "clock", "value", "acknowledged", "ns", "name", "severity", "r_eventid", "c_eventid", "correlationid", "userid", "suppressed", "opdata", "urls", "host", "hostname", "age", "status"},
"user": {"userid", "username", "name", "surname", "url", "autologin", "autologout", "lang", "refresh", "theme", "roleid", "userdirectoryid", "ts_provisioned"},
"service": {"serviceid", "name", "status", "algorithm", "description", "sortorder", "weight", "propagation_rule", "propagation_value", "readonly"},
"sla": {"slaid", "name", "period", "slo", "effective_date", "timezone", "status", "description", "service_tags"},
"dashboard": {"dashboardid", "name", "userid", "private", "display_period", "auto_start"},
"history": {"itemid", "clock", "value", "ns"},
}
KnownResourceAttributes lists known standard field attributes for each resource type.
var ResourceSchemas = map[string][]ColumnDefinition{ "problem": { {Header: "EVENTID", Keys: []string{"eventid"}}, {Header: "HOST", Keys: []string{"host", "hostname", "host_name"}}, {Header: "PROBLEM", Keys: []string{"name", "problem", "description"}}, {Header: "SEVERITY", Keys: []string{"severity", "priority"}, Formatter: formatSeverityCol}, {Header: "STATUS", Keys: []string{"status", "value"}, Formatter: formatProblemStatusCol}, {Header: "AGE", Keys: []string{"age", "clock"}, Formatter: formatAgeCol}, {Header: "ACK", Keys: []string{"ack", "acknowledged"}, Formatter: formatAckCol}, }, "host": { {Header: "HOSTID", Keys: []string{"hostid"}}, {Header: "HOST", Keys: []string{"host"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "STATUS", Keys: []string{"status"}, Formatter: formatHostStatusCol}, {Header: "AVAILABILITY", Keys: []string{"available", "availability"}, Formatter: formatAvailabilityCol}, }, "inventory": { {Header: "HOSTID", Keys: []string{"hostid"}}, {Header: "HOST", Keys: []string{"host"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "MODE", Keys: []string{"inventory_mode"}, Formatter: formatInventoryModeCol}, {Header: "TYPE", Keys: []string{"type"}}, {Header: "VENDOR", Keys: []string{"vendor"}}, {Header: "MODEL", Keys: []string{"model", "hardware"}}, {Header: "MAC", Keys: []string{"macaddress_a", "macaddress"}}, {Header: "OS", Keys: []string{"os", "os_full"}}, }, "item": { {Header: "ITEMID", Keys: []string{"itemid"}}, {Header: "HOST", Keys: []string{"host", "hostid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "KEY", Keys: []string{"key_", "key"}}, {Header: "TYPE", Keys: []string{"type"}, Formatter: formatItemTypeCol}, {Header: "STATUS", Keys: []string{"status"}, Formatter: formatItemStatusCol}, {Header: "DELAY", Keys: []string{"delay"}}, {Header: "LASTVALUE", Keys: []string{"lastvalue", "prevvalue", "value"}}, }, "trigger": { {Header: "TRIGGERID", Keys: []string{"triggerid"}}, {Header: "TRIGGER", Keys: []string{"description", "name"}}, {Header: "SEVERITY", Keys: []string{"priority", "severity"}, Formatter: formatSeverityCol}, {Header: "STATUS", Keys: []string{"status"}, Formatter: formatItemStatusCol}, {Header: "VALUE", Keys: []string{"value"}, Formatter: formatTriggerValueCol}, {Header: "EXPRESSION", Keys: []string{"expression"}}, }, "template": { {Header: "TEMPLATEID", Keys: []string{"templateid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "HOST", Keys: []string{"host"}}, }, "hostgroup": { {Header: "GROUPID", Keys: []string{"groupid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "FLAGS", Keys: []string{"flags"}}, }, "maintenance": { {Header: "MAINTENANCEID", Keys: []string{"maintenanceid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "TYPE", Keys: []string{"maintenance_type"}}, {Header: "ACTIVE_SINCE", Keys: []string{"active_since"}, Formatter: formatDateTimeCol}, {Header: "ACTIVE_TILL", Keys: []string{"active_till"}, Formatter: formatDateTimeCol}, }, "event": { {Header: "EVENTID", Keys: []string{"eventid"}}, {Header: "HOST", Keys: []string{"host", "hostname"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "SEVERITY", Keys: []string{"severity", "priority"}, Formatter: formatSeverityCol}, {Header: "STATUS", Keys: []string{"value", "status"}, Formatter: formatTriggerValueCol}, {Header: "AGE", Keys: []string{"age", "clock"}, Formatter: formatAgeCol}, {Header: "ACK", Keys: []string{"acknowledged", "ack"}, Formatter: formatAckCol}, }, "user": { {Header: "USERID", Keys: []string{"userid"}}, {Header: "USERNAME", Keys: []string{"username", "alias"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "SURNAME", Keys: []string{"surname"}}, {Header: "ROLEID", Keys: []string{"roleid"}}, {Header: "AUTOLOGOUT", Keys: []string{"autologout"}}, }, "service": { {Header: "SERVICEID", Keys: []string{"serviceid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "STATUS", Keys: []string{"status"}, Formatter: formatTriggerValueCol}, {Header: "ALGORITHM", Keys: []string{"algorithm"}}, }, "sla": { {Header: "SLAID", Keys: []string{"slaid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "SLO", Keys: []string{"slo"}, Formatter: formatSLOCol}, {Header: "PERIOD", Keys: []string{"period"}}, {Header: "TIMEZONE", Keys: []string{"timezone"}}, {Header: "STATUS", Keys: []string{"status"}, Formatter: formatItemStatusCol}, }, "dashboard": { {Header: "DASHBOARDID", Keys: []string{"dashboardid"}}, {Header: "NAME", Keys: []string{"name"}}, {Header: "USERID", Keys: []string{"userid"}}, {Header: "PRIVATE", Keys: []string{"private"}, Formatter: formatPrivateCol}, }, "history": { {Header: "ITEMID", Keys: []string{"itemid"}}, {Header: "CLOCK", Keys: []string{"clock"}, Formatter: formatAgeCol}, {Header: "VALUE", Keys: []string{"value"}}, {Header: "NS", Keys: []string{"ns"}}, }, }
ResourceSchemas maps each resource type to its standard, curated table columns.
Functions ¶
func FormatClockAgo ¶
func FormatClockAgo(val interface{}) string
FormatClockAgo formats an epoch timestamp into a relative time with "ago" (e.g. 12m ago, 2h ago).
func FormatClockRelative ¶
func FormatClockRelative(val interface{}) string
FormatClockRelative formats an epoch timestamp into a human-friendly relative age (e.g. 12m, 2h, 3d, 45s).
func FormatDefaultCell ¶
FormatDefaultCell applies contextual formatting based on field name and value.
func FormatDuration ¶
FormatDuration formats a time.Duration into a concise human-readable string (e.g. 12m, 2h, 3d, 45s).
func FormatSeverity ¶
func FormatSeverity(val interface{}) string
func IsTerminal ¶
func IsTerminal() bool
func ParseEpoch ¶
ParseEpoch attempts to parse a generic value into a Unix epoch timestamp (int64). Returns the epoch and true if valid (epoch > 0), or (0, false) if invalid.
func PrintErrorEnvelope ¶
func ValidateFields ¶
ValidateFields verifies that each field in fields exists either in rowMaps, ResourceSchemas[resource], or KnownResourceAttributes[resource].
Types ¶
type ColumnDefinition ¶
type ColumnDefinition struct {
Header string
Keys []string
Formatter func(val interface{}, row map[string]interface{}) string
}
ColumnDefinition defines a standard table column with header, field key lookups, and custom cell formatting.
func (ColumnDefinition) ExtractValue ¶
func (col ColumnDefinition) ExtractValue(row map[string]interface{}, resource string) string
type Formatter ¶
func NewFormatter ¶
func (*Formatter) PrintResource ¶
func (*Formatter) PrintWithOptions ¶
func (f *Formatter) PrintWithOptions(data interface{}, opts PrintOptions) error