Windows nscp-local configuration for external script


I had been trying to make a external script work via nscp-local. The script is below
But I am not sure how to configure this from icinga director perspective

I have added the following in nsclient.ini

allow arguments=true

[/settings/external scripts]
allow arguments=true

[/settings/external scripts/scripts]
check_iis_app_pool = cmd /c echo scripts\check_iis8_app_pool_state.ps1 "$ARG1$"; exit($lastexitcode) | powershell.exe -command -

After that I was trying to use the command check_iis_app_pool somehow as command. But not sure how to pass it from icinga director - last but not the list how to pass the argument

template Service "XXX-tmplService-IS-ExternalCommand" {
    import "XXX-tmplService-Default"

    check_command = "nscp-local"
    max_check_attempts = "3"
    check_interval = 3m
    retry_interval = 3m
    check_timeout = 1m
    command_endpoint = host_name
    vars.nscp_modules = [ "CheckExternalScripts" ]
    vars.nscp_query = "check_iis_app_pool"
    vars.u_Middleware = "IIS"

Hi @radioactive9

how do you monitor the agent? Do you use the icinga2 agent for windows (or NRPE, check_nt, …)?

I have icinga agent installed on windows servers

Okay. :slight_smile: Is there a reason that you want to use nscp for the command? You can run powershell directly (explained here).

Honestly there is no reason to run the powershell script through nscp. :slight_smile: I thought it is somewhat cool.

But let me try to explore the option provided in your link. I will post if my stupid brain not able to follow the instruction properly


All Right I am getting the following error not sure what I am doing wrong as usual. Followed like a copy cat.


& : The term 'C:\Program Files\NSClient++\scripts\check_ms_iis_application_pool.ps1 DefaultAppPool' is not recognized
as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was ...

My Service was created from Director


object CheckCommand "powershell_check" {
    import "plugin-check-command"
    command = [
    timeout = 1m
    arguments += {
        "-command" = {
            description = "command"
            order = -1
            value = "$ps_command$"
        "-crit" = {
            description = "Critical"
            value = "$ps_crit$"
        "-warn" = {
            description = "warning"
            value = "$ps_warn$"
        ";exit" = {
            description = "exitcode"
            value = "$$LastExitCode"

Service Template

template Service "XXX-tmplService-IS-PowerShellExternal" {
    import "XXX-tmplService-Default"

    check_command = "powershell_check"
    max_check_attempts = "3"
    check_interval = 3m
    retry_interval = 3m
    command_endpoint = host_name

Single Service

apply Service "XXX-P_IS_AppPoolStatus" {
    import "XXX-tmplService-IS-PowerShellExternal"
    assign where "XXX-tmplHost-IS" in host.templates
    import DirectorOverrideTemplate

Director Override for specific server

object Host "" {
    import "XXX-tmplHost-AG-NT"
    import "XXX-tmplHost-IS"

display_name = ""
address = "XX3.1X6.22.1XX"
groups = [ "XXX-GroupHost-IS-All", "XXX-GroupHost-NT-All" ]
vars.CustomOSType = "Windows"
vars["_override_servicevars"] += {
    "XXX-P_IS_AppPoolStatus" = {
        ps_command = "& 'C:\\Program Files\\NSClient++\\scripts\\check_ms_iis_application_pool.ps1 DefaultAppPool'"

Inspect element look like this

'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' '-command' '& '\''C:\Program Files\NSClient++\scripts\check_ms_iis_application_pool.ps1 DefaultAppPool'\''' ';exit' '$LastExitCode'

one little thing:

Only put the single quotes around the powershell script. :slight_smile:
& 'C:\\Program Files\\NSClient++\\scripts\\check_ms_iis_application_pool.ps1' DefaultAppPool

Thank You. It is interesting :slight_smile: