healthcheck

package
v0.2.2-0...-52a3941 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const FooterHealthcheck = `` /* 314-byte string literal not displayed */

FooterHealthcheck footer for healthchecks

View Source
const TemplateHealthcheckHTML = `` /* 2004-byte string literal not displayed */

TemplateHealthcheckHTML pongo2 template for healthchecks

View Source
const TemplateHealthcheckPostgres = `
CREATE TABLE IF NOT EXISTS {{metadata.schema}}.{{metadata.table}}
(
  title text,
  query text,
  executed text,
  expected text,
  operation text,
  actual text,
  equal text,
  severity text,
  "timestamp" timestamp with time zone
);

INSERT INTO "{{metadata.schema}}"."{{metadata.table}}" ("title", "query", "executed", "expected", "operation", "actual", "equal", "severity", "timestamp") VALUES
{% for element in elements %}
('{{ element.Title }}', '{{ element.Query | safe | addquote }}', '{{ element.Passed}}', '{{ element.Expected  | safe | addquote  }}', '{{ element.Operation  | safe | addquote  }}', '{{ element.Actual  | safe | addquote  }}', '{{ element.Equal  | safe | addquote  }}', '{{ element.Severity }}', '{{ metadata.timestamp }}') ` +
	`{% if forloop.Last%};{%else%},{%endif%}` +
	`{% endfor %}`

TemplateHealthcheckPostgres pongo2 template for healthchecks INSERT

Variables

View Source
var HealthCheckReportHeaders = []string{"Title", "Query", "Passed", "Expected", "Actual", "Equal", "Severity", "Operation"}

HealthCheckReportHeaders headers used for GetHeaders

Functions

func EvaluateHCErrors

func EvaluateHCErrors(hcerrors []HCError) (int, int, bool)

EvaluateHCErrors given a slice of HCErrors, determine if error or early exit

func StatusHealthchecks

func StatusHealthchecks(errors int, warnings int, fatal bool) string

StatusHealthchecks returns a simple summary for all healthchecks

func SubjectHealthcheck

func SubjectHealthcheck(name string, dbName string, hostname string, level string, errors int, warnings int, fatal bool) string

SubjectHealthcheck creates a subject for healthcheck email

Types

type Format

type Format struct {
	Name         string           `yaml:"name"`
	Distribution []string         `yaml:"distribution"`
	Tests        []SQLHealthCheck `yaml:"tests"`
}

Format is for unmarshiling a healthcheck file and contains control information for a set of SQLHealthChecks

func ReadHealthCheckYAMLFromFile

func ReadHealthCheckYAMLFromFile(path string) (format Format, err error)

ReadHealthCheckYAMLFromFile loads healthcheck data from a YAML file

func (*Format) PreformHealthChecks

func (healthChecks *Format) PreformHealthChecks(cxn *sql.DB) (results []SQLHealthCheck, errors []HCError)

PreformHealthChecks runs and evaluates healthChecks one at a time

func (*Format) RejectBadHealthChecks

func (healthChecks *Format) RejectBadHealthChecks()

RejectBadHealthChecks validates all healthchecks in specified file

func (*Format) RunHealthChecks

func (healthChecks *Format) RunHealthChecks(cxn *sql.DB)

RunHealthChecks executes all health checks in the specified file

func (*Format) ValidateHealthChecks

func (healthChecks *Format) ValidateHealthChecks() bool

ValidateHealthChecks validates all healthchecks in specified file

type HCError

type HCError struct {
	Err  string
	Exit bool
}

HCError is a error helper for knowing to exit early on a failed healthcheck

type SQLHealthCheck

type SQLHealthCheck struct {
	Expected  string `yaml:"expected"`
	Query     string `yaml:"query"`
	Title     string `yaml:"title"`
	Severity  string `yaml:"severity"`
	Operation string `yaml:"operation,omitempty"`
	Passed    bool
	Actual    string
	Equal     bool
}

SQLHealthCheck is a data type for storing the definition and results of a SQL based health check

func (*SQLHealthCheck) EvaluateHealthCheck

func (healthCheck *SQLHealthCheck) EvaluateHealthCheck() (err HCError)

EvaluateHealthCheck runs through a single healthcheck and acts on the result

func (SQLHealthCheck) GetHeaders

func (healthCheck SQLHealthCheck) GetHeaders() []string

GetHeaders Implementation for report.Element

func (SQLHealthCheck) GetValue

func (healthCheck SQLHealthCheck) GetValue(key string) string

GetValue Implementation for report.Element

func (*SQLHealthCheck) RunHealthCheck

func (healthCheck *SQLHealthCheck) RunHealthCheck(cxn *sql.DB)

RunHealthCheck runs through a single healthcheck and saves the result

func (SQLHealthCheck) ValidateHealthCheck

func (healthCheck SQLHealthCheck) ValidateHealthCheck() bool

ValidateHealthCheck makes sure a helathcheck has all the fields populated

Jump to

Keyboard shortcuts

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