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; }
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 }
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; }
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; }
int SYSTEM_SW_OS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char type[8], line[MAX_STRING_LEN]; int ret = SYSINFO_RET_FAIL; FILE *f = NULL; if (1 < num_param(param)) return ret; if (0 != get_param(param, 1, type, sizeof(type))) *type = '\0'; if ('\0' == *type || 0 == strcmp(type, "full")) f = fopen(SW_OS_FULL, "r"); else if (0 == strcmp(type, "short")) f = fopen(SW_OS_SHORT, "r"); else if (0 == strcmp(type, "name")) f = fopen(SW_OS_NAME, "r"); if (NULL == f) return ret; if (NULL != fgets(line, sizeof(line), f)) { ret = SYSINFO_RET_OK; zbx_rtrim(line, ZBX_WHITESPACE); SET_STR_RESULT(result, zbx_strdup(NULL, line)); } zbx_fclose(f); return ret; }
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; }
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; }
/* * 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; }
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; }
/* * 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; }
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; }
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; }
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; }
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 }
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; }
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; }
int check_vcenter_hv_discovery(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { struct zbx_json json_data; int i, ret = SYSINFO_RET_FAIL; char *url, *name; 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; zbx_json_init(&json_data, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&json_data, ZBX_PROTO_TAG_DATA); for (i = 0; i < service->data->hvs.values_num; i++) { zbx_vmware_cluster_t *cluster = NULL; zbx_vmware_hv_t *hv = (zbx_vmware_hv_t *)service->data->hvs.values[i]; if (NULL == (name = zbx_xml_read_value(hv->details, ZBX_XPATH_LN2("config", "name")))) continue; if (NULL != hv->clusterid) cluster = cluster_get(&service->data->clusters, hv->clusterid); zbx_json_addobject(&json_data, NULL); zbx_json_addstring(&json_data, "{#HV.UUID}", hv->uuid, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&json_data, "{#HV.ID}", hv->id, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&json_data, "{#HV.NAME}", name, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&json_data, "{#CLUSTER.NAME}", (NULL != cluster ? cluster->name : ""), ZBX_JSON_TYPE_STRING); zbx_json_close(&json_data); zbx_free(name); } zbx_json_close(&json_data); 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; }
int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result) { struct utsname name; if (-1 == uname(&name)) return SYSINFO_RET_FAIL; SET_STR_RESULT(result, zbx_strdup(NULL, name.nodename)); return SYSINFO_RET_OK; }
int SYSTEM_SW_ARCH(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { struct utsname name; if (-1 == uname(&name)) return SYSINFO_RET_FAIL; SET_STR_RESULT(result, zbx_strdup(NULL, name.machine)); return SYSINFO_RET_OK; }
int check_vcenter_vm_vfs_dev_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; zbx_vmware_dev_t *dev; char *url, *uuid; 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_json_init(&json_data, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&json_data, ZBX_PROTO_TAG_DATA); for (i = 0; i < vm->devs.values_num; i++) { dev = (zbx_vmware_dev_t *)vm->devs.values[i]; if (ZBX_VMWARE_DEV_TYPE_DISK != dev->type) continue; zbx_json_addobject(&json_data, NULL); zbx_json_addstring(&json_data, "{#DISKNAME}", dev->instance, ZBX_JSON_TYPE_STRING); zbx_json_close(&json_data); } zbx_json_close(&json_data); 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; }
static int AGENT_VERSION(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { static char version[]=ZABBIX_VERSION; assert(result); init_result(result); SET_STR_RESULT(result, strdup(version)); return SYSINFO_RET_OK; }
int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result) { struct utsname name; if (-1 == uname(&name)) return SYSINFO_RET_FAIL; SET_STR_RESULT(result, zbx_dsprintf(NULL, "%s %s %s %s %s %s", name.sysname, name.nodename, name.release, name.version, name.machine, name.idnumber)); return SYSINFO_RET_OK; }
int zbx_module_unifi_proxy(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret; int i, p, np; zbx_sock_t s; char send_buf[MAX_STRING_LEN]; *send_buf='\0'; np = request->nparam; if (9 < request->nparam) { /* set optional error message */ SET_MSG_RESULT(result, strdup("So much parameters given.")); return SYSINFO_RET_FAIL; } // make request string by concatenate all params for (i=0; i < np; i++) { strcat(send_buf, get_rparam(request, i)); p=strlen(send_buf); send_buf[p]=(i < (np-1)) ? ',' : '\n'; send_buf[p+1]='\0'; } // Connect to UniFi Proxy // item_timeout or (item_timeout-1) ? if (SUCCEED == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, UNIFI_PROXY_SERVER, UNIFI_PROXY_PORT, CONFIG_TIMEOUT))) { // Send request if (SUCCEED == (ret = zbx_tcp_send_raw(&s, send_buf))) { // Recive answer from UniFi Proxy if (SUCCEED == (ret = zbx_tcp_recv(&s))) { zbx_rtrim(s.buffer, "\r\n"); SET_STR_RESULT(result, strdup(s.buffer)); } } zbx_tcp_close(&s); } if (FAIL == ret) { zabbix_log(LOG_LEVEL_DEBUG, "%s: communication error: %s", ZBX_MODULE_NAME, zbx_tcp_strerror()); SET_MSG_RESULT(result, strdup(zbx_tcp_strerror())); return SYSINFO_RET_FAIL; } return SYSINFO_RET_OK; }
static int AGENT_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result) { if (NULL == CONFIG_HOSTNAME) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Hostname parameter is not supported" " in the zabbix_agent configuration file.")); return SYSINFO_RET_FAIL; } SET_STR_RESULT(result, zbx_strdup(NULL, CONFIG_HOSTNAME)); return SYSINFO_RET_OK; }
int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; char line[MAX_STRING_LEN], *p, *mpoint, *mtype; FILE *f; struct zbx_json j; zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); if (NULL != (f = fopen("/proc/mounts", "r"))) { while (NULL != fgets(line, sizeof(line), f)) { if (NULL == (p = strchr(line, ' '))) continue; mpoint = ++p; if (NULL == (p = strchr(mpoint, ' '))) continue; *p = '\0'; mtype = ++p; if (NULL == (p = strchr(mtype, ' '))) continue; *p = '\0'; zbx_json_addobject(&j, NULL); zbx_json_addstring(&j, "{#FSNAME}", mpoint, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&j, "{#FSTYPE}", mtype, ZBX_JSON_TYPE_STRING); zbx_json_close(&j); } zbx_fclose(f); ret = SYSINFO_RET_OK; } zbx_json_close(&j); SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer)); zbx_json_free(&j); return ret; }
int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) { int rc, sz, i, ret = SYSINFO_RET_FAIL; struct vmount *vms = NULL, *vm; struct zbx_json j; /* check how many bytes to allocate for the mounted filesystems */ if (-1 == (rc = mntctl(MCTL_QUERY, sizeof(sz), (char *)&sz))) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } vms = zbx_malloc(vms, (size_t)sz); /* get the list of mounted filesystems */ /* return code is number of filesystems returned */ if (-1 == (rc = mntctl(MCTL_QUERY, sz, (char *)vms))) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); goto error; } zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); for (i = 0, vm = vms; i < rc; i++) { zbx_json_addobject(&j, NULL); zbx_json_addstring(&j, "{#FSNAME}", (char *)vm + vm->vmt_data[VMT_STUB].vmt_off, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&j, "{#FSTYPE}", zbx_get_vfs_name_by_type(vm->vmt_gfstype), ZBX_JSON_TYPE_STRING); zbx_json_close(&j); /* go to the next vmount structure */ vm = (struct vmount *)((char *)vm + vm->vmt_length); } zbx_json_close(&j); SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer)); zbx_json_free(&j); ret = SYSINFO_RET_OK; error: zbx_free(vms); return ret; }
/* * Custom key: pg.modver * * Returns the version string of the libzbxpgsql module. * * Parameters: * * Returns: s */ int MODVER(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "MODVER"; // Function name for log file zabbix_log(LOG_LEVEL_DEBUG, "In %s", __function_name); // Set result SET_STR_RESULT(result, strdup(STRVER)); ret = SYSINFO_RET_OK; zabbix_log(LOG_LEVEL_DEBUG, "End of %s", __function_name); return ret; }
int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result) { struct utsname name; if (-1 == uname(&name)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } SET_STR_RESULT(result, zbx_strdup(NULL, name.machine)); return SYSINFO_RET_OK; }
int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result) { struct utsname name; if (-1 == uname(&name)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } SET_STR_RESULT(result, zbx_dsprintf(NULL, "%s %s %s %s %s %s", name.sysname, name.nodename, name.release, name.version, name.machine, name.idnumber)); return SYSINFO_RET_OK; }
/* * Function: * zbx_module_vpoller_echo() * * Purpose: * Will echo back the first parameter you provide to it * * Return value: * The first parameter it was invoked with */ int zbx_module_vpoller_echo(AGENT_REQUEST *request, AGENT_RESULT *result) { const char *param; if (request->nparam < 1) { SET_MSG_RESULT(result, strdup("Invalid number of key parameters")); return (SYSINFO_RET_FAIL); } param = get_rparam(request, 0); SET_STR_RESULT(result, strdup(param)); return (SYSINFO_RET_OK); }