.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Monitoring::Icinga2::Client::REST 3pm" .TH Monitoring::Icinga2::Client::REST 3pm "2018-05-18" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Monitoring::Icinga2::Client::REST \- REST integration with icinga2 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Module used to integrate with the \s-1REST API\s0 that Icinga2 provides. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .IP "new (\s-1FQDN, PORT, PATH, VERSION, INSECURE\s0)" 4 .IX Item "new (FQDN, PORT, PATH, VERSION, INSECURE)" .PD 0 .IP "new (\s-1FQDN, PORT, PATH, VERSION,\s0 [ \s-1INSECURE\s0 ])" 4 .IX Item "new (FQDN, PORT, PATH, VERSION, [ INSECURE ])" .PD Monitoring::Icinga2::Client::REST object. .Sp 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: .RS 4 .IP "\(bu" 4 \&\s-1FQDN\s0 is your Icinga monitoring host. .IP "\(bu" 4 \&\s-1PORT\s0 is the port the \s-1REST API\s0 runs on. .IP "\(bu" 4 \&\s-1PATH\s0 is the \s-1URI\s0 where to find the \s-1API,\s0 usually \*(L"/\*(R". .IP "\(bu" 4 \&\s-1VERSION\s0 should be set to the \s-1API\s0 version, usually 1. .IP "\(bu" 4 \&\s-1INSECURE\s0 is optional and makes this module skip certificate verification if set. .RE .RS 4 .Sp The latter form treats only the \s-1FQDN\s0 as mandatory and allows all other arguments to be passed hash style with the following keys: .IP "\(bu" 4 \&\f(CW\*(C`port\*(C'\fR see above; defaults to \f(CW5665\fR. .IP "\(bu" 4 \&\f(CW\*(C`path\*(C'\fR see above; defaults to \f(CW\*(C`/\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`version\*(C'\fR see above; defaults to 1 and is therefore completely redundant as long as there is only one \s-1API\s0 version. .IP "\(bu" 4 \&\f(CW\*(C`insecure\*(C'\fR see above; defaults to false .IP "\(bu" 4 \&\f(CW\*(C`cacert\*(C'\fR The file name of a PEM-format file containing the certificate of the \s-1CA\s0 that issued the server's \s-1HTTPS\s0 certificate. As internal monitoring servers often use certs from in-house CAs, this still allows for secure peer identification instead of using insecure mode. .RE .RS 4 .RE .SH "METHODS" .IX Header "METHODS" .IP "login (\s-1USERNAME, PASSWORD\s0)" 4 .IX Item "login (USERNAME, PASSWORD)" Configures and validates credentials. Please note that user needs at least the permission \&\*(L"status/query\*(R". This methos does nothing if it has been called on the sameobject before unless \*(L"logout\*(R" was called before. .IP "logout" 4 .IX Item "logout" Destroys the login session. .IP "login_status" 4 .IX Item "login_status" Returns a human readable login status of the current session. .IP "logged_in" 4 .IX Item "logged_in" Returns true when logged in, otherwise returns undef. .IP "do_request (\s-1HTTP METHOD, URI, PARAMS, DATA\s0)" 4 .IX Item "do_request (HTTP METHOD, URI, PARAMS, DATA)" Performs the actual request. .Sp \&\*(L"\s-1PARAMS\*(R"\s0 is optional and can be any parameters that the Icinga \s-1API\s0 supports. .Sp \&\*(L"\s-1DATA\*(R"\s0 is optional and is a Perl data structure that will be converted to \s-1JSON.\s0 .Sp Returns the result in a perl reference. .IP "export (\s-1FULL, API_ONLY\s0)" 4 .IX Item "export (FULL, API_ONLY)" Returns a Perl Data structure without unnecessary meta data. \f(CW$icinga\fR\->export can only be called after do_request. The name of the object is stored in \&\f(CW$object\fR\->{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. .Sp \&\*(L"\s-1FULL\*(R"\s0 is optional and if it is true, write once attributes will be included in the export. Objects exported with \s-1FULL\s0 set to true can be converted to json and be used for \s-1PUT\s0 requests, but not necessarily for \s-1POST\s0 requests. .Sp \&\*(L"\s-1API_ONLY\*(R"\s0 is optional and if it is true only objects created via the \s-1API\s0 will be exported. .IP "request_code" 4 .IX Item "request_code" Returns the last \s-1HTTP\s0 status code. .IP "request_status_line" 4 .IX Item "request_status_line" Returns the last \s-1HTTP\s0 status line. .SH "DEPENDS" .IX Header "DEPENDS" LWP::UserAgent, HTTP::Request, URI::Escape, \&\s-1JSON\s0, Encode .SH "LICENSE" .IX Header "LICENSE" Copyright (c) 2016\-, \s-1IT\s0 Services, Stockholm University .PP All rights reserved. .PP Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: .PP Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. .PP Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. .PP Neither the name of Stockholm University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. .PP \&\s-1THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \*(L"AS IS\*(R" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\s0 (\s-1INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES\s0; \s-1LOSS OF USE, DATA, OR PROFITS\s0; \s-1OR BUSINESS INTERRUPTION\s0) \s-1HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\s0 (\s-1INCLUDING NEGLIGENCE OR OTHERWISE\s0) \s-1ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\s0 .SH "AUTHOR" .IX Header "AUTHOR" Johan Carlquist , Mikael Nordin Bits and pieces by Matthias Bethke