Code Monkey home page Code Monkey logo

status-checker's Introduction

Status checker

Description

A library that tells you if any external service your app relies on is broken.

Extremely useful for:

  • Creating a command that will show whether the app is ok after deployment
  • Creating a status page for your system admins or monitoring software

Requirements

  • PHP >=7.4 || >=8.0

Usage

CLI

  1. Install the library
composer require nordsec/status-checker
  1. Declare an instance for StatusCheckerService (preferably using a container), pass various status checkers that make sense for your project
$container[StatusCheckerService::class] = function (Container $container) {
    $configuration = $container['config'];

    return new StatusCheckerService([
        new DatabaseChecker('database.default_connection', $configuration['database']['default']),
        new RabbitMqChecker('rabbitmq.amqp_server', $configuration['queue']['connection_nordvpn_core']),
    ]);
};
  1. If needed, register the command with your application
$container[StatusCheckCommand::class] = function (Container $container) {
    return new StatusCheckCommand([
        $container[StatusCheckerService::class],
    ]);
};

$container[ConsoleApplication::class] = $container->extend(
    ConsoleApplication::class,
    function (ConsoleApplication $consoleApplication, Container $container) {
        $consoleApplication->add($container[StatusCheckCommand::class]);

        return $consoleApplication;
    }
);
  1. Run the command
bin/console status:check

WEB

  1. Install the library
composer require nordsec/status-checker
  1. Declare an instance for StatusCheckerService (preferably using a container), pass various status checkers that make sense for your project
$container[StatusCheckerService::class] = function (Container $container) {
    $configuration = $container['config'];

    return new StatusCheckerService([
        new DatabaseChecker('database.default_connection', $configuration['database']['default']),
        new RabbitMqChecker('rabbitmq.nordvpn_core', $configuration['queue']['connection_nordvpn_core']),
    ]);
};
  1. Create an instance of your controller (preferably using a container)
class StatusControllerProvider implements ServiceProviderInterface
{
    public function register(Container $container)
    {
        $container[StatusController::class] = function (Container $container) {
            $configuration = $container['config'];
            return new StatusController(
                $container[StatusCheckerService::class],
            );
        };
    }
}
  1. Add needed routes
$app->get('/status', StatusController::class . ':index');
$app->get('/status/details', StatusController::class . ':details');
  1. Access the above routes via your browser
  • /status produces the overall (global) status
    • if all services produce an OK status it will output {"status":"OK"}
    • if any service fails it will output {"status":"FAIL"}
    • if any service is in maintenance it will output {"status":"MAINTENANCE"}
  • /status/details produces more detailed output about the status of every individual service
{"database.default":"OK","database.other":"OK"}
{"database.default":"OK","database.other":"FAIL"}

status-checker's People

Contributors

andriuspetrauskis avatar developer-ns avatar dima-nordsec avatar gedasli avatar asilgalis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.