# Service check windows powershell script

**URL:** <https://community.icinga.com/t/service-check-windows-powershell-script/4926>\
**Category:** Service Monitoring\
**Created:** [July 8, 2020, 10:01am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926 "2020-07-08T10:01:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 8, 2020, 10:01am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/1 "2020-07-08T10:01:03Z")

</div>

Hi,  
I am an absolute beginner of Icinga. I have a Linux server running Icinga2 and a Windows server for testing. So far I have only operated Icinga2 via the GUI. So far it works well with existing checks. Now I would like to install my own script and this dont work with the instructions found on the net.

e.g.

> [@Windows PowerShell Checks with Icinga2](https://community.icinga.com/t/windows-powershell-checks-with-icinga2/712):
>
> Author: @GordonCole Revision: v0.1 Tested with: Icinga 2 v2.6.3-1 Icinga Web 2 v2.4.1 Windows Server 2012 R2 Introduction A vanilla Windows Icinga2 installation provides access to a number of standard server health and performance metrics. For example hard disk space, CPU, free RAM, or accessing the value of a Windows Performance Counter. Each of these is metrics is measured using a “check”. These are programs called by the main Icinga2 service. Users may write their own “checks”, as lon…

I have the file on the Linux server first:  
/etc/icinga2/conf.d/commands.conf edited.  
I simply copied the part from the link above and appended it to the end of the existing commands.conf.

```auto
object CheckCommand "powershell_check" {
  import "plugin-check-command"
  command = ["C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"]
  arguments = {
    "-command" = {
    value = "$ps_command$"
    order = -1
    }
    "-warn" = {
    value = "$ps_warn$"
    }
    "-crit" = {
    value = "$ps_crit$"
    }
    ";exit" = {
    value = "$LastExitCode"
    }
  }
}

```

then I have the file on the Linux server  
/etc/icinga2/conf.d/services.conf edited. Again, I simply copied the part from the example and appended it to services.conf.

```auto
apply Service "reboot_status_check" {
  import "generic-service"
  display_name = "Reboot Check"
  check_command = "powershell_check"
  vars.ps_command = "& 'C:\\Program Files\\ICINGA2\\sbin\\check_reboot.ps1'"
  command_endpoint = host.address
  assign where host.vars.os == "windows"
}

```

Now I would have expected to see the service somewhere in the GUI. The following parameters are also not entirely clear to me:  
command\_endpoint = host.address  
assign where host.vars.os == “windows”

Do I have to set the variable beforehand or is this an example and individual?

How can I simply assign the service to my test server?

The Powershell script (plugin) must be on my test server. If it is not there I should at least get an error message in my gui?

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 8, 2020, 3:21pm UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/2 "2020-07-08T15:21:54Z")

</div>

> [@el-dummy](#):
>
> /etc/icinga2/conf.d/commands.conf edited.

When you put your check command in this file, you would have to do this on every Windows machine as well. Best practice is to put all new Windows command objects in a global zone that is also existing at your Windows machines. We are using `windows-commands` as global zones to achieve this.

> assign where host.vars.os == “windows”

This just one example to assign a service to many hosts (which have definied `vars.os = “windows”)

For tests you can simply assign a service to test server with e.g.:

> assign where host.name == “your hostname”

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 9, 2020, 6:11am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/3 "2020-07-09T06:11:15Z")

</div>

ok, i thought i just have to configure on the server. Now I have entered the entries in the commands.conf and in the Services.conf on the Windows test server. In the GUI I see neither the service nor the command. Should I see them in the GUI?

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 9, 2020, 7:03am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/4 "2020-07-09T07:03:09Z")

</div>

Yes, there is a way to configure it only on the server (which I’ve described). No seeing it in the GUI is most properly because your assign rule does not fit. After changing you `conf-files` run `icinga2 daemon -C` and check with `icinga2 object list` if your service object has been generated.

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 9, 2020, 11:33am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/5 "2020-07-09T11:33:22Z")

</div>

> [@rsx](#):
>
> Best practice is to put all new Windows command objects in a global zone that is also existing at your Windows machines. We are using `windows-commands` as

sorry for my stupid questions, but how do I get the new windows commands into a zone

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 9, 2020, 11:50am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/6 "2020-07-09T11:50:21Z")

</div>

Don’t mind, newbies questions are welcome. First you need to add such a section to every zones.conf:

```auto
object Zone "windows-commands" {
   global = true
}

```

Second, you need to create the according directory `/etc/icinga2/zones.d/windows-commands/` at your master only. Third, place every command object that shall be executed on your Windows agent in that directory only. Every time icinga2 gets a reload trigger this directory incl. every sub directory is sychronized to all nodes that have `windows-commands` as global zone defined.

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 9, 2020, 12:43pm UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/7 "2020-07-09T12:43:05Z")

</div>

> [@rsx](#):
>
> to every zones.conf

you mean aon the Windows Agents and the Icinga Server?

> [@rsx](#):
>
> place every command object that shall be executed on your Windows agent in that directory

“every command object” you mean a file like the commands.conf?

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 9, 2020, 12:45pm UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/8 "2020-07-09T12:45:51Z")

</div>

> [@el-dummy](#):
>
> you mean aon the Windows Agents and the Icinga Server?

Right.

> [@el-dummy](#):
>
> “every command object” you mean a file like the commands.conf?

The file name doesn’t matter at all. I’d even recommend to a have one file per command object.

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 9, 2020, 1:48pm UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/9 "2020-07-09T13:48:40Z")

</div>

Now I have insert the this

```auto
object Zone "windows-commands" {
   global = true
}

```

in the zones.conf of my Agent and in the /etc/icinga2/zones.conf from my Server.  
I have create a folder /etc/icinga2/Zones.d/windows-commands/  
In this folder I create a file “win\_powershellcheck\_x86.conf”

After a deploy from my Icinga2 GU I was hoping to find the win\_powershell\_x86.conf file on the agent. But it is not there. In the GUI cannot find the zone windows-command.

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 9, 2020, 1:52pm UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/10 "2020-07-09T13:52:41Z")

</div>

> [@el-dummy](#):
>
> I have create a folder /etc/icinga2/Zones.d/windows-commands/

Linux file and directory names are case sensitive, hence, directory name needs to be `/etc/icinga2/zones.d/windows-commands/`

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 6:18am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/11 "2020-07-10T06:18:07Z")

</div>

This was only a typing failure from me

# pwd

/etc/icinga2/zones.d/windows-commands

have I to create the windows-commands folder on the Agent too?

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 10, 2020, 6:21am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/12 "2020-07-10T06:21:08Z")

</div>

> [@el-dummy](#):
>
> have I to create the windows-commands folder on the Agent too?

No, icinga will do that (you’ll find it here C:\ProgramData\icinga2\var\lib\icinga2\api\zones\windows-commands).

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 6:26am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/13 "2020-07-10T06:26:29Z")

</div>

ok… I looked only here:  
c:\Program Files\ICINGA2\

“c:\ProgramData\icinga2\var\lib\icinga2\api\zones” there is only a director-global folder.

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 10, 2020, 6:31am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/14 "2020-07-10T06:31:44Z")

</div>

Does your agent recognize the `windows-commands` zone? Check with

> “c:\Program Files\ICINGA2\sbin\icinga2.exe” object list -n windows-commands

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 7:11am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/15 "2020-07-10T07:11:07Z")

</div>

The output is empty  
which zones.conf have I to edit:

c:\ProgramData\icinga2\etc\icinga2\zones.conf

(it looks like only a sample)  
or

c:\Program Files\ICINGA2\share\skel\etc\icinga2\zones.conf

## Now I have both edit both in the ProgarmData

```
 /*
  * Generated by Icinga 2 node setup commands
  * on 2020-02-10 11:14:45 +0100
  */
 
 object Endpoint "testICINGA.test.de" {
 	host = "testICINGA.test.de"
 	port = "5665"
 }
 
 object Zone "master" {
 	endpoints = ["testICINGA.test.de"]
 }
 
 object Endpoint "windowsAgent.test.de" {
 }
 
 object Zone "windowsAgent.test.de" {
 	endpoints = ["windowsAgent.test.de"]
 	parent = "master"
 }
 
 object Zone "global-templates" {
 	global = true
 }
 
 object Zone "director-global" {
 	global = true
 }
 
 object Zone "windows-commands" {
    global = true
 }

```

* * *

This is the zones.conf on the Server \etc\icinga2\zones.conf

```
 /*
  * Generated by Icinga 2 node setup commands
  * on 2020-02-10 15:19:05 +0100
  */
 
 object Endpoint "testICINGA.test.de" {
 }
 
 object Zone "testICINGA.test.de" {
         endpoints = ["testICINGA.test.de"]
 }
 
 object Zone "global-templates" {
         global = true
 }
 
 object Zone "director-global" {
         global = true
 }
 
 object Zone "windows-commands" {
    global = true
 }
```

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 7:34am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/16 "2020-07-10T07:34:16Z")

</div>

I’m surprised that I don’t see the zone in Icinga Director

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 10, 2020, 7:56am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/17 "2020-07-10T07:56:12Z")

</div>

After changing zones.conf you need to run **Kickstart Wizard** and to reload icinga on your master and restart on you agent.

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 8:03am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/18 "2020-07-10T08:03:45Z")

</div>

Now I have the zone “windows-commands” on the server deleted. Then created the zone “windows commands” via the director. Now I see the following output on the agent:

```
c:\Program Files\ICINGA2\sbin>icinga2.exe object list -n windows-commands
Object 'windows-commands' of type 'Zone':
  % declared in 'C:/ProgramData/icinga2/var/lib/icinga2/api/zones/director-global/director/zones.conf', lines 1:0-1:29
  * __name = "windows-commands"
  * endpoints = null
  * global = true
    % = modified in 'C:/ProgramData/icinga2/var/lib/icinga2/api/zones/director-global/director/zones.conf', lines 2:5-2:17
  * name = "windows-commands"
  * package = "_cluster"
  * parent = ""
  * source_location
    * first_column = 0
    * first_line = 1
    * last_column = 29
    * last_line = 1
    * path = "C:/ProgramData/icinga2/var/lib/icinga2/api/zones/director-global/director/zones.conf"
  * templates = ["windows-commands"]
    % = modified in 'C:/ProgramData/icinga2/var/lib/icinga2/api/zones/director-global/director/zones.conf', lines 1:0-1:29
  * type = "Zone"
  * zone = "director-global"

```

On The Server I get now a warning by the command icinga daemon -C

[2020-07-10 09:52:57 +0200] warning/config: Ignoring directory ‘/etc/icinga2/zones.d/windows-commands’ for unknown zone ‘windows-commands’.

---

<div class="post-metadata">

**Author:** ![el-dummy](https://community.icinga.com/user_avatar/community.icinga.com/el-dummy/32/2825_2.png) [@el-dummy](https://community.icinga.com/u/el-dummy)\
**Post date:** [July 10, 2020, 9:26am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/19 "2020-07-10T09:26:14Z")

</div>

Now I have run the kickstart and I see the zone “windows-commands” in the Director. The output from the command “icinga2.exe object list -n windows-commands” is empty.

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [July 10, 2020, 11:27am UTC](https://community.icinga.com/t/service-check-windows-powershell-script/4926/20 "2020-07-10T11:27:38Z")

</div>

For me it’s ok if you go your own way. However, I cannot help anymore.

[Next page](https://community.icinga.com/t/service-check-windows-powershell-script/4926.md?page=2)
