Ad Widget

Collapse

[1.6.4] [pre-1.6.5] replace .last(0) and .last(1) of text items by actual value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jjochum
    Junior Member
    • Jun 2009
    • 2

    #1

    [1.6.4] [pre-1.6.5] replace .last(0) and .last(1) of text items by actual value

    Currently when using.last(0) and .last(1) in actions, they are replaced only by the first line / the first 255 chars of the whole text output. The attached patch replaces those functions by history_text.value instead of items.lastvalue / items.prevvalue.
    Please consider merging this upstream.
    This should also fix the problem experienced in



    Regards,
    Jonas Jochum

    Code:
    --- src/libs/zbxserver/evalfunc.c.orig	2009-06-04 18:06:59.000000000 +0200
    +++ src/libs/zbxserver/evalfunc.c	2009-06-04 18:12:13.000000000 +0200
    @@ -633,45 +633,62 @@
     	default:
     		return FAIL;
     	}
    -
    -	switch (num) {
    -	case 1:
    -		if (1 != item->lastvalue_null)
    -		{
    -			switch (item->value_type) {
    -			case ITEM_VALUE_TYPE_FLOAT:
    -				zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_DBL, item->lastvalue_dbl);
    -				del_zeroes(value);
    -				break;
    -			case ITEM_VALUE_TYPE_UINT64:
    -				zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_UI64, item->lastvalue_uint64);
    -				break;
    -			default:
    -				zbx_snprintf(value, MAX_STRING_LEN, "%s", item->lastvalue_str);
    -				break;
    -			}
    -			ret = SUCCEED;
    -		}
    -		break;
    -	case 2:
    -		if (1 != item->prevvalue_null)
    -		{
    -			switch (item->value_type) {
    -			case ITEM_VALUE_TYPE_FLOAT:
    -				zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_DBL, item->prevvalue_dbl);
    -				del_zeroes(value);
    +	if( ITEM_VALUE_TYPE_TEXT != item->value_type ) {
    +		switch (num) {
    +			case 1:
    +				if (1 != item->lastvalue_null)
    +				{
    +					switch (item->value_type) {
    +						case ITEM_VALUE_TYPE_FLOAT:
    +							zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_DBL, item->lastvalue_dbl);
    +							del_zeroes(value);
    +							break;
    +						case ITEM_VALUE_TYPE_UINT64:
    +							zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_UI64, item->lastvalue_uint64);
    +							break;
    +						default:
    +							zbx_snprintf(value, MAX_STRING_LEN, "%s", item->lastvalue_str);
    +							break;
    +					}
    +					ret = SUCCEED;
    +				}
     				break;
    -			case ITEM_VALUE_TYPE_UINT64:
    -				zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_UI64, item->prevvalue_uint64);
    +			case 2:
    +				if (1 != item->prevvalue_null)
    +				{
    +					switch (item->value_type) {
    +						case ITEM_VALUE_TYPE_FLOAT:
    +							zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_DBL, item->prevvalue_dbl);
    +							del_zeroes(value);
    +							break;
    +						case ITEM_VALUE_TYPE_UINT64:
    +							zbx_snprintf(value, MAX_STRING_LEN, ZBX_FS_UI64, item->prevvalue_uint64);
    +							break;
    +						default:
    +							zbx_snprintf(value, MAX_STRING_LEN, "%s", item->prevvalue_str);
    +							break;
    +					}
    +					ret = SUCCEED;
    +				}
     				break;
     			default:
    -				zbx_snprintf(value, MAX_STRING_LEN, "%s", item->prevvalue_str);
    -				break;
    -			}
    -			ret = SUCCEED;
    +				zbx_snprintf(sql, sizeof(sql), "select value, clock from %s where itemid=" ZBX_FS_UI64 " order by %s desc",
    +						table,
    +						item->itemid,
    +						key);
    +
    +				result = DBselectN(sql, num);
    +
    +				while (NULL != (row = DBfetch(result)))
    +					if (num == ++rows)
    +					{
    +						zbx_snprintf(value, MAX_STRING_LEN, "%s", row[0]);
    +						ret = SUCCEED;
    +					}
    +
    +				DBfree_result(result);
     		}
    -		break;
    -	default:
    +	} else {
     		zbx_snprintf(sql, sizeof(sql), "select value, clock from %s where itemid=" ZBX_FS_UI64 " order by %s desc",
     				table,
     				item->itemid,
    @@ -688,7 +705,6 @@
     
     		DBfree_result(result);
     	}
    -
     	zabbix_log(LOG_LEVEL_DEBUG, "End of evaluate_LAST()");
     
     	return ret;
    Last edited by jjochum; 05-06-2009, 16:09. Reason: Added patch
  • richlv
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2005
    • 3112

    #2
    Zabbix 3.0 Network Monitoring book

    Comment

    • igor
      ZABBIX Support Specialist
      • Mar 2009
      • 40

      #3
      Hi Jonas!

      Issue ZBX-1038 will be fixed in v2.0 by changing items.lastvalue and tems.prevvalue to be of type text, rather than varchar(255).

      Comment

      Working...