The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FusionInventory::Agent::HTTP::Server::Plugin - A class template for embedded HTTP server plugins

DESCRIPTION

This is a template class to base on FusionInventory::Agent::HTTP::Server plugins.

Plugins purpose is to handle specific requests.

CLASS METHODS

new(%params)

The constructor. The following parameters are allowed, as keys of the %params hash:

server

the associated server

INSTANCE METHODS

$plugin->urlMatch($path)

Returns true if the passed path match the plugin expected URL pattern.

$plugin->handle($client, $request, $clientIp)

Handles the matching incoming request.

$plugin->priority()

Returns plugin priority against any other plugin (default = 10).

Greater priority makes the plugin be used befores lower priority plugins.

$plugin->log_prefix()

Should return a log prefix to be used in logging for a plugin.

$plugin->config_file()

Can return config filename to be loaded from the config dir, none by default.

Config file can contain any key/value pair like the normal agent configuration file. Even include directive could be used. No validation is done during the configuration load. The plugin should carefully check loaded values when used.

$plugin->init()

Initializes a plugin, by default, this loads a configuration file if defined and found.

$plugin->config($name)

Returns the loaded configuration value for the given value name.

$plugin->error($message)

Log error level message using log_prefix

$plugin->info($message)

Log information level message using log_prefix

$plugin->debug($message)

Log debug level message using log_prefix

$plugin->debug2($message)

Log debug2 level message using log_prefix

$plugin->name()

Returns the plugin name

$plugin->defaults()

Returns a hash ref with default value to be used for not set parameters

$plugin->port()

Returns the configurated port or 0 to use the default

$plugin->disable()

Disable the plugin

$plugin->disabled()

Returns true is a plugin is disabled

$plugin->rate_limited()

Returns true if a request reach the rate limitation.

The plugin must support the "maxrate" parameter setting it with a default in defaults() API. You can also set "maxrate_period" in defaults, but it could be not set and then 3600 seconds will be used by default. If "maxrate" request count is reach during the "maxrate_period" period in seconds, the API returns true.

The API keeps the time access by request by IP and will only keep the access of requests in the "maxrate_period" last seconds. It is not advised to set a high "maxrate".

Call this API from your handle() API as soon as possible to avoid any abuse.

$plugin->supported_method($method)

Returns true if $method is supported by this plugin. By default, only 'GET' is supported.

$plugin->keepalive()

Returns true if the current connection should be kept alive.