summaryrefslogtreecommitdiffstats
path: root/src/zabbix_server/functions.c
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-17 07:20:59 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-17 07:20:59 +0000
commit98e1bd9682f96d0c87c4fc66b10edc19afcba796 (patch)
tree6f180cc70c53854fcf8c8dc81bd35d4fbe220370 /src/zabbix_server/functions.c
parentb208fd2c76a4218c38d97c3846a41fa62ac916f1 (diff)
downloadzabbix-98e1bd9682f96d0c87c4fc66b10edc19afcba796.tar.gz
zabbix-98e1bd9682f96d0c87c4fc66b10edc19afcba796.tar.xz
zabbix-98e1bd9682f96d0c87c4fc66b10edc19afcba796.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@2327 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/functions.c')
-rw-r--r--src/zabbix_server/functions.c129
1 files changed, 95 insertions, 34 deletions
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index 0e2179e2..3543a664 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -556,48 +556,23 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
/******************************************************************************
* *
- * Function: process_new_value *
+ * Function: add_history *
* *
- * Purpose: process new item value *
+ * Purpose: add new value to history *
* *
* Parameters: item - item data *
* value - new value of the item *
+ * now - new value of the item *
* *
* Author: Alexei Vladishev *
* *
- * Comments: for trapper poller process *
+ * Comments: *
* *
******************************************************************************/
-void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
+static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now)
{
- time_t now;
char sql[MAX_STRING_LEN];
- char value_esc[MAX_STRING_LEN];
-/* char value_str[MAX_STRING_LEN];
- double value_double;*/
- double multiplier;
- char *e;
-
- zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value()");
-
- now = time(NULL);
-
-/* strscpy(value_str, value);*/
-
-/* value_double=strtod(value_str,&e);*/
-
- if(item->multiplier == ITEM_MULTIPLIER_USE)
- {
- if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) && (value->type & AR_DOUBLE))
- {
- multiplier = strtod(item->formula,&e);
- value->dbl = value->dbl * multiplier;
- }
- if( (item->value_type==ITEM_VALUE_TYPE_UINT64) && (value->type & AR_UINT64))
- {
- value->ui64 = value->ui64 * (zbx_uint64_t)atoll(item->formula);
- }
- }
+ int ret = SUCCEED;
if(item->history>0)
{
@@ -649,7 +624,7 @@ void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
{
zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta);
zabbix_syslog("Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta);
- return;
+ ret = FAIL;
}
}
else if(item->value_type==ITEM_VALUE_TYPE_STR)
@@ -668,6 +643,45 @@ void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
}
}
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: update_item *
+ * *
+ * Purpose: update item info after new value is received *
+ * *
+ * Parameters: item - item data *
+ * value - new value of the item *
+ * now - current timestamp *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
+{
+ char sql[MAX_STRING_LEN];
+ char value_esc[MAX_STRING_LEN];
+ char value_str[MAX_STRING_LEN];
+ double value_double;
+ int ret = SUCCEED;
+
+ if(value->type & AR_UINT64)
+ {
+ snprintf(value_str,MAX_STRING_LEN-1,ZBX_FS_UI64, value->ui64);
+ value_double = (double)value->ui64;
+ }
+ if(value->type & AR_DOUBLE)
+ {
+ snprintf(value_str,MAX_STRING_LEN-1,"%f", value->dbl);
+ value_double = value->dbl;
+ }
+ if(value->type & AR_STRING)
+ strscpy(value_str, value->str);
+
if(item->delta == ITEM_STORE_AS_IS)
{
if((item->prevvalue_null == 1) || (strcmp(value_str,item->lastvalue_str) != 0) || (strcmp(item->prevvalue_str,item->lastvalue_str) != 0) )
@@ -716,12 +730,10 @@ void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
{
if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) )
{
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",now+item->delay,value_double,(value_double - item->prevorgvalue),now,item->itemid);*/
snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid);
}
else
{
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);*/
snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(int)now,item->itemid);
}
@@ -735,5 +747,54 @@ void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
}
DBexecute(sql);
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: process_new_value *
+ * *
+ * Purpose: process new item value *
+ * *
+ * Parameters: item - item data *
+ * value - new value of the item *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: for trapper poller process *
+ * *
+ ******************************************************************************/
+void process_new_value(DB_ITEM *item, AGENT_RESULT *value)
+{
+ time_t now;
+/* char value_str[MAX_STRING_LEN];
+ double value_double;*/
+ double multiplier;
+ char *e;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value()");
+
+ now = time(NULL);
+
+/* strscpy(value_str, value);*/
+
+/* value_double=strtod(value_str,&e);*/
+
+ if(item->multiplier == ITEM_MULTIPLIER_USE)
+ {
+ if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) && (value->type & AR_DOUBLE))
+ {
+ multiplier = strtod(item->formula,&e);
+ value->dbl = value->dbl * multiplier;
+ }
+ if( (item->value_type==ITEM_VALUE_TYPE_UINT64) && (value->type & AR_UINT64))
+ {
+ value->ui64 = value->ui64 * (zbx_uint64_t)atoll(item->formula);
+ }
+ }
+
+ add_history(item, value, now);
+ update_item(item, value, now);
+
update_functions( item );
}