Powershell check - plugin Critical but state ok

Hi I have build my own check with powershell. The plugin output is critical but the state of the service is ok.
Why? What have I to do, that the state is critical? Is this a part of the powershell script or the configuration in the gui?

grafik

Hey @el-dummy

your script returns an exitcode. You can change it with the exit command.

// 0=OK, 1=Warning, 2=Critical, 3=Unknown
if ($good) {
  exit 0;
}  else {
  exit 1;
}

You can get the value of the last exit code with $LASTEXITCODE.

ok. with the exit it works, but if I exit the check before the:

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

I get no plugin output. And behind the “return …” the exit have no effect.

Sorry, I didn’t know that you are using the new powershell framework.
Did you read the docs for the New-IcingaCheckResult command? The function returns the exit code but in your case it seems to always return 0.

The exit code is 2 in the output

grafik

So the plugin seems to be working correctly. :slight_smile: What does the command definition for the check look like?

what do you mean with the command definition. The conf file on the icinga2 Server?

this is the conf:

object CheckCommand “iii-serviceifexist” {
import “PowerShell Base”

arguments += {
    "-C" = {
        value = "try { Use-Icinga; } 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'; exit 3; }; Exit-IcingaPluginNotInstalled 'iii-serviceifexist'; exit iii-serviceifexist"
        order = 0
    }
    "-servicename" = {
        description = "service-name"
                    value = "$iii-serviceifexist_Object_servicename$"
        order = 1
    }
    "-warcrit" = {
        description = "Wert 1 eingeben, wenn im Fehlerfall nur eine Warnung erscheinen soll"
                    value = "$iii-serviceifexist_Object_warcrit$"
        order = 2
    }
}

}

Did you add the | Out-Null to the Check in your module? Like:

    $Check.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;

thank you, thats it.