ZabbixAgent: zabbix-2.4.7.patch

File zabbix-2.4.7.patch, 8.2 KB (added by alx, 8 years ago)
  • src/libs/zbxserver/evalfunc.c

    old new  
    15661566
    15671567/******************************************************************************
    15681568 *                                                                            *
     1569 * Function: evaluate_HEXCODEAT                                             *
     1570 *                                                                            *
     1571 * Purpose: return character code if the item at given position               *
     1572 *                                                                            *
     1573 * Parameters: value - buffer of size MAX_BUFFER_LEN                          *
     1574 *             item - item (performance metric)                               *
     1575 *             parameters - Nth last value and time shift (optional)          *
     1576 *                                                                            *
     1577 * Return value: SUCCEED - evaluated successfully, result is stored in 'value'*
     1578 *               FAIL - failed to evaluate function                           *
     1579 *                                                                            *
     1580 ******************************************************************************/
     1581static int      evaluate_HEXCODEAT(char *value, DC_ITEM *item, const char *function, const char *parameters, time_t now)
     1582{
     1583        const char      *__function_name = "evaluate_HEXCODEAT";
     1584        const char      *str;
     1585        int             nparams, arg, flag, ret = FAIL;
     1586        char            *last_parameters = NULL;
     1587
     1588        zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
     1589
     1590        if (ITEM_VALUE_TYPE_STR != item->value_type && ITEM_VALUE_TYPE_TEXT != item->value_type &&
     1591                        ITEM_VALUE_TYPE_LOG != item->value_type)
     1592                goto clean;
     1593
     1594        if (3 < (nparams = num_param(parameters)))
     1595                goto clean;
     1596
     1597        if (SUCCEED != get_function_parameter_uint31(item->host.hostid, parameters, 2, &arg, &flag) ||
     1598                        ZBX_FLAG_SEC != flag)
     1599        {
     1600                goto clean;
     1601        }
     1602
     1603        /* prepare the 1st and the 3rd parameter for passing to evaluate_LAST() */
     1604        last_parameters = zbx_strdup(NULL, parameters);
     1605        remove_param(last_parameters, 2);
     1606
     1607        if (SUCCEED == evaluate_LAST(value, item, "last", last_parameters, now))
     1608        {
     1609                for (str = value, flag = 0; '\0' != *str; flag++)
     1610                {
     1611                        if (0 == isxdigit(*str))
     1612                                break;
     1613
     1614                        if (0 == isxdigit(*(str + 1)))
     1615                                break;
     1616
     1617                        if(flag == arg) {
     1618                                flag = (zbx_hex2num(*str) << 4) + zbx_hex2num(*(str + 1));
     1619                                zbx_snprintf(value, MAX_BUFFER_LEN, "%d", flag);
     1620                                ret = SUCCEED;
     1621                                break;
     1622                        }
     1623
     1624                        str += 2;
     1625
     1626                        while(isspace(*str))
     1627                            str++;
     1628                }
     1629        }
     1630
     1631        zbx_free(last_parameters);
     1632clean:
     1633        zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
     1634
     1635        return ret;
     1636}
     1637
     1638/******************************************************************************
     1639 *                                                                            *
     1640 * Function: evaluate_NTHWORD                                                 *
     1641 *                                                                            *
     1642 * Purpose: return Nth word from the string item                              *
     1643 *                                                                            *
     1644 * Parameters: value - buffer of size MAX_BUFFER_LEN                          *
     1645 *             item - item (performance metric)                               *
     1646 *             parameters - Nth last value and time shift (optional)          *
     1647 *                                                                            *
     1648 * Return value: SUCCEED - evaluated successfully, result is stored in 'value'*
     1649 *               FAIL - failed to evaluate function                           *
     1650 *                                                                            *
     1651 ******************************************************************************/
     1652static int      evaluate_NTHWORD(char *value, DC_ITEM *item, const char *function, const char *parameters, time_t now)
     1653{
     1654        const char      *__function_name = "evaluate_NTHWORD";
     1655        char            *str, *token;
     1656        int             nparams, arg, flag, ret = FAIL;
     1657        char            *last_parameters = NULL;
     1658        char            *tmpstring = NULL;
     1659
     1660        zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
     1661
     1662        if (ITEM_VALUE_TYPE_STR != item->value_type && ITEM_VALUE_TYPE_TEXT != item->value_type &&
     1663                        ITEM_VALUE_TYPE_LOG != item->value_type)
     1664                goto clean;
     1665
     1666        if (3 < (nparams = num_param(parameters)))
     1667                goto clean;
     1668
     1669        if (SUCCEED != get_function_parameter_uint31(item->host.hostid, parameters, 2, &arg, &flag) ||
     1670                        ZBX_FLAG_SEC != flag)
     1671        {
     1672                goto clean;
     1673        }
     1674
     1675        /* prepare the 1st and the 3rd parameter for passing to evaluate_LAST() */
     1676        last_parameters = zbx_strdup(NULL, parameters);
     1677        remove_param(last_parameters, 2);
     1678
     1679        if (SUCCEED == evaluate_LAST(value, item, "last", last_parameters, now))
     1680        {
     1681            tmpstring = zbx_strdup(NULL, value);
     1682            for(str = tmpstring, flag = 0; (token = strsep(&str, " \t\n\v\f\r")) != NULL; ) {
     1683                if(*token == '\0')
     1684                    continue;           // empty token
     1685
     1686                if(flag == arg) {
     1687                    zbx_snprintf(value, MAX_BUFFER_LEN, "%s", token);
     1688                    ret = SUCCEED;
     1689                    break;
     1690                }
     1691
     1692                flag++;
     1693            }
     1694            zbx_free(tmpstring);
     1695        }
     1696
     1697        zbx_free(last_parameters);
     1698clean:
     1699        zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
     1700
     1701        return ret;
     1702}
     1703
     1704/******************************************************************************
     1705 *                                                                            *
    15691706 * Function: evaluate_FUZZYTIME                                               *
    15701707 *                                                                            *
    15711708 * Purpose: evaluate function 'fuzzytime' for the item                        *
     
    17971934        {
    17981935                ret = evaluate_STRLEN(value, item, function, parameter, now);
    17991936        }
     1937        else if (0 == strcmp(function, "hexcodeat"))
     1938        {
     1939                ret = evaluate_HEXCODEAT(value, item, function, parameter, now);
     1940        }
     1941        else if (0 == strcmp(function, "nthword"))
     1942        {
     1943                ret = evaluate_NTHWORD(value, item, function, parameter, now);
     1944        }
    18001945        else if (0 == strcmp(function, "now"))
    18011946        {
    18021947                zbx_snprintf(value, MAX_BUFFER_LEN, "%d", (int)now);
  • frontends/php/include/classes/validators/CFunctionValidator.php

    old new  
    8989                                ),
    9090                                'value_types' => $valueTypesInt
    9191                        ),
     92                        'hexcodeat' => array(
     93                                'args' => array(
     94                                        array('type' => 'sec_num_zero', 'mandat' => true, 'can_be_empty' => true),
     95                                        array('type' => 'num', 'mandat' => true),
     96                                        array('type' => 'sec_zero', 'can_be_empty' => true)
     97                                ),
     98                                'value_types' => $valueTypesChar
     99                        ),
     100                        'nthword' => array(
     101                                'args' => array(
     102                                        array('type' => 'sec_num_zero', 'mandat' => true, 'can_be_empty' => true),
     103                                        array('type' => 'num', 'mandat' => true),
     104                                        array('type' => 'sec_zero', 'can_be_empty' => true)
     105                                ),
     106                                'value_types' => $valueTypesChar
     107                        ),
    92108                        'change' => array(
    93109                                'args' => $argsIgnored,
    94110                                'value_types' => $valueTypesAll
  • frontends/php/include/triggers.inc.php

    old new  
    20592059
    20602060        $function_info = array(
    20612061                'band' =>               array('value_type' => _('Numeric (integer 64bit)'),     'type' => T_ZBX_INT, 'validation' => NOT_EMPTY),
     2062                'hexcodeat' =>          array('value_type' => _('Numeric (integer 64bit)'),     'type' => T_ZBX_INT, 'validation' => NOT_EMPTY),
     2063                'nthword' =>            array('value_type' => _('Numeric (integer 64bit)'),     'type' => T_ZBX_INT, 'validation' => NOT_EMPTY),
    20622064                'abschange' =>  array('value_type' => $value_type,      'type' => $type_of_value_type,  'validation' => NOT_EMPTY),
    20632065                'avg' =>                array('value_type' => $value_type,      'type' => $type_of_value_type,  'validation' => NOT_EMPTY),
    20642066                'change' =>             array('value_type' => $value_type,      'type' => $type_of_value_type,  'validation' => NOT_EMPTY),
  • src/libs/zbxcommon/str.c

    old new  
    17841784 ******************************************************************************/
    17851785u_char  zbx_hex2num(char c)
    17861786{
     1787        c = tolower(c);
    17871788        if (c >= 'a')
    17881789                return c - 0x57; /* a-f */
    17891790        else