当前位置: 首页>>代码示例>>C++>>正文


C++ SET_MSG_RESULT函数代码示例

本文整理汇总了C++中SET_MSG_RESULT函数的典型用法代码示例。如果您正苦于以下问题:C++ SET_MSG_RESULT函数的具体用法?C++ SET_MSG_RESULT怎么用?C++ SET_MSG_RESULT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SET_MSG_RESULT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SYSTEM_CPU_DISCOVERY

int	SYSTEM_CPU_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    int			i;
    zbx_vector_uint64_t	cpus;
    struct zbx_json		json;

    zbx_vector_uint64_create(&cpus);

    if (SUCCEED != get_cpu_statuses(&cpus))
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Collector is not started."));
        zbx_vector_uint64_destroy(&cpus);
        return SYSINFO_RET_FAIL;
    }

    zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN);
    zbx_json_addarray(&json, ZBX_PROTO_TAG_DATA);

    for (i = 0; i < cpus.values_num; i++)
    {
        zbx_json_addobject(&json, NULL);

        zbx_json_adduint64(&json, "{#CPU.NUMBER}", i);
        zbx_json_addstring(&json, "{#CPU.STATUS}", (SYSINFO_RET_OK == cpus.values[i] ?
                "online" : "offline"), ZBX_JSON_TYPE_STRING);

        zbx_json_close(&json);
    }

    zbx_json_close(&json);
    SET_STR_RESULT(result, zbx_strdup(result->str, json.buffer));

    zbx_json_free(&json);
    zbx_vector_uint64_destroy(&cpus);

    return SYSINFO_RET_OK;
}
开发者ID:SDUATI,项目名称:Zabbix2.4.X,代码行数:37,代码来源:cpu.c

示例2: USER_PERFCOUNTER

int	USER_PERFCOUNTER(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
    PERF_COUNTERS *perfs = NULL;

    int	ret = SYSINFO_RET_FAIL;

    if ( !PERF_COLLECTOR_STARTED(collector) )
    {
        SET_MSG_RESULT(result, strdup("Collector is not started!"));
        return SYSINFO_RET_OK;
    }

    for(perfs = collector->perfs.pPerfCounterList; perfs; perfs=perfs->next)
    {
        if ( 0 == strcmp(perfs->name, param) )
        {
            SET_DBL_RESULT(result, perfs->lastValue);
            ret = SYSINFO_RET_OK;
            break;
        }
    }

    return ret;
}
开发者ID:Shmuma,项目名称:z,代码行数:24,代码来源:pdhmon.c

示例3: get_net_stat

static int	get_net_stat(const char *if_name, net_stat_t *ns, char **error)
{
#if defined(HAVE_LIBPERFSTAT)
    perfstat_id_t		ps_id;
    perfstat_netinterface_t	ps_netif;

    if (NULL == if_name || '\0' == *if_name)
    {
        *error = zbx_strdup(NULL, "Network interface name cannot be empty.");
        return SYSINFO_RET_FAIL;
    }

    strscpy(ps_id.name, if_name);

    if (-1 == perfstat_netinterface(&ps_id, &ps_netif, sizeof(ps_netif), 1))
    {
        *error = zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno));
        return SYSINFO_RET_FAIL;
    }

    ns->ibytes = (zbx_uint64_t)ps_netif.ibytes;
    ns->ipackets = (zbx_uint64_t)ps_netif.ipackets;
    ns->ierr = (zbx_uint64_t)ps_netif.ierrors;

    ns->obytes = (zbx_uint64_t)ps_netif.obytes;
    ns->opackets = (zbx_uint64_t)ps_netif.opackets;
    ns->oerr = (zbx_uint64_t)ps_netif.oerrors;

    ns->colls = (zbx_uint64_t)ps_netif.collisions;

    return SYSINFO_RET_OK;
#else
    SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for Perfstat API."));
    return SYSINFO_RET_FAIL;
#endif
}
开发者ID:HenryGeek,项目名称:auto_deploy,代码行数:36,代码来源:net.c

示例4: web_set_required_response

static int web_set_required_response(AGENT_RESULT *result, struct web *opt, const char *params, int param_id)
{
    char req_code_tmp[WEB_MAX_HTTP_CODE_STRLEN] = {0};
    zbx_uint64_t req_code_test;

    if (get_param(params, param_id, req_code_tmp, WEB_MAX_HTTP_CODE_STRLEN))
        goto failed;

    if (strlen(req_code_tmp))
    {
        if (is_uint_range(req_code_tmp, &req_code_test, WEB_MIN_HTTP_CODE, WEB_MAX_HTTP_CODE))
            goto failed;

        opt->required_response = (int) req_code_test;
        return SUCCEED;
    } else {
        opt->required_response = WEB_DEF_HTTP_CODE;
        return SUCCEED;
    }

failed:
    SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid RESPONSE CODE parameter", NULL));
    return FAIL;
}
开发者ID:dojci,项目名称:zabbix-2.2.6_webcheck,代码行数:24,代码来源:checks_web.c

示例5: SYSTEM_HOSTNAME

int	SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    char	*hostname;
    long 	hostbufsize = 0;

#ifdef _SC_HOST_NAME_MAX
    hostbufsize = sysconf(_SC_HOST_NAME_MAX) + 1;
#endif
    if (0 == hostbufsize)
        hostbufsize = 256;

    hostname = zbx_malloc(NULL, hostbufsize);

    if (0 != gethostname(hostname, hostbufsize))
    {
        zbx_free(hostname);
        SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
        return SYSINFO_RET_FAIL;
    }

    SET_STR_RESULT(result, hostname);

    return SYSINFO_RET_OK;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:24,代码来源:hostname.c

示例6: SYSTEM_CPU_UTIL

int	SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
    char cpuname[MAX_STRING_LEN];
    char type[MAX_STRING_LEN];
    char mode[MAX_STRING_LEN];
    
    int cpu_num = 0;

        assert(result);

        init_result(result);
    
        if(num_param(param) > 3)
        {
                return SYSINFO_RET_FAIL;
        }

        if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
        {
                cpuname[0] = '\0';
        }

    if(cpuname[0] == '\0')
    {
        /* default parameter */
        zbx_snprintf(cpuname, sizeof(cpuname), "all");
    }

    if(get_param(param, 2, type, sizeof(type)) != 0)
        {
                type[0] = '\0';
        }
        if(type[0] == '\0')
    {
        /* default parameter */
        zbx_snprintf(type, sizeof(type), "user");
    }
    
    if(get_param(param, 3, mode, sizeof(mode)) != 0)
        {
                mode[0] = '\0';
        }
    
        if(mode[0] == '\0')
    {
        /* default parameter */
        zbx_snprintf(mode, sizeof(mode), "avg1");
    }

    if ( !CPU_COLLECTOR_STARTED(collector) )
    {
        SET_MSG_RESULT(result, strdup("Collector is not started!"));
        return SYSINFO_RET_OK;
    }

    if(strcmp(cpuname,"all") == 0)
    {
        cpu_num = 0;
    }
    else
    {
        cpu_num = atoi(cpuname)+1;
        if ((cpu_num < 1) || (cpu_num > collector->cpus.count))
            return SYSINFO_RET_FAIL;
    }

    if( 0 == strcmp(type,"idle"))
    {
        if( 0 == strcmp(mode,"avg1"))		SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].idle1)
        else if( 0 == strcmp(mode,"avg5"))	SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].idle5)
        else if( 0 == strcmp(mode,"avg15"))	SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].idle15)
        else return SYSINFO_RET_FAIL;

    }
    else if( 0 == strcmp(type,"nice"))
开发者ID:Shmuma,项目名称:z,代码行数:75,代码来源:cpu.c

示例7: vfs_dev_rw

static int	vfs_dev_rw(const char *param, AGENT_RESULT *result, int rw)
{
    ZBX_SINGLE_DISKDEVICE_DATA *device;
    char		devname[32], tmp[16];
    int		type, mode, nparam;
    zbx_uint64_t	dstats[ZBX_DSTAT_MAX];
    char		*pd;			/* pointer to device name without '/dev/' prefix, e.g. 'da0' */

    if (3 < (nparam = num_param(param)))	/* too many parameters? */
        return SYSINFO_RET_FAIL;

    if (0 != get_param(param, 1, devname, sizeof(devname)))
        return SYSINFO_RET_FAIL;

    pd = devname;

    if ('\0' != *pd)
    {
        if (0 == strcmp(pd, "all"))
            *pd = '\0';
        else
        {
            /* skip prefix ZBX_DEV_PFX, if present */
            if (0 == strncmp(pd, ZBX_DEV_PFX, sizeof(ZBX_DEV_PFX) - 1))
                pd += sizeof(ZBX_DEV_PFX) - 1;
        }
    }

    if (0 != get_param(param, 2, tmp, sizeof(tmp)))
        *tmp = '\0';

    if ('\0' == *tmp || 0 == strcmp(tmp, "bps"))	/* default parameter */
        type = ZBX_DSTAT_TYPE_BPS;
    else if (0 == strcmp(tmp, "ops"))
        type = ZBX_DSTAT_TYPE_OPS;
    else if (0 == strcmp(tmp, "bytes"))
        type = ZBX_DSTAT_TYPE_BYTE;
    else if (0 == strcmp(tmp, "operations"))
        type = ZBX_DSTAT_TYPE_OPER;
    else
        return SYSINFO_RET_FAIL;

    if (type == ZBX_DSTAT_TYPE_BYTE || type == ZBX_DSTAT_TYPE_OPER)
    {
        if (nparam > 2)
            return SYSINFO_RET_FAIL;

        if (FAIL == get_diskstat(pd, dstats))
            return SYSINFO_RET_FAIL;

        if (ZBX_DSTAT_TYPE_BYTE == type)
            SET_UI64_RESULT(result, dstats[(ZBX_DEV_READ == rw ? ZBX_DSTAT_R_BYTE : ZBX_DSTAT_W_BYTE)]);
        else	/* ZBX_DSTAT_TYPE_OPER */
            SET_UI64_RESULT(result, dstats[(ZBX_DEV_READ == rw ? ZBX_DSTAT_R_OPER : ZBX_DSTAT_W_OPER)]);

        return SYSINFO_RET_OK;
    }

    if (0 != get_param(param, 3, tmp, sizeof(tmp)))
        *tmp = '\0';

    if ('\0' == *tmp || 0 == strcmp(tmp, "avg1"))	/* default parameter */
        mode = ZBX_AVG1;
    else if (0 == strcmp(tmp, "avg5"))
        mode = ZBX_AVG5;
    else if (0 == strcmp(tmp, "avg15"))
        mode = ZBX_AVG15;
    else
        return SYSINFO_RET_FAIL;

    if (NULL == collector)
    {
        /* CPU statistics collector and (optionally) disk statistics collector is started only when Zabbix */
        /* agentd is running as a daemon. When Zabbix agent or agentd is started with "-p" or "-t" parameter */
        /* the collectors are not available and keys "vfs.dev.read", "vfs.dev.write" with some parameters */
        /* (e.g. sps, ops) are not supported. */

        SET_MSG_RESULT(result, strdup("This parameter is available only in daemon mode when collectors are started."));
        return SYSINFO_RET_FAIL;
    }

    if (NULL == (device = collector_diskdevice_get(pd)))
    {
        if (FAIL == get_diskstat(pd, dstats))	/* validate device name */
            return SYSINFO_RET_FAIL;

        if (NULL == (device = collector_diskdevice_add(pd)))
            return SYSINFO_RET_FAIL;
    }

    if (ZBX_DSTAT_TYPE_BPS == type)	/* default parameter */
        SET_DBL_RESULT(result, (ZBX_DEV_READ == rw ? device->r_bps[mode] : device->w_bps[mode]));
    else if (ZBX_DSTAT_TYPE_OPS == type)
        SET_DBL_RESULT(result, (ZBX_DEV_READ == rw ? device->r_ops[mode] : device->w_ops[mode]));

    return SYSINFO_RET_OK;
}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:97,代码来源:diskio.c

示例8: PROC_NUM

int	PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    char	*procname, *proccomm, *param;
    int	zbx_proc_stat, count, i,
        proc_ok, stat_ok, comm_ok;

    int	proccount = 0;

    size_t	sz;

    struct passwd		*usrinfo;

#ifdef KERN_PROC2
    int			mib[6];
    struct kinfo_proc2	*proc = NULL;
#else
    int			mib[4];
    struct kinfo_proc	*proc = NULL;
#endif

    char	**argv = NULL, *args = NULL;
    size_t	argv_alloc = 0, args_alloc = 0;
    int	argc;

    if (4 < request->nparam)
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
        return SYSINFO_RET_FAIL;
    }

    procname = get_rparam(request, 0);
    param = get_rparam(request, 1);

    if (NULL != param && '\0' != *param)
    {
        errno = 0;

        if (NULL == (usrinfo = getpwnam(param)))
        {
            if (0 == errno)
                SET_MSG_RESULT(result, zbx_strdup(NULL, "Specified user does not exist."));
            else
                SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain user information: %s",
                        zbx_strerror(errno)));

            return SYSINFO_RET_FAIL;
        }
    }
    else
        usrinfo = NULL;

    param = get_rparam(request, 2);

    if (NULL == param || '\0' == *param || 0 == strcmp(param, "all"))
        zbx_proc_stat = ZBX_PROC_STAT_ALL;
    else if (0 == strcmp(param, "run"))
        zbx_proc_stat = ZBX_PROC_STAT_RUN;
    else if (0 == strcmp(param, "sleep"))
        zbx_proc_stat = ZBX_PROC_STAT_SLEEP;
    else if (0 == strcmp(param, "zomb"))
        zbx_proc_stat = ZBX_PROC_STAT_ZOMB;
    else
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
        return SYSINFO_RET_FAIL;
    }

    proccomm = get_rparam(request, 3);

    mib[0] = CTL_KERN;
    if (NULL != usrinfo)
    {
        mib[2] = KERN_PROC_UID;
        mib[3] = usrinfo->pw_uid;
    }
    else
    {
        mib[2] = KERN_PROC_ALL;
        mib[3] = 0;
    }

#ifdef KERN_PROC2
    mib[1] = KERN_PROC2;
    mib[4] = sizeof(struct kinfo_proc2);
    mib[5] = 0;

    sz = 0;
    if (0 != sysctl(mib, 6, NULL, &sz, NULL, 0))
    {
        SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s",
                zbx_strerror(errno)));
        return SYSINFO_RET_FAIL;
    }

    proc = (struct kinfo_proc2 *)zbx_malloc(proc, sz);
    mib[5] = (int)(sz / sizeof(struct kinfo_proc2));
    if (0 != sysctl(mib, 6, proc, &sz, NULL, 0))
    {
        zbx_free(proc);
        SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s",
//.........这里部分代码省略.........
开发者ID:HupuInc,项目名称:zabbix,代码行数:101,代码来源:proc.c

示例9: convert_result

static bool convert_result(PyObject *py_result, AGENT_RESULT *result,
        const char *request_key)
{
    uint64_t ui64;
    bool has_ui64_val;
    if (!get_uint64_attr_from_py(py_result, result_attr_ui64,
            &ui64, &has_ui64_val)) {
        log(LOG_ERR,
                "Unable to get value '%s': "
                "unable to get attribute '%s'",
                request_key, result_attr_ui64);
        return false;
    }
    if (has_ui64_val) {
        SET_UI64_RESULT(result, ui64);
    }

    double dbl;
    bool has_dbl_val;
    if (!get_double_attr_from_py(py_result, result_attr_dbl,
            &dbl, &has_dbl_val)) {
        log(LOG_ERR,
                "Unable to get value '%s': "
                "unable to get attribute '%s'",
                request_key, result_attr_dbl);
        return false;
    }
    if (has_dbl_val) {
        SET_DBL_RESULT(result, dbl);
    }

    char *str = NULL;
    if (!get_string_attr_from_py(py_result, result_attr_str, &str, true)) {
        log(LOG_ERR,
                "Unable to get value '%s': "
                "unable to get attribute '%s'",
                request_key, result_attr_str);
        return false;
    }
    if (str) {
        SET_STR_RESULT(result, str);
    }

    char *text = NULL;
    if (!get_string_attr_from_py(py_result, result_attr_text, &text, true)) {
        log(LOG_ERR,
                "Unable to get value '%s': "
                "unable to get attribute '%s'",
                request_key, result_attr_text);
        return false;
    }
    if (text) {
        SET_TEXT_RESULT(result, text);
    }

    char *msg = NULL;
    if (!get_string_attr_from_py(py_result, result_attr_msg, &msg, true)) {
        log(LOG_ERR,
                "Unable to get value '%s': "
                "unable to get attribute '%s'",
                request_key, result_attr_msg);
        return false;
    }
    if (msg) {
        SET_MSG_RESULT(result, msg);
    }

    return true;
}
开发者ID:im-0,项目名称:python-zabbix-modules,代码行数:69,代码来源:python_zabbix_modules.c

示例10: check_service

int	check_service(AGENT_REQUEST *request, const char *default_addr, AGENT_RESULT *result, int perf)
{
    unsigned short	port = 0;
    char		*service, *ip_str, ip[MAX_ZBX_DNSNAME_LEN + 1], *port_str;
    int		value_int, ret = SYSINFO_RET_FAIL;
    double		check_time;

    check_time = zbx_time();

    if (3 < request->nparam)
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
        return SYSINFO_RET_FAIL;
    }

    service = get_rparam(request, 0);
    ip_str = get_rparam(request, 1);
    port_str = get_rparam(request, 2);

    if (NULL == service || '\0' == *service)
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
        return SYSINFO_RET_FAIL;
    }

    if (NULL == ip_str || '\0' == *ip_str)
        strscpy(ip, default_addr);
    else
        strscpy(ip, ip_str);

    if (NULL != port_str && '\0' != *port_str && SUCCEED != is_ushort(port_str, &port))
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
        return SYSINFO_RET_FAIL;
    }

    if (0 == strncmp("net.tcp.service", get_rkey(request), 15))
    {
        if (0 == strcmp(service, "ssh"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_SSH_PORT;
            ret = check_ssh(ip, port, CONFIG_TIMEOUT, &value_int);
        }
        else if (0 == strcmp(service, "ldap"))
        {
#ifdef HAVE_LDAP
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_LDAP_PORT;
            ret = check_ldap(ip, port, CONFIG_TIMEOUT, &value_int);
#else
            SET_MSG_RESULT(result, zbx_strdup(NULL, "Support for LDAP check was not compiled in."));
#endif
        }
        else if (0 == strcmp(service, "smtp"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_SMTP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, validate_smtp, "QUIT\r\n", &value_int);
        }
        else if (0 == strcmp(service, "ftp"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_FTP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, validate_ftp, "QUIT\r\n", &value_int);
        }
        else if (0 == strcmp(service, "http"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_HTTP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, NULL, NULL, &value_int);
        }
        else if (0 == strcmp(service, "pop"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_POP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, validate_pop, "QUIT\r\n", &value_int);
        }
        else if (0 == strcmp(service, "nntp"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_NNTP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, validate_nntp, "QUIT\r\n", &value_int);
        }
        else if (0 == strcmp(service, "imap"))
        {
            if (NULL == port_str || '\0' == *port_str)
                port = ZBX_DEFAULT_IMAP_PORT;
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, validate_imap, "a1 LOGOUT\r\n", &value_int);
        }
        else if (0 == strcmp(service, "tcp"))
        {
            if (NULL == port_str || '\0' == *port_str)
            {
                SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
                return SYSINFO_RET_FAIL;
            }
            ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, NULL, NULL, &value_int);
        }
        else if (0 == strcmp(service, "https"))
//.........这里部分代码省略.........
开发者ID:zabbix,项目名称:zabbix,代码行数:101,代码来源:simple.c

示例11: evaluate_aggregate

/******************************************************************************
 *                                                                            *
 * Function: evaluate_aggregate                                               *
 *                                                                            *
 * Parameters: item      - [IN] aggregated item                               *
 *             grp_func  - [IN] one of ZBX_GRP_FUNC_*                         *
 *             groups    - [IN] list of comma-separated host groups           *
 *             itemkey   - [IN] item key to aggregate                         *
 *             item_func - [IN] one of ZBX_DB_GET_HIST_*                      *
 *             param     - [IN] item_func parameter (optional)                *
 *                                                                            *
 * Return value: SUCCEED - aggregate item evaluated successfully              *
 *               FAIL - otherwise                                             *
 *                                                                            *
 ******************************************************************************/
static int	evaluate_aggregate(DC_ITEM *item, AGENT_RESULT *res, int grp_func, const char *groups,
                               const char *itemkey, int item_func, const char *param)
{
    const char		*__function_name = "evaluate_aggregate";

    char			*sql = NULL;
    size_t			sql_alloc = 1024, sql_offset = 0;
    zbx_uint64_t		itemid;
    zbx_vector_uint64_t	itemids;
    DB_RESULT		result;
    DB_ROW			row;
    unsigned char		value_type;
    history_value_t		value;
    int			num = 0, ret = FAIL;

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() grp_func:%d groups:'%s' itemkey:'%s' item_func:%d param:'%s'",
               __function_name, grp_func, groups, itemkey, item_func, param);

    memset(&value, 0, sizeof(value));

    zbx_vector_uint64_create(&itemids);
    aggregate_get_items(&itemids, groups, itemkey);

    if (0 == itemids.values_num)
    {
        SET_MSG_RESULT(res, zbx_dsprintf(NULL, "No items for key [%s] in group(s) [%s]", itemkey, groups));
        goto clean;
    }

    sql = zbx_malloc(sql, sql_alloc);

    if (ZBX_DB_GET_HIST_VALUE == item_func)
    {
        zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
                           "select value_type,lastvalue"
                           " from items"
                           " where lastvalue is not null"
                           " and value_type in (%d,%d)"
                           " and",
                           ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
        DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "itemid", itemids.values, itemids.values_num);

        result = DBselect("%s", sql);

        while (NULL != (row = DBfetch(result)))
        {
            value_type = (unsigned char)atoi(row[0]);

            evaluate_one(item, &value, &num, grp_func, row[1], value_type);
        }
        DBfree_result(result);
    }
    else
    {
        int		clock_from;
        unsigned int	period;
        char		**h_value;

        if (FAIL == is_uint_suffix(param, &period))
        {
            SET_MSG_RESULT(res, zbx_strdup(NULL, "Invalid fourth parameter"));
            goto clean;
        }

        clock_from = time(NULL) - period;

        zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
                           "select itemid,value_type"
                           " from items"
                           " where value_type in (%d,%d)"
                           " and",
                           ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
        DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "itemid", itemids.values, itemids.values_num);

        result = DBselect("%s", sql);

        while (NULL != (row = DBfetch(result)))
        {
            ZBX_STR2UINT64(itemid, row[0]);
            value_type = (unsigned char)atoi(row[1]);

            h_value = DBget_history(itemid, value_type, item_func, clock_from, 0, NULL, NULL, 0);

            if (NULL != h_value[0])
                evaluate_one(item, &value, &num, grp_func, h_value[0], value_type);
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:checks_aggregate.c

示例12: get_value_agent

/******************************************************************************
 *                                                                            *
 * Function: get_value_agent                                                  *
 *                                                                            *
 * Purpose: retrieve data from Zabbix agent                                   *
 *                                                                            *
 * Parameters: item - item we are interested in                               *
 *                                                                            *
 * Return value: SUCCEED - data successfully retrieved and stored in result   *
 *                         and result_str (as string)                         *
 *               NETWORK_ERROR - network related error occurred               *
 *               NOTSUPPORTED - item not supported by the agent               *
 *               AGENT_ERROR - uncritical error on agent side occurred        *
 *               FAIL - otherwise                                             *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments: error will contain error message                                 *
 *                                                                            *
 ******************************************************************************/
int	get_value_agent(DC_ITEM *item, AGENT_RESULT *result)
{
    const char	*__function_name = "get_value_agent";
    zbx_socket_t	s;
    char		buffer[MAX_STRING_LEN];
    int		ret = SUCCEED;
    ssize_t		received_len;

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() host:'%s' addr:'%s' key:'%s'",
            __function_name, item->host.host, item->interface.addr, item->key);

    if (SUCCEED == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, item->interface.addr, item->interface.port, 0)))
    {
        zbx_snprintf(buffer, sizeof(buffer), "%s\n", item->key);
        zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", buffer);

        /* send requests using old protocol */
        if (SUCCEED != zbx_tcp_send_raw(&s, buffer))
            ret = NETWORK_ERROR;
        else if (FAIL != (received_len = zbx_tcp_recv_ext(&s, ZBX_TCP_READ_UNTIL_CLOSE, 0)))
            ret = SUCCEED;
        else
            ret = TIMEOUT_ERROR;
    }
    else
        ret = NETWORK_ERROR;

    if (SUCCEED == ret)
    {
        zbx_rtrim(s.buffer, " \r\n");
        zbx_ltrim(s.buffer, " ");

        zabbix_log(LOG_LEVEL_DEBUG, "get value from agent result: '%s'", s.buffer);

        if (0 == strcmp(s.buffer, ZBX_NOTSUPPORTED))
        {
            /* 'ZBX_NOTSUPPORTED\0<error message>' */
            if (sizeof(ZBX_NOTSUPPORTED) < s.read_bytes)
                zbx_snprintf(buffer, sizeof(buffer), "%s", s.buffer + sizeof(ZBX_NOTSUPPORTED));
            else
                zbx_snprintf(buffer, sizeof(buffer), "Not supported by Zabbix Agent");

            SET_MSG_RESULT(result, strdup(buffer));
            ret = NOTSUPPORTED;
        }
        else if (0 == strcmp(s.buffer, ZBX_ERROR))
        {
            zbx_snprintf(buffer, sizeof(buffer), "Zabbix Agent non-critical error");
            SET_MSG_RESULT(result, strdup(buffer));
            ret = AGENT_ERROR;
        }
        else if (0 == received_len)
        {
            zbx_snprintf(buffer, sizeof(buffer), "Received empty response from Zabbix Agent at [%s]."
                    " Assuming that agent dropped connection because of access permissions.",
                    item->interface.addr);
            SET_MSG_RESULT(result, strdup(buffer));
            ret = NETWORK_ERROR;
        }
        else if (SUCCEED != set_result_type(result, item->value_type, item->data_type, s.buffer))
            ret = NOTSUPPORTED;
    }
    else
    {
        zbx_snprintf(buffer, sizeof(buffer), "Get value from agent failed: %s",
                zbx_socket_strerror());
        SET_MSG_RESULT(result, strdup(buffer));
    }

    zbx_tcp_close(&s);

    zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

    return ret;
}
开发者ID:dreamsxin,项目名称:zabbix,代码行数:95,代码来源:checks_agent.c

示例13: redis_command

/******************************************************************************
 *                                                                            *
 * Function   : This function will run a redis command and set the reply      *
 * Returns    : 0 (success), 1 (failure)                                      *
 *                                                                            *
 ******************************************************************************/
int redis_command(AGENT_RESULT *result, char *zbx_key, redisContext *redisC, redisReply **redisRptr, char *command, char *param, int redisReplyType)
{

    // Declare Variables
    char          zbx_msg[MAX_LENGTH_MSG] = "";
    char          redisCmd[MAX_LENGTH_STRING];
    redisReply   *redisR;

    // If there are parameters
    if (param != NULL) {zbx_snprintf(redisCmd,MAX_LENGTH_STRING,"%s %s",command,param);}

    // If there are no parameters
    if (param == NULL) {zbx_snprintf(redisCmd,MAX_LENGTH_STRING,"%s",command);}

    // If the connection is lost
    if (redisC == NULL || redisC->err) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis connection lost (%s)",redisC->errstr);

        goto command_invalid;

    }

    // Run the redis command
    redisR = redisCommand(redisC,redisCmd);

    // If the connection is lost
    if (redisR == NULL) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis connection lost (%s)",redisC->errstr);

        goto command_invalid;

    }

    // If the reply type is an error
    if (redisR->type == REDIS_REPLY_ERROR) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis command error (%s)",redisR->str);

        goto command_invalid;


    }

    // If the redis reply type is to be checked
    if (redisReplyType == 9999) {goto command_valid;}

    // If the reply is not valid
    if (redis_reply_valid(redisR->type,redisReplyType,command,zbx_key,zbx_msg) == 1) {goto command_invalid;}

command_valid:

    // Assign the reply
    *redisRptr = redisR;

    return 0;

command_invalid:

    // Log message
    zabbix_log(LOG_LEVEL_DEBUG,"Module (%s) - %s - Key %s",MODULE,zbx_msg,zbx_key);

    // Set message
    SET_MSG_RESULT(result,strdup(zbx_msg));

    return 1;

}
开发者ID:jamescook000,项目名称:libzbxredis,代码行数:78,代码来源:libzbxredis.c

示例14: redis_session


//.........这里部分代码省略.........

    // Declare Variables
    char            zbx_msg[MAX_LENGTH_MSG] = "";
    redisReply     *redisR;
    redisContext   *redisC;
    struct timeval  timeout;

    // Set Timeout
    timeout.tv_sec = atol(redis_timeout);
    timeout.tv_usec = 0;

    // Attempt the connection
    redisC = redisConnectWithTimeout(redis_server,atol(redis_port),timeout);

    // If there was an error connecting
    if (redisC == NULL || redisC->err) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis connection failed (Unknown)");

        // If there is an error message
        if (redisC->err) {

            // Form message
            zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis connection failed (%s)",redisC->errstr);

        }

        goto session_invalid;

    }

    // Authenticate with blank password (The assumption is that there could be a blank password)
    if (strlen(redis_password) == 0) {redisR = redisCommand(redisC,"AUTH ''");}
    if (strlen(redis_password) > 0)  {redisR = redisCommand(redisC,"AUTH %s",redis_password);}

    // If the connection is lost
    if(redisR == NULL) {goto error_connection_lost;}

    // Free the reply
    freeReplyObject(redisR);

    // Test whether authentication has been successful
    redisR = redisCommand(redisC,"ECHO Authentication-Test");

    // If the connection is lost
    if(redisR == NULL) {goto error_connection_lost;}

    // If the authentication failed
    if (strcmp(redisR->str,"NOAUTH Authentication required.") == 0) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis authentication failed",MODULE);

        // Free the reply
        freeReplyObject(redisR);

        goto session_invalid;

    }

    // Free the reply
    freeReplyObject(redisR);

    // We want to set the client name in order to exclude from client discovery
    redisR = redisCommand(redisC,"CLIENT SETNAME %s",MODULE);

    // If the connection is lost
    if(redisR == NULL) {goto error_connection_lost;}

    // Free the reply
    freeReplyObject(redisR);

    goto session_valid;

error_connection_lost:

    // Form message
    zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"Redis connection lost (%s)",redisC->errstr);

    goto session_invalid;

session_valid:

    return redisC;

session_invalid:

    // Free the context
    redisFree(redisC);

    // Log message
    zabbix_log(LOG_LEVEL_DEBUG,"Module (%s) - %s - Key %s",MODULE,zbx_msg,zbx_key);

    // Set message
    SET_MSG_RESULT(result,strdup(zbx_msg));

    return NULL;

}
开发者ID:jamescook000,项目名称:libzbxredis,代码行数:101,代码来源:libzbxredis.c

示例15: validate_param

/*************************************************************
 *                                                           *
 * Function   : This function will validate standard params  *
 * Returns    : 0 (valid), 1 (invalid)                       *
 *                                                           *
 *************************************************************/
int validate_param(AGENT_RESULT *result,char *zbx_key, char *param, char *value, char *value_default, int allow_empty, int min, int max)
{

    // Declare variables
    char zbx_msg[MAX_LENGTH_MSG] = "";

    // If the value is empty and there is a default value
    if (strlen(value) == 0 && strlen(value_default) > 0) {

        // Set the value to default
        zbx_strlcpy(value,value_default,MAX_LENGTH_PARAM);

    }

    // If the value is empty and thats not allowed
    if (strlen(value) == 0 && ! allow_empty) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"%s must not be empty",param);

        goto param_invalid;

    }

    // If there is a minimum required
    if (min > 0 && atol(value) < min) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"%s must be an integer greater than or equal to %lld",param,min);

        goto param_invalid;

    }

    // If there is a maximum required
    if (max > 0 && atol(value) > max) {

        // Form message
        zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"%s must be an integer less than or equal to %lld",param,max);

        goto param_invalid;

    }

    // For specific parameters that required specific values
    if (strcmp(param,"Datatype") == 0) {

        // Validate value contents
        if (strcmp(value,"integer") != 0 &&
            strcmp(value,"float") != 0 &&
            strcmp(value,"string") != 0 &&
            strcmp(value,"text") != 0) {

            // Form message
            zbx_snprintf(zbx_msg,MAX_LENGTH_MSG,"%s must be an integer,float,string,text",param);

            goto param_invalid;

        }

    }

param_valid:

    return 0;

param_invalid:

        // Log message
        zabbix_log(LOG_LEVEL_DEBUG,"Module (%s) - %s - Key %s",MODULE,zbx_msg,zbx_key);

        // Set message
        SET_MSG_RESULT(result,strdup(zbx_msg));

    return 1;

}
开发者ID:jamescook000,项目名称:libzbxredis,代码行数:83,代码来源:libzbxredis.c


注:本文中的SET_MSG_RESULT函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。