本文整理汇总了C++中SET_STR_RESULT函数的典型用法代码示例。如果您正苦于以下问题:C++ SET_STR_RESULT函数的具体用法?C++ SET_STR_RESULT怎么用?C++ SET_STR_RESULT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SET_STR_RESULT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WEB_PAGE_REGEXP
int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char hostname[MAX_STRING_LEN];
char path[MAX_STRING_LEN];
char port_str[8];
char regexp[MAX_STRING_LEN];
char len_str[16];
char back[MAX_BUFFER_LEN];
char *buffer = NULL, *found;
int len, found_len;
if (num_param(param) > 5)
return SYSINFO_RET_FAIL;
if (0 != get_param(param, 1, hostname, sizeof(hostname)))
return SYSINFO_RET_FAIL;
if (0 != get_param(param, 2, path, sizeof(path)))
*path = '\0';
if (0 != get_param(param, 3, port_str, sizeof(port_str)) || '\0' == *port_str)
zbx_snprintf(port_str, sizeof(port_str), "%d", ZBX_DEFAULT_HTTP_PORT);
else if (FAIL == is_uint(port_str))
return SYSINFO_RET_FAIL;
if (0 != get_param(param, 4, regexp, sizeof(regexp)))
return SYSINFO_RET_FAIL;
if (0 != get_param(param, 5, len_str, sizeof(len_str)) || '\0' == *len_str)
zbx_snprintf(len_str, sizeof(len_str), "%d", MAX_BUFFER_LEN - 1);
else if (FAIL == is_uint(len_str))
return SYSINFO_RET_FAIL;
buffer = zbx_malloc(buffer, ZBX_MAX_WEBPAGE_SIZE);
if (SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, ZBX_MAX_WEBPAGE_SIZE))
{
if (NULL != (found = zbx_regexp_match(buffer, regexp, &found_len)))
{
len = atoi(len_str) + 1;
len = MIN(len, found_len + 1);
len = MIN(len, sizeof(back));
zbx_strlcpy(back, found, len);
SET_STR_RESULT(result, strdup(back));
}
else
SET_STR_RESULT(result, strdup("EOF"));
}
else
SET_STR_RESULT(result, strdup("EOF"));
zbx_free(buffer);
return SYSINFO_RET_OK;
}
示例2: SYSTEM_HOSTNAME
int SYSTEM_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef _WINDOWS
DWORD dwSize = 256;
TCHAR computerName[256];
char buffer[256];
int netbios, ret;
WSADATA sockInfo;
if (1 < num_param(param))
return SYSINFO_RET_FAIL;
if (0 != get_param(param, 1, buffer, sizeof(buffer)))
*buffer = '\0';
if ('\0' == *buffer || 0 == strcmp(buffer, "netbios"))
netbios = 1;
else if (0 == strcmp(buffer, "host"))
netbios = 0;
else
return SYSINFO_RET_FAIL;
if (1 == netbios)
{
/* Buffer size is chosen large enough to contain any DNS name, not just MAX_COMPUTERNAME_LENGTH + 1 */
/* characters. MAX_COMPUTERNAME_LENGTH is usually less than 32, but it varies among systems, so we */
/* cannot use the constant in a precompiled Windows agent, which is expected to work on any system. */
if (0 == GetComputerName(computerName, &dwSize))
zabbix_log(LOG_LEVEL_ERR, "GetComputerName() failed: %s", strerror_from_system(GetLastError()));
else
SET_STR_RESULT(result, zbx_unicode_to_utf8(computerName));
}
else
{
if (0 != (ret = WSAStartup(MAKEWORD(2, 2), &sockInfo)))
zabbix_log(LOG_LEVEL_ERR, "WSAStartup() failed: %s", strerror_from_system(ret));
else if (SUCCEED != gethostname(buffer, sizeof(buffer)))
zabbix_log(LOG_LEVEL_ERR, "gethostname() failed: %s", strerror_from_system(WSAGetLastError()));
else
SET_STR_RESULT(result, zbx_strdup(NULL, buffer));
}
if (ISSET_STR(result))
return SYSINFO_RET_OK;
else
return SYSINFO_RET_FAIL;
#else
return EXECUTE_STR(cmd, "hostname", flags, result);
#endif
}
示例3: VFS_FS_DISCOVERY
int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statvfs *mntbuf;
struct zbx_json j;
if (0 == (rc = getmntinfo(&mntbuf, MNT_WAIT)))
{
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
for (i = 0; i < rc; i++)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#FSNAME}", mntbuf[i].f_mntonname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#FSTYPE}", mntbuf[i].f_fstypename, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
zbx_json_close(&j);
SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer));
zbx_json_free(&j);
return SYSINFO_RET_OK;
}
示例4: NET_IF_DISCOVERY
int NET_IF_DISCOVERY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct if_nameindex *ni;
struct zbx_json j;
int i;
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
for (ni = if_nameindex(), i = 0; 0 != ni[i].if_index; i++)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#IFNAME}", ni[i].if_name, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
if_freenameindex(ni);
zbx_json_close(&j);
SET_STR_RESULT(result, strdup(j.buffer));
zbx_json_free(&j);
return SYSINFO_RET_OK;
}
示例5: SYSTEM_HW_CHASSIS
int SYSTEM_HW_CHASSIS(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode, buf[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
if (1 < request->nparam)
return ret;
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "full")) /* show full info by default */
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_TYPE | DMI_GET_VENDOR | DMI_GET_MODEL | DMI_GET_SERIAL);
else if (0 == strcmp(mode, "type"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_TYPE);
else if (0 == strcmp(mode, "vendor"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_VENDOR);
else if (0 == strcmp(mode, "model"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_MODEL);
else if (0 == strcmp(mode, "serial"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_SERIAL);
if (SYSINFO_RET_OK == ret)
SET_STR_RESULT(result, zbx_strdup(NULL, buf + 1)); /* buf has a leading space */
return ret;
}
示例6: SYSTEM_HW_CHASSIS
int SYSTEM_HW_CHASSIS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char tmp[8], buf[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
if (1 < num_param(param))
return ret;
if (0 != get_param(param, 1, tmp, sizeof(tmp)))
*tmp = '\0';
if ('\0' == *tmp || 0 == strcmp(tmp, "full")) /* show full info by default */
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_TYPE | DMI_GET_VENDOR | DMI_GET_MODEL | DMI_GET_SERIAL);
else if (0 == strcmp(tmp, "type"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_TYPE);
else if (0 == strcmp(tmp, "vendor"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_VENDOR);
else if (0 == strcmp(tmp, "model"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_MODEL);
else if (0 == strcmp(tmp, "serial"))
ret = get_dmi_info(buf, sizeof(buf), DMI_GET_SERIAL);
if (SYSINFO_RET_OK == ret)
SET_STR_RESULT(result, zbx_strdup(NULL, buf + 1)); /* buf has a leading space */
return ret;
}
示例7: PG_SETTING
/*
* Function: PG_SETTING
*
* Provides access to run-time parameters of the server such as those returned
* by `SHOW` commands.
*
* Parameter [0-4]: <host,port,db,user,passwd>
*
* Parameter [setting]: run-time configuration parameter name
*
* Returns: determined by parameter vartype
*/
int PG_SETTING(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL; // Request result code
const char *__function_name = "PG_SETTING"; // Function name for log file
PGconn *conn = NULL;
PGresult *res = NULL;
char *setting = NULL;
char *value = NULL;
char *type = NULL;
char query[MAX_STRING_LEN];
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
// Build the query
setting = get_rparam(request, PARAM_FIRST);
if(NULL == setting || '\0' == *setting) {
zabbix_log(LOG_LEVEL_ERR, "No setting name specified in %s()", __function_name);
goto out;
}
zbx_snprintf(query, sizeof(query), PGSQL_GET_SETTING, setting);
// Connect to PostreSQL
if(NULL == (conn = pg_connect(request)))
goto out;
// Execute the query
res = PQexec(conn, query);
if(PQresultStatus(res) != PGRES_TUPLES_OK) {
zabbix_log(LOG_LEVEL_ERR, "Failed to execute PostgreSQL query in %s() with: %s", __function_name, PQresultErrorMessage(res));
goto out;
}
if(0 == PQntuples(res)) {
zabbix_log(LOG_LEVEL_DEBUG, "No results returned for query \"%s\" in %s()", query, __function_name);
goto out;
}
// Set result
value = strdup(PQgetvalue(res, 0, 0));
type = strdup(PQgetvalue(res, 0, 1));
if(0 == strncmp("integer", type, 7))
SET_UI64_RESULT(result, strtoull(value, NULL, 10));
else if(0 == strncmp("real", type, 4))
SET_DBL_RESULT(result, strtold(value, NULL));
else
SET_STR_RESULT(result, value);
ret = SYSINFO_RET_OK;
out:
PQclear(res);
PQfinish(conn);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s(%s)", __function_name, request->key);
return ret;
}
示例8: NET_IF_DISCOVERY
int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct if_nameindex *ni;
struct zbx_json j;
int i;
if (NULL == (ni = if_nameindex()))
{
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
for (i = 0; 0 != ni[i].if_index; i++)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#IFNAME}", ni[i].if_name, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
if_freenameindex(ni);
zbx_json_close(&j);
SET_STR_RESULT(result, strdup(j.buffer));
zbx_json_free(&j);
return SYSINFO_RET_OK;
}
示例9: PG_TABLE_DISCOVERY
/*
* Custom key pg.table.discovery
*
* Returns all known Tables in a PostgreSQL database
*
* Parameter [0-4]: <host,port,db,user,passwd>
* *
* Returns:
* {
* "data":[
* {
* "{#DATABASE}":"MyDatabase",
* "{#SCHEMA}":"public",
* "{#TABLESPACE}":"pg_default",
* "{#TABLE}":"MyTable",
* "{#TYPE}":"MyTable",
* "{#OWNER}":"postgres",
* "{#PERSISTENCE":"permenant|temporary",
* "{#ISSUBCLASS}":"0"}]}
*/
int PG_TABLE_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL; // Request result code
const char *__function_name = "PG_TABLE_DISCOVERY"; // Function name for log file
struct zbx_json j; // JSON response for discovery rule
PGconn *conn = NULL;
PGresult *res = NULL;
char query[MAX_STRING_LEN] = PGSQL_DISCOVER_TABLES;
int i = 0, count = 0;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
// Connect to PostreSQL
if(NULL == (conn = pg_connect(request)))
goto out;
// Execute a query
res = PQexec(conn, query);
if(PQresultStatus(res) != PGRES_TUPLES_OK) {
zabbix_log(LOG_LEVEL_ERR, "Failed to execute PostgreSQL query in %s() with: %s", __function_name, PQresultErrorMessage(res));
goto out;
}
if(0 == (count = PQntuples(res))) {
zabbix_log(LOG_LEVEL_DEBUG, "No results returned for query \"%s\" in %s()", query, __function_name);
}
// Create JSON array of discovered objects
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
for(i = 0; i < count; i++) {
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#OID}", PQgetvalue(res, i, 0), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#DATABASE}", PQgetvalue(res, i, 1), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#SCHEMA}", PQgetvalue(res, i, 2), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#TABLESPACE}", PQgetvalue(res, i, 3), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#TABLE}", PQgetvalue(res, i, 4), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#TYPE}", PQgetvalue(res, i, 5), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#OWNER}", PQgetvalue(res, i, 6), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#PERSISTENCE}", PQgetvalue(res, i, 7), ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#ISSUBCLASS}", PQgetvalue(res, i, 8), ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
// Finalize JSON response
zbx_json_close(&j);
SET_STR_RESULT(result, strdup(j.buffer));
zbx_json_free(&j);
ret = SYSINFO_RET_OK;
out:
PQclear(res);
PQfinish(conn);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
return ret;
}
示例10: NET_IF_DISCOVERY
int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL, i;
struct zbx_json j;
struct if_nameindex *interfaces;
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
if (NULL != (interfaces = if_nameindex()))
{
i = 0;
while (0 != interfaces[i].if_index)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#IFNAME}", interfaces[i].if_name, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
i++;
}
ret = SYSINFO_RET_OK;
}
zbx_json_close(&j);
SET_STR_RESULT(result, strdup(j.buffer));
zbx_json_free(&j);
return ret;
}
示例11: VFS_FS_DISCOVERY
int VFS_FS_DISCOVERY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
int i, rc, ret = SYSINFO_RET_FAIL;
struct statfs *mntbuf;
struct zbx_json j;
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
if (0 != (rc = getmntinfo(&mntbuf, MNT_WAIT)))
{
for (i = 0; i < rc; i++)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#FSNAME}", mntbuf[i].f_mntonname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#FSTYPE}", mntbuf[i].f_fstypename, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
ret = SYSINFO_RET_OK;
}
zbx_json_close(&j);
SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer));
zbx_json_free(&j);
return ret;
}
示例12: check_vcenter_fullname
int check_vcenter_fullname(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
char *url, *fullname;
int ret = SYSINFO_RET_FAIL;
zbx_vmware_service_t *service;
if (1 != request->nparam)
return SYSINFO_RET_FAIL;
url = get_rparam(request, 0);
zbx_vmware_lock();
if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
goto unlock;
if (NULL == (fullname = zbx_xml_read_value(service->contents, ZBX_XPATH_LN2("about", "fullName"))))
goto unlock;
SET_STR_RESULT(result, fullname);
ret = SYSINFO_RET_OK;
unlock:
zbx_vmware_unlock();
return ret;
}
示例13: NET_IF_DISCOVERY
int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_LIBPERFSTAT)
int rc, i, ret = SYSINFO_RET_FAIL;
perfstat_id_t ps_id;
perfstat_netinterface_t *ps_netif = NULL;
struct zbx_json j;
/* check how many perfstat_netinterface_t structures are available */
if (-1 == (rc = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)))
{
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
if (0 == rc) /* no network interfaces found */
{
ret = SYSINFO_RET_OK;
goto end;
}
ps_netif = zbx_malloc(ps_netif, rc * sizeof(perfstat_netinterface_t));
/* set name to first interface */
strscpy(ps_id.name, FIRST_NETINTERFACE); /* pseudo-name for the first network interface */
/* ask to get all the structures available in one call */
/* return code is number of structures returned */
if (-1 != (rc = perfstat_netinterface(&ps_id, ps_netif, sizeof(perfstat_netinterface_t), rc)))
ret = SYSINFO_RET_OK;
/* collecting of the information for each of the interfaces */
for (i = 0; i < rc; i++)
{
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#IFNAME}", ps_netif[i].name, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);
}
zbx_free(ps_netif);
end:
zbx_json_close(&j);
SET_STR_RESULT(result, strdup(j.buffer));
zbx_json_free(&j);
return ret;
#else
SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for Perfstat API."));
return SYSINFO_RET_FAIL;
#endif
}
示例14: check_vcenter_vm_vfs_fs_discovery
int check_vcenter_vm_vfs_fs_discovery(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
struct zbx_json json_data;
zbx_vmware_service_t *service;
zbx_vmware_vm_t *vm = NULL;
char *url, *uuid;
zbx_vector_str_t disks;
int i, ret = SYSINFO_RET_FAIL;
if (2 != request->nparam)
return SYSINFO_RET_FAIL;
url = get_rparam(request, 0);
uuid = get_rparam(request, 1);
if ('\0' == *uuid)
return SYSINFO_RET_FAIL;
zbx_vmware_lock();
if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
goto unlock;
if (NULL == (vm = service_vm_get(service, uuid)))
goto unlock;
zbx_vector_str_create(&disks);
zbx_xml_read_values(vm->details, ZBX_XPATH_LN2("disk", "diskPath"), &disks);
zbx_json_init(&json_data, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&json_data, ZBX_PROTO_TAG_DATA);
for (i = 0; i < disks.values_num; i++)
{
zbx_json_addobject(&json_data, NULL);
zbx_json_addstring(&json_data, "{#FSNAME}", disks.values[i], ZBX_JSON_TYPE_STRING);
zbx_json_close(&json_data);
}
zbx_json_close(&json_data);
zbx_vector_str_clean(&disks);
zbx_vector_str_destroy(&disks);
SET_STR_RESULT(result, zbx_strdup(NULL, json_data.buffer));
zbx_json_free(&json_data);
ret = SYSINFO_RET_OK;
unlock:
zbx_vmware_unlock();
return ret;
}
示例15: AGENT_HOSTNAME
static int AGENT_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* zabbix_agent standalone does not support the Hostname in the configuration file */
if (NULL == CONFIG_HOSTNAME)
return SYSINFO_RET_FAIL;
SET_STR_RESULT(result, zbx_strdup(NULL, CONFIG_HOSTNAME));
return SYSINFO_RET_OK;
}