active-surveillance
Configurable website monitoring.
Last updated 2 years ago by andrew-hagedorn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install active-surveillance 
SYNC missed versions from official npm registry.

Active Surveillance: Schedule based website monitoring.

Build Status

Continously monitor a set of URLs to ensure a website or API is functioning properly by repeatably getting the content and validating that it is correct.

Configs

The configuration for the surveillance is simple:

  • toWatch: The only required configuration, this is the an array of objects that represent URL configurations that should be watched.
  • onFailure: An optional configuration, this is a function that will be run every time a URL under surveillance fails to return a 200 or fails a user defined validation check. By default this will print to console.
  • onSuccess: An optional configuration, this is a function that will be run every time a URL under surveillance successfully returns a 200 and passes any provided validation check. By default this will print to console.

URL Configs

Each URL configuration provided in toWatch can pass the following properties:

  • url: A required property that is a fully qualified URL (e.g. https://www.mulletify.com).
  • rateInSeconds: How often the url should be put under surveillance.
  • name: An optional property that describes the URL. This is used to report statistics, so any configurations with duplicate names will coalesce their results. By default this is the url.
  • fetchParameters: An optional property that can be set to an object containing any additional parameters that should be provided to fetch
  • validatePage: An optional property that can be set to a function that accepts the page source and performs any validation of that page.
  • validateJson: An optional property that can be set to a function that accepts the json returned and performs any validation on that result. If both validatePage and validateJson are provided than only validatePage will be run.

Example Usage

import createActiveSurveillance from 'active-surveillance';

const surveillance = createActiveSurveillance({
    toWatch: [{
        name: 'Webpage',
        url: 'https://www.mulletify.com',
        validatePage: pageSource => {
            //validate the page text with your favorite assertion library
        },
        rateInSeconds: 1,
    }, {
        name: 'API endpoint',
        url: 'https://www.mulletify.com/v1/mullets/123',
        validateJson: json => {
            // validate a pre-parsed json blob with your favorite assertion library
        },
        rateInSeconds: 1000,
    }, {
        name: 'POST endpoint',
        url: 'https://www.mulletify.com/v1/mullets/',
        fetchParameters: {
            method: 'POST',
            body: { /* your post */ }
        }
        validateJson: json => {
            // validate a pre-parsed json blob with your favorite assertion library
        },
        rateInSeconds: 1000,
    }],
    onFailure: f => { console.log(f); },
    onSuccess: s => { console.log(s); },
});

// begin monitoring watched urls
surveillance.start();

// get metrics about each url under test
console.log(surveillance.status());

// stop watching urls
surveillance.stop();

Current Tags

  • 1.1.2                                ...           latest (2 years ago)

7 Versions

  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 14
Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |