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:
authorVladimir Levijev <vladimir.levijev@zabbix.com>2016-01-18 17:42:50 +0300
committerVladimir Levijev <vladimir.levijev@zabbix.com>2016-01-18 17:42:50 +0300
commit058abd3a0e3b57bfc5a57bd115b2e5a85935cf16 (patch)
tree5d42a02d1be8ba51de394ed7715c3ea1fcd58a54
parent9a653370af797762ced5a9965386f02e2093e2e0 (diff)
...GI..PS. [ZBX-10102] add support for log file meta information update for items with value type other than log (disregard r57741)
By accident, commit r57741 that claims adding this functionality does nothing. Please consider this commit.
-rw-r--r--create/src/schema.tmpl4
-rw-r--r--frontends/php/include/defines.inc.php2
-rw-r--r--frontends/php/latest.php42
-rw-r--r--include/common.h4
-rw-r--r--include/dbcache.h2
-rw-r--r--include/module.h32
-rw-r--r--include/proxy.h2
-rw-r--r--include/sysinfo.h143
-rw-r--r--src/libs/zbxdbcache/dbcache.c554
-rw-r--r--src/libs/zbxdbhigh/proxy.c121
-rw-r--r--src/libs/zbxdbupgrade/dbupgrade_2050.c21
-rw-r--r--src/libs/zbxsysinfo/sysinfo.c88
-rw-r--r--src/zabbix_agent/active.c2
-rw-r--r--src/zabbix_agent/active.h2
-rw-r--r--src/zabbix_server/poller/checks_java.c6
-rw-r--r--src/zabbix_server/poller/checks_simple.c12
-rw-r--r--src/zabbix_server/poller/checks_simple.h2
-rw-r--r--src/zabbix_server/poller/checks_simple_vmware.c100
-rw-r--r--src/zabbix_server/poller/checks_simple_vmware.h7
-rw-r--r--src/zabbix_server/poller/poller.c96
-rw-r--r--src/zabbix_server/snmptrapper/snmptrapper.c2
-rw-r--r--src/zabbix_server/vmware/vmware.c17
22 files changed, 773 insertions, 488 deletions
diff --git a/create/src/schema.tmpl b/create/src/schema.tmpl
index 4e0b19dd07a..fe16c338595 100644
--- a/create/src/schema.tmpl
+++ b/create/src/schema.tmpl
@@ -1004,7 +1004,7 @@ FIELD |ns |t_nanosec |'0' |NOT NULL |0
FIELD |state |t_integer |'0' |NOT NULL |0
FIELD |lastlogsize |t_bigint |'0' |NOT NULL |0
FIELD |mtime |t_integer |'0' |NOT NULL |0
-FIELD |meta |t_integer |'0' |NOT NULL |0
+FIELD |flags |t_integer |'0' |NOT NULL |0
INDEX |1 |clock
TABLE|proxy_dhistory|id|0
@@ -1337,4 +1337,4 @@ FIELD |inventory_mode |t_integer |'0' |NOT NULL |0
TABLE|dbversion||
FIELD |mandatory |t_integer |'0' |NOT NULL |
FIELD |optional |t_integer |'0' |NOT NULL |
-ROW |2050104 |2050104
+ROW |2050106 |2050106
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index a77458bf990..0bb8885124d 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -22,7 +22,7 @@
define('ZABBIX_VERSION', '3.0.0alpha7');
define('ZABBIX_API_VERSION', '3.0.0');
define('ZABBIX_EXPORT_VERSION', '3.0');
-define('ZABBIX_DB_VERSION', 2050104);
+define('ZABBIX_DB_VERSION', 2050106);
define('ZABBIX_COPYRIGHT_FROM', '2001');
define('ZABBIX_COPYRIGHT_TO', '2016');
diff --git a/frontends/php/latest.php b/frontends/php/latest.php
index 8d5770a3871..c067fe23cbf 100644
--- a/frontends/php/latest.php
+++ b/frontends/php/latest.php
@@ -190,7 +190,7 @@ if ($hosts) {
$items = API::Item()->get([
'hostids' => array_keys($hosts),
'output' => ['itemid', 'name', 'type', 'value_type', 'units', 'hostid', 'state', 'valuemapid', 'status',
- 'error', 'trends', 'history', 'delay', 'key_', 'flags'],
+ 'error', 'trends', 'history', 'delay', 'key_', 'flags', 'lastlogsize', 'mtime'],
'selectApplications' => ['applicationid'],
'selectItemDiscovery' => ['ts_delete'],
'applicationids' => ($applications !== null) ? zbx_objectValues($applications, 'applicationid') : null,
@@ -432,9 +432,11 @@ if ($filter['showDetails']) {
: make_sorting_header(_('Host'), 'host', $sortField, $sortOrder)->addStyle('width: 13%'),
make_sorting_header(_('Name'), 'name', $sortField, $sortOrder)
->addStyle('width: '.($singleHostSelected ? 34 : 21).'%'),
- (new CColHeader(_('Interval')))->addStyle('width: 5%'),
- (new CColHeader(_('History')))->addStyle('width: 5%'),
- (new CColHeader(_('Trends')))->addStyle('width: 5%'),
+// (new CColHeader(_('Interval')))->addStyle('width: 5%'),
+ (new CColHeader(_('Lastlogsize')))->addStyle('width: 14%'),
+ (new CColHeader(_('Mtime')))->addStyle('width: 14%'),
+// (new CColHeader(_('History')))->addStyle('width: 5%'),
+// (new CColHeader(_('Trends')))->addStyle('width: 5%'),
(new CColHeader(_('Type')))->addStyle('width: 8%'),
make_sorting_header(_('Last check'), 'lastclock', $sortField, $sortOrder)->addStyle('width: 14%'),
(new CColHeader(_('Last value')))->addStyle('width: 14%'),
@@ -561,13 +563,15 @@ foreach ($items as $key => $item){
$checkbox,
$hostColumn,
(new CCol([$item['name_expanded'], BR(), $itemKey]))->addClass($state_css),
- (new CCol(
- ($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER)
- ? UNKNOWN_VALUE
- : $item['delay']
- ))->addClass($state_css),
- (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css),
- (new CCol($trendValue))->addClass($state_css),
+// (new CCol(
+// ($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER)
+// ? UNKNOWN_VALUE
+// : $item['delay']
+// ))->addClass($state_css),
+ (new CCol($item['lastlogsize']))->addClass($state_css),
+ (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $item['mtime'])))->addClass($state_css),
+// (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css),
+// (new CCol($trendValue))->addClass($state_css),
(new CCol(item_type2str($item['type'])))->addClass($state_css),
(new CCol($lastClock))->addClass($state_css),
(new CCol($lastValue))->addClass($state_css),
@@ -742,13 +746,15 @@ foreach ($items as $item) {
$checkbox,
$hostColumn,
(new CCol([$item['name_expanded'], BR(), $itemKey]))->addClass($state_css),
- (new CCol(
- ($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER)
- ? UNKNOWN_VALUE
- : $item['delay']
- ))->addClass($state_css),
- (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css),
- (new CCol($trendValue))->addClass($state_css),
+// (new CCol(
+// ($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER)
+// ? UNKNOWN_VALUE
+// : $item['delay']
+// ))->addClass($state_css),
+ (new CCol($item['lastlogsize']))->addClass($state_css),
+ (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $item['mtime'])))->addClass($state_css),
+// (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css),
+// (new CCol($trendValue))->addClass($state_css),
(new CCol(item_type2str($item['type'])))->addClass($state_css),
(new CCol($lastClock))->addClass($state_css),
(new CCol($lastValue))->addClass($state_css),
diff --git a/include/common.h b/include/common.h
index 7fa1a23cbb0..1e9af7e6a4e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -611,6 +611,10 @@ const char *zbx_item_logtype_string(unsigned char logtype);
#define ZBX_HTTPITEM_TYPE_LASTSTEP 3
#define ZBX_HTTPITEM_TYPE_LASTERROR 4
+/* proxy_history flags */
+#define PROXY_HISTORY_FLAG_META 0x01
+#define PROXY_HISTORY_FLAG_NOVALUE 0x02
+
/* user permissions */
typedef enum
{
diff --git a/include/dbcache.h b/include/dbcache.h
index c2cbbd815e4..540f4946d15 100644
--- a/include/dbcache.h
+++ b/include/dbcache.h
@@ -305,7 +305,7 @@ zbx_queue_item_t;
int is_item_processed_by_server(unsigned char type, const char *key);
int in_maintenance_without_data_collection(unsigned char maintenance_status, unsigned char maintenance_type,
unsigned char type);
-void dc_add_history(zbx_uint64_t itemid, unsigned char value_type, unsigned char flags, AGENT_RESULT *value,
+void dc_add_history(zbx_uint64_t itemid, unsigned char value_type, unsigned char item_flags, AGENT_RESULT *result,
const zbx_timespec_t *ts, unsigned char state, const char *error);
void dc_flush_history();
int DCsync_history(int sync_type, int *sync_num);
diff --git a/include/module.h b/include/module.h
index e0117840ee9..f0c5ecd21fc 100644
--- a/include/module.h
+++ b/include/module.h
@@ -60,38 +60,36 @@ typedef struct
{
char *value;
char *source;
- zbx_uint64_t lastlogsize;
int timestamp;
int severity;
int logeventid;
- int mtime;
- unsigned char meta; /* meta information update (log size and mtime) */
}
zbx_log_t;
+/* agent result types */
+#define AR_UINT64 0x01
+#define AR_DOUBLE 0x02
+#define AR_STRING 0x04
+#define AR_TEXT 0x08
+#define AR_LOG 0x10
+#define AR_MESSAGE 0x20
+#define AR_META 0x40
+
/* agent return structure */
typedef struct
{
- int type;
+ zbx_uint64_t lastlogsize; /* meta information */
zbx_uint64_t ui64;
double dbl;
char *str;
char *text;
- char *msg;
-
- /* null-terminated list of pointers */
- zbx_log_t **logs;
+ char *msg; /* possible error message */
+ zbx_log_t *log;
+ int type; /* flags: see AR_* above */
+ int mtime; /* meta information */
}
AGENT_RESULT;
-/* agent result types */
-#define AR_UINT64 0x01
-#define AR_DOUBLE 0x02
-#define AR_STRING 0x04
-#define AR_TEXT 0x08
-#define AR_LOG 0x10
-#define AR_MESSAGE 0x20
-
/* SET RESULT */
#define SET_UI64_RESULT(res, val) \
@@ -124,7 +122,7 @@ AGENT_RESULT;
#define SET_LOG_RESULT(res, val) \
( \
(res)->type |= AR_LOG, \
- (res)->logs = (zbx_log_t **)(val) \
+ (res)->log = (zbx_log_t *)(val) \
)
/* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */
diff --git a/include/proxy.h b/include/proxy.h
index a11155b4c98..cac7b58289d 100644
--- a/include/proxy.h
+++ b/include/proxy.h
@@ -41,7 +41,7 @@ typedef struct
int severity;
int logeventid;
unsigned char state;
- unsigned char meta; /* meta information update (log size and mtime) */
+ unsigned char meta; /* non-zero of contains meta information (lastlogsize and mtime) */
}
AGENT_VALUE;
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 67fffefad48..69e6b82e694 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -31,80 +31,89 @@
#define ISSET_TEXT(res) ((res)->type & AR_TEXT)
#define ISSET_LOG(res) ((res)->type & AR_LOG)
#define ISSET_MSG(res) ((res)->type & AR_MESSAGE)
+#define ISSET_META(res) ((res)->type & AR_META)
+
+#define ISSET_VALUE(res) ((res)->type & (AR_UINT64 | AR_DOUBLE | AR_STRING | AR_TEXT | AR_LOG))
/* UNSET RESULT */
-#define UNSET_UI64_RESULT(res) \
-( \
- (res)->type &= ~AR_UINT64, \
- (res)->ui64 = (zbx_uint64_t)0 \
-)
-
-#define UNSET_DBL_RESULT(res) \
-( \
- (res)->type &= ~AR_DOUBLE, \
- (res)->dbl = (double)0 \
-)
-
-#define UNSET_STR_RESULT(res) \
- \
-do \
-{ \
- if ((res)->type & AR_STRING) \
- { \
- zbx_free((res)->str); \
- (res)->type &= ~AR_STRING; \
- } \
-} \
+#define UNSET_UI64_RESULT(res) \
+ \
+do \
+{ \
+ (res)->type &= ~AR_UINT64; \
+ (res)->ui64 = (zbx_uint64_t)0; \
+} \
+while (0)
+
+#define UNSET_DBL_RESULT(res) \
+ \
+do \
+{ \
+ (res)->type &= ~AR_DOUBLE; \
+ (res)->dbl = (double)0; \
+} \
while (0)
-#define UNSET_TEXT_RESULT(res) \
- \
-do \
-{ \
- if ((res)->type & AR_TEXT) \
- { \
- zbx_free((res)->text); \
- (res)->type &= ~AR_TEXT; \
- } \
-} \
+#define UNSET_STR_RESULT(res) \
+ \
+do \
+{ \
+ if ((res)->type & AR_STRING) \
+ { \
+ zbx_free((res)->str); \
+ (res)->type &= ~AR_STRING; \
+ } \
+} \
while (0)
-#define UNSET_LOG_RESULT(res) \
- \
-do \
-{ \
- if ((res)->type & AR_LOG) \
- { \
- zbx_logs_free((res)->logs); \
- (res)->type &= ~AR_LOG; \
- } \
-} \
+#define UNSET_TEXT_RESULT(res) \
+ \
+do \
+{ \
+ if ((res)->type & AR_TEXT) \
+ { \
+ zbx_free((res)->text); \
+ (res)->type &= ~AR_TEXT; \
+ } \
+} \
while (0)
-#define UNSET_MSG_RESULT(res) \
- \
-do \
-{ \
- if ((res)->type & AR_MESSAGE) \
- { \
- zbx_free((res)->msg); \
- (res)->type &= ~AR_MESSAGE; \
- } \
-} \
+#define UNSET_LOG_RESULT(res) \
+ \
+do \
+{ \
+ if ((res)->type & AR_LOG) \
+ { \
+ zbx_log_free((res)->log); \
+ (res)->type &= ~AR_LOG; \
+ } \
+} \
while (0)
-#define UNSET_RESULT_EXCLUDING(res, exc_type) \
- \
-do \
-{ \
- if (!(exc_type & AR_UINT64)) UNSET_UI64_RESULT(res); \
- if (!(exc_type & AR_DOUBLE)) UNSET_DBL_RESULT(res); \
- if (!(exc_type & AR_STRING)) UNSET_STR_RESULT(res); \
- if (!(exc_type & AR_TEXT)) UNSET_TEXT_RESULT(res); \
- if (!(exc_type & AR_LOG)) UNSET_LOG_RESULT(res); \
- if (!(exc_type & AR_MESSAGE)) UNSET_MSG_RESULT(res); \
-} \
+#define UNSET_MSG_RESULT(res) \
+ \
+do \
+{ \
+ if ((res)->type & AR_MESSAGE) \
+ { \
+ zbx_free((res)->msg); \
+ (res)->type &= ~AR_MESSAGE; \
+ } \
+} \
+while (0)
+
+#define UNSET_RESULT_EXCLUDING(res, exc_type) \
+ \
+do \
+{ \
+ if (!(exc_type & AR_UINT64)) UNSET_UI64_RESULT(res); \
+ if (!(exc_type & AR_DOUBLE)) UNSET_DBL_RESULT(res); \
+ if (!(exc_type & AR_STRING)) UNSET_STR_RESULT(res); \
+ if (!(exc_type & AR_TEXT)) UNSET_TEXT_RESULT(res); \
+ if (!(exc_type & AR_LOG)) UNSET_LOG_RESULT(res); \
+ if (!(exc_type & AR_MESSAGE)) UNSET_MSG_RESULT(res); \
+} \
while (0)
/* RETRIEVE RESULT VALUE */
@@ -113,7 +122,7 @@ while (0)
#define GET_DBL_RESULT(res) ((double *)get_result_value_by_type(res, AR_DOUBLE))
#define GET_STR_RESULT(res) ((char **)get_result_value_by_type(res, AR_STRING))
#define GET_TEXT_RESULT(res) ((char **)get_result_value_by_type(res, AR_TEXT))
-#define GET_LOG_RESULT(res) ((zbx_log_t **)get_result_value_by_type(res, AR_LOG))
+#define GET_LOG_RESULT(res) ((zbx_log_t *)get_result_value_by_type(res, AR_LOG))
#define GET_MSG_RESULT(res) ((char **)get_result_value_by_type(res, AR_MESSAGE))
void *get_result_value_by_type(AGENT_RESULT *result, int require_type);
@@ -190,7 +199,7 @@ void test_parameters();
void test_parameter(const char *key);
void init_result(AGENT_RESULT *result);
-void zbx_logs_free(zbx_log_t **logs);
+void zbx_log_free(zbx_log_t *log);
void free_result(AGENT_RESULT *result);
void init_request(AGENT_REQUEST *request);
@@ -198,13 +207,11 @@ void free_request(AGENT_REQUEST *request);
int parse_item_key(const char *itemkey, AGENT_REQUEST *request);
-zbx_log_t *add_log_result(AGENT_RESULT *result, const char *value);
-void set_log_result_empty(AGENT_RESULT *result);
-
void unquote_key_param(char *param);
void quote_key_param(char **param, int forced);
int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c);
+void set_result_meta(AGENT_RESULT *result, zbx_uint64_t lastlogsize, int mtime);
#ifdef HAVE_KSTAT_H
zbx_uint64_t get_kstat_numeric_value(const kstat_named_t *kn);
diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c
index c0eece0924d..628a1c04439 100644
--- a/src/libs/zbxdbcache/dbcache.c
+++ b/src/libs/zbxdbcache/dbcache.c
@@ -82,10 +82,15 @@ ZBX_DC_IDS;
static ZBX_DC_IDS *ids = NULL;
+#define ZBX_DC_FLAG_META 0x01 /* contains meta information (lastlogsize and mtime) */
+#define ZBX_DC_FLAG_NOVALUE 0x02 /* entry contains no value */
+#define ZBX_DC_FLAG_LLD 0x04 /* low-level discovery value */
+#define ZBX_DC_FLAG_UNDEF 0x08 /* unsupported or undefined (delta calculation failed) value */
+
typedef struct
{
zbx_uint64_t itemid;
- history_value_t value_orig; /* empty in case of meta record (see "meta" field below) */
+ history_value_t value_orig; /* empty if flag ZBX_DC_FLAG_NOVALUE is set */
history_value_t value; /* used as source for log items */
zbx_uint64_t lastlogsize;
zbx_timespec_t ts;
@@ -94,8 +99,7 @@ typedef struct
int logeventid;
int mtime;
unsigned char value_type;
- unsigned char value_undef; /* unsupported or undefined (delta calculation failed) */
- unsigned char meta; /* meta information update (log size and mtime) */
+ unsigned char flags; /* see ZBX_DC_FLAG_* above */
unsigned char keep_history;
unsigned char keep_trends;
unsigned char state;
@@ -194,15 +198,14 @@ typedef struct
dc_value_t value;
zbx_timespec_t ts;
dc_value_str_t source; /* for log items only */
- zbx_uint64_t lastlogsize; /* for log items only */
+ zbx_uint64_t lastlogsize;
int timestamp; /* for log items only */
int severity; /* for log items only */
int logeventid; /* for log items only */
- int mtime; /* for log items only */
- unsigned char meta; /* for log items only: meta information update (log size and mtime) */
+ int mtime;
unsigned char value_type;
unsigned char state;
- unsigned char flags;
+ unsigned char flags; /* see ZBX_DC_FLAG_* above */
}
dc_item_value_t;
@@ -689,7 +692,7 @@ static void DCflush_trend(ZBX_DC_TREND *trend, ZBX_DC_TREND **trends, int *trend
* Author: Alexander Vladishev *
* *
******************************************************************************/
-static void DCadd_trend(ZBX_DC_HISTORY *history, ZBX_DC_TREND **trends, int *trends_alloc, int *trends_num)
+static void DCadd_trend(const ZBX_DC_HISTORY *history, ZBX_DC_TREND **trends, int *trends_alloc, int *trends_num)
{
ZBX_DC_TREND *trend = NULL;
int hour;
@@ -752,13 +755,15 @@ static void DCmass_update_trends(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 == history[i].keep_trends)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
continue;
- if (history[i].value_type != ITEM_VALUE_TYPE_FLOAT && history[i].value_type != ITEM_VALUE_TYPE_UINT64)
+ if (0 == h->keep_trends)
continue;
- DCadd_trend(&history[i], &trends, &trends_alloc, &trends_num);
+ DCadd_trend(h, &trends, &trends_alloc, &trends_num);
}
if (cache->trends_last_cleanup_hour < hour && ZBX_TRENDS_CLEANUP_TIME < seconds)
@@ -861,11 +866,13 @@ static void DCmass_update_triggers(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 != history[i].meta)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
continue;
- itemids[item_num] = history[i].itemid;
- timespecs[item_num] = history[i].ts;
+ itemids[item_num] = h->itemid;
+ timespecs[item_num] = h->ts;
item_num++;
}
@@ -965,7 +972,7 @@ static void DCcalculate_item_delta_float(DC_ITEM *item, ZBX_DC_HISTORY *h, zbx_i
if (SUCCEED != DBchk_double(h->value.dbl))
{
h->state = ITEM_STATE_NOTSUPPORTED;
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
}
break;
@@ -981,11 +988,11 @@ static void DCcalculate_item_delta_float(DC_ITEM *item, ZBX_DC_HISTORY *h, zbx_i
if (SUCCEED != DBchk_double(h->value.dbl))
{
h->state = ITEM_STATE_NOTSUPPORTED;
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
}
}
else
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
break;
case ITEM_STORE_SIMPLE_CHANGE:
@@ -997,11 +1004,11 @@ static void DCcalculate_item_delta_float(DC_ITEM *item, ZBX_DC_HISTORY *h, zbx_i
if (SUCCEED != DBchk_double(h->value.dbl))
{
h->state = ITEM_STATE_NOTSUPPORTED;
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
}
}
else
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
break;
}
@@ -1048,7 +1055,7 @@ static void DCcalculate_item_delta_uint64(DC_ITEM *item, ZBX_DC_HISTORY *h, zbx_
h->value.ui64 = multiply_item_value_uint64(item, h->value.ui64);
}
else
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
break;
case ITEM_STORE_SIMPLE_CHANGE:
@@ -1058,7 +1065,7 @@ static void DCcalculate_item_delta_uint64(DC_ITEM *item, ZBX_DC_HISTORY *h, zbx_
h->value.ui64 = multiply_item_value_uint64(item, h->value.ui64);
}
else
- h->value_undef = 1;
+ h->flags |= ZBX_DC_FLAG_UNDEF;
break;
}
@@ -1114,19 +1121,24 @@ static void DCadd_update_item_sql(size_t *sql_offset, DC_ITEM *item, ZBX_DC_HIST
if (ITEM_STATE_NOTSUPPORTED == h->state)
goto notsupported;
- switch (item->value_type)
+ if (0 == (ZBX_DC_FLAG_NOVALUE & h->flags))
{
- case ITEM_VALUE_TYPE_FLOAT:
- DCcalculate_item_delta_float(item, h, deltaitem);
- break;
- case ITEM_VALUE_TYPE_UINT64:
- DCcalculate_item_delta_uint64(item, h, deltaitem);
- break;
- case ITEM_VALUE_TYPE_LOG:
- zbx_snprintf_alloc(&sql, &sql_alloc, sql_offset, "%slastlogsize=" ZBX_FS_UI64 ",mtime=%d",
- sql_start, h->lastlogsize, h->mtime);
- sql_start = sql_continue;
- break;
+ switch (item->value_type)
+ {
+ case ITEM_VALUE_TYPE_FLOAT:
+ DCcalculate_item_delta_float(item, h, deltaitem);
+ break;
+ case ITEM_VALUE_TYPE_UINT64:
+ DCcalculate_item_delta_uint64(item, h, deltaitem);
+ break;
+ }
+ }
+
+ if (0 != (ZBX_DC_FLAG_META & h->flags))
+ {
+ zbx_snprintf_alloc(&sql, &sql_alloc, sql_offset, "%slastlogsize=" ZBX_FS_UI64 ",mtime=%d",
+ sql_start, h->lastlogsize, h->mtime);
+ sql_start = sql_continue;
}
notsupported:
@@ -1224,8 +1236,11 @@ static void DCinventory_value_add(zbx_vector_ptr_t *inventory_values, DC_ITEM *i
if (HOST_INVENTORY_AUTOMATIC != item->host.inventory_mode)
return;
- if (0 != h->value_undef || NULL == (inventory_field = DBget_inventory_field(item->inventory_link)))
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags) ||
+ NULL == (inventory_field = DBget_inventory_field(item->inventory_link)))
+ {
return;
+ }
switch (h->value_type)
{
@@ -1374,11 +1389,11 @@ static void DCmass_update_items(ZBX_DC_HISTORY *history, int history_num)
zbx_vector_ptr_clear_ext(&inventory_values, (zbx_clean_func_t)DCinventory_value_free);
zbx_vector_ptr_destroy(&inventory_values);
- /* disable processing of deleted and disabled items by setting value_undef */
+ /* disable processing of deleted and disabled items by setting ZBX_DC_FLAG_UNDEF flag */
for (i = 0; i < history_num; i++)
{
if (FAIL == zbx_vector_uint64_bsearch(&ids, history[i].itemid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
- history[i].value_undef = 1;
+ history[i].flags |= ZBX_DC_FLAG_UNDEF;
}
zbx_vector_uint64_destroy(&ids);
@@ -1428,7 +1443,7 @@ static void DCmass_proxy_update_items(ZBX_DC_HISTORY *history, int history_num)
if (ITEM_STATE_NOTSUPPORTED == history[i].state)
continue;
- if (ITEM_VALUE_TYPE_LOG != history[i].value_type)
+ if (0 == (ZBX_DC_FLAG_META & history[i].flags))
continue;
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
@@ -1465,14 +1480,18 @@ static void dc_add_history_dbl(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 == history[i].keep_history)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
+ continue;
+
+ if (0 == h->keep_history)
continue;
- if (ITEM_VALUE_TYPE_FLOAT != history[i].value_type)
+ if (ITEM_VALUE_TYPE_FLOAT != h->value_type)
continue;
- zbx_db_insert_add_values(&db_insert, history[i].itemid, history[i].ts.sec, history[i].ts.ns,
- history[i].value.dbl);
+ zbx_db_insert_add_values(&db_insert, h->itemid, h->ts.sec, h->ts.ns, h->value.dbl);
}
zbx_db_insert_execute(&db_insert);
@@ -1495,14 +1514,18 @@ static void dc_add_history_uint(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 == history[i].keep_history)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
+ continue;
+
+ if (0 == h->keep_history)
continue;
if (ITEM_VALUE_TYPE_UINT64 != history[i].value_type)
continue;
- zbx_db_insert_add_values(&db_insert, history[i].itemid, history[i].ts.sec, history[i].ts.ns,
- history[i].value.ui64);
+ zbx_db_insert_add_values(&db_insert, h->itemid, h->ts.sec, h->ts.ns, h->value.ui64);
}
zbx_db_insert_execute(&db_insert);
@@ -1525,14 +1548,18 @@ static void dc_add_history_str(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 == history[i].keep_history)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
continue;
- if (ITEM_VALUE_TYPE_STR != history[i].value_type)
+ if (0 == h->keep_history)
continue;
- zbx_db_insert_add_values(&db_insert, history[i].itemid, history[i].ts.sec, history[i].ts.ns,
- history[i].value_orig.str);
+ if (ITEM_VALUE_TYPE_STR != h->value_type)
+ continue;
+
+ zbx_db_insert_add_values(&db_insert, h->itemid, h->ts.sec, h->ts.ns, h->value_orig.str);
}
zbx_db_insert_execute(&db_insert);
@@ -1558,14 +1585,18 @@ static void dc_add_history_text(ZBX_DC_HISTORY *history, int history_num, int ht
for (i = 0; i < history_num; i++)
{
- if (0 != history[i].value_undef || 0 == history[i].keep_history)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
+ continue;
+
+ if (0 == h->keep_history)
continue;
- if (ITEM_VALUE_TYPE_TEXT != history[i].value_type)
+ if (ITEM_VALUE_TYPE_TEXT != h->value_type)
continue;
- zbx_db_insert_add_values(&db_insert, id++, history[i].itemid, history[i].ts.sec, history[i].ts.ns,
- history[i].value_orig.str);
+ zbx_db_insert_add_values(&db_insert, id++, h->itemid, h->ts.sec, h->ts.ns, h->value_orig.str);
}
zbx_db_insert_execute(&db_insert);
@@ -1584,7 +1615,6 @@ static void dc_add_history_log(ZBX_DC_HISTORY *history, int history_num, int hlo
int i;
zbx_uint64_t id;
zbx_db_insert_t db_insert;
- const ZBX_DC_HISTORY *h;
zbx_db_insert_prepare(&db_insert, "history_log", "id", "itemid", "clock", "ns", "timestamp", "source",
"severity", "value", "logeventid", NULL);
@@ -1593,9 +1623,12 @@ static void dc_add_history_log(ZBX_DC_HISTORY *history, int history_num, int hlo
for (i = 0; i < history_num; i++)
{
- h = &history[i];
+ const ZBX_DC_HISTORY *h = &history[i];
- if (0 != h->value_undef || 0 != h->meta || 0 == h->keep_history)
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
+ continue;
+
+ if (0 == h->keep_history)
continue;
if (ITEM_VALUE_TYPE_LOG != h->value_type)
@@ -1626,16 +1659,18 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num)
{
const char *__function_name = "DCmass_add_history";
- ZBX_DC_HISTORY *h;
int i, h_num = 0, huint_num = 0, hstr_num = 0, htext_num = 0, hlog_num = 0, rc = ZBX_DB_OK;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
for (i = 0; i < history_num; i++)
{
- h = &history[i];
+ const ZBX_DC_HISTORY *h = &history[i];
- if (0 != h->value_undef || 0 != h->meta || 0 == h->keep_history)
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
+ continue;
+
+ if (0 == h->keep_history)
continue;
switch (h->value_type)
@@ -1692,9 +1727,12 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num)
for (i = 0; i < history_num; i++)
{
- h = &history[i];
+ ZBX_DC_HISTORY *h = &history[i];
+
+ if (0 == h->keep_history)
+ continue;
- if (0 != h->value_undef || 0 != h->meta || 0 == h->keep_history)
+ if (0 != (ZBX_DC_FLAG_UNDEF & h->flags) || 0 != (ZBX_DC_FLAG_NOVALUE & h->flags))
continue;
switch (h->value_type)
@@ -1735,6 +1773,9 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num)
* *
* Purpose: helper function for DCmass_proxy_add_history() *
* *
+ * Comment: this function is meant for items with value_type other other than *
+ * ITEM_VALUE_TYPE_LOG not containing meta information in result *
+ * *
******************************************************************************/
static void dc_add_proxy_history(ZBX_DC_HISTORY *history, int history_num)
{
@@ -1748,6 +1789,12 @@ static void dc_add_proxy_history(ZBX_DC_HISTORY *history, int history_num)
{
const ZBX_DC_HISTORY *h = &history[i];
+ if (0 != (h->flags & ZBX_DC_FLAG_UNDEF))
+ continue;
+
+ if (0 != (h->flags & ZBX_DC_FLAG_META))
+ continue;
+
if (ITEM_STATE_NOTSUPPORTED == h->state)
continue;
@@ -1761,6 +1808,7 @@ static void dc_add_proxy_history(ZBX_DC_HISTORY *history, int history_num)
break;
case ITEM_VALUE_TYPE_STR:
case ITEM_VALUE_TYPE_TEXT:
+ case ITEM_VALUE_TYPE_LOG:
pvalue = h->value_orig.str;
break;
default:
@@ -1776,10 +1824,82 @@ static void dc_add_proxy_history(ZBX_DC_HISTORY *history, int history_num)
/******************************************************************************
* *
+ * Function: dc_add_proxy_history_meta *
+ * *
+ * Purpose: helper function for DCmass_proxy_add_history() *
+ * *
+ * Comment: this function is meant for items with value_type other other than *
+ * ITEM_VALUE_TYPE_LOG containing meta information in result *
+ * *
+ ******************************************************************************/
+static void dc_add_proxy_history_meta(ZBX_DC_HISTORY *history, int history_num)
+{
+ int i;
+ char buffer[64], *pvalue;
+ zbx_db_insert_t db_insert;
+
+ zbx_db_insert_prepare(&db_insert, "proxy_history", "itemid", "clock", "ns", "value", "lastlogsize", "mtime",
+ "flags", NULL);
+
+ for (i = 0; i < history_num; i++)
+ {
+ unsigned int flags = PROXY_HISTORY_FLAG_META;
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (ITEM_STATE_NOTSUPPORTED == h->state)
+ continue;
+
+ if (0 != (h->flags & ZBX_DC_FLAG_UNDEF))
+ continue;
+
+ if (0 == (h->flags & ZBX_DC_FLAG_META))
+ continue;
+
+ if (ITEM_VALUE_TYPE_LOG == h->value_type)
+ continue;
+
+ if (0 == (h->flags & ZBX_DC_FLAG_NOVALUE))
+ {
+ switch (h->value_type)
+ {
+ case ITEM_VALUE_TYPE_FLOAT:
+ zbx_snprintf(pvalue = buffer, sizeof(buffer), ZBX_FS_DBL, h->value_orig.dbl);
+ break;
+ case ITEM_VALUE_TYPE_UINT64:
+ zbx_snprintf(pvalue = buffer, sizeof(buffer), ZBX_FS_UI64, h->value_orig.ui64);
+ break;
+ case ITEM_VALUE_TYPE_STR:
+ case ITEM_VALUE_TYPE_TEXT:
+ pvalue = h->value_orig.str;
+ break;
+ default:
+ THIS_SHOULD_NEVER_HAPPEN;
+ continue;
+ }
+ }
+ else
+ {
+ flags |= PROXY_HISTORY_FLAG_NOVALUE;
+ pvalue = "";
+ }
+
+ zbx_db_insert_add_values(&db_insert, h->itemid, h->ts.sec, h->ts.ns, pvalue, h->lastlogsize, h->mtime,
+ flags);
+ }
+
+ zbx_db_insert_execute(&db_insert);
+ zbx_db_insert_clean(&db_insert);
+}
+
+/******************************************************************************
+ * *
* Function: dc_add_proxy_history_log *
* *
* Purpose: helper function for DCmass_proxy_add_history() *
* *
+ * Comment: this function is meant for items with value_type *
+ * ITEM_VALUE_TYPE_LOG *
+ * *
******************************************************************************/
static void dc_add_proxy_history_log(ZBX_DC_HISTORY *history, int history_num)
{
@@ -1787,22 +1907,31 @@ static void dc_add_proxy_history_log(ZBX_DC_HISTORY *history, int history_num)
zbx_db_insert_t db_insert;
zbx_db_insert_prepare(&db_insert, "proxy_history", "itemid", "clock", "ns", "timestamp", "source", "severity",
- "value", "logeventid", "lastlogsize", "mtime", "meta", NULL);
+ "value", "logeventid", "lastlogsize", "mtime", "flags", NULL);
for (i = 0; i < history_num; i++)
{
+ unsigned int flags = PROXY_HISTORY_FLAG_META;
+ const char *pvalue;
const ZBX_DC_HISTORY *h = &history[i];
- if (ITEM_VALUE_TYPE_LOG != h->value_type)
+ if (ITEM_STATE_NOTSUPPORTED == h->state)
continue;
- if (ITEM_STATE_NOTSUPPORTED == h->state)
+ if (ITEM_VALUE_TYPE_LOG != h->value_type)
continue;
+ if (0 != (h->flags & ZBX_DC_FLAG_NOVALUE))
+ {
+ flags |= PROXY_HISTORY_FLAG_NOVALUE;
+ pvalue = "";
+ }
+ else
+ pvalue = h->value_orig.str;
+
zbx_db_insert_add_values(&db_insert, h->itemid, h->ts.sec, h->ts.ns, h->timestamp,
- NULL != h->value.str ? h->value.str : "", h->severity,
- NULL != h->value_orig.str ? h->value_orig.str : "", h->logeventid, h->lastlogsize,
- h->mtime, h->meta);
+ NULL != h->value.str ? h->value.str : "", h->severity, pvalue, h->logeventid,
+ h->lastlogsize, h->mtime, flags);
}
zbx_db_insert_execute(&db_insert);
@@ -1852,28 +1981,37 @@ static void dc_add_proxy_history_notsupported(ZBX_DC_HISTORY *history, int histo
static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num)
{
const char *__function_name = "DCmass_proxy_add_history";
- int i, h_num = 0, hlog_num = 0, notsupported_num = 0;
+ int i, h_num = 0, h_meta_num = 0, hlog_num = 0, notsupported_num = 0;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
for (i = 0; i < history_num; i++)
{
- if (ITEM_STATE_NOTSUPPORTED == history[i].state)
+ const ZBX_DC_HISTORY *h = &history[i];
+
+ if (ITEM_STATE_NOTSUPPORTED == h->state)
{
notsupported_num++;
continue;
}
- switch (history[i].value_type)
+ switch (h->value_type)
{
case ITEM_VALUE_TYPE_LOG:
- hlog_num++;
+ /* if log item has no meta information it has no other information but value */
+ if (0 != (h->flags & ZBX_DC_FLAG_META))
+ hlog_num++;
+ else
+ h_num++;
break;
case ITEM_VALUE_TYPE_FLOAT:
case ITEM_VALUE_TYPE_UINT64:
case ITEM_VALUE_TYPE_STR:
case ITEM_VALUE_TYPE_TEXT:
- h_num++;
+ if (0 != (h->flags & ZBX_DC_FLAG_META))
+ h_meta_num++;
+ else
+ h_num++;
break;
default:
THIS_SHOULD_NEVER_HAPPEN;
@@ -1883,6 +2021,9 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num)
if (0 != h_num)
dc_add_proxy_history(history, history_num);
+ if (0 != h_meta_num)
+ dc_add_proxy_history_meta(history, history_num);
+
if (0 != hlog_num)
dc_add_proxy_history_log(history, history_num);
@@ -2093,7 +2234,8 @@ static dc_item_value_t *dc_local_get_history_slot()
return &item_values[item_values_num++];
}
-static void dc_local_add_history_dbl(zbx_uint64_t itemid, const zbx_timespec_t *ts, double value_orig)
+static void dc_local_add_history_dbl(zbx_uint64_t itemid, const zbx_timespec_t *ts, double value_orig,
+ zbx_uint64_t lastlogsize, int mtime, unsigned char flags)
{
dc_item_value_t *item_value;
@@ -2103,11 +2245,20 @@ static void dc_local_add_history_dbl(zbx_uint64_t itemid, const zbx_timespec_t *
item_value->ts = *ts;
item_value->value_type = ITEM_VALUE_TYPE_FLOAT;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = 0;
- item_value->value.value_dbl = value_orig;
+ item_value->flags = flags;
+
+ if (0 != (item_value->flags & ZBX_DC_FLAG_META))
+ {
+ item_value->lastlogsize = lastlogsize;
+ item_value->mtime = mtime;
+ }
+
+ if (0 == (item_value->flags & ZBX_DC_FLAG_NOVALUE))
+ item_value->value.value_dbl = value_orig;
}
-static void dc_local_add_history_uint(zbx_uint64_t itemid, const zbx_timespec_t *ts, zbx_uint64_t value_orig)
+static void dc_local_add_history_uint(zbx_uint64_t itemid, const zbx_timespec_t *ts, zbx_uint64_t value_orig,
+ zbx_uint64_t lastlogsize, int mtime, unsigned char flags)
{
dc_item_value_t *item_value;
@@ -2117,11 +2268,20 @@ static void dc_local_add_history_uint(zbx_uint64_t itemid, const zbx_timespec_t
item_value->ts = *ts;
item_value->value_type = ITEM_VALUE_TYPE_UINT64;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = 0;
- item_value->value.value_uint = value_orig;
+ item_value->flags = flags;
+
+ if (0 != (item_value->flags & ZBX_DC_FLAG_META))
+ {
+ item_value->lastlogsize = lastlogsize;
+ item_value->mtime = mtime;
+ }
+
+ if (0 == (item_value->flags & ZBX_DC_FLAG_NOVALUE))
+ item_value->value.value_uint = value_orig;
}
-static void dc_local_add_history_str(zbx_uint64_t itemid, const zbx_timespec_t *ts, const char *value_orig)
+static void dc_local_add_history_str(zbx_uint64_t itemid, const zbx_timespec_t *ts, const char *value_orig,
+ zbx_uint64_t lastlogsize, int mtime, unsigned char flags)
{
dc_item_value_t *item_value;
@@ -2131,16 +2291,29 @@ static void dc_local_add_history_str(zbx_uint64_t itemid, const zbx_timespec_t *
item_value->ts = *ts;
item_value->value_type = ITEM_VALUE_TYPE_STR;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = 0;
- item_value->value.value_str.len = zbx_db_strlen_n(value_orig, HISTORY_STR_VALUE_LEN) + 1;
+ item_value->flags = flags;
- dc_string_buffer_realloc(item_value->value.value_str.len);
- item_value->value.value_str.pvalue = string_values_offset;
- memcpy(&string_values[string_values_offset], value_orig, item_value->value.value_str.len);
- string_values_offset += item_value->value.value_str.len;
+ if (0 != (item_value->flags & ZBX_DC_FLAG_META))
+ {
+ item_value->lastlogsize = lastlogsize;
+ item_value->mtime = mtime;
+ }
+
+ if (0 == (item_value->flags & ZBX_DC_FLAG_NOVALUE))
+ {
+ item_value->value.value_str.len = zbx_db_strlen_n(value_orig, HISTORY_STR_VALUE_LEN) + 1;
+ dc_string_buffer_realloc(item_value->value.value_str.len);
+
+ item_value->value.value_str.pvalue = string_values_offset;
+ memcpy(&string_values[string_values_offset], value_orig, item_value->value.value_str.len);
+ string_values_offset += item_value->value.value_str.len;
+ }
+ else
+ item_value->value.value_str.len = 0;
}
-static void dc_local_add_history_text(zbx_uint64_t itemid, const zbx_timespec_t *ts, const char *value_orig)
+static void dc_local_add_history_text(zbx_uint64_t itemid, const zbx_timespec_t *ts, const char *value_orig,
+ zbx_uint64_t lastlogsize, int mtime, unsigned char flags)
{
dc_item_value_t *item_value;
@@ -2150,18 +2323,29 @@ static void dc_local_add_history_text(zbx_uint64_t itemid, const zbx_timespec_t
item_value->ts = *ts;
item_value->value_type = ITEM_VALUE_TYPE_TEXT;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = 0;
- item_value->value.value_str.len = zbx_db_strlen_n(value_orig, HISTORY_TEXT_VALUE_LEN) + 1;
+ item_value->flags = flags;
- dc_string_buffer_realloc(item_value->value.value_str.len);
- item_value->value.value_str.pvalue = string_values_offset;
- memcpy(&string_values[string_values_offset], value_orig, item_value->value.value_str.len);
- string_values_offset += item_value->value.value_str.len;
+ if (0 != (item_value->flags & ZBX_DC_FLAG_META))
+ {
+ item_value->lastlogsize = lastlogsize;
+ item_value->mtime = mtime;
+ }
+
+ if (0 == (item_value->flags & ZBX_DC_FLAG_NOVALUE))
+ {
+ item_value->value.value_str.len = zbx_db_strlen_n(value_orig, HISTORY_TEXT_VALUE_LEN) + 1;
+ dc_string_buffer_realloc(item_value->value.value_str.len);
+
+ item_value->value.value_str.pvalue = string_values_offset;
+ memcpy(&string_values[string_values_offset], value_orig, item_value->value.value_str.len);
+ string_values_offset += item_value->value.value_str.len;
+ }
+ else
+ item_value->value.value_str.len = 0;
}
-static void dc_local_add_history_log(zbx_uint64_t itemid, const zbx_timespec_t *ts, const char *value_orig,
- int timestamp, const char *source, int severity, int logeventid, zbx_uint64_t lastlogsize, int mtime,
- unsigned char meta)
+static void dc_local_add_history_log(zbx_uint64_t itemid, const zbx_timespec_t *ts, const zbx_log_t *log,
+ zbx_uint64_t lastlogsize, int mtime, unsigned char flags)
{
dc_item_value_t *item_value;
@@ -2171,23 +2355,33 @@ static void dc_local_add_history_log(zbx_uint64_t itemid, const zbx_timespec_t *
item_value->ts = *ts;
item_value->value_type = ITEM_VALUE_TYPE_LOG;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = 0;
- if (NULL != value_orig)
- item_value->value.value_str.len = zbx_db_strlen_n(value_orig, HISTORY_LOG_VALUE_LEN) + 1;
- else
- item_value->value.value_str.len = 0;
- item_value->timestamp = timestamp;
+ item_value->flags = flags;
+
+ if (0 != (item_value->flags & ZBX_DC_FLAG_META))
+ {
+ item_value->lastlogsize = lastlogsize;
+ item_value->mtime = mtime;
+ }
- if (NULL != source && '\0' != *source)
- item_value->source.len = zbx_db_strlen_n(source, HISTORY_LOG_SOURCE_LEN) + 1;
+ if (0 == (item_value->flags & ZBX_DC_FLAG_NOVALUE))
+ {
+ item_value->severity = log->severity;
+ item_value->logeventid = log->logeventid;
+ item_value->timestamp = log->timestamp;
+
+ item_value->value.value_str.len = zbx_db_strlen_n(log->value, HISTORY_LOG_VALUE_LEN) + 1;
+
+ if (NULL != log->source && '\0' != *log->source)
+ item_value->source.len = zbx_db_strlen_n(log->source, HISTORY_LOG_SOURCE_LEN) + 1;
+ else
+ item_value->source.len = 0;
+ }
else
+ {
+ item_value->value.value_str.len = 0;
item_value->source.len = 0;
- item_value->severity = severity;
- item_value->logeventid = logeventid;
- item_value->lastlogsize = lastlogsize;
- item_value->mtime = mtime;
- item_value->meta = meta;
+ }
if (0 != item_value->value.value_str.len + item_value->source.len)
{
@@ -2196,14 +2390,14 @@ static void dc_local_add_history_log(zbx_uint64_t itemid, const zbx_timespec_t *
if (0 != item_value->value.value_str.len)
{
item_value->value.value_str.pvalue = string_values_offset;
- memcpy(&string_values[string_values_offset], value_orig, item_value->value.value_str.len);
+ memcpy(&string_values[string_values_offset], log->value, item_value->value.value_str.len);
string_values_offset += item_value->value.value_str.len;
}
if (0 != item_value->source.len)
{
item_value->source.pvalue = string_values_offset;
- memcpy(&string_values[string_values_offset], source, item_value->source.len);
+ memcpy(&string_values[string_values_offset], log->source, item_value->source.len);
string_values_offset += item_value->source.len;
}
}
@@ -2235,7 +2429,7 @@ static void dc_local_add_history_lld(zbx_uint64_t itemid, const zbx_timespec_t *
item_value->itemid = itemid;
item_value->ts = *ts;
item_value->state = ITEM_STATE_NORMAL;
- item_value->flags = ZBX_FLAG_DISCOVERY_RULE;
+ item_value->flags = ZBX_DC_FLAG_LLD;
item_value->value.value_str.len = strlen(value_orig) + 1;
dc_string_buffer_realloc(item_value->value.value_str.len);
@@ -2250,75 +2444,90 @@ static void dc_local_add_history_lld(zbx_uint64_t itemid, const zbx_timespec_t *
* *
* Purpose: add new value to the cache *
* *
- * Author: Alexander Vladishev *
+ * Parameters: itemid - [IN] the itemid *
+ * value_type - [IN] the value type (see ITEM_VALUE_TYPE_* defs) *
+ * item_flags - [IN] the item flags (e. g. lld rule) *
+ * result - [IN] agent result containing the value to add *
+ * ts - [IN] the value timestamp *
+ * state - [IN] the item state *
+ * error - [IN] the error message in case item state is *
+ * ITEM_STATE_NOTSUPPORTED *
* *
******************************************************************************/
-void dc_add_history(zbx_uint64_t itemid, unsigned char value_type, unsigned char flags, AGENT_RESULT *value,
+void dc_add_history(zbx_uint64_t itemid, unsigned char value_type, unsigned char item_flags, AGENT_RESULT *result,
const zbx_timespec_t *ts, unsigned char state, const char *error)
{
+ unsigned char value_flags;
+
if (ITEM_STATE_NOTSUPPORTED == state)
{
dc_local_add_history_notsupported(itemid, ts, error);
return;
}
- if (0 != (ZBX_FLAG_DISCOVERY_RULE & flags))
+ if (0 != (ZBX_FLAG_DISCOVERY_RULE & item_flags))
{
- if (NULL == GET_TEXT_RESULT(value))
+ if (NULL == GET_TEXT_RESULT(result))
return;
/* server processes low-level discovery (lld) items while proxy stores their values in db */
if (0 != (ZBX_PROGRAM_TYPE_SERVER & program_type))
- lld_process_discovery_rule(itemid, value->text, ts);
+ lld_process_discovery_rule(itemid, result->text, ts);
else
- dc_local_add_history_lld(itemid, ts, value->text);
+ dc_local_add_history_lld(itemid, ts, result->text);
return;
}
+ if (!ISSET_VALUE(result) && !ISSET_META(result))
+ return;
+
+ value_flags = 0;
+
+ if (!ISSET_VALUE(result))
+ value_flags |= ZBX_DC_FLAG_NOVALUE;
+
+ if (ISSET_META(result))
+ value_flags |= ZBX_DC_FLAG_META;
+
+ /* Add data to the local history cache if: */
+ /* 1) the NOVALUE flag is set (data contains only meta information) */
+ /* 2) the NOVALUE flag is not set and value conversion succeeded */
switch (value_type)
{
case ITEM_VALUE_TYPE_FLOAT:
- if (GET_DBL_RESULT(value))
- dc_local_add_history_dbl(itemid, ts, value->dbl);
+ if (0 != (value_flags & ZBX_DC_FLAG_NOVALUE) || GET_DBL_RESULT(result))
+ {
+ dc_local_add_history_dbl(itemid, ts, result->dbl, result->lastlogsize, result->mtime,
+ value_flags);
+ }
break;
case ITEM_VALUE_TYPE_UINT64:
- if (GET_UI64_RESULT(value))
- dc_local_add_history_uint(itemid, ts, value->ui64);
+ if (0 != (value_flags & ZBX_DC_FLAG_NOVALUE) || GET_UI64_RESULT(result))
+ {
+ dc_local_add_history_uint(itemid, ts, result->ui64, result->lastlogsize, result->mtime,
+ value_flags);
+ }
break;
case ITEM_VALUE_TYPE_STR:
- if (GET_STR_RESULT(value))
- dc_local_add_history_str(itemid, ts, value->str);
+ if (0 != (value_flags & ZBX_DC_FLAG_NOVALUE) || GET_STR_RESULT(result))
+ {
+ dc_local_add_history_str(itemid, ts, result->str, result->lastlogsize, result->mtime,
+ value_flags);
+ }
break;
case ITEM_VALUE_TYPE_TEXT:
- if (GET_TEXT_RESULT(value))
- dc_local_add_history_text(itemid, ts, value->text);
+ if (0 != (value_flags & ZBX_DC_FLAG_NOVALUE) || GET_TEXT_RESULT(result))
+ {
+ dc_local_add_history_text(itemid, ts, result->text, result->lastlogsize, result->mtime,
+ value_flags);
+ }
break;
case ITEM_VALUE_TYPE_LOG:
- if (GET_LOG_RESULT(value))
+ if (0 != (value_flags & ZBX_DC_FLAG_NOVALUE) || GET_LOG_RESULT(result))
{
- size_t i;
- zbx_log_t *log;
- zbx_timespec_t ts_tmp;
-
- /* ensure that every log item value timestamp is unique */
- ts_tmp.sec = ts->sec;
- ts_tmp.ns = ts->ns;
-
- for (i = 0; NULL != value->logs[i]; i++)
- {
- log = value->logs[i];
-
- dc_local_add_history_log(itemid, &ts_tmp, log->value, log->timestamp,
- log->source, log->severity, log->logeventid, log->lastlogsize,
- log->mtime, log->meta);
-
- if (++ts_tmp.ns == 1000000000)
- {
- ts_tmp.sec++;
- ts_tmp.ns = 0;
- }
- }
+ dc_local_add_history_log(itemid, ts, result->log, result->lastlogsize, result->mtime,
+ value_flags);
}
break;
default:
@@ -2360,7 +2569,7 @@ typedef struct zbx_hc_data_t
zbx_timespec_t ts;
int mtime;
unsigned char value_type;
- unsigned char meta;
+ unsigned char flags;
unsigned char state;
struct zbx_hc_data_t *next;
@@ -2403,21 +2612,23 @@ static void hc_free_data(zbx_hc_data_t *data)
}
else
{
- switch (data->value_type)
+ if (0 == (data->flags & ZBX_DC_FLAG_NOVALUE))
{
- case ITEM_VALUE_TYPE_STR:
- case ITEM_VALUE_TYPE_TEXT:
- __hc_mem_free_func(data->value.str);
- break;
- case ITEM_VALUE_TYPE_LOG:
- if (NULL != data->value.log->value)
+ switch (data->value_type)
+ {
+ case ITEM_VALUE_TYPE_STR:
+ case ITEM_VALUE_TYPE_TEXT:
+ __hc_mem_free_func(data->value.str);
+ break;
+ case ITEM_VALUE_TYPE_LOG:
__hc_mem_free_func(data->value.log->value);
- if (NULL != data->value.log->source)
- __hc_mem_free_func(data->value.log->source);
+ if (NULL != data->value.log->source)
+ __hc_mem_free_func(data->value.log->source);
- __hc_mem_free_func(data->value.log);
- break;
+ __hc_mem_free_func(data->value.log);
+ break;
+ }
}
}
@@ -2565,7 +2776,7 @@ static int hc_clone_history_log_data(zbx_log_value_t **dst, const dc_item_value_
* *
* Function: hc_clone_history_data *
* *
- * Purpose: clones item value into history data memory *
+ * Purpose: clones item value from local cache into history cache *
* *
* Parameters: data - [IN/OUT] a reference to the cloned value *
* item_value - [IN] the item value *
@@ -2588,6 +2799,7 @@ static int hc_clone_history_data(zbx_hc_data_t **data, const dc_item_value_t *it
(*data)->state = item_value->state;
(*data)->ts = item_value->ts;
+ (*data)->flags = item_value->flags;
DCcheck_ns(&(*data)->ts);
}
@@ -2601,7 +2813,7 @@ static int hc_clone_history_data(zbx_hc_data_t **data, const dc_item_value_t *it
return SUCCEED;
}
- if (0 != (ZBX_FLAG_DISCOVERY_RULE & item_value->flags))
+ if (0 != (ZBX_DC_FLAG_LLD & item_value->flags))
{
if (NULL == ((*data)->value.str = hc_mem_value_str_dup(&item_value->value.value_str)))
return FAIL;
@@ -2640,15 +2852,13 @@ static int hc_clone_history_data(zbx_hc_data_t **data, const dc_item_value_t *it
if (SUCCEED != hc_clone_history_log_data(&(*data)->value.log, item_value))
return FAIL;
- (*data)->lastlogsize = item_value->lastlogsize;
- (*data)->mtime = item_value->mtime;
- (*data)->meta = item_value->meta;
-
cache->stats.history_log_counter++;
break;
}
(*data)->value_type = item_value->value_type;
+ (*data)->lastlogsize = item_value->lastlogsize;
+ (*data)->mtime = item_value->mtime;
cache->stats.history_counter++;
@@ -2713,8 +2923,8 @@ static void hc_add_item_values(dc_item_value_t *item_values, int item_values_num
* *
* Function: hc_copy_history_data *
* *
- * Purpose: copies item value from history data memory into the specified *
- * history value *
+ * Purpose: copies item value from history cache into the specified history *
+ * value *
* *
* Parameters: history - [OUT] the history value *
* itemid - [IN] the item identifier *
@@ -2726,20 +2936,20 @@ static void hc_copy_history_data(ZBX_DC_HISTORY *history, zbx_uint64_t itemid, z
history->itemid = itemid;
history->ts = data->ts;
history->state = data->state;
- history->meta = data->meta;
+ history->flags = data->flags;
history->keep_history = 0;
history->keep_trends = 0;
if (ITEM_STATE_NOTSUPPORTED == data->state)
{
history->value_orig.err = data->value.str;
- history->value_undef = 1;
-
+ history->flags |= ZBX_DC_FLAG_UNDEF;
return;
}
- history->value_undef = 0;
history->value_type = data->value_type;
+ history->lastlogsize = data->lastlogsize;
+ history->mtime = data->mtime;
switch (data->value_type)
{
@@ -2763,8 +2973,6 @@ static void hc_copy_history_data(ZBX_DC_HISTORY *history, zbx_uint64_t itemid, z
history->severity = data->value.log->severity;
history->logeventid = data->value.log->logeventid;
- history->lastlogsize = data->lastlogsize;
- history->mtime = data->mtime;
break;
}
}
diff --git a/src/libs/zbxdbhigh/proxy.c b/src/libs/zbxdbhigh/proxy.c
index c04762b0283..a31ec9b97d7 100644
--- a/src/libs/zbxdbhigh/proxy.c
+++ b/src/libs/zbxdbhigh/proxy.c
@@ -1735,7 +1735,7 @@ static int proxy_get_history_data(struct zbx_json *j, zbx_uint64_t *lastid)
int logeventid;
int mtime;
unsigned char state;
- unsigned char meta;
+ unsigned char flags;
}
zbx_history_data_t;
@@ -1766,7 +1766,7 @@ static int proxy_get_history_data(struct zbx_json *j, zbx_uint64_t *lastid)
try_again:
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
"select id,itemid,clock,ns,timestamp,source,severity,"
- "value,logeventid,state,lastlogsize,mtime,meta"
+ "value,logeventid,state,lastlogsize,mtime,flags"
" from proxy_history"
" where id>" ZBX_FS_UI64
" order by id",
@@ -1820,7 +1820,7 @@ try_again:
ZBX_STR2UCHAR(hd->state, row[9]);
ZBX_STR2UINT64(hd->lastlogsize, row[10]);
hd->mtime = atoi(row[11]);
- ZBX_STR2UCHAR(hd->meta, row[12]);
+ ZBX_STR2UCHAR(hd->flags, row[12]);
len1 = strlen(row[5]) + 1;
len2 = strlen(row[7]) + 1;
@@ -1870,31 +1870,28 @@ try_again:
zbx_json_adduint64(j, ZBX_PROTO_TAG_CLOCK, hd->clock);
zbx_json_adduint64(j, ZBX_PROTO_TAG_NS, hd->ns);
- /* meta information update record does not need those */
- if (0 == hd->meta)
- {
- if (0 != hd->timestamp)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGTIMESTAMP, hd->timestamp);
+ if (0 != hd->timestamp)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGTIMESTAMP, hd->timestamp);
- if ('\0' != string_buffer[hd->psource])
- {
- zbx_json_addstring(j, ZBX_PROTO_TAG_LOGSOURCE, &string_buffer[hd->psource],
- ZBX_JSON_TYPE_STRING);
- }
-
- if (0 != hd->severity)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGSEVERITY, hd->severity);
+ if ('\0' != string_buffer[hd->psource])
+ {
+ zbx_json_addstring(j, ZBX_PROTO_TAG_LOGSOURCE, &string_buffer[hd->psource],
+ ZBX_JSON_TYPE_STRING);
+ }
- zbx_json_addstring(j, ZBX_PROTO_TAG_VALUE, &string_buffer[hd->pvalue], ZBX_JSON_TYPE_STRING);
+ if (0 != hd->severity)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGSEVERITY, hd->severity);
- if (0 != hd->logeventid)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGEVENTID, hd->logeventid);
- }
+ if (0 != hd->logeventid)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGEVENTID, hd->logeventid);
if (0 != hd->state)
zbx_json_adduint64(j, ZBX_PROTO_TAG_STATE, hd->state);
- if (ITEM_VALUE_TYPE_LOG == dc_items[i].value_type)
+ if (0 == (PROXY_HISTORY_FLAG_NOVALUE & hd->flags))
+ zbx_json_addstring(j, ZBX_PROTO_TAG_VALUE, &string_buffer[hd->pvalue], ZBX_JSON_TYPE_STRING);
+
+ if (0 != (PROXY_HISTORY_FLAG_META & hd->flags))
{
zbx_json_adduint64(j, ZBX_PROTO_TAG_LASTLOGSIZE, hd->lastlogsize);
zbx_json_adduint64(j, ZBX_PROTO_TAG_MTIME, hd->mtime);
@@ -2016,7 +2013,7 @@ void process_mass_data(zbx_socket_t *sock, zbx_uint64_t proxy_hostid, AGENT_VALU
int *processed)
{
const char *__function_name = "process_mass_data";
- AGENT_RESULT agent;
+ AGENT_RESULT result;
DC_ITEM *items = NULL;
zbx_host_key_t *keys = NULL;
size_t i;
@@ -2079,8 +2076,11 @@ void process_mass_data(zbx_socket_t *sock, zbx_uint64_t proxy_hostid, AGENT_VALU
continue;
/* empty values are only allowed for meta information update packets */
- if (ITEM_VALUE_TYPE_LOG != items[i].value_type && NULL == values[i].value)
+ if (NULL == values[i].value && 0 == values[i].meta)
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "item %s value is empty", items[i].key_orig);
continue;
+ }
if (ITEM_TYPE_AGGREGATE == items[i].type || ITEM_TYPE_CALCULATED == items[i].type)
continue;
@@ -2192,53 +2192,56 @@ void process_mass_data(zbx_socket_t *sock, zbx_uint64_t proxy_hostid, AGENT_VALU
}
else
{
- init_result(&agent);
+ int res = SUCCEED;
- if (SUCCEED == set_result_type(&agent, items[i].value_type,
- proxy_hostid ? ITEM_DATA_TYPE_DECIMAL : items[i].data_type, values[i].value))
- {
- if (ITEM_VALUE_TYPE_LOG == items[i].value_type)
- {
- zbx_log_t *log;
+ init_result(&result);
- log = agent.logs[0];
+ if (NULL != values[i].value)
+ {
+ res = set_result_type(&result, items[i].value_type,
+ (0 != proxy_hostid ? ITEM_DATA_TYPE_DECIMAL : items[i].data_type),
+ values[i].value);
+ }
- log->timestamp = values[i].timestamp;
+ if (SUCCEED == res)
+ {
+ if (ITEM_VALUE_TYPE_LOG == items[i].value_type && NULL != values[i].value)
+ {
+ result.log->timestamp = values[i].timestamp;
if (NULL != values[i].source)
{
zbx_replace_invalid_utf8(values[i].source);
- log->source = zbx_strdup(log->source, values[i].source);
+ result.log->source = zbx_strdup(result.log->source, values[i].source);
}
- log->severity = values[i].severity;
- log->logeventid = values[i].logeventid;
- log->lastlogsize = values[i].lastlogsize;
- log->mtime = values[i].mtime;
- log->meta = values[i].meta;
-
- if (NULL != log->value)
- calc_timestamp(log->value, &log->timestamp, items[i].logtimefmt);
+ result.log->severity = values[i].severity;
+ result.log->logeventid = values[i].logeventid;
+
+ calc_timestamp(result.log->value, &result.log->timestamp, items[i].logtimefmt);
}
+ if (0 != values[i].meta)
+ set_result_meta(&result, values[i].lastlogsize, values[i].mtime);
+
items[i].state = ITEM_STATE_NORMAL;
- dc_add_history(items[i].itemid, items[i].value_type, items[i].flags, &agent,
+ dc_add_history(items[i].itemid, items[i].value_type, items[i].flags, &result,
&values[i].ts, items[i].state, NULL);
if (NULL != processed)
(*processed)++;
}
- else if (ISSET_MSG(&agent))
+ else if (ISSET_MSG(&result))
{
zabbix_log(LOG_LEVEL_DEBUG, "item [%s:%s] error: %s",
- items[i].host.host, items[i].key_orig, agent.msg);
+ items[i].host.host, items[i].key_orig, result.msg);
items[i].state = ITEM_STATE_NOTSUPPORTED;
dc_add_history(items[i].itemid, items[i].value_type, items[i].flags, NULL,
- &values[i].ts, items[i].state, agent.msg);
+ &values[i].ts, items[i].state, result.msg);
}
else
- THIS_SHOULD_NEVER_HAPPEN; /* set_result_type() always sets MSG result if not SUCCEED */
+ THIS_SHOULD_NEVER_HAPPEN; /* set_result_type() always sets MSG result if not SUCCEED */
- free_result(&agent);
+ free_result(&result);
}
itemids[num] = items[i].itemid;
@@ -2389,35 +2392,41 @@ int process_hist_data(zbx_socket_t *sock, struct zbx_json_parse *jp, const zbx_u
else
zbx_timespec(&av->ts);
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, av->host_name, sizeof(av->host_name)))
+ if (SUCCEED != zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, av->host_name, sizeof(av->host_name)))
continue;
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_KEY, av->key, sizeof(av->key)))
+ if (SUCCEED != zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_KEY, av->key, sizeof(av->key)))
continue;
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_STATE, &tmp, &tmp_alloc))
av->state = (unsigned char)atoi(tmp);
+ if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_LASTLOGSIZE, &tmp, &tmp_alloc))
+ {
+ av->meta = 1; /* contains meta information */
+
+ is_uint64(tmp, &av->lastlogsize);
+ }
+
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &tmp, &tmp_alloc))
{
av->value = zbx_strdup(av->value, tmp);
}
else
{
- /* meta information update (lastlogsize and mtime) packet is missing value tag */
-
if (ITEM_STATE_NOTSUPPORTED == av->state)
{
- /* unsupported items cannot have NULL-string error message */
+ /* unsupported items cannot have empty error message */
continue;
}
- av->meta = 1;
+ if (0 == av->meta)
+ {
+ /* only meta information update packets can have empty value*/
+ continue;
+ }
}
- if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_LASTLOGSIZE, &tmp, &tmp_alloc))
- is_uint64(tmp, &av->lastlogsize);
-
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_MTIME, &tmp, &tmp_alloc))
av->mtime = atoi(tmp);
diff --git a/src/libs/zbxdbupgrade/dbupgrade_2050.c b/src/libs/zbxdbupgrade/dbupgrade_2050.c
index b49a6d197f4..873444d6da9 100644
--- a/src/libs/zbxdbupgrade/dbupgrade_2050.c
+++ b/src/libs/zbxdbupgrade/dbupgrade_2050.c
@@ -912,7 +912,6 @@ out:
return ret;
}
-
static int DBpatch_2050093(void)
{
const ZBX_FIELD field = {"userid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
@@ -1019,6 +1018,24 @@ static int DBpatch_2050104(void)
return DBadd_foreign_key("screen_usrgrp", 2, &field);
}
+static int DBpatch_2050105(void)
+{
+ const ZBX_FIELD field = {"flags", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
+
+ return DBrename_field("proxy_history", "meta", &field);
+}
+
+static int DBpatch_2050106(void)
+{
+ /* convert meta value (1) to PROXY_HISTORY_FLAG_META | PROXY_HISTORY_FLAG_NOVALUE (0x03) flags */
+ if (ZBX_DB_OK > DBexecute("update proxy_history set flags=3 where flags=1"))
+ {
+ return FAIL;
+ }
+
+ return SUCCEED;
+}
+
#endif
DBPATCH_START(2050)
@@ -1117,5 +1134,7 @@ DBPATCH_ADD(2050101, 0, 1)
DBPATCH_ADD(2050102, 0, 1)
DBPATCH_ADD(2050103, 0, 1)
DBPATCH_ADD(2050104, 0, 1)
+DBPATCH_ADD(2050105, 0, 1)
+DBPATCH_ADD(2050106, 0, 1)
DBPATCH_END()
diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c
index 45e8023e0ed..fde825af86a 100644
--- a/src/libs/zbxsysinfo/sysinfo.c
+++ b/src/libs/zbxsysinfo/sysinfo.c
@@ -242,11 +242,9 @@ static void zbx_log_init(zbx_log_t *log)
{
log->value = NULL;
log->source = NULL;
- log->lastlogsize = 0;
log->timestamp = 0;
log->severity = 0;
log->logeventid = 0;
- log->mtime = 0;
}
void init_result(AGENT_RESULT *result)
@@ -257,7 +255,7 @@ void init_result(AGENT_RESULT *result)
result->dbl = 0;
result->str = NULL;
result->text = NULL;
- result->logs = NULL;
+ result->log = NULL;
result->msg = NULL;
}
@@ -267,16 +265,10 @@ static void zbx_log_clean(zbx_log_t *log)
zbx_free(log->value);
}
-void zbx_logs_free(zbx_log_t **logs)
+void zbx_log_free(zbx_log_t *log)
{
- size_t i;
-
- for (i = 0; NULL != logs[i]; i++)
- {
- zbx_log_clean(logs[i]);
- zbx_free(logs[i]);
- }
- zbx_free(logs);
+ zbx_log_clean(log);
+ zbx_free(log);
}
void free_result(AGENT_RESULT *result)
@@ -663,43 +655,21 @@ notsupported:
return ret;
}
-void set_log_result_empty(AGENT_RESULT *result)
-{
- result->logs = zbx_malloc(result->logs, sizeof(zbx_log_t *));
-
- result->logs[0] = NULL;
- result->type |= AR_LOG;
-}
-
-zbx_log_t *add_log_result(AGENT_RESULT *result, const char *value)
+static void add_log_result(AGENT_RESULT *result, const char *value)
{
- zbx_log_t *log;
- size_t i;
-
- log = zbx_malloc(NULL, sizeof(zbx_log_t));
+ result->log = zbx_malloc(result->log, sizeof(zbx_log_t));
- zbx_log_init(log);
-
- if (NULL != value)
- log->value = zbx_strdup(log->value, value);
-
- for (i = 0; NULL != result->logs && NULL != result->logs[i]; i++)
- ;
+ zbx_log_init(result->log);
- result->logs = zbx_realloc(result->logs, sizeof(zbx_log_t *) * (i + 2));
-
- result->logs[i++] = log;
- result->logs[i] = NULL;
+ result->log->value = zbx_strdup(result->log->value, value);
result->type |= AR_LOG;
-
- return log;
}
int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c)
{
- int ret = FAIL;
zbx_uint64_t value_uint64;
double value_double;
+ int ret = FAIL;
assert(result);
@@ -760,6 +730,7 @@ int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c
if (SUCCEED != is_double(c))
break;
+
value_double = atof(c);
SET_DBL_RESULT(result, value_double);
@@ -776,8 +747,7 @@ int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c
ret = SUCCEED;
break;
case ITEM_VALUE_TYPE_LOG:
- if (NULL != c)
- zbx_replace_invalid_utf8(c);
+ zbx_replace_invalid_utf8(c);
add_log_result(result, c);
ret = SUCCEED;
break;
@@ -806,6 +776,13 @@ int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c
return ret;
}
+void set_result_meta(AGENT_RESULT *result, zbx_uint64_t lastlogsize, int mtime)
+{
+ result->lastlogsize = lastlogsize;
+ result->mtime = mtime;
+ result->type |= AR_META;
+}
+
static zbx_uint64_t *get_result_ui64_value(AGENT_RESULT *result)
{
zbx_uint64_t value;
@@ -957,38 +934,29 @@ static char **get_result_text_value(AGENT_RESULT *result)
return NULL;
}
-static zbx_log_t **get_result_log_value(AGENT_RESULT *result)
+static zbx_log_t *get_result_log_value(AGENT_RESULT *result)
{
if (0 != ISSET_LOG(result))
- return result->logs;
+ return result->log;
- if (0 != ISSET_STR(result) || 0 != ISSET_TEXT(result) || 0 != ISSET_UI64(result) || 0 != ISSET_DBL(result))
+ if (0 != ISSET_VALUE(result))
{
- zbx_log_t *log;
- size_t i;
+ result->log = zbx_malloc(result->log, sizeof(zbx_log_t));
- log = zbx_malloc(NULL, sizeof(zbx_log_t));
+ zbx_log_init(result->log);
- zbx_log_init(log);
if (0 != ISSET_STR(result))
- log->value = zbx_strdup(log->value, result->str);
+ result->log->value = zbx_strdup(result->log->value, result->str);
else if (0 != ISSET_TEXT(result))
- log->value = zbx_strdup(log->value, result->text);
+ result->log->value = zbx_strdup(result->log->value, result->text);
else if (0 != ISSET_UI64(result))
- log->value = zbx_dsprintf(log->value, ZBX_FS_UI64, result->ui64);
+ result->log->value = zbx_dsprintf(result->log->value, ZBX_FS_UI64, result->ui64);
else if (0 != ISSET_DBL(result))
- log->value = zbx_dsprintf(log->value, ZBX_FS_DBL, result->dbl);
-
- for (i = 0; NULL != result->logs && NULL != result->logs[i]; i++)
- ;
-
- result->logs = zbx_realloc(result->logs, sizeof(zbx_log_t *) * (i + 2));
+ result->log->value = zbx_dsprintf(result->log->value, ZBX_FS_DBL, result->dbl);
- result->logs[i++] = log;
- result->logs[i] = NULL;
result->type |= AR_LOG;
- return result->logs;
+ return result->log;
}
return NULL;
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index 13f7400864d..64419107293 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -959,7 +959,7 @@ static int need_meta_update(ZBX_ACTIVE_METRIC *metric, zbx_uint64_t lastlogsize_
int ret = FAIL;
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() key:%s", __function_name, metric->key);
if (0 != (ZBX_METRIC_FLAG_LOG & metric->flags))
{
diff --git a/src/zabbix_agent/active.h b/src/zabbix_agent/active.h
index 7e5e8e26b2b..cf6d3a1e1a3 100644
--- a/src/zabbix_agent/active.h
+++ b/src/zabbix_agent/active.h
@@ -71,7 +71,7 @@ extern int CONFIG_LISTEN_PORT;
#define ZBX_METRIC_FLAG_LOG_LOG 0x04 /* log[ */
#define ZBX_METRIC_FLAG_LOG_LOGRT 0x08 /* logrt[ */
#define ZBX_METRIC_FLAG_LOG_EVENTLOG 0x10 /* eventlog[ */
-#define ZBX_METRIC_FLAG_LOG /* item value type is log, one of the above */ \
+#define ZBX_METRIC_FLAG_LOG /* item for log file monitoring, one of the above */ \
(ZBX_METRIC_FLAG_LOG_LOG | ZBX_METRIC_FLAG_LOG_LOGRT | ZBX_METRIC_FLAG_LOG_EVENTLOG)
typedef struct
diff --git a/src/zabbix_server/poller/checks_java.c b/src/zabbix_server/poller/checks_java.c
index b688150f6df..97aca52bfe6 100644
--- a/src/zabbix_server/poller/checks_java.c
+++ b/src/zabbix_server/poller/checks_java.c
@@ -71,9 +71,11 @@ static int parse_response(const DC_ITEM *items, AGENT_RESULT *results, int *errc
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &value, &value_alloc))
{
- if (SUCCEED == set_result_type(&results[i],
- items[i].value_type, items[i].data_type, value))
+ if (SUCCEED == set_result_type(&results[i], items[i].value_type,
+ items[i].data_type, value))
+ {
errcodes[i] = SUCCEED;
+ }
else
errcodes[i] = NOTSUPPORTED;
}
diff --git a/src/zabbix_server/poller/checks_simple.c b/src/zabbix_server/poller/checks_simple.c
index 5fdc0049f9e..f223af7ca2c 100644
--- a/src/zabbix_server/poller/checks_simple.c
+++ b/src/zabbix_server/poller/checks_simple.c
@@ -43,7 +43,6 @@ static zbx_vmcheck_t vmchecks[] =
{
{"cluster.discovery", VMCHECK_FUNC(check_vcenter_cluster_discovery)},
{"cluster.status", VMCHECK_FUNC(check_vcenter_cluster_status)},
- {"eventlog", VMCHECK_FUNC(check_vcenter_eventlog)},
{"version", VMCHECK_FUNC(check_vcenter_version)},
{"fullname", VMCHECK_FUNC(check_vcenter_fullname)},
@@ -136,7 +135,7 @@ static int get_vmware_function(const char *key, vmfunc_t *vmfunc)
return FAIL;
}
-int get_value_simple(DC_ITEM *item, AGENT_RESULT *result)
+int get_value_simple(DC_ITEM *item, AGENT_RESULT *result, zbx_vector_ptr_t *add_results)
{
const char *__function_name = "get_value_simple";
@@ -173,6 +172,15 @@ int get_value_simple(DC_ITEM *item, AGENT_RESULT *result)
else
SET_MSG_RESULT(result, zbx_strdup(NULL, "Support for VMware checks was not compiled in."));
}
+ else if (0 == strcmp(request.key, ZBX_VMWARE_PREFIX "eventlog"))
+ {
+#if defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL)
+ if (SYSINFO_RET_OK == check_vcenter_eventlog(&request, item, result, add_results))
+ ret = SUCCEED;
+#else
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Support for VMware checks was not compiled in."));
+#endif
+ }
else
{
/* it will execute item from a loadable module if any */
diff --git a/src/zabbix_server/poller/checks_simple.h b/src/zabbix_server/poller/checks_simple.h
index 5a18631ee15..0b2eed6488e 100644
--- a/src/zabbix_server/poller/checks_simple.h
+++ b/src/zabbix_server/poller/checks_simple.h
@@ -24,6 +24,6 @@
#include "dbcache.h"
#include "sysinfo.h"
-int get_value_simple(DC_ITEM *item, AGENT_RESULT *result);
+int get_value_simple(DC_ITEM *item, AGENT_RESULT *result, zbx_vector_ptr_t *add_results);
#endif
diff --git a/src/zabbix_server/poller/checks_simple_vmware.c b/src/zabbix_server/poller/checks_simple_vmware.c
index 88f1f682036..1f7076b7568 100644
--- a/src/zabbix_server/poller/checks_simple_vmware.c
+++ b/src/zabbix_server/poller/checks_simple_vmware.c
@@ -654,7 +654,8 @@ out:
return ret;
}
-static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, AGENT_RESULT *result)
+static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, const DC_ITEM *item,
+ AGENT_RESULT *result, zbx_vector_ptr_t *add_results)
{
const char *__function_name = "vmware_get_events";
@@ -663,7 +664,6 @@ static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, AGENT
zbx_uint64_t key;
char *value, xpath[MAX_STRING_LEN];
int i, ret = SYSINFO_RET_FAIL;
- zbx_log_t *log;
struct tm tm;
time_t t;
@@ -697,6 +697,8 @@ static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, AGENT
for (i = 0; i < ids.values_num; i++)
{
+ AGENT_RESULT *add_result;
+
zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN2("Event", "key") "[.='" ZBX_FS_UI64 "']/.."
ZBX_XPATH_LN("fullFormattedMessage"), ids.values[i]);
@@ -704,49 +706,62 @@ static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, AGENT
continue;
zbx_replace_invalid_utf8(value);
- log = add_log_result(result, value);
- log->logeventid = ids.values[i];
- log->lastlogsize = ids.values[i];
- zbx_free(value);
+ add_result = zbx_malloc(NULL, sizeof(AGENT_RESULT));
- /* timestamp */
-
- zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN2("Event", "key") "[.='" ZBX_FS_UI64 "']/.."
- ZBX_XPATH_LN("createdTime"), ids.values[i]);
-
- if (NULL == (value = zbx_xml_read_value(events, xpath)))
- continue;
-
- /* 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))
+ init_result(add_result);
+ if (SUCCEED == (ret = set_result_type(add_result, item->value_type, item->flags, value)))
{
- int tz_offset;
+ set_result_meta(add_result, ids.values[i], 0);
+
+ if (ITEM_VALUE_TYPE_LOG == item->value_type)
+ {
+ char *timestamp;
+
+ add_result->log->logeventid = ids.values[i];
+ add_result->log->timestamp = 0;
+
+ zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_LN2("Event", "key")
+ "[.='" ZBX_FS_UI64 "']/.." ZBX_XPATH_LN("createdTime"),
+ ids.values[i]);
+
+ if (NULL != (timestamp = zbx_xml_read_value(events, xpath)))
+ {
+ /* 2013-06-04T14:19:23.406298Z */
+ if (6 == sscanf(timestamp, "%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)))
+ add_result->log->timestamp = (int)t + tz_offset;
+ }
- if (0 < (t = mktime(&tm)))
- log->timestamp = (int)t + tz_offset;
+ zbx_free(timestamp);
+ }
+ }
}
zbx_free(value);
+
+ zbx_vector_ptr_append(add_results, add_result);
}
}
- else
- set_log_result_empty(result);
zbx_vector_uint64_destroy(&ids);
@@ -755,13 +770,14 @@ static int vmware_get_events(const char *events, zbx_uint64_t lastlogsize, AGENT
ret = SYSINFO_RET_OK;
out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s events:%d", __function_name, sysinfo_ret_string(ret),
+ add_results->values_num);
return ret;
}
-int check_vcenter_eventlog(AGENT_REQUEST *request, const char *username, const char *password,
- AGENT_RESULT *result)
+int check_vcenter_eventlog(AGENT_REQUEST *request, const DC_ITEM *item, AGENT_RESULT *result,
+ zbx_vector_ptr_t *add_results)
{
const char *__function_name = "check_vcenter_eventlog";
@@ -781,13 +797,10 @@ int check_vcenter_eventlog(AGENT_REQUEST *request, const char *username, const c
zbx_vmware_lock();
- if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
- {
- set_log_result_empty(result);
+ if (NULL == (service = get_vmware_service(url, item->username, item->password, result, &ret)))
goto unlock;
- }
- ret = vmware_get_events(service->data->events, request->lastlogsize, result);
+ ret = vmware_get_events(service->data->events, request->lastlogsize, item, result, add_results);
unlock:
zbx_vmware_unlock();
out:
@@ -839,7 +852,7 @@ int check_vcenter_fullname(AGENT_REQUEST *request, const char *username, const c
{
const char *__function_name = "check_vcenter_fullname";
- char *url, *fullname;
+ char *url, *fullname = NULL;
zbx_vmware_service_t *service;
int ret = SYSINFO_RET_FAIL;
@@ -867,7 +880,8 @@ int check_vcenter_fullname(AGENT_REQUEST *request, const char *username, const c
unlock:
zbx_vmware_unlock();
out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, sysinfo_ret_string(ret));
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s fullname:[%s]", __function_name, sysinfo_ret_string(ret),
+ ZBX_NULL2STR(fullname));
return ret;
}
@@ -1686,7 +1700,7 @@ int check_vcenter_vm_cluster_name(AGENT_REQUEST *request, const char *username,
for (i = 0; i < service->data->hvs.values_num; i++)
{
zbx_vmware_hv_t *hv = service->data->hvs.values[i];
- zbx_vmware_vm_t *vm;
+ zbx_vmware_vm_t *vm;
if (NULL != (vm = vm_get(&hv->vms, uuid)))
{
@@ -1711,7 +1725,7 @@ out:
int check_vcenter_vm_cpu_ready(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
- const char *__function_name = "check_vcenter_vm_cpu_ready";
+ const char *__function_name = "check_vcenter_vm_cpu_ready";
zbx_vmware_service_t *service;
int ret = SYSINFO_RET_FAIL;
diff --git a/src/zabbix_server/poller/checks_simple_vmware.h b/src/zabbix_server/poller/checks_simple_vmware.h
index 51b5ea74d31..15503c634ad 100644
--- a/src/zabbix_server/poller/checks_simple_vmware.h
+++ b/src/zabbix_server/poller/checks_simple_vmware.h
@@ -23,13 +23,13 @@
#include "common.h"
#if defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL)
#include "sysinfo.h"
+#include "zbxalgo.h"
+#include "dbcache.h"
int check_vcenter_cluster_discovery(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
int check_vcenter_cluster_status(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
-int check_vcenter_eventlog(AGENT_REQUEST *request, const char *username, const char *password,
- AGENT_RESULT *result);
int check_vcenter_version(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
int check_vcenter_fullname(AGENT_REQUEST *request, const char *username, const char *password,
@@ -141,5 +141,8 @@ int check_vcenter_vm_vfs_fs_discovery(AGENT_REQUEST *request, const char *userna
int check_vcenter_vm_vfs_fs_size(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
+int check_vcenter_eventlog(AGENT_REQUEST *request, const DC_ITEM *item, AGENT_RESULT *result,
+ zbx_vector_ptr_t *add_results);
+
#endif /* defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL) */
#endif
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index c088958b5b8..8b1790329b9 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -416,7 +416,13 @@ out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
-static int get_value(DC_ITEM *item, AGENT_RESULT *result)
+static void free_result_ptr(AGENT_RESULT *result)
+{
+ free_result(result);
+ zbx_free(result);
+}
+
+static int get_value(DC_ITEM *item, AGENT_RESULT *result, zbx_vector_ptr_t *add_results)
{
const char *__function_name = "get_value";
int res = FAIL;
@@ -440,7 +446,7 @@ static int get_value(DC_ITEM *item, AGENT_RESULT *result)
break;
case ITEM_TYPE_SIMPLE:
/* simple checks use their own timeouts */
- res = get_value_simple(item, result);
+ res = get_value_simple(item, result, add_results);
break;
case ITEM_TYPE_INTERNAL:
res = get_value_internal(item, result);
@@ -517,15 +523,14 @@ static int get_value(DC_ITEM *item, AGENT_RESULT *result)
******************************************************************************/
static int get_values(unsigned char poller_type, int *nextcheck)
{
- const char *__function_name = "get_values";
- DC_ITEM items[MAX_POLLER_ITEMS];
- AGENT_RESULT results[MAX_POLLER_ITEMS];
- zbx_uint64_t lastlogsizes[MAX_POLLER_ITEMS];
- int errcodes[MAX_POLLER_ITEMS];
- zbx_timespec_t timespec;
- int i, num;
- char *port = NULL, error[ITEM_ERROR_LEN_MAX];
- int last_available = HOST_AVAILABLE_UNKNOWN;
+ const char *__function_name = "get_values";
+ DC_ITEM items[MAX_POLLER_ITEMS];
+ AGENT_RESULT results[MAX_POLLER_ITEMS];
+ int errcodes[MAX_POLLER_ITEMS];
+ zbx_timespec_t timespec;
+ char *port = NULL, error[ITEM_ERROR_LEN_MAX];
+ int i, num, last_available = HOST_AVAILABLE_UNKNOWN;
+ zbx_vector_ptr_t add_results;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
@@ -542,7 +547,6 @@ static int get_values(unsigned char poller_type, int *nextcheck)
{
init_result(&results[i]);
errcodes[i] = SUCCEED;
- lastlogsizes[i] = 0;
ZBX_STRDUP(items[i].key, items[i].key_orig);
if (SUCCEED != substitute_key_macros(&items[i].key, NULL, &items[i], NULL,
@@ -635,6 +639,8 @@ static int get_values(unsigned char poller_type, int *nextcheck)
zbx_free(port);
+ zbx_vector_ptr_create(&add_results);
+
/* retrieve item values */
if (SUCCEED == is_snmp_type(items[0].type))
{
@@ -661,7 +667,7 @@ static int get_values(unsigned char poller_type, int *nextcheck)
else if (1 == num)
{
if (SUCCEED == errcodes[0])
- errcodes[0] = get_value(&items[0], &results[0]);
+ errcodes[0] = get_value(&items[0], &results[0], &add_results);
}
else
THIS_SHOULD_NEVER_HAPPEN;
@@ -671,6 +677,8 @@ static int get_values(unsigned char poller_type, int *nextcheck)
/* process item values */
for (i = 0; i < num; i++)
{
+ zbx_uint64_t lastlogsize, *plastlogsize = NULL;
+
switch (errcodes[i])
{
case SUCCEED:
@@ -698,30 +706,55 @@ static int get_values(unsigned char poller_type, int *nextcheck)
/* remove formatting symbols from the end of the result */
/* so it could be checked by "is_uint64" and "is_double" functions */
/* when we try to get "int" or "float" values from "string" result */
- if (ISSET_STR(&results[i]))
+ if (0 != ISSET_STR(&results[i]))
zbx_rtrim(results[i].str, ZBX_WHITESPACE);
- if (ISSET_TEXT(&results[i]))
+ if (0 != ISSET_TEXT(&results[i]))
zbx_rtrim(results[i].text, ZBX_WHITESPACE);
- items[i].state = ITEM_STATE_NORMAL;
- dc_add_history(items[i].itemid, items[i].value_type, items[i].flags, &results[i], &timespec,
- items[i].state, NULL);
-
- if (0 != ISSET_LOG(&results[i]))
+ if (0 == add_results.values_num)
{
- if (NULL != results[i].logs[0])
- {
- size_t j;
+ items[i].state = ITEM_STATE_NORMAL;
+ dc_add_history(items[i].itemid, items[i].value_type, items[i].flags, &results[i],
+ &timespec, items[i].state, NULL);
+ }
+ else
+ {
+ /* vmware.eventlog item returns vector of AGENT_RESULT representing events */
- for (j = 1; NULL != results[i].logs[j]; j++)
- ;
+ int j;
+ zbx_timespec_t ts_tmp = timespec;
- lastlogsizes[i] = results[i].logs[j - 1]->lastlogsize;
+ for (j = 0; j < add_results.values_num; j++)
+ {
+ AGENT_RESULT *add_result = add_results.values[j];
+
+ if (ISSET_MSG(add_result))
+ {
+ items[i].state = ITEM_STATE_NOTSUPPORTED;
+ dc_add_history(items[i].itemid, items[i].value_type, items[i].flags,
+ NULL, &ts_tmp, items[i].state, add_result->msg);
+ }
+ else
+ {
+ items[i].state = ITEM_STATE_NORMAL;
+ dc_add_history(items[i].itemid, items[i].value_type, items[i].flags,
+ add_result, &ts_tmp, items[i].state, NULL);
+
+ if (0 != ISSET_META(add_result))
+ {
+ plastlogsize = &lastlogsize;
+ lastlogsize = add_result->lastlogsize;
+ }
+ }
+
+ /* ensure that every log item value timestamp is unique */
+ if (++ts_tmp.ns == 1000000000)
+ {
+ ts_tmp.sec++;
+ ts_tmp.ns = 0;
+ }
}
- else
- lastlogsizes[i] = items[i].lastlogsize;
}
-
}
else if (HOST_AVAILABLE_FALSE != last_available)
{
@@ -730,7 +763,7 @@ static int get_values(unsigned char poller_type, int *nextcheck)
items[i].state, results[i].msg);
}
- DCpoller_requeue_items(&items[i].itemid, &items[i].state, &timespec.sec, &lastlogsizes[i], NULL,
+ DCpoller_requeue_items(&items[i].itemid, &items[i].state, &timespec.sec, plastlogsize, NULL,
&errcodes[i], 1, poller_type, nextcheck);
zbx_free(items[i].key);
@@ -764,6 +797,9 @@ static int get_values(unsigned char poller_type, int *nextcheck)
free_result(&results[i]);
}
+ zbx_vector_ptr_clear_ext(&add_results, (zbx_mem_free_func_t)free_result_ptr);
+ zbx_vector_ptr_destroy(&add_results);
+
DCconfig_clean_items(items, NULL, num);
dc_flush_history();
diff --git a/src/zabbix_server/snmptrapper/snmptrapper.c b/src/zabbix_server/snmptrapper/snmptrapper.c
index e7c1d3d6d3f..1cf2bd90179 100644
--- a/src/zabbix_server/snmptrapper/snmptrapper.c
+++ b/src/zabbix_server/snmptrapper/snmptrapper.c
@@ -177,7 +177,7 @@ next:
case SUCCEED:
if (ITEM_VALUE_TYPE_LOG == items[i].value_type)
{
- calc_timestamp(results[i].logs[0]->value, &results[i].logs[0]->timestamp,
+ calc_timestamp(results[i].log->value, &results[i].log->timestamp,
items[i].logtimefmt);
}
diff --git a/src/zabbix_server/vmware/vmware.c b/src/zabbix_server/vmware/vmware.c
index ee7fce84bfb..292db857e60 100644
--- a/src/zabbix_server/vmware/vmware.c
+++ b/src/zabbix_server/vmware/vmware.c
@@ -3359,14 +3359,17 @@ int zbx_vmware_service_get_counterid(zbx_vmware_service_t *service, const char *
zabbix_log(LOG_LEVEL_DEBUG, "In %s() path:%s", __function_name, path);
- if (NULL != (counter = zbx_hashset_search(&service->counters, &path)))
- {
- *counterid = counter->id;
- ret = SUCCEED;
- }
+ if (NULL == (counter = zbx_hashset_search(&service->counters, &path)))
+ goto out;
+
+ *counterid = counter->id;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() counterid:" ZBX_FS_UI64, __function_name, *counterid);
+
+ ret = SUCCEED;
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s counterid:" ZBX_FS_UI64, __function_name, zbx_result_string(ret),
- *counterid);
return ret;
#else
return FAIL;