Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save higebu/e88cff00fc6ef40d5f1a to your computer and use it in GitHub Desktop.
Save higebu/e88cff00fc6ef40d5f1a to your computer and use it in GitHub Desktop.
--- 2.4/src/zabbix_server/poller/checks_simple_vmware.c 2014-10-27 14:48:30.232956561 +0900
+++ ZBXNEXT-2354/src/zabbix_server/poller/checks_simple_vmware.c 2014-10-27 15:47:37.704576458 +0900
@@ -179,30 +179,74 @@
return cluster;
}
-
-static int vmware_counter_get(const char *stats, const char *instance, zbx_uint64_t counterid, int coeff,
- AGENT_RESULT *result)
+static int vmware_service_counter_get(zbx_vmware_service_t *service, const char *type, const char *id,
+ const char *path, const char *instance, int coeff, AGENT_RESULT *result)
{
- const char *__function_name = "vmware_counter_get";
-
- int ret = SYSINFO_RET_FAIL;
- char xpath[MAX_STRING_LEN], *value;
+ const char *__function_name = "vmware_service_counter_get";
+ int ret = SYSINFO_RET_FAIL;
+ zbx_uint64_t counterid;
+ int i;
+ zbx_vmware_perf_entity_t *entity;
+ zbx_vmware_perf_counter_t *perfcounter;
+ zbx_ptr_pair_t *perfvalue;
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() %s: " ZBX_FS_UI64, __function_name, instance, counterid);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() type:%s id:%s path:%s instance:%s", __function_name, type, id, path,
+ instance);
- zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN3("value", "id", "counterId") "[.='" ZBX_FS_UI64 "']/.."
- ZBX_XPATH_LN("instance") "[.='%s']/../.." ZBX_XPATH_LN("value"), counterid, instance);
-
- if (NULL == (value = zbx_xml_read_value(stats, xpath)))
+ if (FAIL == zbx_vmware_service_get_perfcounterid(service, path, &counterid))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter is not available."));
goto out;
}
- if (SUCCEED == set_result_type(result, ITEM_VALUE_TYPE_UINT64, ITEM_DATA_TYPE_DECIMAL, value))
+ if (NULL == (entity = zbx_vmware_service_get_perf_entity(service, type, id)))
+ {
+ /* the requested counter has not been queried yet */
+ zabbix_log(LOG_LEVEL_DEBUG, "performance data is not yet ready, ignoring request");
ret = SYSINFO_RET_OK;
+ goto out;
+ }
- zbx_free(value);
+ for (i = 0; i < entity->counters.values_num; i++)
+ {
+ perfcounter = (zbx_vmware_perf_counter_t *)entity->counters.values[i];
+
+ if (perfcounter->counterid == counterid)
+ break;
+ }
+
+ if (i == entity->counters.values_num)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter data was not found."));
+ goto out;
+ }
+
+ for (i = 0; i < perfcounter->values.values_num; i++)
+ {
+ perfvalue = (zbx_ptr_pair_t *)&perfcounter->values.values[i];
+
+ if (NULL == perfvalue->first)
+ {
+ if ('\0' == *instance)
+ break;
+ continue;
+ }
+
+ if (0 == strcmp(perfvalue->first, instance))
+ break;
+ }
+
+ if (i == perfcounter->values.values_num)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter instance was not found."));
+ goto out;
+ }
+
+ if (SUCCEED == set_result_type(result, ITEM_VALUE_TYPE_UINT64, ITEM_DATA_TYPE_DECIMAL, perfvalue->second))
+ {
+ result->ui64 *= coeff;
+ ret = SYSINFO_RET_OK;
+ }
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -210,7 +254,7 @@
}
static int vmware_service_get_vm_counter(zbx_vmware_service_t *service, const char *uuid, const char *instance,
- zbx_uint64_t counterid, int coeff, AGENT_RESULT *result)
+ const char *path, int coeff, AGENT_RESULT *result)
{
const char *__function_name = "vmware_service_get_vm_counter";
@@ -218,7 +262,7 @@
zbx_vmware_vm_t *vm = NULL;
zbx_vmware_dev_t *dev;
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() uuid:'%s' %s: " ZBX_FS_UI64, __function_name, uuid, instance, counterid);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() uuid:%s instance:%s path:%s", __function_name, uuid, instance, path);
if (NULL == (vm = service_vm_get(service, uuid)))
{
@@ -240,7 +284,7 @@
goto out;
}
- ret = vmware_counter_get(vm->stats, instance, counterid, coeff, result);
+ ret = vmware_service_counter_get(service, "VirtualMachine", vm->id, path, instance, coeff, result);
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -251,90 +295,111 @@
{
const char *__function_name = "vmware_get_events";
- zbx_vector_str_t keys;
zbx_uint64_t key;
- char *value, xpath[MAX_STRING_LEN];
+ char *value, *error = NULL;
int i, ret = SYSINFO_RET_FAIL;
zbx_log_t *log;
struct tm tm;
time_t t;
+ xmlDoc *doc;
+ xmlXPathContext *xpathCtx;
+ xmlXPathObject *xpathObj;
+ xmlNodeSetPtr nodeset;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() lastlogsize:" ZBX_FS_UI64, __function_name, lastlogsize);
- zbx_vector_str_create(&keys);
-
- if (SUCCEED != zbx_xml_read_values(events, ZBX_XPATH_LN2("Event", "key"), &keys))
+ if (NULL == (doc = xmlReadMemory(events, strlen(events), "noname.xml", NULL, 0)))
{
- SET_MSG_RESULT(result, zbx_strdup(NULL, "No event key found."));
- zbx_vector_str_destroy(&keys);
+ error = zbx_strdup(error, "Cannot parse event data.");
goto out;
}
- for (i = keys.values_num - 1; i >= 0; i--)
- {
- if (SUCCEED != is_uint64(keys.values[i], &key))
- continue;
+ xpathCtx = xmlXPathNewContext(doc);
- if (key <= lastlogsize)
- continue;
+ if (NULL == (xpathObj = xmlXPathEvalExpression((xmlChar *)ZBX_VMWARE_EVENTS(), xpathCtx)))
+ {
+ error = zbx_strdup(error, "Cannot make event parsing query.");
+ goto clean;
+ }
- /* value */
+ if (xmlXPathNodeSetIsEmpty(xpathObj->nodesetval))
+ {
+ error = zbx_strdup(error, "Cannot find event keys in event data.");
+ goto clean;
+ }
- zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN2("Event", "key") "[.='" ZBX_FS_UI64 "']/.."
- ZBX_XPATH_LN("fullFormattedMessage"), key);
+ nodeset = xpathObj->nodesetval;
- if (NULL == (value = zbx_xml_read_value(events, xpath)))
+ for (i = 0; i < nodeset->nodeNr; i++)
+ {
+ if (NULL == (value = zbx_xml_read_node_value(doc, nodeset->nodeTab[i], "*[local-name()='key']")))
continue;
- zbx_replace_invalid_utf8(value);
- log = add_log_result(result, value);
- log->logeventid = key;
- log->lastlogsize = key;
-
- zbx_free(value);
-
- /* timestamp */
+ if (SUCCEED == is_uint64(value, &key) && key > lastlogsize)
+ {
+ zbx_free(value);
- zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN2("Event", "key") "[.='" ZBX_FS_UI64 "']/.."
- ZBX_XPATH_LN("createdTime"), key);
+ value = zbx_xml_read_node_value(doc, nodeset->nodeTab[i],
+ "*[local-name()='fullFormattedMessage']");
- if (NULL == (value = zbx_xml_read_value(events, xpath)))
- continue;
+ if (NULL != value)
+ {
+ zbx_replace_invalid_utf8(value);
+ log = add_log_result(result, value);
+ log->logeventid = key;
+ log->lastlogsize = key;
- /* 2013-06-04T14:19:23.406298Z */
- if (6 == sscanf(value, "%d-%d-%dT%d:%d:%d.%*s", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour,
- &tm.tm_min, &tm.tm_sec))
+ zbx_free(value);
+ value = zbx_xml_read_node_value(doc, nodeset->nodeTab[i],
+ "*[local-name()='createdTime']");
- {
- int tz_offset;
+ if (NULL != value)
+ {
+ if (6 == sscanf(value, "%d-%d-%dT%d:%d:%d.%*s", &tm.tm_year, &tm.tm_mon,
+ &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec))
+ {
+ int tz_offset;
#if defined(HAVE_TM_TM_GMTOFF)
- struct tm *ptm;
- time_t now;
+ struct tm *ptm;
+ time_t now;
- now = time(NULL);
- ptm = localtime(&now);
- tz_offset = ptm->tm_gmtoff;
+ now = time(NULL);
+ ptm = localtime(&now);
+ tz_offset = ptm->tm_gmtoff;
#else
- tz_offset = -timezone;
+ tz_offset = -timezone;
#endif
- tm.tm_year -= 1900;
- tm.tm_mon--;
- tm.tm_isdst = -1;
+ tm.tm_year -= 1900;
+ tm.tm_mon--;
+ tm.tm_isdst = -1;
+
+ if (0 < (t = mktime(&tm)))
+ log->timestamp = (int)t + tz_offset;
+ }
- if (0 < (t = mktime(&tm)))
- log->timestamp = (int)t + tz_offset;
+ }
+ }
}
+
zbx_free(value);
}
if (!ISSET_LOG(result))
set_log_result_empty(result);
- zbx_vector_str_clean(&keys);
- zbx_vector_str_destroy(&keys);
-
ret = SYSINFO_RET_OK;
+
+clean:
+ if (NULL != xpathObj)
+ xmlXPathFreeObject(xpathObj);
+
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
out:
+ if (NULL != error)
+ SET_MSG_RESULT(result, error);
+
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
return ret;
@@ -388,7 +453,7 @@
if (0 != (service->state & ZBX_VMWARE_STATE_FAILED))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, NULL != service->data->error ? service->data->error :
- "Unknown VMware service error"));
+ "Unknown VMware service error."));
zabbix_log(LOG_LEVEL_DEBUG, "failed to query VMware service: %s",
NULL != service->data->error ? service->data->error : "unknown error");
@@ -500,7 +565,7 @@
SET_UI64_RESULT(result, hv->vms.values_num);
break;
case ZBX_OPT_MEM_BALLOONED:
- xpath = ZBX_XPATH_LN2("quickStats", "balloonedMemory");
+ xpath = ZBX_VM_QUICKSTATS("balloonedMemory");
value_uint64_sum = 0;
for (i = 0; i < hv->vms.values_num; i++)
@@ -691,7 +756,7 @@
else if (0 == strcmp(status, "red"))
SET_UI64_RESULT(result, 3);
else
- ret = SYSINFO_RET_FAIL;
+ ret = SYSINFO_RET_FAIL;
zbx_free(status);
unlock:
@@ -759,7 +824,7 @@
if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
goto unlock;
- if (NULL == (version = zbx_xml_read_value(service->contents, ZBX_XPATH_LN2("about", "version"))))
+ if (NULL == (version = zbx_xml_read_value(service->contents, ZBX_VMWARE_ABOUT("version"))))
goto unlock;
SET_STR_RESULT(result, version);
@@ -797,7 +862,7 @@
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"))))
+ if (NULL == (fullname = zbx_xml_read_value(service->contents, ZBX_VMWARE_ABOUT("fullName"))))
goto unlock;
SET_STR_RESULT(result, fullname);
@@ -874,7 +939,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH,
- ZBX_XPATH_LN2("quickStats", "overallCpuUsage"), result);
+ ZBX_HV_QUICKSTATS("overallCpuUsage"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * 1000000;
@@ -917,7 +982,7 @@
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"))))
+ if (NULL == (name = zbx_xml_read_value(hv->details, ZBX_HV_CONFIG("name"))))
continue;
if (NULL != hv->clusterid)
@@ -958,7 +1023,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("product", "fullName"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_CONFIG_PRODUCT("fullName"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -975,7 +1040,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "numCpuCores"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("numCpuCores"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -992,7 +1057,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "cpuMhz"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("cpuMhz"),
result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
@@ -1012,7 +1077,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "cpuModel"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("cpuModel"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1029,8 +1094,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH,
- ZBX_XPATH_LN2("hardware", "numCpuThreads"), result);
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("numCpuThreads"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1046,8 +1110,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "memorySize"),
- result);
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("memorySize"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1063,7 +1126,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "model"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("model"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1080,7 +1143,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "uuid"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("uuid"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1097,7 +1160,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "vendor"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_HARDWARE("vendor"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1134,7 +1197,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH,
- ZBX_XPATH_LN2("quickStats", "overallMemoryUsage"), result);
+ ZBX_HV_QUICKSTATS("overallMemoryUsage"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1153,8 +1216,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("val", "overallStatus"),
- result);
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_STATUS(), result);
if (SYSINFO_RET_OK == ret && NULL != GET_STR_RESULT(result))
{
@@ -1186,7 +1248,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("quickStats", "uptime"),
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_QUICKSTATS("uptime"),
result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1203,8 +1265,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("product", "version"),
- result);
+ ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_HV_CONFIG_PRODUCT("version"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1266,7 +1327,8 @@
goto unlock;
}
- ret = vmware_counter_get(hv->stats, "", service->counters.nic_received, ZBX_KIBIBYTE, result);
+ ret = vmware_service_counter_get(service, "HostSystem", hv->id, "net/received[average]", "", ZBX_KIBIBYTE,
+ result);
unlock:
zbx_vmware_unlock();
out:
@@ -1314,7 +1376,9 @@
goto unlock;
}
- ret = vmware_counter_get(hv->stats, "", service->counters.nic_transmitted, ZBX_KIBIBYTE, result);
+ ret = vmware_service_counter_get(service, "HostSystem", hv->id, "net/transmitted[average]", "", ZBX_KIBIBYTE,
+ result);
+
unlock:
zbx_vmware_unlock();
out:
@@ -1432,8 +1496,8 @@
if (NULL == datastore->uuid)
break;
- ret = vmware_counter_get(hv->stats, datastore->uuid,
- service->counters.datastore_read_latency, 1, result);
+ ret = vmware_service_counter_get(service, "HostSystem", hv->id,
+ "datastore/totalReadLatency[average]", datastore->uuid, 1, result);
goto unlock;
}
}
@@ -1496,8 +1560,8 @@
if (NULL == datastore->uuid)
break;
- ret = vmware_counter_get(hv->stats, datastore->uuid,
- service->counters.datastore_write_latency, 1, result);
+ ret = vmware_service_counter_get(service, "HostSystem", hv->id,
+ "datastore/totalWriteLatency[average]", datastore->uuid, 1, result);
goto unlock;
}
}
@@ -1511,6 +1575,67 @@
return ret;
}
+int check_vcenter_hv_perfcounter(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result)
+{
+ const char *__function_name = "check_vcenter_hv_perfcounter";
+ int ret = SYSINFO_RET_FAIL;
+ char *url, *uuid, *path, *instance;
+ zbx_vmware_service_t *service;
+ zbx_vmware_hv_t *hv;
+ zbx_uint64_t counterid;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+
+ if (3 > request->nparam || request->nparam > 4)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
+ goto out;
+ }
+
+ url = get_rparam(request, 0);
+ uuid = get_rparam(request, 1);
+ path = get_rparam(request, 2);
+ instance = get_rparam(request, 3);
+
+ if (NULL == instance)
+ instance = "";
+
+ zbx_vmware_lock();
+
+ if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
+ goto unlock;
+
+ if (NULL == (hv = hv_get(&service->data->hvs, uuid)))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Unknown hypervisor uuid."));
+ goto unlock;
+ }
+
+ if (FAIL == zbx_vmware_service_get_perfcounterid(service, path, &counterid))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter is not available."));
+ goto unlock;
+ }
+
+ if (SUCCEED == zbx_vmware_service_start_monitoring(service, "HostSystem", hv->id, counterid))
+ {
+ ret = SYSINFO_RET_OK;
+ goto unlock;
+ }
+
+ /* the performance counter is already being monitored, try to get the results from statistics */
+ ret = vmware_service_counter_get(service, "HostSystem", hv->id, path, instance, 1, result);
+
+unlock:
+ zbx_vmware_unlock();
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
+
+ return ret;
+}
+
+
int check_vcenter_vm_cpu_num(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
@@ -1520,7 +1645,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("config", "numCpu"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_CONFIG("numCpu"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -1593,7 +1718,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "overallCpuUsage"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("overallCpuUsage"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * 1000000;
@@ -1646,10 +1771,10 @@
{
vm = (zbx_vmware_vm_t *)hv->vms.values[k];
- if (NULL == (vm_name = zbx_xml_read_value(vm->details, ZBX_XPATH_LN2("config", "name"))))
+ if (NULL == (vm_name = zbx_xml_read_value(vm->details, ZBX_VM_CONFIG("name"))))
continue;
- if (NULL == (hv_name = zbx_xml_read_value(hv->details, ZBX_XPATH_LN2("config", "name"))))
+ if (NULL == (hv_name = zbx_xml_read_value(hv->details, ZBX_HV_CONFIG("name"))))
{
zbx_free(vm_name);
continue;
@@ -1727,7 +1852,7 @@
if (i != service->data->hvs.values_num)
{
- name = zbx_xml_read_value(hv->details, ZBX_XPATH_LN2("config", "name"));
+ name = zbx_xml_read_value(hv->details, ZBX_HV_CONFIG("name"));
SET_STR_RESULT(result, name);
ret = SYSINFO_RET_OK;
@@ -1751,7 +1876,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("config", "memorySizeMB"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_CONFIG("memorySizeMB"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1770,7 +1895,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "balloonedMemory"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("balloonedMemory"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1789,7 +1914,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "compressedMemory"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("compressedMemory"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1808,7 +1933,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "swappedMemory"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("swappedMemory"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1827,7 +1952,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "guestMemoryUsage"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("guestMemoryUsage"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1846,7 +1971,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "hostMemoryUsage"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("hostMemoryUsage"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1865,7 +1990,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "privateMemory"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("privateMemory"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1884,7 +2009,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "sharedMemory"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("sharedMemory"), result);
if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result))
result->ui64 = result->ui64 * ZBX_MEBIBYTE;
@@ -1903,7 +2028,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("runtime", "powerState"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_RUNTIME("powerState"), result);
if (SYSINFO_RET_OK == ret)
ret = vmware_set_powerstate_result(result);
@@ -1993,8 +2118,8 @@
char *url, *uuid, *instance, *mode;
zbx_vmware_service_t *service;
- zbx_uint64_t counterid;
int coeff, ret = SYSINFO_RET_FAIL;
+ const char *path;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
@@ -2028,12 +2153,12 @@
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bps"))
{
- counterid = service->counters.nic_received;
+ path = "net/received[average]";
coeff = ZBX_KIBIBYTE;
}
else if (0 == strcmp(mode, "pps"))
{
- counterid = service->counters.nic_packets_rx;
+ path = "net/packetsRx[summation]";
coeff = 1;
}
else
@@ -2042,7 +2167,7 @@
goto unlock;
}
- ret = vmware_service_get_vm_counter(service, uuid, instance, counterid, coeff, result);
+ ret = vmware_service_get_vm_counter(service, uuid, instance, path, coeff, result);
unlock:
zbx_vmware_unlock();
out:
@@ -2058,8 +2183,8 @@
char *url, *uuid, *instance, *mode;
zbx_vmware_service_t *service;
- zbx_uint64_t counterid;
int coeff, ret = SYSINFO_RET_FAIL;
+ const char *path;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
@@ -2093,12 +2218,12 @@
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bps"))
{
- counterid = service->counters.nic_transmitted;
+ path = "net/transmitted[average]";
coeff = ZBX_KIBIBYTE;
}
else if (0 == strcmp(mode, "pps"))
{
- counterid = service->counters.nic_packets_tx;
+ path = "net/packetsTx[summation]";
coeff = 1;
}
else
@@ -2107,7 +2232,7 @@
goto unlock;
}
- ret = vmware_service_get_vm_counter(service, uuid, instance, counterid, coeff, result);
+ ret = vmware_service_get_vm_counter(service, uuid, instance, path, coeff, result);
unlock:
zbx_vmware_unlock();
out:
@@ -2125,7 +2250,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("storage", "committed"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_STORAGE("committed"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -2141,7 +2266,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("storage", "unshared"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_STORAGE("unshared"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -2157,7 +2282,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("storage", "uncommitted"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_STORAGE("uncommitted"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -2173,7 +2298,7 @@
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
- ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "uptimeSeconds"), result);
+ ret = get_vcenter_vmstat(request, username, password, ZBX_VM_QUICKSTATS("uptimeSeconds"), result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
@@ -2259,8 +2384,8 @@
char *url, *uuid, *instance, *mode;
zbx_vmware_service_t *service;
- zbx_uint64_t counterid;
int coeff, ret = SYSINFO_RET_FAIL;
+ const char *path;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
@@ -2294,12 +2419,12 @@
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bps"))
{
- counterid = service->counters.disk_read;
+ path = "virtualDisk/read[average]";
coeff = ZBX_KIBIBYTE;
}
else if (0 == strcmp(mode, "ops"))
{
- counterid = service->counters.disk_number_read_averaged;
+ path = "virtualDisk/numberReadAveraged[average]";
coeff = 1;
}
else
@@ -2308,7 +2433,7 @@
goto unlock;
}
- ret = vmware_service_get_vm_counter(service, uuid, instance, counterid, coeff, result);
+ ret = vmware_service_get_vm_counter(service, uuid, instance, path, coeff, result);
unlock:
zbx_vmware_unlock();
out:
@@ -2324,8 +2449,8 @@
char *url, *uuid, *instance, *mode;
zbx_vmware_service_t *service;
- zbx_uint64_t counterid;
int coeff, ret = SYSINFO_RET_FAIL;
+ const char *path;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
@@ -2359,12 +2484,12 @@
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bps"))
{
- counterid = service->counters.disk_write;
+ path = "virtualDisk/write[average]";
coeff = ZBX_KIBIBYTE;
}
else if (0 == strcmp(mode, "ops"))
{
- counterid = service->counters.disk_number_write_averaged;
+ path = "virtualDisk/numberWriteAveraged[average]";
coeff = 1;
}
else
@@ -2373,7 +2498,7 @@
goto unlock;
}
- ret = vmware_service_get_vm_counter(service, uuid, instance, counterid, coeff, result);
+ ret = vmware_service_get_vm_counter(service, uuid, instance, path, coeff, result);
unlock:
zbx_vmware_unlock();
out:
@@ -2544,4 +2669,65 @@
return ret;
}
+int check_vcenter_vm_perfcounter(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result)
+{
+ const char *__function_name = "check_vcenter_vm_perfcounter";
+ int ret = SYSINFO_RET_FAIL;
+ char *url, *uuid, *path, *instance;
+ zbx_vmware_service_t *service;
+ zbx_vmware_vm_t *vm;
+ zbx_uint64_t counterid;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+
+ if (3 > request->nparam || request->nparam > 4)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
+ goto out;
+ }
+
+ url = get_rparam(request, 0);
+ uuid = get_rparam(request, 1);
+ path = get_rparam(request, 2);
+ instance = get_rparam(request, 3);
+
+ if (NULL == instance)
+ instance = "";
+
+ zbx_vmware_lock();
+
+ if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
+ goto unlock;
+
+ if (NULL == (vm = service_vm_get(service, uuid)))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Unknown virtual machine uuid."));
+ goto unlock;
+ }
+
+ if (FAIL == zbx_vmware_service_get_perfcounterid(service, path, &counterid))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter is not available."));
+ goto unlock;
+ }
+
+ if (SUCCEED == zbx_vmware_service_start_monitoring(service, "VirtualMachine", vm->id, counterid))
+ {
+ ret = SYSINFO_RET_OK;
+ goto unlock;
+ }
+
+ /* the performance counter is already being monitored, try to get the results from statistics */
+ ret = vmware_service_counter_get(service, "VirtualMachine", vm->id, path, instance, 1, result);
+
+unlock:
+ zbx_vmware_unlock();
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
+
+ return ret;
+}
+
+
#endif /* defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment