webwatch

package module
v0.0.0-...-99e4dfe Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: Unlicense Imports: 9 Imported by: 1

README

Webwatch

THIS PROJECT IS ARCHIVED

Monibot is a much better alternative: https://monibot.io




GoDoc Build Status Go Report Card

Webwatch checks HTTP/HTTPS URLs and sends mail if there's a problem.

You run webwatch on your server(s) and let it watch local or remote URLs. When the state of one or more URLS change (from 'reachable' to 'not reachable' or vice versa), webwatch will send an email. You can rate-limit emails to avoid being flooded.

If you run two or more servers, install webwatch on each of them and let them check each other.

Build

Webwatch is written in Go (we need 1.9.0 or higher).

user@wombat ~ # mkdir ~/webwatch
user@wombat ~ # export GOPATH=~/webwatch
user@wombat ~ # cd $GOPATH
user@wombat webwatch # go get -u github.com/cvilsmeier/webwatch/cmd/webwatch
user@wombat webwatch # cd bin
user@wombat bin # chmod 700 webwatch
user@wombat bin # ./webwatch -help

Usage

user@wombat webwatch # bin/webwatch -help
Usage of webwatch:
  -config string
        the name of the config file (default "config.json")
  -v    verbose output (default off)
user@wombat ~ # webwatch -config home/cv/webwatch/config.json -v

Configuration

Webwatch loads its configuration from a json file with the following structure:

{
    "urls": [
        "https://www.google.com",
        "https://www.twitter.com"
    ],
    "checks": "5m",
    "reports": "12h",
    "limit": "1h",
    "mail" : {
        "subject" : "[Webwatch] MY_SERVER",
        "from" : "mail@example.com",
        "to" : "myself@example.com",
        "host" : "smtp.example.com",
        "username" : "example_username_00012",
        "password" : "example_password_00012"
    }
}
  • urls The URLs you want to watch. Configure any number of URLs here.

  • checks The check interval for your URLs. Valid suffixes are 'h' for hours, 'm' for minutes and 's' for seconds. Default is '5m'.

  • reports The interval webwatch should send report mails. This setting applies only if the states the URLs did not change since the last mail. If the state of one URL changes, webwatch will send mail immediately and not wait for the 'reports' interval. Default is '12h'.

  • limit Rate-limit for mails. webwatch will sent at most one mail per 'limit' period, no matter what. Default is '1h'.

  • mail Mail configuration.

    • subject The mail subject. webwatch will append "restarted" or "OK" or "ERR" to that subject, depending on the state of your URLs.

    • from The from address.

    • to The to address.

    • host The host name of the smtp server webwatch sends mail to. webwatch will try to talk smtp over port 25.

    • username The username for authenticating against the smtp server.

    • password The password for that username.

Author

C. Vilsmeier

License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Documentation

Overview

Package webwatch provides the Webwatch tool.

Webwatch checks HTTP/HTTPS URLs and sends mail if there's a problem.

See https://github.com/cvilsmeier/webwatch for more info..

Index

Constants

This section is empty.

Variables

View Source
var (
	// INFO logger, writes to stdout.
	INFO = log.New(os.Stdout, "INFO ", log.LstdFlags)

	// DEBUG logger, writes to stdout. Default disabled.
	DEBUG = log.New(ioutil.Discard, "DEBG ", log.LstdFlags)
)

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	Ok   bool
	Text string
}

A CheckResult contains the result of checking a number of URLs for their reachability.

func (CheckResult) IsDifferent

func (cr CheckResult) IsDifferent(other CheckResult) bool

IsDifferent returns true if cr differs from other.

type Checker

type Checker interface {

	// Check checks URLs and returns a CheckResult.
	Check() CheckResult
}

A Checker checks URLs and returns a CheckResult.

func NewChecker

func NewChecker(urls []string) Checker

NewChecker creates a new Checker that checks a list of URLs.

type Config

type Config struct {
	Urls    []string   `json:"urls"`
	Checks  Interval   `json:"checks"`
	Reports Interval   `json:"reports"`
	Limit   Interval   `json:"limit"`
	Mail    MailConfig `json:"mail"`
}

Config holds the configuration data found in the config.json file.

func LoadConfig

func LoadConfig(filename string) (Config, error)

LoadConfig loads the JSON configuration file and converts it to a Config structure. LoadConfig returns an error if the fil cannot be loaded or parsed.

type Interval

type Interval time.Duration

Interval is a time.Duration that can be marshalled to and unmarshalled from JSON.

func (Interval) MarshalJSON

func (iv Interval) MarshalJSON() ([]byte, error)

MarshalJSON converts a JSON value to an Interval.

func (Interval) String

func (iv Interval) String() string

String() returns a string representation of this Interval, see https://golang.org/pkg/time/#Duration.String for more info.

func (*Interval) UnmarshalJSON

func (iv *Interval) UnmarshalJSON(b []byte) error

UnmarshalJSON converts an Interval to JSON.

type Loop

type Loop struct {
	// contains filtered or unexported fields
}

Loop is the main loop.

func NewLoop

func NewLoop(sleeper Sleeper, checker Checker, mailer Mailer, checks, reports, limit time.Duration) *Loop

NewLoop creates a new Loop.

func (*Loop) Tick

func (l *Loop) Tick(now time.Time)

Tick executes the main loop. It invokes the checker and (maybe) sends a mail and then sleeps for a certain time.

type MailConfig

type MailConfig struct {
	Subject  string `json:"subject"`
	From     string `json:"from"`
	To       string `json:"to"`
	Host     string `json:"host"`
	Username string `json:"username"`
	Password string `json:"password"`
}

MailConfig holds the mail configuration found in the config.json file.

type Mailer

type Mailer interface {

	// SendRestarted sends a 'restarted' mail.
	SendRestarted(now time.Time)

	// SendReport sends a 'OK' or 'ERR' mail.
	SendReport(now time.Time, ok bool, text string)
}

A Mailer sends emails.

func NewMailer

func NewMailer(config MailConfig) Mailer

NewMailer creates Mailer with a configuration.

type Sleeper

type Sleeper interface {

	// Sleep sleeps the specified duration.
	Sleep(duration time.Duration)
}

A Sleeper sleeps.

func NewSleeper

func NewSleeper() Sleeper

NewSleeper creates a new Sleeper.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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