//dbconfig.c
int DChost_deactivate(zbx_uint64_t hostid, unsigned char agent_type, const zbx_timespec_t *ts,
zbx_agent_availability_t *in, zbx_agent_availability_t *out, const char *error_msg)
{
int ret = FAIL, errors_from,disable_until;
const char *error;
unsigned char available;
ZBX_DC_HOST *dc_host;
/* don't try deactivating host if the unreachable delay has not passed since the first error */
if (CONFIG_UNREACHABLE_DELAY > ts->sec - in->errors_from)
goto out;
WRLOCK_CACHE;
if (NULL == (dc_host = (ZBX_DC_HOST *)zbx_hashset_search(&config->hosts, &hostid)))
goto unlock;
/* Don't try deactivating host if: */
/* - (server, proxy) it's not monitored any more; */
/* - (server) it's monitored by proxy. */
if ((0 != (program_type & ZBX_PROGRAM_TYPE_SERVER) && 0 != dc_host->proxy_hostid) ||
HOST_STATUS_MONITORED != dc_host->status)
{
goto unlock;
}
DChost_get_agent_availability(dc_host, agent_type, in);
available = in->available;
error = in->error;
if (0 == in->errors_from)
{
/* first error, schedule next unreachable check */
errors_from = ts->sec;
disable_until = ts->sec + CONFIG_UNREACHABLE_DELAY;
}
else
{
errors_from = in->errors_from;
disable_until = in->disable_until;
/* 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;
}
}
}
zbx_agent_availability_init(out, available, error, errors_from, disable_until);
DChost_set_agent_availability(dc_host, ts->sec, agent_type, out);
if (ZBX_FLAGS_AGENT_STATUS_NONE != out->flags)
ret = SUCCEED;
unlock:
UNLOCK_CACHE;
out:
return ret;
}
if (0 == in->errors_from)
{
/* first error, schedule next unreachable check */
errors_from = ts->sec;
disable_until = ts->sec + CONFIG_UNREACHABLE_DELAY;
}
else
{
errors_from = in->errors_from;
disable_until = in->disable_until