diff options
Diffstat (limited to 'src/libs/zbxsysinfo/netbsd/diskspace.c')
-rw-r--r-- | src/libs/zbxsysinfo/netbsd/diskspace.c | 82 |
1 files changed, 58 insertions, 24 deletions
diff --git a/src/libs/zbxsysinfo/netbsd/diskspace.c b/src/libs/zbxsysinfo/netbsd/diskspace.c index d59b797acac..f79eea03d89 100644 --- a/src/libs/zbxsysinfo/netbsd/diskspace.c +++ b/src/libs/zbxsysinfo/netbsd/diskspace.c @@ -20,9 +20,10 @@ #include "common.h" #include "sysinfo.h" #include "zbxjson.h" +#include "log.h" static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free, - zbx_uint64_t *used, double *pfree, double *pused) + zbx_uint64_t *used, double *pfree, double *pused, char **error) { #ifdef HAVE_SYS_STATVFS_H # define ZBX_STATFS statvfs @@ -34,7 +35,10 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f struct ZBX_STATFS s; if (0 != ZBX_STATFS(fs, &s)) + { + *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s", zbx_strerror(errno)); return SYSINFO_RET_FAIL; + } if (total) *total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE; @@ -64,10 +68,14 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f static int VFS_FS_USED(const char *fs, AGENT_RESULT *result) { - zbx_uint64_t value = 0; + zbx_uint64_t value; + char *error; - if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, &value, NULL, NULL)) + if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, &value, NULL, NULL, &error)) + { + SET_MSG_RESULT(result, error); return SYSINFO_RET_FAIL; + } SET_UI64_RESULT(result, value); @@ -76,10 +84,14 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result) static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result) { - zbx_uint64_t value = 0; + zbx_uint64_t value; + char *error; - if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, &value, NULL, NULL, NULL)) + if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, &value, NULL, NULL, NULL, &error)) + { + SET_MSG_RESULT(result, error); return SYSINFO_RET_FAIL; + } SET_UI64_RESULT(result, value); @@ -88,10 +100,14 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result) static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result) { - zbx_uint64_t value = 0; + zbx_uint64_t value; + char *error; - if (SYSINFO_RET_OK != get_fs_size_stat(fs, &value, NULL, NULL, NULL, NULL)) + if (SYSINFO_RET_OK != get_fs_size_stat(fs, &value, NULL, NULL, NULL, NULL, &error)) + { + SET_MSG_RESULT(result, error); return SYSINFO_RET_FAIL; + } SET_UI64_RESULT(result, value); @@ -101,10 +117,14 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result) static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result) { - double value = 0; + double value; + char *error; - if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, &value, NULL)) + if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, &value, NULL, &error)) + { + SET_MSG_RESULT(result, error); return SYSINFO_RET_FAIL; + } SET_DBL_RESULT(result, value); @@ -113,10 +133,14 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result) static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result) { - double value = 0; + double value; + char *error; - if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &value)) + if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &value, &error)) + { + SET_MSG_RESULT(result, error); return SYSINFO_RET_FAIL; + } SET_DBL_RESULT(result, value); @@ -129,13 +153,19 @@ int VFS_FS_SIZE(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; + } fsname = get_rparam(request, 0); mode = get_rparam(request, 1); if (NULL == fsname || '\0' == *fsname) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; + } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) ret = VFS_FS_TOTAL(fsname, result); @@ -148,32 +178,36 @@ int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(mode, "pused")) ret = VFS_FS_PUSED(fsname, result); else - ret = SYSINFO_RET_FAIL; + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); + return SYSINFO_RET_FAIL; + } return SYSINFO_RET_FAIL; } int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) { - int i, rc, ret = SYSINFO_RET_FAIL; + 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); - if (0 != (rc = getmntinfo(&mntbuf, MNT_WAIT))) + for (i = 0; i < rc; i++) { - 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_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); @@ -182,5 +216,5 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) zbx_json_free(&j); - return ret; + return SYSINFO_RET_OK; } |