Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxsysinfo/osf/cpu.c')
-rw-r--r--src/libs/zbxsysinfo/osf/cpu.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/src/libs/zbxsysinfo/osf/cpu.c b/src/libs/zbxsysinfo/osf/cpu.c
index 845b60c37b1..d9b9db46526 100644
--- a/src/libs/zbxsysinfo/osf/cpu.c
+++ b/src/libs/zbxsysinfo/osf/cpu.c
@@ -20,6 +20,46 @@
#include "common.h"
#include "sysinfo.h"
#include "../common/common.h"
+#include "zbxalgo.h"
+#include "zbxjson.h"
+
+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;
+}
int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
{
@@ -27,19 +67,28 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
int ret = SYSINFO_RET_FAIL;
if (3 < request->nparam)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
+ }
tmp = get_rparam(request, 0);
/* only "all" (default) for parameter "cpu" is supported */
if (NULL != tmp && '\0' != *tmp && 0 != strcmp(tmp, "all"))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
+ }
tmp = get_rparam(request, 2);
/* only "avg1" (default) for parameter "mode" is supported */
if (NULL != tmp && '\0' != *tmp && 0 != strcmp(tmp, "avg1"))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
return SYSINFO_RET_FAIL;
+ }
tmp = get_rparam(request, 1);
@@ -52,7 +101,10 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
else if (0 == strcmp(tmp, "idle"))
ret = EXECUTE_DBL("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF))}'", result);
else
- ret = SYSINFO_RET_FAIL;
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
+ return SYSINFO_RET_FAIL;
+ }
return ret;
}
@@ -63,13 +115,19 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
int ret = SYSINFO_RET_FAIL;
if (2 < request->nparam)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
+ }
tmp = get_rparam(request, 0);
/* only "all" (default) for parameter "cpu" is supported */
if (NULL != tmp && '\0' != *tmp && 0 != strcmp(tmp, "all"))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
+ }
tmp = get_rparam(request, 1);
@@ -80,7 +138,10 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
else if (0 == strcmp(tmp, "avg15"))
ret = EXECUTE_DBL(cmd, "uptime | awk '{printf(\"%s\", $(NF-2))}' | sed 's/[ ,]//g'", result);
else
- ret = SYSINFO_RET_FAIL;
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
+ return SYSINFO_RET_FAIL;
+ }
return ret;
}