update readme, remove tcp/icmp

This commit is contained in:
Matej Kramny
2017-02-12 17:35:09 -08:00
parent 8aae002623
commit 6a51993296
7 changed files with 188 additions and 103 deletions

View File

@@ -179,14 +179,6 @@ func getConfiguration(path string) (*cachet.CachetMonitor, error) {
var s cachet.DNSMonitor var s cachet.DNSMonitor
err = mapstructure.Decode(rawMonitor, &s) err = mapstructure.Decode(rawMonitor, &s)
t = &s t = &s
case "icmp":
var s cachet.ICMPMonitor
err = mapstructure.Decode(rawMonitor, &s)
t = &s
case "tcp":
var s cachet.TCPMonitor
err = mapstructure.Decode(rawMonitor, &s)
t = &s
default: default:
logrus.Errorf("Invalid monitor type (index: %d) %v", index, monType) logrus.Errorf("Invalid monitor type (index: %d) %v", index, monType)
continue continue

View File

@@ -1,14 +1,65 @@
api: api:
# cachet url
url: https://demo.cachethq.io/api/v1 url: https://demo.cachethq.io/api/v1
# cachet api token
token: 9yMHsdioQosnyVK4iCVR token: 9yMHsdioQosnyVK4iCVR
insecure: false
# https://golang.org/src/time/format.go#L57
date_format: 02/01/2006 15:04:05 MST
monitors: monitors:
# http monitor example
- name: google - name: google
target: https://google.com # test url
threshold: 80 target: http://localhost:2000/ping
# strict certificate checking for https
strict: true
# HTTP method
method: POST
# set to update component (either component_id or metric_id are required)
component_id: 1 component_id: 1
interval: 10 # set to post lag to cachet metric (graph)
timeout: 5 metric_id: 4
# custom templates (see readme for details)
template:
investigating:
subject: "{{ .Monitor.Name }} - {{ .SystemName }}"
message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}"
fixed:
subject: "I HAVE BEEN FIXED"
# seconds between checks
interval: 1
# seconds for timeout
timeout: 1
# If % of downtime is over this threshold, open an incident
threshold: 80
# custom HTTP headers
headers: headers:
Authorization: Basic <hash> Authorization: Basic <hash>
# expected status code (either status code or body must be supplied)
expected_status_code: 200 expected_status_code: 200
strict: true # regex to match body
expected_body: "P.*NG"
# dns monitor example
- name: dns
# fqdn
target: matej.me.
# question type (A/AAAA/CNAME/...)
question: mx
type: dns
# set component_id/metric_id
component_id: 2
# poll every 1s
interval: 1
timeout: 1
# custom DNS server (defaults to system)
dns: 8.8.4.4:53
answers:
# exact/regex check
- regex: [1-9] alt[1-9].aspmx.l.google.com.
- exact: 10 aspmx2.googlemail.com.
- exact: 1 aspmx.l.google.com.
- exact: 10 aspmx3.googlemail.com.

View File

@@ -1,5 +0,0 @@
package cachet
type ICMPMonitor struct {
AbstractMonitor `mapstructure:",squash"`
}

View File

@@ -28,7 +28,7 @@ type AbstractMonitor struct {
Name string Name string
Target string Target string
// (default)http, tcp, dns, icmp // (default)http / dns
Type string Type string
Strict bool Strict bool

7
monitor_test.go Normal file
View File

@@ -0,0 +1,7 @@
package cachet
import (
"testing"
)
func TestAnalyseData(t *testing.T) {}

193
readme.md
View File

@@ -1,100 +1,155 @@
![screenshot](https://castawaylabs.github.io/cachet-monitor/screenshot.png) ![screenshot](https://castawaylabs.github.io/cachet-monitor/screenshot.png)
Features ## Features
--------
- [x] Creates & Resolves Incidents - [x] Creates & Resolves Incidents
- [x] Check URLs by response code and/or body contents
- [x] Posts monitor lag to cachet graphs - [x] Posts monitor lag to cachet graphs
- [x] HTTP Checks (body/status code)
- [x] DNS Checks
- [x] Updates Component to Partial Outage - [x] Updates Component to Partial Outage
- [x] Updates Component to Major Outage if already in Partial Outage (works well with distributed monitoring) - [x] Updates Component to Major Outage if already in Partial Outage (works with distributed monitors)
- [x] Can be run on multiple servers and geo regions - [x] Can be run on multiple servers and geo regions
Configuration ## Example Configuration
-------------
``` ```yaml
{ api:
// URL for the API. Note: Must end with /api/v1 # cachet url
"api_url": "https://<cachet domain>/api/v1", url: https://demo.cachethq.io/api/v1
// Your API token for Cachet # cachet api token
"api_token": "<cachet api token>", token: 9yMHsdioQosnyVK4iCVR
// optional, false default, set if your certificate is self-signed/untrusted insecure: false
"insecure_api": false, # https://golang.org/src/time/format.go#L57
"monitors": [{ date_format: 02/01/2006 15:04:05 MST
// required, friendly name for your monitor monitors:
"name": "Name of your monitor", # http monitor example
// required, url to probe - name: google
"url": "Ping URL", # test url
// optional, http method (defaults GET) target: http://localhost:2000/ping
"method": "get", # strict certificate checking for https
// optional, http Headers to add (default none) strict: true
"headers": [ # HTTP method
// specify Name and Value of Http-Header, eg. Authorization method: POST
{ "name": "Authorization", "value": "Basic <hash>" }
], # set to update component (either component_id or metric_id are required)
// self-signed ssl certificate component_id: 1
"strict_tls": true, # set to post lag to cachet metric (graph)
// seconds between checks metric_id: 4
"interval": 10,
// seconds for http timeout # custom templates (see readme for details)
"timeout": 5, template:
// post lag to cachet metric (graph) investigating:
// note either metric ID or component ID are required subject: "{{ .Monitor.Name }} - {{ .SystemName }}"
"metric_id": <metric id>, message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}"
// post incidents to this component fixed:
"component_id": <component id>, subject: "I HAVE BEEN FIXED"
// If % of downtime is over this threshold, open an incident
"threshold": 80, # seconds between checks
// optional, expected status code (either status code or body must be supplied) interval: 1
"expected_status_code": 200, # seconds for timeout
// optional, regular expression to match body content timeout: 1
"expected_body": "P.*NG" # If % of downtime is over this threshold, open an incident
}], threshold: 80
// optional, system name to identify bot (uses hostname by default)
"system_name": "", # custom HTTP headers
// optional, defaults to stdout headers:
"log_path": "" Authorization: Basic <hash>
} # expected status code (either status code or body must be supplied)
expected_status_code: 200
# regex to match body
expected_body: "P.*NG"
# dns monitor example
- name: dns
# fqdn
target: matej.me.
# question type (A/AAAA/CNAME/...)
question: mx
type: dns
# set component_id/metric_id
component_id: 2
# poll every 1s
interval: 1
timeout: 1
# custom DNS server (defaults to system)
dns: 8.8.4.4:53
answers:
# exact/regex check
- regex: [1-9] alt[1-9].aspmx.l.google.com.
- exact: 10 aspmx2.googlemail.com.
- exact: 1 aspmx.l.google.com.
- exact: 10 aspmx3.googlemail.com.
``` ```
Installation ## Installation
------------
1. Download binary from [release page](https://github.com/CastawayLabs/cachet-monitor/releases) 1. Download binary from [release page](https://github.com/CastawayLabs/cachet-monitor/releases)
2. Create your configuration ([example](https://raw.githubusercontent.com/CastawayLabs/cachet-monitor/master/example.config.json)) 2. Create a configuration
3. `cachet-monitor -c /etc/cachet-monitor.config.json` 3. `cachet-monitor -c /etc/cachet-monitor.yaml`
pro tip: run in background using `nohup cachet-monitor 2>&1 > /var/log/cachet-monitor.log &` pro tip: run in background using `nohup cachet-monitor 2>&1 > /var/log/cachet-monitor.log &`
``` ```
Usage of cachet-monitor: Usage:
-c="/etc/cachet-monitor.config.json": Config path cachet-monitor (-c PATH | --config PATH) [--log=LOGPATH] [--name=NAME] [--immediate]
-log="": Log path cachet-monitor -h | --help | --version
-name="": System Name cachet-monitor print-config
Arguments:
PATH path to config.json
LOGPATH path to log output (defaults to STDOUT)
NAME name of this logger
Examples:
cachet-monitor -c /root/cachet-monitor.json
cachet-monitor -c /root/cachet-monitor.json --log=/var/log/cachet-monitor.log --name="development machine"
Options:
-c PATH.json --config PATH Path to configuration file
-h --help Show this screen.
--version Show version
--immediate Tick immediately (by default waits for first defined interval)
print-config Print example configuration
Environment varaibles:
CACHET_API override API url from configuration
CACHET_TOKEN override API token from configuration
CACHET_DEV set to enable dev logging
``` ```
Environment variables ## Templates
---------------------
| Name | Example Value | Description | This package makes use of [`text/template`](https://godoc.org/text/template).
| ------------ | ------------------------------ | --------------------------- |
| CACHET_API | http://demo.cachethq.io/api/v1 | URL endpoint for cachet api |
| CACHET_TOKEN | APIToken123 | API Authentication token |
| CACHET_DEV | 1 | Strips logging |
Vision and goals The following variables are available:
----------------
| Root objects |
| ------------- | -----------------
| `.SystemName` | system name
| `.API` | `api` object from configuration
| `.Monitor` | `monitor` object from configuration
| `.now` | formatted date string
| Monitor variables |
| ------------------ |
| `.Name` |
| `.Target` |
| `.Type` |
| `.Strict` |
| `.MetricID` |
| ... |
All monitor variables are available from `monitor.go`
## Vision and goals
We made this tool because we felt the need to have our own monitoring software (leveraging on Cachet). We made this tool because we felt the need to have our own monitoring software (leveraging on Cachet).
The idea is a stateless program which collects data and pushes it to a central cachet instance. The idea is a stateless program which collects data and pushes it to a central cachet instance.
This gives us power to have an army of geographically distributed loggers and reveal issues in both latency & downtime on client websites. This gives us power to have an army of geographically distributed loggers and reveal issues in both latency & downtime on client websites.
Package usage ## Package usage
-------------
When using `cachet-monitor` as a package in another program, you should follow what `cli/main.go` does. It is important to call `ValidateConfiguration` on `CachetMonitor` and all the monitors inside. When using `cachet-monitor` as a package in another program, you should follow what `cli/main.go` does. It is important to call `Validate` on `CachetMonitor` and all the monitors inside.
[API Documentation](https://godoc.org/github.com/CastawayLabs/cachet-monitor) [API Documentation](https://godoc.org/github.com/CastawayLabs/cachet-monitor)

15
tcp.go
View File

@@ -1,15 +0,0 @@
package cachet
type TCPMonitor struct {
AbstractMonitor `mapstructure:",squash"`
// same as output from net.JoinHostPort
// defaults to parsed config from /etc/resolv.conf when empty
DNSServer string
// Will be converted to FQDN
Domain string
Type string
// expected answers (regex)
Expect []string
}