bpmconcept/ping-this

v2.0 2020-05-03 10:59 UTC

This package is auto-updated.

Last update: 2025-01-13 23:37:20 UTC


README

Build Status

PingThis is a lightweight PHP 7.2+ tool to build simple but functional headless monitoring systems.

Example

use PingThis\Daemon;
use PingThis\Alarm\PhpEmailAlarm;
use PingThis\Ping\NetworkPing;
use PingThis\Ping\WebScraperPing;
use PingThis\Ping\DatabasePing;
use PingThis\Ping\TlsCertificateExpirationPing;

$daemon = new Daemon();

// Check if the host correctly answers to ping every 10 seconds
$daemon->registerPing(new NetworkPing(10, 'domain.com'));

// Check if a webserver responds correctly to a HTTP request every 30 seconds
$daemon->registerPing(new WebScraperPing(30, 'GET', 'http://domain.com', 'response.getStatusCode() == 200'));
$daemon->registerPing(new WebScraperPing(30, 'GET', 'http://domain.com', 'content.filter(".css").count()'));

// Or equivalently using any PHP callable
$daemon->registerPing(new WebScraperPing(30, 'GET', 'http://domain.com', function ($response, $content) {
    return $response->getStatus() < 400 && $content->filter('.element')->text() === "Hello";
}));

// Check every day that a certificate won't expire during the next week
$daemon->registerPing(new TlsCertificateExpirationPing(86400, 'domain.com', 443, TlsCertificateExpirationPing::IMPLICIT_TLS, '+7 days'));

// Check if a remote SQL server is still up every 10 seconds
$daemon->registerPing(new DatabasePing(10, 'mysql:host=my.sql.server', 'login', 'password'));

// Otherwise send an email to alert an admin
$daemon->registerAlarm(new PhpEmailAlarm('your@email.com'));

$daemon->run();

Quick description

PingThis aims to provide a simple and effective way for monitoring whatever you want. Configure a daemon with one Alarm and one or multiple Pings. The Daemon periodically verifies each Ping and, in case of failing, triggers the Alarm. Any class could act like an Alarm or a Ping, provided that it implements respectively the AlarmInterface or the PingInterface.

The different built-in Pings rely on Symfony's Expression Language Component to allow a quick and easy construction of triggering logic but can be equivalently replaced by a PHP callable.

Built-in Pings

Network

Web

Mails

Other services

Built-in Alarms

Installation

The recommended way to install PingThis is through Composer :

composer require bpmconcept/ping-this

PingThis does not intend to provide a fully functional daemon out of the box. You are still responsible for writing a configured daemon like in the previous example. Thereafter, a real daemon can be registered to your favorite init system like systemd, upstart or supervisor.