cachet

package module
v3.7.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 18 Imported by: 0

README

Enhanced Cachet Monitor

CircleCI codecov GitHub GitHub tag (latest SemVer)

Features

  • Creates & Resolves Incidents
  • Posts monitor lag to cachet graphs
  • HTTP Checks (body/status code)
  • DNS Checks
  • Updates Component to Partial Outage
  • Updates Component to Major Outage if already in Partial Outage (works with distributed monitors)
  • Can be run on multiple servers and geo regions
  • NEW TCP Checks
  • NEW SAP Cloud Application Status Checks
  • NEW Configuration schema file
  • NEW Auto configuration from cachet server
  • NEW Reload configuration from cachet server
  • REFACTOR cli
  • REFACTOR threshold removed

Example Configuration

Note: configuration can be in json or yaml format. example.config.json, example.config.yaml files.

Installation

Not support windows platform.

  1. Download binary
  2. Add the binary to an executable path (/usr/bin, etc.)
  3. Create a configuration following provided examples
  4. cachet-monitor -c /etc/cachet-monitor.yaml
NAME:
   Cachet Monitor - A Command Line Tool for Cachet Monitor

USAGE:
   cli [global options] command [command options] [arguments...]

VERSION:
   SNAPSHOT

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value, -c value  Path to configuration file (default: "./config.json") [$CONFIG_FILE]
   --log value, -l value     Path to log file [$LOG_FILE]
   --name value, -n value    System name [$SYSTEM_NAME]
   --help, -h                show help
   --version, -v             print the version

CHANGELOG

LICENSE

Documentation

Index

Constants

View Source
const DefaultInterval = 15
View Source
const DefaultThreshold = 3
View Source
const DefaultTimeFormat = time.RFC3339
View Source
const DefaultTimeout = 10
View Source
const HistorySize = 3

Variables

This section is empty.

Functions

func CheckTCPPortAlive

func CheckTCPPortAlive(ip, port string, timeout int64) (bool, error)

CheckTCPPortAlive func

func GetMonitorType

func GetMonitorType(t string) string

GetMonitorType string

Types

type AbstractMonitor

type AbstractMonitor struct {
	Name   string
	Target string

	// (default)http / dns
	Type   string
	Strict bool

	Interval time.Duration
	Timeout  time.Duration

	MetricID    int `mapstructure:"metric_id"`
	ComponentID int `mapstructure:"component_id"`

	// Templating stuff
	Template struct {
		Investigating MessageTemplate
		Fixed         MessageTemplate
	}

	// Threshold = percentage / number of down incidents
	Threshold      float32
	ThresholdCount bool `mapstructure:"threshold_count"`
	// contains filtered or unexported fields
}

AbstractMonitor data model

func (*AbstractMonitor) AnalyseData

func (mon *AbstractMonitor) AnalyseData()

AnalyseData decides if the monitor is statistically up or down and creates / resolves an incident

func (*AbstractMonitor) ClockStart

func (mon *AbstractMonitor) ClockStart(cfg *CachetMonitor, iface MonitorInterface, wg *sync.WaitGroup)

func (*AbstractMonitor) ClockStop

func (mon *AbstractMonitor) ClockStop()

func (*AbstractMonitor) Describe

func (mon *AbstractMonitor) Describe() []string

func (*AbstractMonitor) GetMonitor

func (mon *AbstractMonitor) GetMonitor() *AbstractMonitor

func (*AbstractMonitor) SetDefaultIncident

func (m *AbstractMonitor) SetDefaultIncident(i *Incident)

SetDefaultIncident for monitor

func (*AbstractMonitor) Validate

func (mon *AbstractMonitor) Validate() []string

Validate configuration

type CachetAPI

type CachetAPI struct {
	URL      string `json:"url"`
	Token    string `json:"token"`
	Insecure bool   `json:"insecure"`
}

func (CachetAPI) GetAllComponents

func (api CachetAPI) GetAllComponents() ([]Datum, error)

GetAllComponents func

func (CachetAPI) GetComponentStatus

func (api CachetAPI) GetComponentStatus(componentID int) (int, error)

GetComponentStatus

func (CachetAPI) GetConfigurationFromRemote

func (api CachetAPI) GetConfigurationFromRemote() (*CachetMonitor, error)

GetConfigurationFromRemote server

func (CachetAPI) NewRequest

func (api CachetAPI) NewRequest(requestType, url string, reqBody []byte) (*http.Response, CachetResponse, error)

NewRequest wraps http.NewRequest

func (CachetAPI) Ping

func (api CachetAPI) Ping() error

Ping system is alive

func (CachetAPI) SendMetric

func (api CachetAPI) SendMetric(id int, lag int64)

SendMetric adds a data point to a cachet monitor

type CachetMonitor

type CachetMonitor struct {
	SystemName  string                   `json:"system_name" yaml:"system_name"`
	DateFormat  string                   `json:"date_format" yaml:"date_format"`
	API         CachetAPI                `json:"api"`
	RawMonitors []map[string]interface{} `json:"monitors" yaml:"monitors"`

	Monitors  []MonitorInterface `json:"-" yaml:"-"`
	Immediate bool               `json:"-" yaml:"-"`
}

func (*CachetMonitor) Validate

func (cfg *CachetMonitor) Validate() bool

Validate configuration

type CachetResponse

type CachetResponse struct {
	Data json.RawMessage `json:"data"`
}

type Components

type Components struct {
	Meta Meta    `json:"meta"`
	Data []Datum `json:"data"`
}

func UnmarshalComponents

func UnmarshalComponents(data []byte) (Components, error)

func (*Components) Marshal

func (r *Components) Marshal() ([]byte, error)

type DNSAnswer

type DNSAnswer struct {
	Regex string

	Exact string
	// contains filtered or unexported fields
}

type DNSMonitor

type DNSMonitor struct {
	AbstractMonitor `mapstructure:",squash"`

	// IP:port format or blank to use system defined DNS
	DNS string

	// A(default), AAAA, MX, ...
	Question string

	Answers []DNSAnswer
	// contains filtered or unexported fields
}

func (*DNSMonitor) Validate

func (monitor *DNSMonitor) Validate() []string

type Datum

type Datum struct {
	ID          int64       `json:"id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Link        string      `json:"link"`
	Status      int64       `json:"status"`
	Order       int64       `json:"order"`
	GroupID     int64       `json:"group_id"`
	CreatedAt   string      `json:"created_at"`
	UpdatedAt   string      `json:"updated_at"`
	DeletedAt   interface{} `json:"deleted_at"`
	Enabled     bool        `json:"enabled"`
	StatusName  string      `json:"status_name"`
	Tags        Tags        `json:"tags"`
}

type HTTPMonitor

type HTTPMonitor struct {
	AbstractMonitor `mapstructure:",squash"`

	Method             string
	ExpectedStatusCode int `mapstructure:"expected_status_code"`
	Headers            map[string]string

	// compiled to Regexp
	ExpectedBody string `mapstructure:"expected_body"`
	// contains filtered or unexported fields
}

func (*HTTPMonitor) Describe

func (mon *HTTPMonitor) Describe() []string

func (*HTTPMonitor) Validate

func (mon *HTTPMonitor) Validate() []string

Validate configuration

type Incident

type Incident struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	Message string `json:"message"`
	Status  int    `json:"status"`
	Visible int    `json:"visible"`
	Notify  bool   `json:"notify"`

	ComponentID     int `json:"component_id"`
	ComponentStatus int `json:"component_status"`
	// contains filtered or unexported fields
}

Incident Cachet data model

func (*Incident) GetComponentStatus

func (incident *Incident) GetComponentStatus(cfg *CachetMonitor) (int, error)

GetComponentStatus func

func (*Incident) Send

func (incident *Incident) Send(cfg *CachetMonitor) (err error, updatedComponentStatus int)

Send - Create or Update incident

func (*Incident) SetFixed

func (incident *Incident) SetFixed()

SetFixed sets status to Fixed

func (*Incident) SetIdentified

func (incident *Incident) SetIdentified()

SetIdentified sets status to Identified not used now

func (*Incident) SetInvestigating

func (incident *Incident) SetInvestigating()

SetInvestigating sets status to Investigating

func (*Incident) SetWatching

func (incident *Incident) SetWatching()

SetWatching sets status to Watching not used now

type IncidentResponse

type IncidentResponse struct {
	ID          int64       `json:"id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Link        string      `json:"link"`
	Status      int64       `json:"status"`
	Order       int64       `json:"order"`
	GroupID     int64       `json:"group_id"`
	CreatedAt   string      `json:"created_at"`
	UpdatedAt   string      `json:"updated_at"`
	DeletedAt   interface{} `json:"deleted_at"`
	Enabled     bool        `json:"enabled"`
	StatusName  string      `json:"status_name"`
}

IncidentResponse struct

type Links struct {
	NextPage     interface{} `json:"next_page"`
	PreviousPage interface{} `json:"previous_page"`
}

type MessageTemplate

type MessageTemplate struct {
	Subject string `json:"subject"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

func (*MessageTemplate) Compile

func (t *MessageTemplate) Compile() error

TODO: test

func (*MessageTemplate) Exec

func (t *MessageTemplate) Exec(data interface{}) (string, string)

func (*MessageTemplate) SetDefault

func (t *MessageTemplate) SetDefault(d MessageTemplate)

type Meta

type Meta struct {
	Pagination Pagination `json:"pagination"`
}

type MonitorInterface

type MonitorInterface interface {
	ClockStart(*CachetMonitor, MonitorInterface, *sync.WaitGroup)
	ClockStop()

	Validate() []string
	GetMonitor() *AbstractMonitor
	Describe() []string
	// contains filtered or unexported methods
}

type Pagination

type Pagination struct {
	Total       int64 `json:"total"`
	Count       int64 `json:"count"`
	PerPage     int64 `json:"per_page"`
	CurrentPage int64 `json:"current_page"`
	TotalPages  int64 `json:"total_pages"`
	Links       Links `json:"links"`
}

type TCPMonitor

type TCPMonitor struct {
	AbstractMonitor `mapstructure:",squash"`
	Port            string
}

TCPMonitor struct

func (*TCPMonitor) Validate

func (m *TCPMonitor) Validate() []string

Validate configuration

type Tags

type Tags struct {
	Empty *string `json:",omitempty"`
	Cpi   *string `json:"cpi,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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