Ad Widget

Collapse

Try to run powershell script Timeout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frazou1
    Junior Member
    • Feb 2025
    • 2

    #1

    Try to run powershell script Timeout

    I set a system.run command in zabbix

    When the agent try to execute i always get Timeout while executing a shell script. I already increase timeout on server side at 30s and client side at 30s

    2025/02/17 12:13:45.002819 [SystemRun] Executing command:'powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Cortex\script\version.ps1"'
    2025/02/17 12:13:49.056493 check 'system.run[powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Cortex\script\version.ps1"]' is not supported: Timeout while executing a shell script.

  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #2
    Why use system.run for 1 specific script, better user userparameter
    Code:
    UserParameter=getsoftware,powershell -ExecutionPolicy bypass -File "C:\Program Files\Zabbix Agent 2\installedsoftware.ps1"
    The patch to the script can be something else but you get the idea.
    In this why you can use a zabbix agent (passive or active) with itemkey, getsoftware
    I have many of these Userparamaters. If you have a simple script you can also use
    Code:
    UserParameter=stscert, powershell -c "'['Get-ChildItem -path cert:\LocalMachine\My | where {$_.Subject -like '*my app name*'} | select Thumbprint, NotAfter, Issuer | ConvertTo-json -Compress ;']'"
    The ; is a newline for the powershell command.
    With zabbix 7 these time-out option should work

    Comment

    • vikkar
      Junior Member
      • Aug 2025
      • 3

      #3
      I have the same problem, i have a script that checks ad-replications on DC's.

      check_ad_replication.ps1
      Code:
      # Run repadmin and capture output
      try {
      $repadminOutput = repadmin /replsummary
      } catch {
      Write-Host "Failed to execute 'repadmin'. Please check if the command exists and if you have the necessary permissions."
      exit
      }
      
      # Variable to keep track of the highest number of fails
      $maxFails = 0
      
      # Process each line from the output
      $repadminOutput | ForEach-Object {
      # Match the line containing "fails/total"
      if ($_ -match "\s(\d+)\s*/\s*(\d+)") {
      $fails = [int]$matches[1] # Retrieves the "fails" value
      
      # Check if this "fails" value is higher than what we have so far
      if ($fails -gt $maxFails) {
      $maxFails = $fails
      }
      }
      }
      
      # Output the highest number of "fails"
      Write-Host "$maxFails"

      Zabbix agent 2 (7.4.1)
      "Check 'ad.replication.status' is not supported: Timeout occurred while gathering data."

      Config-file:
      Code:
      RefreshActiveChecks=600
      Timeout=30
      UserParameter=ad.replication.status, powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\Zabbix Agent 2\scripts\check_ad_replication.ps1"
      the same scripts works fine on others DC's running older Zabbix agent (4.4.10)

      Comment

      • vikkar
        Junior Member
        • Aug 2025
        • 3

        #4
        Originally posted by vikkar
        I have the same problem, i have a script that checks ad-replications on DC's.

        check_ad_replication.ps1
        Code:
        # Run repadmin and capture output
        try {
        $repadminOutput = repadmin /replsummary
        } catch {
        Write-Host "Failed to execute 'repadmin'. Please check if the command exists and if you have the necessary permissions."
        exit
        }
        
        # Variable to keep track of the highest number of fails
        $maxFails = 0
        
        # Process each line from the output
        $repadminOutput | ForEach-Object {
        # Match the line containing "fails/total"
        if ($_ -match "\s(\d+)\s*/\s*(\d+)") {
        $fails = [int]$matches[1] # Retrieves the "fails" value
        
        # Check if this "fails" value is higher than what we have so far
        if ($fails -gt $maxFails) {
        $maxFails = $fails
        }
        }
        }
        
        # Output the highest number of "fails"
        Write-Host "$maxFails"

        Zabbix agent 2 (7.4.1)
        "Check 'ad.replication.status' is not supported: Timeout occurred while gathering data."

        Config-file:
        Code:
        RefreshActiveChecks=600
        Timeout=30
        UserParameter=ad.replication.status, powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\Zabbix Agent 2\scripts\check_ad_replication.ps1"
        the same scripts works fine on others DC's running older Zabbix agent (4.4.10)
        I have done some more troubleshooting and i can run the script manually from both proxy and from the host itself.

        On Host
        Code:
        PS C:\Program Files\Zabbix Agent 2> .\zabbix_agent2.exe -t ad.replication.status
        ad.replication.status [s|0]
        On Proxy
        Code:
        mgmt-zbx-proxy:~$ zabbix_get -s [host] -k ad.replication.status
        0

        Comment

        • vikkar
          Junior Member
          • Aug 2025
          • 3

          #5
          Originally posted by vikkar

          I have done some more troubleshooting and i can run the script manually from both proxy and from the host itself.

          On Host
          Code:
          PS C:\Program Files\Zabbix Agent 2> .\zabbix_agent2.exe -t ad.replication.status
          ad.replication.status [s|0]
          On Proxy
          Code:
          mgmt-zbx-proxy:~$ zabbix_get -s [host] -k ad.replication.status
          0
          SOLVED!

          The ITEM Timeout (in webgui) was set to 3sec (default) which was not enough for script to run and send back to zabbix-server through zabbix-proxy. Changed to 30sec and working now.

          Comment

          Working...