Ad Widget

Collapse

bypassing agent script timeout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wamsterdam
    Member
    • Apr 2013
    • 34

    #1

    bypassing agent script timeout

    Hello all,

    I am using a custom Low Level Discovery Windows PowerShell script to collect some statistics of user home directories. Zabbix Server is at version 2.4.1 and the particular Agent is a 2.4.8. The problem is that the script takes longer than the 30 seconds script timeout configured in the agent. I tried to bypass this timeout by having the script calling itself without waiting for this new process to finish. When I run this script from the Windows PowerShell commandline, this works fine. The first instance of the script exists fast and some time later the second one writes my statistics.txt file and than exits. But when I call the script from the Zabbix server using zabbix_get, the agent seem te wait for all instances to finish. When I call the 'wait' part as the second instance using zabbix_get, the agent response is exactly 10 seconds later. When I call the 'wait' part from powershell.exe on the remote machine, the response is instantly.

    A simplified version of my PowerShell script:

    Code:
    param([string] $action)
    
    $exe 	= "C:\Program Files\Zabbix Agent\zabbix_sender.exe"
    $server = "zabbix-server"
    $agent	= "sbs2011"
    $path	= "C:\SomePath\"
    $file	= $path + "statistics.txt"
    
    switch ($action) {
    	'discover'
    	{
    		# Return JSON string for Low Level Discovery	
    	break
    	}
    
    	'collect'
    	{
    		# Collect the statistics. This can take a lot longer than the timeout configured in Zabbix Agent
    		write-host "done collecting"
    	break
    	}
    	
    	'wait'
    	{
    		# For testing purposes
    		Start-Sleep -s 10
    		write-host "done waiting"
    	}
    	
    	'execute'
    	{
    		# Call the 'collect' part, but do not wait for the process to be terminated
    		$script	= $path + "this_script.ps1 collect"
    		$vars	= "-ExecutionPolicy ByPass"
    		
    		Start-Process $pshome\powershell.exe -ArgumentList "& `"\$script`" $vars"
    		write-host "second instance started"
    	break
    	}
    	
    	'zabbix'
    	{
    		# Call Zabbix Sender to write the contects of the statistics file to Zabbix Server
    		& $exe -z $server -i $file
    	break
    	}
    	
    	default 
    	{		
    		write-host "error - no action defined"
    	}
    }
    The UserParameter in my zabbix_agentd.conf for this item:

    Code:
    UserParameter=homedir.info[*],powershell.exe C:\SomePath\this_script.ps1 '$1'
    And I have a few items to call the different script parts:

    Code:
    homedir.info[execute] to start the collection of statistics
    homedir.info[zabbix] to insert the data into Zabbix
    But the big question is: why does Zabbix Agent wait for all instances to finish and not for the first script instance to finish?

    Thanks,
    Wouter
Working...