Monitoring service state in Zabbix by using Powershell script

In this article I will show you how to create a Powershell script that will discover certain services running on your Windows Servers. The script will then send service information (name and state) to my Zabbix monitoring server. You’ll see that the code is pretty simple to understand since it uses some basic Powershell commands.
I’ve used two user parameters keys to send data to Zabbix, one is used to populate host items while the other one sends the service state information:

#val parameter will be used to execute the script to either populate the items or retrieve values.

$services = get-service | Where-Object {$_.Name -like “IT*” } 
if ($val -eq “1”)
write-host “{“
write-host ” `”data`”:[“

foreach ($ser in $services)

    if ( $val -eq “1”)

        $line = ” { `”{#SERVICENAME}`”:`”” + $ser.Name + “`” },”
        Write-Host $line
        $computer = “$env:computername.$env:userdnsdomain”.ToLower()
        $line = “- getservice.state[`”” + $ser.Name + “`”] ” + $ser.Status
        write-host $line

# Close the JSON message
if ($val -eq “1”)
write-host ” ]”
write-host “}”

Now modify the Zabbix configuration file (zabbix_agentd config) on each server and add the following lines:, powershell -NoProfile -ExecutionPolicy Bypass -file “C:\Program Files\Zabbix Agent\UserParameters\script\GetService.ps1” -val 1
UserParameter=getservice.status, powershell -NoProfile -ExecutionPolicy Bypass -file “C:\Program Files\Zabbix Agent\UserParameters\script\GetService.ps1” -val 0 | “C:\Program Files\Zabbix Agent\zabbix_sender.exe” -v -c “C:\Program Files\Zabbix Agent\zabbix_agentd.conf” -i –


2 thoughts on “Monitoring service state in Zabbix by using Powershell script

  1. Hi,

    I’m trying to implement this script in zabbix.
    However, i’ve noticed some strange codes:

    I would change the following:
    instead of only taking processes on drive d:\ I would exclude everything in c:\windows
    #Get the processes that run on the machine from a certain path
    $colItems = Get-Process | Where-Object {$_.Path -notlike “C:\windows\*” -and $_.path -ne $null}

    Next is how you type the JSON file, this is much easier: (haven’t checked what the minimum requirement is for convertTo-JSON

    if ( $keys -eq “1”){
    Write-host ($colitems | select-object @{Name=’#processname’; Expression={$_.Processname}}, @{Name=’#path’; Expression={$_.path}}, @{Name=’#id’; Expression={$}} | ConvertTo-Json)


    can you shortly tell how to create the LLD in zabbix web interface, i’m having a hard time figuring it out.


  2. Hello,
    You can try to use something like
    If process path not (get-process | Where-Object { $_.Name -like “procesname” }).Path do

    For the json from what i know you can use get-process | ConvertTo-Json and it will simply convert all values to Json.

    For the low level discovery you need to use the discovery rules in a template or host and use items/triggers probes. You need to specify a key that will be used by Zabbix server to execute the script and fetch in the values. The key is then added in the userparameter section of the config file on each of the client nodes.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s