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/solaris/diskspace.c')
-rw-r--r--src/libs/zbxsysinfo/solaris/diskspace.c93
1 files changed, 62 insertions, 31 deletions
diff --git a/src/libs/zbxsysinfo/solaris/diskspace.c b/src/libs/zbxsysinfo/solaris/diskspace.c
index 7752cda1043..57f754ab3ad 100644
--- a/src/libs/zbxsysinfo/solaris/diskspace.c
+++ b/src/libs/zbxsysinfo/solaris/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
# ifdef HAVE_SYS_STATVFS64
@@ -37,10 +38,11 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#endif
struct ZBX_STATFS s;
- assert(fs);
-
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;
@@ -70,10 +72,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);
@@ -82,10 +88,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);
@@ -94,10 +104,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);
@@ -107,10 +121,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);
@@ -119,10 +137,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);
@@ -132,16 +154,22 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
- int ret = SYSINFO_RET_FAIL;
+ int ret;
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);
@@ -154,44 +182,47 @@ 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 ret;
}
int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- int ret = SYSINFO_RET_FAIL;
struct mnttab mt;
FILE *f;
struct zbx_json j;
+ /* opening the mounted filesystems file */
+ if (NULL == (f = fopen("/etc/mnttab", "r")))
+ {
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /etc/mnttab: %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);
- /* opening the mounted filesystems file */
- if (NULL != (f = fopen("/etc/mnttab", "r")))
+ /* fill mnttab structure from file */
+ while (-1 != getmntent(f, &mt))
{
- /* fill mnttab structure from file */
- while (-1 != getmntent(f, &mt))
- {
- zbx_json_addobject(&j, NULL);
- zbx_json_addstring(&j, "{#FSNAME}", mt.mnt_mountp, ZBX_JSON_TYPE_STRING);
- zbx_json_addstring(&j, "{#FSTYPE}", mt.mnt_fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_close(&j);
- }
-
- zbx_fclose(f);
-
- ret = SYSINFO_RET_OK;
+ zbx_json_addobject(&j, NULL);
+ zbx_json_addstring(&j, "{#FSNAME}", mt.mnt_mountp, ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&j, "{#FSTYPE}", mt.mnt_fstype, ZBX_JSON_TYPE_STRING);
+ zbx_json_close(&j);
}
+ zbx_fclose(f);
+
zbx_json_close(&j);
SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer));
zbx_json_free(&j);
- return ret;
+ return SYSINFO_RET_OK;
}