Own checks downt work since I installed new Agent on windows

I have installed that versions:
Icinga2-v2.12.4-x86_64.msi
icinga-powershell-framework-1.5.2.zip
icinga-powershell-plugins-1.5.1.zip
icinga-service-v1.1.0.zip

After I have updated framework, agent and plugins I have a problem in all my checks with that command:
return New-IcingaCheckresult -Check $Check -noPerfdata $True -Compile

This is the error:

Exception calling "Compile" with "0" argument(s): "Cannot index into a null array."
At C:\Program
Files\WindowsPowerShell\Modules\icinga-powershell-framework\lib\icinga\plugin\New-IcingaCheckResult.psm1:34 char:16
+         return $IcingaCheckResult.Compile();
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ScriptMethodRuntimeException

If I replace this file from a old icinga-powershell-framework 1.5.0 Version it works:

c:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\lib\icinga\plugin\New-IcingaCheckBaseObject.psm1

Is this a known failure in the framework Version 1.5.2 ?

Hello,

this issue is interesting and shouldn’t happen. There were only bugfixes with 1.5.1 and 1.5.2 which shouldn’t cause problems in addition, but resolve them.

The issue is resolved once you replace New-IcingaCheckBaseObject from 1.5.2 with 1.5.0?

Yes, this is what I do. … I replace the

New-IcingaCheckBaseObject from 1.5.2 with 1.5.0?

And my own checks work again. But I don’t know what now not work

Could you please try to test your plugin with the Master of 1.6.0?
Wohld it be possible to Share your code snippet for the Check causing the Error, allowing us to reproduce the issue?

1 Like

Yes I can do it … but I am on holiday for the next two weeks. Than I will try it.

1 Like

I have installed that versions:
Icinga2-v2.13.0-x86_64.msi
icinga-powershell-framework-1.5.2.zip
icinga-powershell-plugins-1.5.1.zip
icinga-service-v1.1.0.zip

This is the check:

Function i-pathexist()
{
param(
$path = $null,
$exist = $null,
$warncrit = $null

);  

switch ($exist) {
“1” {$wert=test-path $path}
“0” {$wert=(!(test-path $path))}

                default{$wert=test-path $path}
              }

#Checkwert setzen
$Check = New-IcingaCheck -Name $path -Value $wert;

#Check ausführen
switch ($warncrit) {
“warn” {$Check.WarnifLike(‘false’) |Out-Null}
“crit” {$Check.CritifLike(‘false’) |Out-Null}
default {$Check.CritifLike(‘false’) |Out-Null}
}

return (New-IcingaCheckresult -Check $Check -noPerfdata $True -Compile );

}

If I call the script on the client:

use-icinga
i-pathexist c:\temp

If I replace the New-IcingaCheckBaseObject from the framework 1.5.0 I don’t get the error.

I don’t think the Master is relevant. The error is on the Windows Agent.

Hello there @moreamazingnick ,
For better readability we always love to see posts formatted according to this guideline. :slight_smile:

1 Like

Hi thank you for your studies. Is that a bug or a feature. I don’t want to have these long names.

here you go:

There is something.
if the Check is not named Invoke-Icinga* for example Invoke-MyIcingaCheckAppPool the check fails, after running a check with the name Invoke-Icinga* and the same check again the error is gone

PS C:\Users\Nicolas> Use-Icinga

PS C:\Users\Nicolas> Invoke-MyIcingaCheckAppPool
\APP_POOL_WAS(_Total)\Current Application Pool State
\APP_POOL_WAS(DefaultAppPool)\Current Application Pool State
[OK] Performance Counter
Ausnahme beim Aufrufen von "Compile" mit 0 Argument(en):  "Es ist nicht möglich, einen Index auf ein NULL-Array
anzuwenden."
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache\framework_cache.psm1:20871 Zeichen:16
+         return $IcingaCheckResult.Compile();
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ScriptMethodRuntimeException


Check
-----
@{Name=Performance Counter; Verbose=0; __CheckPerfData=System.Collections.Hashtable; __Hidden=False; __Parent=; __In...
PS C:\Users\Nicolas> Invoke-IcingaCheckBiosSerial
[OK] BIOS SerialNumber: PF26DF1L
0
PS C:\Users\Nicolas> Invoke-MyIcingaCheckAppPool
\APP_POOL_WAS(_Total)\Current Application Pool State
\APP_POOL_WAS(DefaultAppPool)\Current Application Pool State
[OK] Performance Counter
| 'app_pool_wasdefaultapppoolcurrent_application_pool_state'=3;;3
0

Github bug report:
https://github.com/Icinga/icinga-powershell-framework/issues/359

Hello and thank for the issue - I just replied to the issue.

Using Invoke-IcingaCheck as namespace is described inside the Developer Guide: Custom Plugins - Icinga for Windows and is being valid since version 1.0.0.

This allows us to ensure we are inside a plugin context and can automate certain tasks behind, without the developer to worry about.

If we remove this “restriction”, writing custom plugins will require much more effort in the future. For that reason I would love to stick to that rule.

Ok. thanks. I think I have to rename all my checks.

try again with FW 1.6

2 Likes

Now I have installed
Icinga2-v2.13.1-x86_64.msi
icinga-powershell-framework-1.6.1.zip
icinga-powershell-plugins-1.6.0.zip

and my checks works fine - thanks.