Import invoke-icingacheckhttpstatus

I have a the problem to import the invoke-icngacheckhttpstatus

First I have generate the check with:

Get-IcingaCheckCommandConfig -CheckName Invoke-IcingaCheckHTTPStatus -IcingaConfig -OutDirectory 'C:\temp\' -FileName 'icingacheckhttp.conf';

than I copy the conf to the other .conf files on the Icinga Server

After the reload with

icinga2 daemon -C

I got the following error:

[2021-07-13 15:59:34 +0200] information/cli: Icinga application loader (version: 2.12.4-1)
[2021-07-13 15:59:34 +0200] information/cli: Loading configuration file(s).
[2021-07-13 15:59:34 +0200] critical/config: Error: syntax error, unexpected T_IDENTIFIER
Location: in /etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf: 2:7-2:18
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(1):
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(2): bject CheckCommand "Invoke-IcingaCheckHTTPStatus" {
                                                                           ^^^^^^^^^^^^
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(3):     import "PowerShell Base"
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(4):

[2021-07-13 15:59:34 +0200] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.
[root@SERVER windows-commands]# icinga2 daemon -C
[2021-07-13 16:46:40 +0200] information/cli: Icinga application loader (version: 2.12.4-1)
[2021-07-13 16:46:40 +0200] information/cli: Loading configuration file(s).
[2021-07-13 16:46:40 +0200] critical/config: Error: syntax error, unexpected T_IDENTIFIER
Location: in /etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf: 2:7-2:18
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(1):
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(2): bject CheckCommand "Invoke-IcingaCheckHTTPStatus" {
                                                                           ^^^^^^^^^^^^
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(3):     import "PowerShell Base"
/etc/icinga2/zones.d/windows-commands/icingacheckhttpstatus.conf(4):

[2021-07-13 16:46:40 +0200] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

This is my generated conf file:

object CheckCommand "Invoke-IcingaCheckHTTPStatus" {
    import "PowerShell Base"

    arguments += {
        "-StatusCode" = {
            value = {{
                var arr = macro("$IcingaCheckHTTPStatus_Array_StatusCode$");
                    if (len(arr) == 0) {
                        return "@()";
                    }
                    return arr.map(
                        x => if (typeof(x) == String) {
                            var argLen = len(x);
                            if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
                                x;
                            } else {
                                "'" + x + "'";
                            }
                        } else {
                            x;
                        }
                    ).join(",");
            }}
            order = 14
        }
        "-NoPerfData" = {
            set_if = "$IcingaCheckHTTPStatus_Switchparameter_NoPerfData$"
            order = 99
        }
        "-Verbosity" = {
            description = "Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])"
            value = "$IcingaCheckHTTPStatus_Int32_Verbosity$"
            order = 16
        }
        "-Content" = {
            description = "Used to specify an array of regex-match-strings to match against the content of the webrequest response."
            value = {{
                var arr = macro("$IcingaCheckHTTPStatus_Array_Content$");
                    if (len(arr) == 0) {
                        return "@()";
                    }
                    return arr.map(
                        x => if (typeof(x) == String) {
                            var argLen = len(x);
                            if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
                                x;
                            } else {
                                "'" + x + "'";
                            }
                        } else {
                            x;
                        }
                    ).join(",");
            }}
            order = 13
        }
        "-ProxyUsername" = {
            description = "Used to specify a proxy username as string to authenticate with. Use with: -ProxyPassword & -ProxyServer"
            value = "$IcingaCheckHTTPStatus_String_ProxyUsername$"
            order = 10
        }
        "-Username" = {
            description = "Used to specify a username as string to authenticate with. Authentication is only possible with 'https://'. Use with: -Password"
            value = "$IcingaCheckHTTPStatus_String_Username$"
            order = 8
        }
        "-C" = {
            value = "try { Use-Icinga -Minimal; } catch { Write-Output 'The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'; Write-Output "Error: $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable "icinga-powershell-*" )`r`nModule-Path:`r`n$$($$Env:PSModulePath)"; exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheckHTTPStatus' "
            order = 0
        }
        "-ThresholdInterval" = {
            description = "Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described here: https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/ An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring."
            value = "$IcingaCheckHTTPStatus_String_ThresholdInterval$"
            order = 100
        }
        "-Negate" = {
            set_if = "$IcingaCheckHTTPStatus_Switchparameter_Negate$"
            order = 99
        }
        "-Password" = {
            description = "Used to specify a password as securestring to authenticate with. Authentication is only possible with 'https://'.Use with: -Username"
            value = "(ConvertTo-IcingaSecureString '$IcingaCheckHTTPStatus_Securestring_Password$')"
            order = 9
        }
        "-Warning" = {
            description = "Used to specify the webrequest response time warning threshold in seconds, everything past that threshold is considered a WARNING."
            value = "$IcingaCheckHTTPStatus_Object_Warning$"
            order = 2
        }
        "-ProxyServer" = {
            description = "Used to specify a proxy server as string to authenticate with."
            value = "$IcingaCheckHTTPStatus_String_ProxyServer$"
            order = 12
        }
        "-ProxyPassword" = {
            description = "Used to specify a proxy password as securestring to authenticate with. Use with: -ProxyUsername & -ProxyServer"
            value = "(ConvertTo-IcingaSecureString '$IcingaCheckHTTPStatus_Securestring_ProxyPassword$')"
            order = 11
        }
        "-Minimum" = {
            value = "$IcingaCheckHTTPStatus_Int32_Minimum$"
            order = 15
        }
        "-VHost" = {
            description = "Used to specify a VHost as string."
            value = "$IcingaCheckHTTPStatus_String_VHost$"
            order = 5
        }
        "-Critical" = {
            description = "Used to specify the webrequest response time critical threshold in seconds, everything past that threshold is considered a CRITICAL."
            value = "$IcingaCheckHTTPStatus_Object_Critical$"
            order = 3
        }
        "-Headers" = {
            description = "Used to specify headers as Array. Like: -Headers 'Accept:application/json'"
            value = {{
                var arr = macro("$IcingaCheckHTTPStatus_Array_Headers$");
                    if (len(arr) == 0) {
                        return "@()";
                    }
                    return arr.map(
                        x => if (typeof(x) == String) {
                            var argLen = len(x);
                            if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
                                x;
                            } else {
                                "'" + x + "'";
                            }
                        } else {
                            x;
                        }
                    ).join(",");
            }}
            order = 6
        }
        "-Timeout" = {
            description = "Used to specify the timeout in seconds of the webrequest as integer. The default is 10 for 10 seconds."
            value = "$IcingaCheckHTTPStatus_Int32_Timeout$"
            order = 7
        }
        "-Url" = {
            description = "Used to specify the URL of the host to check http as string. Use 'http://' or 'https://' to actively chose a protocol. Likewise ':80' or any other port number to specify a port, etc."
            value = {{
                var arr = macro("$IcingaCheckHTTPStatus_Array_Url$");
                    if (len(arr) == 0) {
                        return "@()";
                    }
                    return arr.map(
                        x => if (typeof(x) == String) {
                            var argLen = len(x);
                            if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
                                x;
                            } else {
                                "'" + x + "'";
                            }
                        } else {
                            x;
                        }
                    ).join(",");
            }}
            order = 4
        }
    }
    vars.IcingaCheckHTTPStatus_Switchparameter_NoPerfData = false
    vars.IcingaCheckHTTPStatus_Switchparameter_Negate = false
}
  • Director version (System - About):1.8.0
  • Icinga Web 2 version and modules (System - About):2.8.2
  • Icinga 2 version (icinga2 --version):
  • Operating System and version:redhat 7.8
  • Webserver,
  • PHP versions: 7.3.20

How did you copy and are you sure you did not lose the “o” from “object”? This is the only thing I can see on a first look.

I had copy the file with winscp. The “o” from object is in the file

I can only re-produce this issue when I remove the “o” from the “object” type.
When I generate the config file and put it inside Icinga 2, everything works fine. If i remove the “o”, I get the same error:

[2021-07-14 10:41:28 +0200] information/cli: Icinga application loader (version: 2.12.4-1)
[2021-07-14 10:41:28 +0200] information/cli: Loading configuration file(s).
[2021-07-14 10:41:28 +0200] critical/config: Error: syntax error, unexpected T_IDENTIFIER
Location: in /etc/icinga2/conf.d/http_windows.conf: 1:6-1:17
/etc/icinga2/conf.d/http_windows.conf(1): bject CheckCommand "Invoke-IcingaCheckHTTPStatus" {
                                               ^^^^^^^^^^^^
/etc/icinga2/conf.d/http_windows.conf(2):     import "PowerShell Base"
/etc/icinga2/conf.d/http_windows.conf(3):

[2021-07-14 10:41:28 +0200] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

Is there some sort of encoding issue happen, that WinSCP is using different line endings and “cutting” the “o” in this case?

Can you show us the file size in bytes of both the original and the copied file,
and is it possible to calculate the MD5sum of a file on Windows (on Linux this
would simply be “md5sum filename”)? If so, do they match for the original and
the copy?

Antony.

You can use Get-FileHash for this:

Get-FileHash -Algorithm MD5 -Path '<path to the file>'

vom Icinga Server

der Export vom Client

I honestly have no idea on why the loading fails. To me it looks like the “o” is missing, because I can reproduce the exact same error in this case.

Generating the configuration file on my system and using scp to copy it to the Linux system works just fine and is loaded by Icinga.

Is anyone else having an idea?

I don’t get the same error. The blue section in the screenshot is with the “o” and the orange is without the “o”

Now I get the problem - that part was missing from the first screenshot. Which version of Icinga for Windows did you use to create the config?
There was one issue with v1.5.0 and plain Icinga config, because of improved error handling which wasn’t escaped properly.

This was fixed with v1.5.1 and the config is valid with this version.

I think, you mean the Framework. Yes I have Version 1.5.0. I try it with the next version - but not today. Thank you.

I had updated the plugins and the framework. Now it works. Thanks

1 Like