|
| 1 | +# Experimental: Forward Checks to internal API |
| 2 | + |
| 3 | +With Icinga for Windows v1.4.0 we introduced a new experimental feature, allowing to forward executed checks to an internal REST-Api. This will move the check execution from the current PowerShell scope to an internal REST-Api daemon and endpoint and run the command with all provided arguments there. |
| 4 | + |
| 5 | +This will reduce the performance impact on the CPU as well as lower the loading time of the Icinga PowerShell Framework, as only very basic core functionality is required for this. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +To use this feature, you wil require the following |
| 10 | + |
| 11 | +* Icinga Agent is certificates installed |
| 12 | +* Icinga for Windows v1.4.0 installed |
| 13 | +* [Icinga for Windows Service installed](https://icinga.com/docs/icinga-for-windows/latest/doc/service/01-Install-Service/) |
| 14 | +* Icinga for Windows v1.4.0 CheckCommand configuration applied (**Important:** Update your entire Windows environment to v1.4.0 before updating the Icinga configuration!) |
| 15 | +* [Icinga for Windows REST-Api](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/01-Introduction/) |
| 16 | +* [Icinga for Windows Api-Checks](https://github.com/Icinga/icinga-powershell-apichecks/blob/master/doc/01-Introduction.md) |
| 17 | + |
| 18 | +## Install Dependencies |
| 19 | + |
| 20 | +### Additional Modules |
| 21 | + |
| 22 | +At first you will require to install both required modules, the [REST-Api](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/01-Introduction/) and [Api-Checks](https://github.com/Icinga/icinga-powershell-apichecks/blob/master/doc/01-Introduction.md) component. |
| 23 | + |
| 24 | +Like any other Icinga for Windows component, you can use the Framework tools to install them: |
| 25 | + |
| 26 | +```powershell |
| 27 | +Install-IcingaFrameworkComponent -Name restapi -Release; |
| 28 | +``` |
| 29 | + |
| 30 | +```powershell |
| 31 | +Install-IcingaFrameworkComponent -Name apichecks -Release; |
| 32 | +``` |
| 33 | + |
| 34 | +If this does not work for you, please have a look on the [REST-Api installation guide](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/02-Installation/) and [Api-Checks installation guide](https://github.com/Icinga/icinga-powershell-apichecks/blob/master/doc/02-Installation.md). |
| 35 | + |
| 36 | +### Icinga for Windows Service |
| 37 | + |
| 38 | +To make this entire construct work, we will require to install the Icinga for Windows service. You can follow [this guide to install it manually](https://icinga.com/docs/icinga-for-windows/latest/doc/service/01-Install-Service/) if it is not already installed on your machine. |
| 39 | + |
| 40 | +## Register Background Daemon |
| 41 | + |
| 42 | +To access our REST-Api we have to register it as background daemon as mentioned inside the [REST-Api installation guide](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/02-Installation/#daemon-registration). |
| 43 | + |
| 44 | +We can do this by running the command |
| 45 | + |
| 46 | +```powershell |
| 47 | +Register-IcingaBackgroundDaemon -Command 'Start-IcingaWindowsRESTApi'; |
| 48 | +``` |
| 49 | + |
| 50 | +By default, it will start listening on Port `5668` and use the Icinga Agents certificates for TLS encrypted communication. As long as the Windows firewall is not allowing access to this port, external communication is not possible. |
| 51 | + |
| 52 | +To modify any REST-Api arguments, please follow the [REST-Api installation guide](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/02-Installation/#daemon-registration). |
| 53 | + |
| 54 | +Last but not least restart the Icinga for Windows service: |
| 55 | + |
| 56 | +```powershell |
| 57 | +Restart-Service icingapowershell; |
| 58 | +``` |
| 59 | + |
| 60 | +## Whitelist Check Commands |
| 61 | + |
| 62 | +By default the Api-Checks module is rejecting every single request to execute commands, as long as they are not whitelisted. |
| 63 | + |
| 64 | +You can whitelist all check commands with an wildcard by using `Invoke-IcingaCheck*` for the `apichecks` module. |
| 65 | + |
| 66 | +```powershell |
| 67 | +Add-IcingaRESTApiCommand -Command 'Invoke-IcingaCheck*' -Endpoint 'apichecks'; |
| 68 | +``` |
| 69 | + |
| 70 | +Of course, you can also whitelist every single command without wildcard for more security. |
| 71 | + |
| 72 | +## Blacklist Check Commands |
| 73 | + |
| 74 | +If you do not want to execute certain checks, but keep the previous wildcard whitelist, you can blacklist a single command (or use wildcard to match multiple): |
| 75 | + |
| 76 | +```powershell |
| 77 | +Add-IcingaRESTApiCommand -Command 'Invoke-IcingaCheckCertificate' -Endpoint 'apichecks' -Blacklist; |
| 78 | +``` |
| 79 | + |
| 80 | +Blacklists are checked prior to whitelist. If you are running wildcard filters for both, whitelist and blacklist, blacklist entries will win first and block the execution if they match the filter. |
| 81 | + |
| 82 | +## Enable Api Check Feature |
| 83 | + |
| 84 | +Now as we configured our host with all required components, we simply require to enable the api checks feature: |
| 85 | + |
| 86 | +```powershell |
| 87 | +Enable-IcingaFrameworkApiChecks; |
| 88 | +``` |
| 89 | + |
| 90 | +As long as the feature is enabled, the Icinga for Windows service is running, the REST-Api daemon is registered and both modules, [icinga-powershell-restapi](https://icinga.com/docs/icinga-for-windows/latest/restapi/doc/01-Introduction/) and [icinga-powershell-apichecks](https://github.com/Icinga/icinga-powershell-apichecks/blob/master/doc/01-Introduction.md) are installed, checks will be forwarded to the REST-Api and executed, if whitelisted. |
| 91 | + |
| 92 | +## Disable Api Check Feature |
| 93 | + |
| 94 | +You can disable the Api check feature anytime by running |
| 95 | + |
| 96 | +```powershell |
| 97 | +Disable-IcingaFrameworkApiChecks; |
| 98 | +``` |
| 99 | + |
| 100 | +Once disabled checks will be executed within the local, current shell and not being forwarded to the API. |
| 101 | + |
| 102 | +## EventLog Errors |
| 103 | + |
| 104 | +In case a check could not be executed by using this experimental feature, either because of timeouts or other issues, they are added with `EventId 1553` inside the EventLog for `Icinga for Windows`. A description on why the check could not be executed is added within the event output. |
| 105 | + |
| 106 | +## Summary |
| 107 | + |
| 108 | +For quick installation, here the list of commands to get everything running: |
| 109 | + |
| 110 | +```powershell |
| 111 | +Install-IcingaFrameworkComponent -Name restapi -Release; |
| 112 | +Install-IcingaFrameworkComponent -Name apichecks -Release; |
| 113 | +
|
| 114 | +Register-IcingaBackgroundDaemon -Command 'Start-IcingaWindowsRESTApi'; |
| 115 | +Restart-Service icingapowershell; |
| 116 | +
|
| 117 | +Add-IcingaRESTApiCommand -Command 'Invoke-IcingaCheck*' -Endpoint 'apichecks'; |
| 118 | +
|
| 119 | +Enable-IcingaFrameworkApiChecks; |
| 120 | +``` |
0 commit comments