happydemon/statuscake

Interface for StatusCake API

0.2.1 2019-12-09 10:11 UTC

This package is auto-updated.

Last update: 2024-04-09 19:27:03 UTC


README

#StatusCake API wrapper

StatusCake is a monitoring service that monitors website/servers over HTTP/TCP/PING.

This project wraps most endpoints StatusCake has to offer.

Install

Via Composer

composer require happydemon/statuscake

Usage

Setting up the client:

$statusCake = new StatusCake\Client(`USER', 'TOKEN');

Checking if the credentials are valid:

$statusCake->validAccount(); // return true or false

Getting basic account info:

$statusCake->account();

Tests

These are actually your monitors, each test would represent a website you're monitoring.

Each returned test will be parsed into a class StatusCake\Test, all the properties are documented in there, be sure to check it out.

Creating a test

To create a test you need to initialise StatusCake\Test. There are just a few properties that are actually required; websiteName, websiteURL, testType.

$test = new StatusCake\Test();

// Required parameters
$test->websiteName = 'HappyDemon';
$test->websiteURL = 'http://happydemon.xyz';
$test->testType = StatusCake\Test::TYPE_HTTP;

// I'm a little impatient, so I'd like more frequest checks (every 2 minutes)
$test->checkRate = 120;

// Save everything
$statusCake->updateTest($test);

Updating a test

Updating is done in the same way:

// I've changed my mind, let's check every 5 minutes
$test->checkRate = 300;

// Save the change
$statusCake->updateTest($test);

Deleting a test

$statusCake->deleteTest($test);

Retrieving tests

Retrieving a list of existing tests is simple:

$tests = $statusCake->getTests();

Retrieving a test's period

A period of data is two time stamps in which status has remained the same.

$periods = $test->getPeriods();

Retrieving a test's performance data

Retrieves a list of checks performed for the current site (this statusCake users with a premium account).

$periods = $test->getPerformance();

Retrieve a test's previously sent alerts

Retrieves a list of alerts that have, previously, been sent.

$periods = $test->getAlerts();

Contact Groups

One of the properties tests could need assigned is contact groups. You can retrieve and manage them through the API as wel.

The same principles as Tests are applied here, meaning every contact group will be loaded in a StatusCake\ContactGroup class (check the class definition for more info on the properties).

A few helper functions are included to work with email addresses.

Creating a contact group

$contactGroup = new StatusCake\ContactGroup();

// The only required parameter
$contactGroup->groupName = 'personal mail';

// let's add an email to get notifications
$contactGroup->addEmail('maxim.kerstens@gmail.com');

// Save everything
$statusCake->updateContactGroup($contactGroup);

Updating a contact group

// I've changed my mind, different email
$contactGroup->removeEmail('maxim.kerstens@gmail.com');
$contactGroup->addEmail('maxim@happydemon.xyz');

// Which is the same as doing
$contactGroup->email = ['maxim@happydemon.xyz']

// Save everything
$statusCake->updateContactGroup($contactGroup);

Deleting a contact group

$statusCake->deleteContactGroup($contactGroup);