# Windows nscp-local configuration for external script

**URL:** <https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838>\
**Category:** Events and Community\
**Created:** [March 3, 2021, 7:38am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838 "2021-03-03T07:38:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![radioactive9](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radioactive9](https://community.icinga.com/u/radioactive9)\
**Post date:** [March 3, 2021, 7:38am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/1 "2021-03-03T07:38:02Z")

</div>

Hello

I had been trying to make a external script work via nscp-local. The script is below  
[https://exchange.nagios.org/directory/Plugins/Web-Servers/IIS/check\_iis8\_app\_pool\_state/details](https://exchange.nagios.org/directory/Plugins/Web-Servers/IIS/check_iis8_app_pool_state/details)  
But I am not sure how to configure this from icinga director perspective

I have added the following in nsclient.ini

```
[/settings/NRPE/server]
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"
}
```

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [March 3, 2021, 8:08am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/2 "2021-03-03T08:08:46Z")

</div>

Hi @radioactive9

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

---

<div class="post-metadata">

**Author:** ![radioactive9](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radioactive9](https://community.icinga.com/u/radioactive9)\
**Post date:** [March 3, 2021, 8:09am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/3 "2021-03-03T08:09:08Z")

</div>

I have icinga agent installed on windows servers

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [March 3, 2021, 8:49am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/4 "2021-03-03T08:49:01Z")

</div>

Okay. 🙂 Is there a reason that you want to use nscp for the command? You can run powershell directly ([explained here](https://community.icinga.com/t/windows-powershell-checks-with-icinga2/712)).

---

<div class="post-metadata">

**Author:** ![radioactive9](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radioactive9](https://community.icinga.com/u/radioactive9)\
**Post date:** [March 4, 2021, 3:21am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/5 "2021-03-04T03:21:41Z")

</div>

Honestly there is no reason to run the powershell script through nscp. 🙂 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

**EDIT:**

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

Error

```
& : 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

**Command:**

```
object CheckCommand "powershell_check" {
    import "plugin-check-command"
    command = [
        "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
    ]
    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 "s065.dc.corpint.net" {
    import "XXX-tmplHost-AG-NT"
    import "XXX-tmplHost-IS"

display_name = "s065.dc.corpint.net"
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'`

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [March 4, 2021, 5:24pm UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/6 "2021-03-04T17:24:55Z")

</div>

one little thing:

> [@radioactive9](#):
>
> ```auto
> ps_command = "& 'C:\\Program Files\\NSClient++\\scripts\\check_ms_iis_application_pool.ps1 DefaultAppPool'"
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![radioactive9](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radioactive9](https://community.icinga.com/u/radioactive9)\
**Post date:** [March 5, 2021, 3:46am UTC](https://community.icinga.com/t/windows-nscp-local-configuration-for-external-script/6838/7 "2021-03-05T03:46:16Z")

</div>

> [@radioactive9](#):
>
> ‘C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe’ ‘-command’

Thank You. It is interesting 🙂
