NAME
    Sensu::API::Client - API client for the Sensu monitoring framework

SYNOPSIS
        use Try::Tiny;
        use Sensu::API::Client;

        my $api = Sensu::API::Client->new(url => 'http://user:pass@host:port');

        # Retrieve current events
        my $events = $api->events;
        foreach my $e (@$events) {
            printf("%s, %s, %d\n", $e->{client}, $e->{check}, $e->{status});

            # Resolve them
            $api->resolve($e->{client}, $e->{check});
        }

        # Retrieve envents for a single client
        my $client_events = $api->events('my-client');

        # Get a list of clients
        my $clients = $api->clients;
        foreach my $c (@$clients) {
            printf("%s, %s\n", $c->{name}, $c->{address});
        }

        # Get a single client
        my $client;
        try {
            # Some methods throw an exception if the object is not found
            $client = $api->client('my-client');
        } catch {
            if ($_ =~ /404/) {
                warn 'my-client not found';
            } else {
                warn "Something bad happened: $_";
            }
        };

        # Get check result history for a client
        my $hist = $api->client_history('my-client');

        # Delete it
        try {
            $api->delete_client('my-client');
        } catch {
            if ($_ =~ /404/) {
                warn 'my-client not found';
            } else {
                warn "Something bad happened: $_";
            }
        };

DESCRIPTION
    Set of modules to access the REST API provided by the Sensu monitoring
    framework. Currently supports the version 0.12 of the Sensu API.

    All methods throw exceptions in case of errors. Not passing a required
    parameter is considered to be an error.

METHODS
  new
    Returns an instance of Sensu::API::Client.

   Required Arguments
    url It is the URL where the API resides. It accepts user and password
        for basic authentication. Example:
        http://admin:secret@localhost:4567

  events($client)
    Returns an arrayref containing events. Each event is a hashref with the
    following keys: client, check, occurrences, output, status and flapping.

    The client name is an optional arbument to filter the result by Sensu
    client.

  event($client, $check)
    Returns a single event.

    Both arguments are required.

    Throws an exception "404" if the event does not exist.

  resolve($client, $check)
    Resolves an event identified by client and check.

    Both arguments are required.

    Throws an exception "404" if the event does not exist.

  info
    Returns a hashref containing info about the API service.

    Docs about the returned data: <http://sensuapp.org/docs/0.12/api-info>

  stashes
    Returns an arrayref containing all the stashes. Each stash is a hash
    containing the following keys: path (string), content (hashref), expire
    (integer).

  stash($path)
    Returns a single stash as a hashref.

    Throws an exception "404" if the stash does not exist.

  create_stash(%args)
    Creates a stash.

   Arguments
    path
        Required. String. The path identifying this stash.

    content
        Required. Hashref. Set of key values stored in the stash.

    expire
        Optional. Integer. Time in seconds before the stash expires and is
        deleted.

  delete_stash($path)
    Deletes a stash.

    Argument required.

  health(%args)
    Returns a boolean. Checks the health of the API to see if it can connect
    to Redis and RabbitMQ.

    Takes parameters for minimum consumers and maximum messages and checks
    RabbitMQ.

   Arguments
    consumers
        Required. Integer. Minimum number of consumers to consider the
        service healthy.

    messages
        Required. Integer. Maximum number of messages in queue to consider
        the service healthy.

  client($name)
    Returns a single client as a hashref. Each one contains the following
    keys: name (string), address (string), subscriptions (arrayref),
    timestamp (integer).

    Name is required.

    Throws an exception "404" if the client is not found.

  clients
    Returns an arrayref with a list of clients.

  delete_client($name)
    Deletes a client, resolving all its events. It returns inmediately, but
    the actual deletion is delayed.

    Name is required.

    Throws an exception "404" if the client is not found.

  client_history($name)
    Returns an arrayref with the historic results for each check of a
    client. Each element in the list contains the following keys: check
    (string), last_status (integer), last_execution (integer), history
    (arrayref with status codes).

    Name is required.

  check($name)
    Returns a check as a hashref containing: name (string), command
    (string), subscribers (arrayref), interval (integer).

    Name is required

    Throws an exception "404" if the check does not exist.

  checks
    Returns the list of checks.

  request($name, @subscribers)
    Issues a check request.

    The name of the check, and an arrayref of subscribers are required.

SEE ALSO
    *   <http://sensuapp.org/docs/0.12/api>

AUTHOR
    *   Miquel Ruiz <mruiz@cpan.org>

COPYRIGHT AND LICENSE
    This software is copyright (c) 2014 by Miquel Ruiz.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.