"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "doc/12-icinga2-api.md" between
icinga2-2.11.5.tar.gz and icinga2-2.12.0.tar.gz

About: Icinga 2 is an enterprise grade monitoring system which keeps watch over networks and any conceivable network resource.

12-icinga2-api.md  (icinga2-2.11.5):12-icinga2-api.md  (icinga2-2.12.0)
skipping to change at line 655 skipping to change at line 655
``` ```
https://localhost:5665/v1/objects/services?all_joins=1 https://localhost:5665/v1/objects/services?all_joins=1
``` ```
> **Note** > **Note**
> >
> For performance reasons you should only request attributes which your applicat ion > For performance reasons you should only request attributes which your applicat ion
> requires. > requires.
The following joins are available: Please note that the object type refers to the URL endpoint with `/v1/objects/<o
bject type>`
where the following joins are available:
Object Type | Object Relations (`joins` prefix name) Object Type | Object Relations (`joins` prefix name)
-------------|------------------------------------------ -------------|------------------------------------------
Service | host, check\_command, check\_period, event\_command, command\_e ndpoint Service | host, check\_command, check\_period, event\_command, command\_e ndpoint
Host | check\_command, check\_period, event\_command, command\_endpoin t Host | check\_command, check\_period, event\_command, command\_endpoin t
Notification | host, service, command, period Notification | host, service, command, period
Dependency | child\_host, child\_service, parent\_host, parent\_service, per iod Dependency | child\_host, child\_service, parent\_host, parent\_service, per iod
User | period User | period
Zones | parent Zones | parent
skipping to change at line 1201 skipping to change at line 1202
} }
``` ```
### remove-acknowledgement <a id="icinga2-api-actions-remove-acknowledgement"></ a> ### remove-acknowledgement <a id="icinga2-api-actions-remove-acknowledgement"></ a>
Removes the acknowledgements for services or hosts. Once the acknowledgement has Removes the acknowledgements for services or hosts. Once the acknowledgement has
been removed the next notification will be sent again. been removed the next notification will be sent again.
Send a `POST` request to the URL endpoint `/v1/actions/remove-acknowledgement`. Send a `POST` request to the URL endpoint `/v1/actions/remove-acknowledgement`.
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid ty Parameter | Type | Description
pes for this action are `Host` and `Service`. ----------|--------|--------------
author | String | **Optional.** Name of the removal requestor.
In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters
) must be provided. The valid types for this action are `Host` and `Service`.
The example removes all service acknowledgements: The example removes all service acknowledgements:
``` ```
$ curl -k -s -u root:icinga -H 'Accept: application/json' \ $ curl -k -s -u root:icinga -H 'Accept: application/json' \
-X POST 'https://localhost:5665/v1/actions/remove-acknowledgement' \ -X POST 'https://localhost:5665/v1/actions/remove-acknowledgement' \
-d '{ "type": "Service", "pretty": true }' -d '{ "type": "Service", "pretty": true }'
{ {
"results": [ "results": [
skipping to change at line 1269 skipping to change at line 1274
### remove-comment <a id="icinga2-api-actions-remove-comment"></a> ### remove-comment <a id="icinga2-api-actions-remove-comment"></a>
Remove the comment using its `name` attribute , returns `OK` if the Remove the comment using its `name` attribute , returns `OK` if the
comment did not exist. comment did not exist.
**Note**: This is **not** the legacy ID but the comment name returned by **Note**: This is **not** the legacy ID but the comment name returned by
Icinga 2 when [adding a comment](12-icinga2-api.md#icinga2-api-actions-add-comme nt). Icinga 2 when [adding a comment](12-icinga2-api.md#icinga2-api-actions-add-comme nt).
Send a `POST` request to the URL endpoint `/v1/actions/remove-comment`. Send a `POST` request to the URL endpoint `/v1/actions/remove-comment`.
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid ty Parameter | Type | Description
pes for this action are `Host`, `Service` and `Comment`. ----------|--------|--------------
author | String | **Optional.** Name of the removal requestor.
In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters
) must be provided. The valid types for this action are `Host`, `Service` and `C
omment`.
Example for a simple filter using the `comment` URL parameter: Example for a simple filter using the `comment` URL parameter:
``` ```
$ curl -k -s -u root:icinga -H 'Accept: application/json' \ $ curl -k -s -u root:icinga -H 'Accept: application/json' \
-X POST 'https://localhost:5665/v1/actions/remove-comment' \ -X POST 'https://localhost:5665/v1/actions/remove-comment' \
-d '{ "comment": "icinga2-satellite2.localdomain!ping4!9a4c43f5-9407-a536-18bf- 4a6cc4b73a9f", "pretty": true }' -d '{ "comment": "icinga2-satellite2.localdomain!ping4!9a4c43f5-9407-a536-18bf- 4a6cc4b73a9f", "pretty": true }'
{ {
"results": [ "results": [
{ {
skipping to change at line 1378 skipping to change at line 1387
### remove-downtime <a id="icinga2-api-actions-remove-downtime"></a> ### remove-downtime <a id="icinga2-api-actions-remove-downtime"></a>
Remove the downtime using its `name` attribute , returns `OK` if the Remove the downtime using its `name` attribute , returns `OK` if the
downtime did not exist. downtime did not exist.
**Note**: This is **not** the legacy ID but the downtime name returned by **Note**: This is **not** the legacy ID but the downtime name returned by
Icinga 2 when [scheduling a downtime](12-icinga2-api.md#icinga2-api-actions-sche dule-downtime). Icinga 2 when [scheduling a downtime](12-icinga2-api.md#icinga2-api-actions-sche dule-downtime).
Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime`. Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime`.
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid ty Parameter | Type | Description
pes for this action are `Host`, `Service` and `Downtime`. ----------|--------|--------------
author | String | **Optional.** Name of the removal requestor.
In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters
) must be provided. The valid types for this action are `Host`, `Service` and `D
owntime`.
Example for a simple filter using the `downtime` URL parameter: Example for a simple filter using the `downtime` URL parameter:
``` ```
$ curl -k -s -u root:icinga -H 'Accept: application/json' \ $ curl -k -s -u root:icinga -H 'Accept: application/json' \
-X POST 'https://localhost:5665/v1/actions/remove-downtime' \ -X POST 'https://localhost:5665/v1/actions/remove-downtime' \
-d '{ "downtime": "icinga2-satellite2.localdomain!ping4!abc59032-4589-abcd-4567 -ecf67856c347", "pretty": true }' -d '{ "downtime": "icinga2-satellite2.localdomain!ping4!abc59032-4589-abcd-4567 -ecf67856c347", "pretty": true }'
{ {
"results": [ "results": [
{ {
skipping to change at line 1842 skipping to change at line 1855
to maintain multiple configuration versions for a package. Once a new stage to maintain multiple configuration versions for a package. Once a new stage
is deployed, the content is validated and set as active stage on success. is deployed, the content is validated and set as active stage on success.
On failure, the older stage remains active, and the caller can fetch the `startu p.log` On failure, the older stage remains active, and the caller can fetch the `startu p.log`
from this stage deployment attempt to see what exactly failed. You can see that from this stage deployment attempt to see what exactly failed. You can see that
in the Director's deployment log. in the Director's deployment log.
Send a `POST` request to the URL endpoint `/v1/config/stages` and add the name o f an existing Send a `POST` request to the URL endpoint `/v1/config/stages` and add the name o f an existing
configuration package to the URL path (e.g. `example-cmdb`). configuration package to the URL path (e.g. `example-cmdb`).
The request body must contain the `files` attribute with the value being The request body must contain the `files` attribute with the value being
a dictionary of file targets and their content. You can also specify an optional a dictionary of file targets and their content.
`reload` attribute
that will tell icinga2 to reload after stage config validation. By default this Optional attributes include `reload` (defaults to `true`) and `activate` (defaul
is set to `true`. ts to `true`).
The `reload` attribute will tell icinga2 to reload after stage config validation
.
The `activate` attribute will tell icinga2 to activate the stage if it validates
.
If `activate` is set to `false`, `reload` must also be `false`.
The file path requires one of these two directories inside its path: The file path requires one of these two directories inside its path:
Directory | Description Directory | Description
------------|------------------------------------ ------------|------------------------------------
conf.d | Local configuration directory. conf.d | Local configuration directory.
zones.d | Configuration directory for cluster zones, each zone must be put into its own zone directory underneath. Supports the [cluster config sync](06-d istributed-monitoring.md#distributed-monitoring-top-down-config-sync). zones.d | Configuration directory for cluster zones, each zone must be put into its own zone directory underneath. Supports the [cluster config sync](06-d istributed-monitoring.md#distributed-monitoring-top-down-config-sync).
Example for a local configuration in the `conf.d` directory: Example for a local configuration in the `conf.d` directory:
skipping to change at line 1892 skipping to change at line 1909
``` ```
The Icinga 2 API returns the `package` name this stage was created for, and also The Icinga 2 API returns the `package` name this stage was created for, and also
generates a unique name for the `stage` attribute you'll need for later requests . generates a unique name for the `stage` attribute you'll need for later requests .
Icinga 2 automatically restarts the daemon in order to activate the new config s tage. This Icinga 2 automatically restarts the daemon in order to activate the new config s tage. This
can be disabled by setting `reload` to `false` in the request. can be disabled by setting `reload` to `false` in the request.
If the validation for the new config stage failed, the old stage If the validation for the new config stage failed, the old stage
and its configuration objects will remain active. and its configuration objects will remain active.
Activation may be inhibited even for stages that validate correctly by setting
`activate` to `false`. This may be useful for validating the contents of a stage
without making it active, for example in a CI (continuous integration) system.
> **Note** > **Note**
> >
> Old stages are not purged automatically. You can [remove stages](12-icinga2-ap i.md#icinga2-api-config-management-delete-config-stage) that are no longer in us e. > Old stages are not purged automatically. You can [remove stages](12-icinga2-ap i.md#icinga2-api-config-management-delete-config-stage) that are no longer in us e.
Icinga 2 creates the following files in the configuration package Icinga 2 creates the following files in the configuration package
stage after configuration validation: stage after configuration validation:
File | Description File | Description
------------|-------------- ------------|--------------
status | Contains the [configuration validation](11-cli-commands.md#confi g-validation) exit code (everything else than 0 indicates an error). status | Contains the [configuration validation](11-cli-commands.md#confi g-validation) exit code (everything else than 0 indicates an error).
skipping to change at line 2290 skipping to change at line 2311
Additional [programmatic examples](12-icinga2-api.md#icinga2-api-clients-program matic-examples) Additional [programmatic examples](12-icinga2-api.md#icinga2-api-clients-program matic-examples)
will help you getting started using the Icinga 2 API in your environment. will help you getting started using the Icinga 2 API in your environment.
### Libraries <a id="icinga2-api-clients-libraries"></a> ### Libraries <a id="icinga2-api-clients-libraries"></a>
Name | Language | Description Name | Language | Description
-------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- --------- -------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- ---------
[ruby-icinga2](https://github.com/bodsch/ruby-icinga2) | Ruby | Ruby library [ruby-icinga2](https://github.com/bodsch/ruby-icinga2) | Ruby | Ruby library
[python-icinga2_api](https://github.com/KevinHonka/Icinga2_Python_API) | Python | Python library [python-icinga2_api](https://github.com/KevinHonka/Icinga2_Python_API) | Python | Python library
[python-icinga2-api](https://github.com/fmnisme/python-icinga2api) | Python | Python bindings for Icinga 2 interaction [python-icinga2-api](https://github.com/fmnisme/python-icinga2api) | Python | Python bindings for Icinga 2 interaction
[python-icinga2-api-continued](https://github.com/joni1993/icinga2apic) | Python | Python bindings for Icinga 2 interaction forke d and continued from fmnisme's python binding
[go-icinga2](https://github.com/xert/go-icinga2) | Golang | Golang functions and type definitions [go-icinga2](https://github.com/xert/go-icinga2) | Golang | Golang functions and type definitions
[go-icinga2-api](https://github.com/lrsmith/go-icinga2-api/) | Golang | Golang implementation used inside the Terraform provider [go-icinga2-api](https://github.com/lrsmith/go-icinga2-api/) | Golang | Golang implementation used inside the Terraform provider
[go-icinga2-client](https://github.com/Nexinto/go-icinga2-client) | Golang | Golang implementation for the Rancher integration. [go-icinga2-client](https://github.com/Nexinto/go-icinga2-client) | Golang | Golang implementation for the Rancher integration.
[Monitoring::Icinga2::Client::REST](https://metacpan.org/release/THESEAL/Monitor ing-Icinga2-Client-REST-2.0.0) | Perl | Perl bindings. [Monitoring::Icinga2::Client::REST](https://metacpan.org/release/THESEAL/Monitor ing-Icinga2-Client-REST-2.0.0) | Perl | Perl bindings.
[Icinga 2 API in PHP](https://github.com/uniwue-rz/icinga2-api) | PHP | PHP implementation. For other examples, look into Icinga Web 2 and Director. [Icinga 2 API in PHP](https://github.com/uniwue-rz/icinga2-api) | PHP | PHP implementation. For other examples, look into Icinga Web 2 and Director.
### Status <a id="icinga2-api-clients-status"></a> ### Status <a id="icinga2-api-clients-status"></a>
Name | Language | Description Name | Language | Description
-------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- --------- -------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- ---------
[Dashing](https://github.com/dnsmichi/dashing-icinga2) | Ruby, HTML | Dashboard for Dashing querying the REST API for current host/service/global status [Dashing](https://github.com/dnsmichi/dashing-icinga2) | Ruby, HTML | Dashboard for Dashing querying the REST API for current host/service/global status
[InfluxDB Telegraf Input](https://github.com/influxdata/telegraf/blob/master/plu gins/inputs/icinga2/README.md) | Golang | [Telegraf](https://github.com/i nfluxdata/telegraf) is an agent written in Go for collecting, processing, aggreg ating, and writing metrics. [InfluxDB Telegraf Input](https://github.com/influxdata/telegraf/blob/master/plu gins/inputs/icinga2/README.md) | Golang | [Telegraf](https://github.com/i nfluxdata/telegraf) is an agent written in Go for collecting, processing, aggreg ating, and writing metrics.
[Icinga Slack Bot](https://github.com/bb-Ricardo/icinga-slack-bot) | Python | It can be used to interact with Icinga2 from yo ur Slack client. It uses the Icinga2 API to get Host/Service status details. Sim ple status filters can be used to narrow down the returned status list. [Icinga Slack Bot](https://github.com/bb-Ricardo/icinga-slack-bot) | Python | It can be used to interact with Icinga2 from yo ur Slack client. It uses the Icinga2 API to get Host/Service status details. Sim ple status filters can be used to narrow down the returned status list.
[Icinga 2 Slack Bot](https://github.com/mlabouardy/icinga2-slack-bot) | Golang | Query host/service details from a [Slack](https://slac k.com/) channel [Icinga 2 Slack Bot](https://github.com/mlabouardy/icinga2-slack-bot) | Golang | Query host/service details from a [Slack](https://slac k.com/) channel
[icinga2bot](https://github.com/reikoNeko/icinga2bot) | Python | [Errbot](http://errbot.io/en/latest/user_guide/ setup.html) plugin to fetch status and event stream information and forward to X MPP, IRC, etc. [icinga2bot](https://github.com/reikoNeko/icinga2bot) | Python | [Errbot](http://errbot.io/en/latest/user_guide/ setup.html) plugin to fetch status and event stream information and forward to X MPP, IRC, etc.
[IcingaBusyLightAgent](https://github.com/stdevel/IcingaBusylightAgent) | C# | Notification Agent in Systray [IcingaBusyLightAgent](https://github.com/stdevel/IcingaBusylightAgent) | C# | Notification Agent in Systray
[BitBar for OSX](https://getbitbar.com/plugins/Dev/Icinga2/icinga2.24m.py) | Python | macOS tray app for highlighting the host/servic e status [BitBar for OSX](https://getbitbar.com/plugins/Dev/Icinga2/icinga2.24m.py) | Python | macOS tray app for highlighting the host/servic e status
[Icinga 2 Multistatus](https://chrome.google.com/webstore/detail/icinga-multi-st atus/khabbhcojgkibdeipanmiphceeoiijal/related) | - | Chrome Extension [Icinga 2 Multistatus](https://chrome.google.com/webstore/detail/icinga-multi-st atus/khabbhcojgkibdeipanmiphceeoiijal/related) | - | Chrome Extension
[Naglite4](https://github.com/wftech/icinga2-naglite4) | Python | Naglite3 rewrite using the Icinga 2 REST API. [Naglite4](https://github.com/wftech/icinga2-naglite4) | Python | Naglite3 rewrite using the Icinga 2 REST API.
[icinga-telegram-bot](https://github.com/joni1993/icinga-telegram-bot) | Python | Telegram Bot using the Icinga 2 REST API
### Manage Objects <a id="icinga2-api-clients-management"></a> ### Manage Objects <a id="icinga2-api-clients-management"></a>
Name | Language | Description Name | Language | Description
-------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- --------- -------------------------------------------------------------------------------- ----------------|---------------|----------------------------------------------- ---------
[Icinga Director](https://icinga.com/docs/director/latest) | PHP, JS | Icinga 2 configuration interface with a nice fr ontend, and automated imports for nearly any source. [Icinga Director](https://icinga.com/docs/director/latest) | PHP, JS | Icinga 2 configuration interface with a nice fr ontend, and automated imports for nearly any source.
[Terraform Provider](https://github.com/terraform-providers/terraform-provider-i cinga2) | Golang | Register hosts from Terraform in Icinga 2. [Official docs](https://www.terraform.io/docs/providers/icinga2/index.html). [Terraform Provider](https://github.com/terraform-providers/terraform-provider-i cinga2) | Golang | Register hosts from Terraform in Icinga 2. [Official docs](https://www.terraform.io/docs/providers/icinga2/index.html).
[Kube Icinga](https://github.com/gyselroth/kube-icinga) | Typescript | Monitor Kubernetes services / resources using icinga2 (including autodiscovery support) [Kube Icinga](https://github.com/gyselroth/kube-icinga) | Typescript | Monitor Kubernetes services / resources using icinga2 (including autodiscovery support)
[Logstash output for Icinga](https://www.icinga.com/products/integrations/elasti c/) | Ruby | Forward check results and create objects from log events [Logstash output for Icinga](https://www.icinga.com/products/integrations/elasti c/) | Ruby | Forward check results and create objects from log events
[Foreman Smart Proxy Monitoring](https://github.com/theforeman/smart_proxy_monit oring) | Ruby | Smart Proxy extension for Foreman creating and deleting hosts and services in Icinga 2 [Foreman Smart Proxy Monitoring](https://github.com/theforeman/smart_proxy_monit oring) | Ruby | Smart Proxy extension for Foreman creating and deleting hosts and services in Icinga 2
skipping to change at line 2645 skipping to change at line 2668
Build the binary: Build the binary:
``` ```
go build icinga.go go build icinga.go
./icinga ./icinga
``` ```
#### Example API Client in Powershell <a id="icinga2-api-clients-programmatic-ex amples-powershell"></a> #### Example API Client in Powershell <a id="icinga2-api-clients-programmatic-ex amples-powershell"></a>
Requires Windows 10+ with Powershell 5+. This example compares the given certificate with the certificate from icinga2 fo
r a trusted connection.
More info: https://stackoverflow.com/a/58494718/9397788
Note: The workaround for self signed certificates is not considered Invoke-RestMethod with PUT is buggy with Powershell 3.0. So we need at least Pow
best practice. ershell 4.0.
https://stackoverflow.com/questions/18278977/powershell-v3-invoke-restmethod-hea
ders
``` ```
# Workaround for self signed certificates $icingaApiHost = "icinga.master.local"
# https://stackoverflow.com/questions/36456104/invoke-restmethod-ignore-self-sig $IcingaApiPort = 5665
ned-certs $icingaApiUser = "root"
if (-not("dummy" -as [type])) { $icingaApiPassword = "icinga"
add-type -TypeDefinition @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class Dummy {
public static bool ReturnTrue(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; }
public static RemoteCertificateValidationCallback GetDelegate() { $requestUrl = "https://{0}:{1}/v1/objects/services" -f $icingaApiHost,$IcingaApi
return new RemoteCertificateValidationCallback(Dummy.ReturnTrue); Port
}
} # Put the certificate from your master (/etc/icinga2/pki/*.crt) here.
# You will get it with "openssl s_client -connect <master>:5665" too.
$cert64=@"
-----BEGIN CERTIFICATE-----
MIIE5TCCAs2gAwIBAgIBAjANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAlJY2lu
Z2EgQ0EwHhcNMTYwNzA3MDYxOTM4WhcNMzEwNzA0MDYxOTM4WjAiMSAwHgYDVQQD
DBdpY2luZ2EuZXh0ZXJuMS56bXQuaW5mbzCCAiIwDQYJKoZIhvcNAQEBBQADggIP
ADCCAgoCggIBAJ2/ufxCb1m8PbUCxLkZqZNLxZ/vpulOcKmOGYm6VBWbOXQA50on
IewnMRUDGF9DHajLk1nyUu1TyKxGzBbja+06/kVd/8Muv0MUNF6iC1U3F3h0W9da
kk5rK1L+A534csHCFcG3dZkbdOMrh5hy4kMf9c2FEpviL54Fo4e+b3ZJFA6rv5D9
7LzaxfLcsMwXIZ/WRnxjjfnA+RenHeYLlNM8Uk3vqI6tBc1qpFzFeRWMbclFzSLN
5x+J6cuyFjVi+Vv8c6SU6W3ykw8Vvq1QQUixl9lwxqNJNsWWfGR8ycmFiv1ZYxiu
HpmuLslExZ2qxdGe/raMBEOGgVsUTDZNyTm/9TxgOa3m9cv3R0YIFUmfoBQ3d51S
wburJG2eC0ETpnt0TptwMdTfL+HYVWB71djg2Pb8R3vldnhFVpy9vyx3FyHoN7ZQ
h7+r6HK2jpwWo7/jK9ExpglVoV8vUbNYqXiA/lZGEkT3YLwTyUhqXKei3Xu2CGGR
UId6fAj6OWk9TLW+OaR9BcS74mpiTWNDlbEP+/LQnUhte8scX5cSqBzy4vpuG1G+
NGDbYcG4xn6Pc6qt/QddKU/pB/GbJv9SlHU8SjSt09oG9GtuXVjPoZX5msi3NmMy
DpAcab5Lx4MgOS/GwRLRI3IjZ3ZK+UkLvRgesSH5/JPUIgfTdr/Eg5dVAgMBAAGj
NDAyMAwGA1UdEwEB/wQCMAAwIgYDVR0RBBswGYIXaWNpbmdhLmV4dGVybjEuem10
LmluZm8wDQYJKoZIhvcNAQELBQADggIBAEpEJt35KZuvDzU/xrVaVC3ct6CHmXOh
DDj5PdwkYtO0vw9WE7aVc88Fs6uhW2BxFkLvm7TpJ6g05egtBozHYrhTEir/fPna
rVAD9wEQU6KuSayeToXlgWhKDRAAv1lrQwU4xAAdJP8faxQGc7nAwN/h0g14UTmU
LSkyJU4a+1SkEUOs2YCq9vChS3MowO+6I35e98dIA1swHLeQ/QJowspODQvi6pGX
VH8FaaqfGwhv+gMwDoAW9hB74VZXO8I3mueZUccPiJXlaojx5hpaHRNRvpdBPclA
HHLRQniEOkai2Wg2cft/wq6/fYLE/yv5ej15MNyt3Wjj41DEK5B/bvmN/chOrZlv
8rh3ek12ngVtXF+Jcmfsij8+hj/IOM6SeELtW+c0KRaPoVR7oR9o6ce/dyfiw6Hv
iQsAV6x//kytpRnUY3VAH4QTJzQ5bgz1Cwr6H+cWE2ca4MHCtPYaZnDiOv4b/Yz7
97Nrc7QPGewMl0hYeykpLP2hBJldw01NXhztuq1j38vYY38lKCN6v1INUujEUZg7
NwgfHUvJmGIE/fwLAvP7do8gf+1MGPEimsgvias5YtDtrEOz7K/oF3Qgk3sepwAz
XXlNLnJAY4p0d/sgCCFQnstQMM95X0Y6cfITzkz3HIUcNF2sbvVnn8xHi0TSH/8J
tPLHO1xOLz7N
-----END CERTIFICATE-----
"@
# register callback for comparing the certificate
function set-SSLCertificate {
param(
$Cert
)
if (-not("validateCert" -as [type])) {
add-type -TypeDefinition @"
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class ValidateCert {
static X509Certificate2 MyCert;
public static bool Validate(object sender,
X509Certificate cert,
X509Chain chain,
SslPolicyErrors sslPolicyErrors) {
if (MyCert.Equals(cert)) {
return true;
} else {
return false;
}
}
public static RemoteCertificateValidationCallback GetDelegate(X5
09Certificate2 Cert) {
MyCert = Cert;
return new RemoteCertificateValidationCallback(ValidateCert.
Validate);
}
}
"@ "@
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [val
idateCert]::GetDelegate($Cert)
} }
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]: # convert base64 based certificate to X509 certificate
:GetDelegate() function get-x509 {
param(
[string]
$Cert64
)
$icingaApiHost = "localhost" $CertBin=[System.Convert]::FromBase64String(($Cert64.Trim(" ") -replace "-.*
$icingaApiUser = "root" -",""))
$icingaApiPassword = "icinga"
Write-Host ($Cert64.Trim(" ") -replace "-.*-","")
[System.Security.Cryptography.X509Certificates.X509Certificate2]$CertBin
}
# Allow TLS 1.2. Old powershell (.net) uses TLS 1.0 only. Icinga2 >2.10 needs TL
S 1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtoco
lType]'Ssl3,Tls,Tls11,Tls12'
$requestUrl = "https://{0}:5665/v1/objects/services" -f $icingaApiHost $SecPass = ConvertTo-SecureString $icingaApiPassword -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential($icingaApiUser, $Se
cPass)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0 $Cert = get-x509 $Cert64
}:{1}" -f $icingaApiUser, $icingaApiPassword))) set-SSLCertificate $Cert
$httpAuthInfo = "Basic $base64AuthInfo"
$httpAcceptInfo = "application/json"
$httpHeaders = @{ $httpHeaders = @{
"Authorization" = $httpAuthInfo
"Accept" = $httpAcceptInfo
"X-HTTP-Method-Override" = "GET" "X-HTTP-Method-Override" = "GET"
"accept" = "application/json"
} }
$attrs = @( "name", "state", "last_check_result" ) $attrs = @( "name", "state", "last_check_result" )
$joins = @( "host.name", "host.state", "host.last_check_result") $joins = @( "host.name", "host.state", "host.last_check_result")
$filter = 'match("ping*", service.name)' $filter = 'match("ping*", service.name)'
$data = @{ $data = @{
"attrs" = $attrs "attrs" = $attrs
"joins" = $joins "joins" = $joins
"filter" = $filter "filter" = $filter
} }
$result = Invoke-RestMethod -Headers $httpHeaders -Uri $requestUrl -Method "POST " -Body ($data|ConvertTo-Json) $result = Invoke-RestMethod -Uri $requestUrl -Method "POST" -Body (ConvertTo-Jso n -InputObject $data) -Credential $Cred -ContentType "application/json" -Header s $httpHeaders
foreach ($s in $result.results) { foreach ($s in $result.results) {
Write-Host "Service " $s.attrs.name " on Host " $s.joins.host.name "State " $s.attrs.state " Output: " $s.attrs.last_check_result.output Write-Host "Service " $s.attrs.name " on Host " $s.joins.host.name "State " $s.attrs.state " Output: " $s.attrs.last_check_result.output
# Debug # Debug
Write-Host "Debug: Attributes " $s.attrs | ConvertTo-Json Write-Host "Debug: Attributes " $s.attrs | ConvertTo-Json
Write-Host "Debug: Joins Host" $s.joins.host | ConvertTo-Json Write-Host "Debug: Joins Host" $s.joins.host | ConvertTo-Json
Write-Host "`n" Write-Host "`n"
} }
``` ```
 End of changes. 20 change blocks. 
46 lines changed or deleted 147 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)