Merge pull request #1319 from spinza/timeout

Add timeout on unix agent execution after connect.
This commit is contained in:
Neil Lathwood
2015-06-21 21:37:18 +01:00
2 changed files with 17 additions and 2 deletions

View File

@@ -622,4 +622,9 @@ $config['ipmi']['type'][] = "open";
// Options needed for dyn config - do NOT edit
$dyn_config['email_backend'] = array('mail','sendmail','smtp');
$dyn_config['email_smtp_secure'] = array('', 'tls', 'ssl');
// Unix-agent poller module config settings
$config['unix-agent-connection-time-out'] = 10; //seconds
$config['unix-agent-read-time-out'] = 10; //seconds
?>

View File

@@ -10,15 +10,25 @@ if ($device['os_group'] == "unix")
$agent_port='6556';
$agent_start = utime();
$agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, 10);
$agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, $config['unix-agent-connection-time-out'] );
// Set stream timeout (for timeouts during agent fetch
stream_set_timeout($agent,$config['unix-agent-read-time-out']);
$agentinfo = stream_get_meta_data($agent);
if (!$agent)
{
echo "Connection to UNIX agent failed on port ".$port.".";
} else {
while (!feof($agent))
// fetch data while not eof and not timed-out
while ((!feof($agent)) && (!$agentinfo['timed_out']))
{
$agent_raw .= fgets($agent, 128);
$agentinfo = stream_get_meta_data($agent);
}
if ($agentinfo['timed_out'])
{
echo "Connection to UNIX agent timed out during fetch on port ".$port.".";
}
}