示例#1
0
/******************************************************************************
 *                                                                            *
 * Function: process_trap_for_interface                                       *
 *                                                                            *
 * Purpose: add trap to all matching items for the specified interface        *
 *                                                                            *
 * Return value: SUCCEED - a matching item was found                          *
 *               FAIL - no matching item was found (including fallback items) *
 *                                                                            *
 * Author: Rudolfs Kreicbergs                                                 *
 *                                                                            *
 ******************************************************************************/
static int	process_trap_for_interface(zbx_uint64_t interfaceid, char *trap, zbx_timespec_t *ts)
{
	DC_ITEM		*items = NULL;
	char		cmd[MAX_STRING_LEN], params[MAX_STRING_LEN], regex[MAX_STRING_LEN];
	int		count, i, ret = FAIL, fallback = -1;

	count = DCconfig_get_snmp_items_by_interfaceid(interfaceid, &items);

	for (i = 0; i < count; i++)
	{
		if (0 == parse_command(items[i].key_orig, cmd, sizeof(cmd), params, sizeof(params)))
			continue;

		if (0 == strcmp(cmd, "snmptrap.fallback"))
		{
			fallback = i;
			continue;
		}

		if (0 != strcmp(cmd, "snmptrap") || 0 != get_param(params, 1, regex, sizeof(regex)))
			continue;

		if (NULL == zbx_regexp_match(trap, regex, NULL))
			continue;

		ret = SUCCEED;
		set_item_value(&items[i], trap, ts);
	}

	if (FAIL == ret && -1 != fallback)
	{
		ret = SUCCEED;
		set_item_value(&items[fallback], trap, ts);
	}

	zbx_free(items);

	return ret;
}
示例#2
0
/*
 * Item value get/set functions - mitem_value(3X) man page
 */
static VALUE rbncurs_c_set_item_value(VALUE rb_item, VALUE value)
{
  ITEM *item = get_item(rb_item);
  return INT2NUM(set_item_value(item, RTEST(value)));
}