zabbix报错分析

zabbix报错分析

报错信息如下:

3128:20150429:114455.871 history data from active proxy on “115.29.182.109” failed: proxy “jinrong” not found

查找源码

[root@monitor src]# grep “history data from active proxy” * -r|more
zabbix_server/trapper/trapper.c: zabbix_log(LOG_LEVEL_WARNING, “history data from active proxy on \”%s\” failed: %s”,

得出是trapper.c 导致。

分析trapper.c

/******************************************************************************
 *                                                                            *
 * Function: recv_proxyhistory                                                *
 *                                                                            *
 * Purpose: processes the received values from active proxies                 *
 *                                                                            *
 ******************************************************************************/
static void     recv_proxyhistory(zbx_sock_t *sock, struct zbx_json_parse *jp)
{
        const char      *__function_name = "recv_proxyhistory";
        zbx_uint64_t    proxy_hostid;
        char            host[HOST_HOST_LEN_MAX], *error = NULL;
        int             ret;

        zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

        if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
        {
                zabbix_log(LOG_LEVEL_WARNING, "history data from active proxy on \"%s\" failed: %s",
                                get_ip_by_socket(sock), error);
                goto out;
        }

        update_proxy_lastaccess(proxy_hostid);

        ret = process_hist_data(sock, jp, proxy_hostid, error, sizeof(error));
out:
        zbx_send_response(sock, ret, error, CONFIG_TIMEOUT);

        zbx_free(error);

        zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}

也就是说 get_active_proxy_id(jp, &proxy_hostid, host, &error)) 这个函数执行不正确的话,会报上面的错。
问题又转化为 get_active_proxy_id的执行了。
继续搜索 get_active_proxy_id 这个函数的源码文件,

[root@monitor src]# grep get_active_proxy_id * -r
Binary file libs/zbxdbhigh/libzbxdbhigh.a matches
Binary file libs/zbxdbhigh/libzbxdbhigh_a-proxy.o matches
libs/zbxdbhigh/proxy.c: * Function: get_active_proxy_id                                              *
libs/zbxdbhigh/proxy.c:int  get_active_proxy_id(struct zbx_json_parse *jp, zbx_uint64_t *hostid, char *host, char **error)
Binary file zabbix_server/trapper/proxyhosts.o matches
zabbix_server/trapper/proxydiscovery.c: if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
zabbix_server/trapper/trapper.c:    if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
zabbix_server/trapper/trapper.c:    if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
Binary file zabbix_server/trapper/trapper.o matches
Binary file zabbix_server/trapper/proxydiscovery.o matches
Binary file zabbix_server/trapper/proxyconfig.o matches
zabbix_server/trapper/proxyautoreg.c:   if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
zabbix_server/trapper/proxyconfig.c:    if (SUCCEED != get_active_proxy_id(jp, &proxy_hostid, host, &error))
Binary file zabbix_server/trapper/proxyautoreg.o matches
Binary file zabbix_server/trapper/libzbxtrapper.a matches
zabbix_server/trapper/proxyhosts.c: if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error)))
Binary file zabbix_server/zabbix_server matches

可以看到是在libs/zbxdbhigh/proxy.c 文件中定义

/******************************************************************************
 *                                                                            *
 * Function: get_active_proxy_id                                              *
 *                                                                            *
 * Purpose: extract a proxy name from JSON and find the proxy ID in database. *
 *          The proxy must be configured in active mode.                      *
 *                                                                            *
 * Parameters: jp            - [IN] JSON with the proxy name                  *
 *             hostid        - [OUT] proxy host ID found in database          *
 *             host          - [IN] buffer with minimum size                  *
 *                                  'HOST_HOST_LEN_MAX'                       *
 *             error         - [OUT] error message                            *
 *                                                                            *
 * Return value:  SUCCEED - proxy ID was found in database                    *
 *                FAIL    - an error occurred (e.g. an unknown proxy or the   *
 *                          proxy is configured in passive mode               *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 ******************************************************************************/
int     get_active_proxy_id(struct zbx_json_parse *jp, zbx_uint64_t *hostid, char *host, char **error)
{
        DB_RESULT       result;
        DB_ROW          row;
        char            *host_esc;
        int             ret = FAIL, status;

        if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, HOST_HOST_LEN_MAX))
        {
                if (FAIL == zbx_check_hostname(host))
                {
                        *error = zbx_dsprintf(*error, "invalid proxy name \"%s\"", host);
                        return ret;
                }

                host_esc = DBdyn_escape_string(host);

                result = DBselect(
                                "select hostid,status"
                                " from hosts"
                                " where host='%s'"
                                        " and status in (%d,%d)"
                                        ZBX_SQL_NODE,
                                host_esc, HOST_STATUS_PROXY_ACTIVE, HOST_STATUS_PROXY_PASSIVE,
                                DBand_node_local("hostid"));

                zbx_free(host_esc);

                if (NULL != (row = DBfetch(result)) && FAIL == DBis_null(row[0]))
                {
                        if (SUCCEED == is_uint31(row[1], &status))
                        {
                                if (HOST_STATUS_PROXY_ACTIVE == status)
                                {
                                        ZBX_STR2UINT64(*hostid, row[0]);
                                        ret = SUCCEED;
                                }
                                else
                                {
                                        *error = zbx_dsprintf(*error, "proxy \"%s\" is configured in passive mode",
                                                        host);
                                }
                        }
                        else
                                THIS_SHOULD_NEVER_HAPPEN;
                }
                else
                        *error = zbx_dsprintf(*error, "proxy \"%s\" not found", host);

                DBfree_result(result);
        }
        else
                *error = zbx_strdup(*error, "missing name of proxy");

        return ret;
}

分析这段源码,也就是说hosts表中查不到的时候是会报 proxy \”%s\” not found 的。

hosts表结构

MySQL [zabbix]> desc hosts;
+——————–+———————+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——————–+———————+——+—–+———+——-+
| hostid | bigint(20) unsigned | NO | PRI | NULL | |
| proxy_hostid | bigint(20) unsigned | YES | MUL | NULL | |
| host | varchar(64) | NO | MUL | | |
| status | int(11) | NO | MUL | 0 | |
| disable_until | int(11) | NO | | 0 | |
| error | varchar(128) | NO | | | |
| available | int(11) | NO | | 0 | |
| errors_from | int(11) | NO | | 0 | |
| lastaccess | int(11)

分析

观察hosts表数据,其实发现status 就是主机状态,HOST_STATUS_PROXY_ACTIVE ,HOST_STATUS_PROXY_PASSIVE 为主动,被动模式的代理,结合zabbix的理论,active 模式的proxy ,只需要配置proxy的名字,不需要配置ip 或者dns 名,是会主动建立和server的连接的。那么现在建立连接的时候没有在hosts表中发现配置,就会报 proxy not found的的错误。联想到之前确实删除过proxy配置,然而机器上面的proxy 还在运行,所以会导致这种情况。但是之前2.2.3都没有这样的报警的。要么是2.2.9里面新push的代码。

处理

在dm 配置中加上原来jinrong的那个proxy 配置之后,zabbix server不在报这样的错。处理完毕。

后记

源码还是要尝试着看,毕竟是“源码面前了无秘密”。不一定要完全理解。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值