Skip to content

kappataumu/async-website-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Website Monitor

A minimal yet functional website uptime and monitoring tool written in Python, using asyncio and aiohttp for maximum speed. When one of your URLs errors out, an e-mail alert will be delivered to your inbox by MailGun.

Installation

$ git clone https://github.com/kappataumu/async-website-monitor
$ pip install -r async-website-monitor/requirements.txt

Features

  • Supports any HTTP verb (POST, GET, PUT, PATCH, DELETE)
  • Can check for custom HTTP status codes
  • Finds text in the parsed HTML
  • Finds any string in the raw response text (useful for finding stuff in HTML source code or JSON responses)
  • E-mail notifications when checks fail
  • Configurable e-mail reports even when no errors are found

Requirements

  • Python 3.5.1 or newer
  • Beautiful Soup 4
  • MailGun credentials (optional)

Configuration

A number of settings are available. If you want to use the e-mail reporting functionality set "USE_MAILGUN": true and configure all the relevant MailGun bits. All the available options are as follows:

Setting Description
MAILGUN_TO E-mail address: Where e-mail reports will be sent.
MAILGUN_FROM E-mail address: From where the e-mails will appear to originate.
MAILGUN_API_KEY Your MailGun API key.
MAILGUN_DOMAIN Your MailGun custom domain.
HEARTBEAT_EVERY Send a report every this amount of seconds, even if no checks failed.
USE_MAILGUN Either true or false. Set to enable e-mail sending. All the other settings should be set as well.

These are expected to be found in ./config.json, but you can specify a custom file on the command line as well:

$ asymo.py --config=/path/to/my/file/config.json

The default config.json is shown below:

{
    "MAILGUN_TO" : "",
    "MAILGUN_FROM" : "",
    "MAILGUN_API_KEY" : "",
    "MAILGUN_CUSTOM_DOMAIN" : "",
    "HEARTBEAT_EVERY" : 86400,
    "USE_MAILGUN": false
}

Environment variables are supported as well, and take precedence if found:

export MAILGUN_TO="[email protected]",
export MAILGUN_FROM="[email protected]",
export MAILGUN_API_KEY="key-ppxxffffd1dceddddda4daaaaaaaaaaa",
export MAILGUN_CUSTOM_DOMAIN="ops.example.com"
export HEARTBEAT_EVERY="86400"
export USE_MAILGUN=""

Setting up checks

The URLs you want to monitor along with any explicit checks should be placed in ./watchlist.json, but you can specify a custom file on the command line as well:

$ asymo.py --watchlist=/path/to/my/file/watchlist.json

In order to keep configuration verbosity to a minimum, if you are happy with a GET request being issued and a 200 status code check, you only need to provide the URL to be checked, like so:

{
    "http://kappataumu.com": {},
    "https://github.com/kappataumu?tab=activity": {}
}

A number of optional checks can be specified, for more advanced monitoring. You can mix and match these as you see fit:

Parameter Description
"method" The HTTP method to use (one of POST, GET, PUT, PATCH, DELETE)
"status" The expected status code
"text_in_html" Parses the HTML and then searches for the given string
"text_in_raw" Searches for the given string in the raw response (useful for finding strings in HTML source code or JSON responses)

Here is a hypothetical watchlist.json with a couple of more advanced examples based on the above:

{
    "http://kappataumu.com": {
        "text_in_html": "About me",
        "text_in_raw": "twitter:image"
    },
    "http://google.com": {
        "status": 302
    },
    "https://api.github.com/zen": {
        "status": 200
    },
    "http://swapi.co/api/planets/3/" : {
        "text_in_raw": "Yavin IV"
    }
}

About

A fast Python 3 website monitor using asyncio and aiohttp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages