Icinga for Windows failed to start on Agent - using self Service API Template

Hi! I am trying to set up an icinga agent using Icinga for Windows, using a selv Service API key, and running the provided PS-script from agent-tab within Icinga director host template. To my understanding it should setup the agent automatically within Icinga director, but when I am running the script in PS on my Windows Server 2016, I get the following error:

[Notice]: Host seems already to be registered within Icinga Director. Trying local Api key if present
[Notice]: No local Api key was found and using your provided template key failed. Please ensure the host is not already registered and drop the set Self-Service key within the Icinga Director for this host.
[Notice]: Starting Icinga for Windows installation
[Error]: Failed to start Icinga for Windows installation, caused by an error while communicating with Icinga Director:

At C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache\framework_cache.psm1:8063 char:9
+         throw $global:Icinga.InstallWizard.DirectorError;
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (System.Object[]:Object[]) [], RuntimeException
    + FullyQualifiedErrorId :

Im running the provided script from director host template:

[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11';
$ProgressPreference                         = 'SilentlyContinue';
[string]$ScriptFile                         = 'C:\Users\Public\IcingaForWindows.ps1';

Invoke-WebRequest `
    -UseBasicParsing `
    -Uri             'https://packages.icinga.com/IcingaForWindows/IcingaForWindows.ps1' `
    -OutFile         $ScriptFile;

& $ScriptFile `
    -ModuleDirectory  'C:\Program Files\WindowsPowerShell\Modules\' `
    -InstallCommand   '{"IfW-DirectorSelfServiceKey":{"Values":["3eb86825f4ff6d34ss44dbgf8dbd936c97af3cgb"]},"IfW-DirectorUrl":{"Values":["http://192.168.10.180/icingaweb2/director/"]},"IfW-StableRepository":{"Values":["https://packages.icinga.com/IcingaForWindows/stable"]}}' `
    -IcingaRepository 'https://packages.icinga.com/IcingaForWindows/stable/ifw.repo.json'

I know im getting a notice about the host already being registered in Director, but im getting that on multiple servers that has never had icinga agent installed, and I havent added them on my master node. I Believe the error is of a different nature, but I can’t seem to figure it out. Any helpful suggestions on how to proceed or troubleshoot?

Icinga2 version: 2.14.0-1

The self service api whats to register the host using template key.

  • If it has a template without any key and you want to use any templater the registration process fails
  • If the host has an api key the registration process fails (previously registered).

Try to use the template key of a template assigned to that host

Hmm im not sure I follow a 100%. Should I create a host in the Director, before I try to run the powershell script?
I dont think the host has an api-key, I tried this:

PS C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework> Show-IcingaDirecorSelfServiceKey
[Warning]: There is no Self-Service Api key configured on this system

So to me it seems as if none is fetched through the installation

  • if the host doesnt exist everything is fine using the template key
    • the host will be created and inherit the template settings
  • if the host exists and has a director template with no template key set that can cause problems
    • assign a template with a template key and use that key as a self service key
  • if the host was connected using the icinga poweshell framework the host key can still persist in the settings even after uninstall (Show-IcingaDirecorSelfServiceKey)
    • having this set can also cause problems during install, but that is not your case

I don’t see any hosts created in on my master, but the issue remains. Do you maybe have any suggestions on how to proceed in my scenario?

this indicates that there is a host with the same name in icinga director, is that true?

If I look inside icinga Director it is completely blank:

what is on your template page?

This is on my template page:

With this on the agent tab of the template:

strange, what’s your director version?

Director version is: 1.11.0

what are your settings in

/icingaweb2/director/settings/self-service

?

Thye look like this:

can you repeat the installation process.

first do “Uninstall-IcingaForWindows” in your powershell
then use Start-Transcript
then perform the install
anonymize the file but since you only use a local ip and the template key can be changed this shouldn’t be an issue
post the transcipt

Here is the transcipt, Hope it is ok with the formatting, can’t seem to get it right, and it makes “Code-boxes” itself:


Windows PowerShell transcript start
Start time: 20231117115003
Username: SSD\SSDJohannes
RunAs User: SSD\SSDJohannes
Configuration Name:
Machine: SSDUDV3 (Microsoft Windows NT 10.0.17763.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 12876
PSVersion: 5.1.17763.4974
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.4974
BuildVersion: 10.0.17763.4974
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1


Transcript started, output file is C:\Users\SSDJohannes\Documents\PowerShell_transcript.SSDUDV3.bjLotjcB.20231117115003.txt
PS C:\Program Files\WindowsPowerShell\Modules> C:\Users\SSDJohannes\Desktop\AgentSetup.ps1
[
Notice
]:
PowerShell Execution-Policies are configured to run Scripts and/or Modules.
[
Notice
]:
Downloading Icinga PowerShell Framework into “C:\Users\SSDJOH~1\AppData\Local\Temp\icinga-powershell-framework-zip”
[
Notice
]:
Installing Icinga PowerShell Framework into "C:\Program Files\WindowsPowerShell\Modules"
[
Notice
]:
Installing new Icinga PowerShell Framework version
[
Notice
]:
Unblocking Icinga PowerShell Framework files
[
Notice
]:
Applying pending migrations required for Icinga for Windows v1.8.0
[
Notice
]:
Applying pending migrations required for Icinga for Windows v1.10.0
[
Notice
]:
Applying pending migrations required for Icinga for Windows v1.10.1
[
Notice
]:
Icinga PowerShell Framework seems to be successfully installed
[
Notice
]:
To use the Icinga PowerShell Framework in the future, please initialize it by running the command “Use-Icinga” inside your PowerShell
PS C:\Program Files\WindowsPowerShell\Modules> TerminatingError(ConvertFrom-Json): “Invalid JSON primitive: .”

TerminatingError(ConvertFrom-Json): “Invalid JSON primitive: .”
PS C:\Program Files\WindowsPowerShell\Modules> TerminatingError(): “Please enter the hostname to use”
[
Notice
]:
Host seems already to be registered within Icinga Director. Trying local Api key if present
[
Notice
]:
No local Api key was found and using your provided template key failed. Please ensure the host is not already registered and drop the set Self-Service key within the Icinga Director for this host.
PS C:\Program Files\WindowsPowerShell\Modules> TerminatingError(): “Please enter either a template or your host key. If this message persists, ensure your host is not having a template key assigned already. If so, you can try dropping it within the Icinga Director.”
[
Notice
]:
Starting Icinga for Windows installation
[
Error
]:
Failed to start Icinga for Windows installation, caused by an error while communicating with Icinga Director:
PS C:\Program Files\WindowsPowerShell\Modules> TerminatingError(): " "
TerminatingError(): " "
TerminatingError(): " "
[
Error
]:
Unable to load the Icinga PowerShell Framework. Please check your PowerShell execution policies for possible problems. Error: System.Management.Automation.RuntimeException:

what’s the module version of the icinga powershell framework?

 (Get-Module -ListAvailable -Name icinga-powershell-framework).Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      11     1      -1

Hey @moreamazingnick ! Did you fall out of ideas? Could there perhaps be issues with a Firewall somewhere, that hinderes communication?

can the agent access the port (in your case port 80) of the machine which hosts icinga director?

I believe so, wouldn’t this suggest so?:

here I tried to connect to master on port 80