;
/* Check if other pollers haven't already attempted deactivating host. */
/* In that case should wait the initial unreachable delay before */
/* trying to make it unavailable. */
if (CONFIG_UNREACHABLE_DELAY <= ts->sec - errors_from)
{
/* repeating error */
if (CONFIG_UNREACHABLE_PERIOD > ts->sec - errors_from)
{
/* leave host available, schedule next unreachable check */
disable_until = ts->sec + CONFIG_UNREACHABLE_DELAY;
}
else
{
/* make host unavailable, schedule next unavailable check */
disable_until = ts->sec + CONFIG_UNAVAILABLE_DELAY;
available = HOST_AVAILABLE_FALSE;
error = error_msg;
}
}
}
如果错误第一次出现:
错误发生时间=检查的时间戳 下次的检查时间 = 时间戳+15s 否则: 错误发生时间 = in->errors_from 下次检查时间 = in->disable_until 检查的时间戳-错误发生时间>=15s: 检查的时间戳-错误发生时间< 45s: 下次的检查时间 = 检查的时间戳+15s 否则: 下一次检查时间 =检查的时间戳+15s 主机可用性为不可用
用配置文件来解释就是: 如果由于网络等原因没有实现项目的及时监控,第一次的监控间隔为UnreachableDelay时间(15s),如果这次也失败了,那么从第一次失败到本次检查在UnreachablePeriod时间内,会再次在UnreachableDelay时间后监控
#9 更新数据库中的主机可用性信息
// poller.c
static int db_host_update_availability(const zbx_host_availability_t *ha)
{
char *sql = NULL;
size_t sql_alloc = 0, sql_offset = 0;
if (SUCCEED == zbx_sql_add_host_availability(&sql, &sql_alloc, &sql_offset, ha))
{
DBbegin();
DBexecute("%s", sql);
DBcommit();
zbx_free(sql);
return SUCCEED;
}
return FAIL;
}
#10 根据agent_type设置主机可用性信息
//poller.c
static int host_set_availability(DC_HOST *dc_host, unsigned char agent, const zbx_host_availability_t *ha)
{
const zbx_agent_availability_t *availability = &ha->agents[agent];
unsigned char *pavailable;
int *perrors_from, *pdisable_until;
char *perror;
switch (agent)
{
case ZBX_AGENT_ZABBIX:
pavailable = &dc_host->available;
perror = dc_host->error;
perrors_from = &dc_host->errors_from;
pdisable_until = &dc_host->disable_until;
break;
case ZBX_AGENT_SNMP:
pavailable = &dc_host->snmp_available;
perror = dc_host->snmp_error;
perrors_from = &dc_host->snmp_errors_from;
pdisable_until = &dc_host->snmp_disable_until;
break;
case ZBX_AGENT_IPMI:
pavailable = &dc_host->ipmi_available;
perror = dc_host->ipmi_error;
perrors_from = &dc_host->ipmi_errors_from;
pdisable_until = &dc_host->ipmi_disable_until;
break;
case ZBX_AGENT_JMX:
pavailable = &dc_host->jmx_available;
perror = dc_host->jmx_error;
pdisable_until = &dc_host->jmx_disable_until;
perrors_from = &dc_host->jmx_errors_from;
break;
default:
return FAIL;
}
if (0 != (availability->flags & ZBX_FLAGS_AGENT_STATUS_AVAILABLE))
*pavailable = availability->available;
if (0 != (availability->flags & ZBX_FLAGS_AGENT_STATUS_ERROR))
zbx_strlcpy(perror, availability->error, HOST_ERROR_LEN_MAX);
if (0 != (availability->flags & ZBX_FLAGS_AGENT_STATUS_ERRORS_FROM))
*perrors_from = availability->errors_from;
if (0 != (availability->flags & ZBX_FLAGS_AGENT_STATUS_DISABLE_UNTIL))
*pdisable_until = availability->disable_until;
return SUCCEED;
}
#11-16
如果是第一次检查:
记录日志first network error, wait for 15 seconds
否则:
&nbs