Monitoring::Icinga2::Client::REST3pm
Rest integration with icinga2
Usage
use strict;use warnings;use Monitoring::Icinga2::Client::REST;my $icinga = new Monitoring::Icinga2::Client::REST("fqdn",port => $port,path => $path,version => $version,cacert => $cacert_file,);$icinga->login("username","password") or die $icinga->login_status;my $host_object = {attrs => {address => "127.0.0.1",check_command => "hostalive"}};my $put_result = $icinga->do_request("PUT", "/objects/hosts/localhost.example.com", "", $host_object)or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);my $post_result = $icinga->do_request("POST", "/objects/hosts/localhost.example.com", "",$host_object)or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);my $get_result = $icinga->do_request("GET", "/objects/hosts/localhost.example.com")or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);my $delete_result = $icinga->do_request("DELETE", "/objects/hosts/localhost.example.com")or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);$icinga->logout;
Overview
Module used to integrate with the REST API that Icinga2 provides.
Constructor
- new (FQDN, PORT, PATH, VERSION, INSECURE)
- new (FQDN, PORT, PATH, VERSION, [ INSECURE ])
-
Monitoring::Icinga2::Client::REST object.
The former calling convention with four mandatory arguments is the old one. If a port number is present after the Icinga host, the constructor assumes you want this form. The arguments are:
- •
-
FQDN is your Icinga monitoring host.
- •
-
PORT is the port the REST API runs on.
- •
-
PATH is the URI where to find the API, usually "/".
- •
-
VERSION should be set to the API version, usually 1.
- •
-
INSECURE is optional and makes this module skip certificate verification if set.
The latter form treats only the FQDN as mandatory and allows all other arguments to be passed hash style with the following keys:
- •
-
"port"see above; defaults to5665.
- •
-
"path"see above; defaults to"/".
- •
-
"version"see above; defaults to 1 and is therefore completely redundant as long as there is only one API version.
- •
-
"insecure"see above; defaults to false
- •
-
"cacert"The file name of a PEM-format file containing the certificate of the CA that issued the server's HTTPS certificate. As internal monitoring servers often use certs from in-house CAs, this still allows for secure peer identification instead of using insecure mode.
Methods
- login (USERNAME, PASSWORD)
-
Configures and validates credentials. Please note that user needs at least the permission "status/query". This methos does nothing if it has been called on the sameobject before unless "logout" was called before.
- logout
-
Destroys the login session.
- login_status
-
Returns a human readable login status of the current session.
- logged_in
-
Returns true when logged in, otherwise returns undef.
- do_request (HTTP METHOD, URI, PARAMS, DATA)
-
Performs the actual request.
"PARAMS" is optional and can be any parameters that the Icinga API supports.
"DATA" is optional and is a Perl data structure that will be converted to JSON.
Returns the result in a perl reference.
- export (FULL, API_ONLY)
-
Returns a Perl Data structure without unnecessary meta data.
$icinga->export can only be called after do_request. The name of the object is stored in$object->{attrs}{vars}{__export_name} so that you can access if you need it, please note that you can't use this variable name for other things if you whis to use this library as it will be overwritten in the exported object."FULL" is optional and if it is true, write once attributes will be included in the export. Objects exported with FULL set to true can be converted to json and be used for PUT requests, but not necessarily for POST requests.
"API_ONLY" is optional and if it is true only objects created via the API will be exported.
- request_code
-
Returns the last HTTP status code.
- request_status_line
-
Returns the last HTTP status line.
Depends
LWP::UserAgent, HTTP::Request, URI::Escape, JSON, Encode
Releases
4 releases since Debian 10 (Buster); the text changed 1 time.