| 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 | ******************************************************************************/ |
| 1581 | static 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); |
| 1632 | clean: |
| 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 | ******************************************************************************/ |
| 1652 | static 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); |
| 1698 | clean: |
| 1699 | zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); |
| 1700 | |
| 1701 | return ret; |
| 1702 | } |
| 1703 | |
| 1704 | /****************************************************************************** |
| 1705 | * * |