Example #1
0
static void
cancel_requests (rb_item *item, mstime when, const char *reason)
{
	ASSERT (item);
	ASSERT (reason);
	ASSERT (item->field_request || item->query_request);

	log_debug ("value for field '%s': %s", item->field, reason);

	/*
	 * We note the failure has having taken place halfway between
	 * the request and the current time.
	 */
	item->last_polled = item->last_request + ((when - item->last_request) / 2);
	item->vtype = VALUE_UNSET;

	complete_requests (item, -1);
}
Example #2
0
void ResourceManager::flush()
{
	m_loader.flush();
	complete_requests();
}
Example #3
0
static void
query_next_response (int request, int code, struct snmp_value *value, void *arg)
{
	rb_item *item = arg;
	asn_subid_t subid;
	int matched;

	/*
	 * Called when we get the next OID in a table
	 */

	ASSERT (request == item->query_request);
	ASSERT (!item->field_request);

	/* Mark this item as done */
	item->query_request = 0;

	if (code == SNMP_ERR_NOERROR) {
		ASSERT (value);

		/* Convert these result codes into 'not found' */
		switch (value->syntax) {
		case SNMP_SYNTAX_NOSUCHOBJECT:
		case SNMP_SYNTAX_NOSUCHINSTANCE:
		case SNMP_SYNTAX_ENDOFMIBVIEW:
			code = SNMP_ERR_NOSUCHNAME;
			break;

		/*
		 * Make sure that we haven't gone past the end. For it to
		 * be in the table it must be exactly one longer (the table index)
		 * and otherwise identical.
		 */
		default:
			if (item->query_oid.len + 1 != value->var.len ||
			    !asn_is_suboid (&item->query_oid, &value->var))
				code = SNMP_ERR_NOSUCHNAME;
			break;
		};
	}

	if (code == SNMP_ERR_NOSUCHNAME)
		log_debug ("query couldn't find table index that matches: %s",
		           item->query_match ? item->query_match : "[null]");


	/* Problems communicating with the server, or not found */
	if (code != SNMP_ERR_NOERROR) {
		memset (&item->query_last, 0, sizeof (item->query_last));
		complete_requests (item, code);
		return;
	}

	/* Save away the last OID we've seen */
	item->query_last = value->var;
	item->query_searched = 1;

	ASSERT (value);

	/* Match the query value received */
	if (item->query_match)
		matched = snmp_engine_match (value, item->query_match);

	/* When query match is null, anything matches */
	else
		matched = 1;

	item->query_matched = matched;
	item->vtype = VALUE_UNSET;

	if (matched) {
		/* Do a query for the field value with this sub id */
		subid = value->var.subs[value->var.len - 1];
		query_value_request (item, subid);
	} else {
		/* Look for the next table index */
		query_search_request (item);
	}
}
Example #4
0
static void
query_match_response (int request, int code, struct snmp_value *value, void *arg)
{
	rb_item *item = arg;
	int matched;

	/*
	 * Callback when SNMP request in query_request() completes.
	 *
	 * We receive a value back from the server when querying the table match OID,
	 * whenever we queried it directly (without the search).
	 */

	ASSERT (request == item->query_request);

	/* Problems communicating with the server? */
	if (code != SNMP_ERR_NOERROR && code != SNMP_ERR_NOSUCHNAME) {
		complete_requests (item, code);
		return;
	}

	/*
	 * Mark this item as done after the possible call to complete_requests
	 * otherwise complete_requests won't free everything.
	 */
	item->query_request = 0;

	matched = 0;

	if (code == SNMP_ERR_NOERROR) {
		ASSERT (value);

		/* These all signify 'not found' in our book */
		switch (value->syntax) {
		case SNMP_SYNTAX_NOSUCHOBJECT:
		case SNMP_SYNTAX_NOSUCHINSTANCE:
		case SNMP_SYNTAX_ENDOFMIBVIEW:
			break;

		/* See if we have a match */
		default:
			if (item->query_match)
				matched = snmp_engine_match (value, item->query_match);

			/* When query match is null, anything matches */
			else
				matched = 1;
			break;
		};
	}

	item->query_matched = matched;
	if (matched)
		return;

	log_debug ("query previous index did not match: %s",
	           item->query_match ? item->query_match : "[null]");

	/*
	 * When it doesn't match cancel any pending value request, and
	 * start a search for a match.
	 */
	if (item->field_request)
		snmp_engine_cancel (item->field_request);
	item->field_request = 0;
	query_search_request (item);
}
Example #5
0
static void
field_response (int request, int code, struct snmp_value *value, void *arg)
{
	rb_item *item = arg;
	mstime when;
	char asnbuf[ASN_OIDSTRLEN];

	ASSERT (request == item->field_request);

	/* Note when the response for this item arrived */
	when = server_get_time ();
	item->last_polled = when;

	/* Mark this item as done */
	item->field_request = 0;

	/* Errors result in us writing U */
	if (code != SNMP_ERR_NOERROR) {
		item->vtype = VALUE_UNSET;

	/* Parse the value from server */
	} else {
		switch(value->syntax)
		{
		case SNMP_SYNTAX_NULL:
			item->vtype = VALUE_UNSET;
			break;
		case SNMP_SYNTAX_INTEGER:
			item->v.i_value = value->v.integer;
			item->vtype = VALUE_REAL;
			break;
		case SNMP_SYNTAX_COUNTER:       /* FALLTHROUGH */
		case SNMP_SYNTAX_GAUGE:         /* FALLTHROUGH */
		case SNMP_SYNTAX_TIMETICKS:
			item->v.i_value = value->v.uint32;
			item->vtype = VALUE_REAL;
			break;
		case SNMP_SYNTAX_COUNTER64:
			item->v.i_value = value->v.counter64;
			item->vtype = VALUE_REAL;
			break;
		case SNMP_SYNTAX_OCTETSTRING:
			if (parse_string_value(value, item))
				break;
			/* FALLTHROUGH */
		case SNMP_SYNTAX_OID: 		/* FALLTHROUGH */
		case SNMP_SYNTAX_IPADDRESS:	/* FALLTHROUGH */
		case SNMP_SYNTAX_NOSUCHOBJECT:	/* FALLTHROUGH */
		case SNMP_SYNTAX_NOSUCHINSTANCE:/* FALLTHROUGH */
		case SNMP_SYNTAX_ENDOFMIBVIEW:	/* FALLTHROUGH */
		default:
			log_warnx("snmp server %s: oid %s: field %s: response %s(%u)",
			    item->hostnames[item->hostindex],
			    asn_oid2str_r(&item->field_oid, asnbuf),
			    item->field,
			    snmp_get_syntaxmsg(value->syntax),
			    value->syntax);
			break;
		};

		if (item->vtype == VALUE_REAL)
			log_debug ("got value for field '%s': %lld",
			           item->field, item->v.i_value);
		else if (item->vtype == VALUE_FLOAT)
			log_debug ("got value for field '%s': %.4lf",
			           item->field, item->v.f_value);
		else
			log_debug ("got value for field '%s': U",
			           item->field);
	}

	complete_requests (item, code);

	/* If the entire poll is done, then complete it */
	finish_poll (item->poller, when);
}