Ad Widget

Collapse

Use Windows Zabbix agent as lightweight "proxy"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • troffasky
    Senior Member
    • Jul 2008
    • 565

    #1

    Use Windows Zabbix agent as lightweight "proxy"

    Scenario:
    Central Site with only Windows VMs. Customer does not want to pay for a Linux VM to run Zabbix proxy on.
    Remote sites VPN tunnel to here. No servers at remote sites.
    Requirement: monitor connectivity between remote sites and central site.

    I am sure others have faced a similar scenario. I assume I can create plenty of custom items on 1 agent at Central Site that do something simple like ping a remote device 10 times and take an average.
    But is there a way to script/automate this to minimise the amount of manual fiddling about?
  • Viktors Fomics
    Member
    • Oct 2025
    • 42

    #2
    Hello

    If only ping monitoring is required, a scheduled PowerShell script can be set up to regularly ping all target devices and store the results as JSON. Afterwards a custom UserParameter in the agent can be created to read that JSON and send it to Zabbix server to be used as the master item; from this master item dependent items can be created with the help of JSONPath peprocessing to get metrics (like average latency or packet loss) for each device.

    Comment

    • Viktors Fomics
      Member
      • Oct 2025
      • 42

      #3
      If going a bit into details here, the motivation for a solution of that type is that using just UserParameter directly can result in timeouts, as every ping takes some time, so doing this part externally as a scheduled task would make sense. The list of hosts could be stored in a separate file (targets.txt in the example script below) that is accessible for the script and the script itself would look approximately like this:

      Code:
      $jsonFile = "C:\Zabbix\scripts\ping_results.json"
      $hostsFile = "C:\Zabbix\scripts\targets.txt"
      
      $hosts = Get-Content $hostsFile | Where-Object { $_ -and $_ -notmatch '^\s*$' }
      $results = @()
      
      foreach ($host in $hosts) {
      $ping = Test-Connection -ComputerName $host -Count 4 -ErrorAction SilentlyContinue
      if ($ping) {
      $avg = ($ping | Measure-Object ResponseTime -Average).Average
      $min = ($ping | Measure-Object ResponseTime -Minimum).Minimum
      $max = ($ping | Measure-Object ResponseTime -Maximum).Maximum
      $loss = 100 - (($ping.Count / 4) * 100)
      } else {
      $avg = $null
      $min = $null
      $max = $null
      $loss = 100
      }
      
      $results += [PSCustomObject]@{
      host = $host
      avg_latency = [math]::Round($avg,2)
      min_latency = $min
      max_latency = $max
      packet_loss = $loss
      }
      }
      
      $results | ConvertTo-Json | Set-Content -Path $jsonFile -Force

      So as a result there will be the required json file, which can be sent to Zabbix server with the following UserParameter=ping.json,Get-Content "C:\Zabbix\scripts\ping_results.json", this agent item with key ping.json would be the master item containing all JSON content, a dependant item can be derived from it with the help of JSONPath preprocessing step. Assuming JSON file's contents will be something like this: [{"host":"10.1.1.1","avg_latency":2.3,"packet_lo ss" :0},
      {"host":"10.1.2.1","avg_latency":5.1,"packet_lo ss" :0}]
      , the JSONPath expression to get the first host's average latency would be: $[?(@.host == '10.1.1.1')].avg_latency.first().


      Comment

      Working...