Esempio n. 1
0
int LibWrapper::getEvents(const struct event_filter *pFilter, struct event *pEvents,
	const NVM_UINT16 count) const
{
	LogEnterExit(__FUNCTION__, __FILE__, __LINE__);
	return nvm_get_events(pFilter, pEvents, count);
}
/*!
 * Helper method to convert library events into a vector of diagnostic result structures.
 * Used by the DiagnosticCompletionRecordFactory class as well.
 */
int wbem::support::DiagnosticLogFactory::gatherDiagnosticResults(diagnosticResults_t *pResults)
throw (framework::Exception)
{
	int count = 0;

	// get all diagnostic events
	struct event_filter filter;
	memset(&filter, 0, sizeof (struct event_filter));
	filter.filter_mask = NVM_FILTER_ON_TYPE;
	filter.type = EVENT_TYPE_DIAG;
	int total_count = nvm_get_event_count(&filter);
	if (total_count < 0)
	{
		throw exception::NvmExceptionLibError(total_count);
	}
	if (total_count > 0)
	{
		struct event events[total_count];
		total_count = nvm_get_events(&filter, events, total_count);
		if (total_count < 0)
		{
			throw exception::NvmExceptionLibError(total_count);
		}
		for (int i = 0; i < total_count; i++)
		{
			bool matched = false;
			// only add a new structure if the test is unique to the type and guid
			// else another message and update the result
			for (diagnosticResults_t::iterator iter = pResults->begin();
					iter != pResults->end(); iter++)
			{
				if ((*iter).type == events[i].type)
				{
					// matched existing result - update data but do not count
					if (guid_cmp((*iter).device_guid, events[i].guid))
					{
						matched = true;
						// update id (if necessary)
						if (events[i].event_id < (*iter).id)
						{
							(*iter).id = events[i].event_id;
						}
						// update overall result (if necessary)
						if (events[i].diag_result > (*iter).result)
						{
							(*iter).result = events[i].diag_result;
						}
						// update time (if necessary)
						if (events[i].time < (*iter).time)
						{
							(*iter).time = events[i].time;
						}
						// add message
						(*iter).messages.push_back(buildDiagnosticResultMessage(&events[i]));
						break;
					}
				}
			}
			// add new result
			if (!matched)
			{
				count++;
				// copy the event information into the diagnostic result struct
				struct diagnosticResult diag;
				diag.id = events[i].event_id;
				diag.time = events[i].time;
				diag.type = events[i].type;
				memmove(diag.device_guid, events[i].guid, NVM_GUID_LEN);
				diag.result = events[i].diag_result;
				diag.messages.push_back(buildDiagnosticResultMessage(&events[i]));
				pResults->push_back(diag);
			}
		} // end for
	} // end if events

	return count;
}
Esempio n. 3
0
/*
 * On start-up look for deleted namespaces and auto-acknowledge action required events
 */
void monitor::EventMonitor::acknowledgeDeletedNamespaces()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// find action required events for all namespaces
	struct event_filter filter;
	memset(&filter, 0, sizeof(filter));
	filter.filter_mask = NVM_FILTER_ON_AR | NVM_FILTER_ON_CODE;
	filter.action_required = true;
	filter.code = EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED;
	int eventCount = nvm_get_event_count(&filter);
	if (eventCount < 0)
	{
		COMMON_LOG_ERROR_F("nvm_get_event_count failed with error %d", eventCount);
	}
	else if (eventCount > 0)
	{
		struct event events[eventCount];
		memset(events, 0, sizeof (struct event) * eventCount);
		eventCount = nvm_get_events(&filter, events, eventCount);
		if (eventCount < 0)
		{
			COMMON_LOG_ERROR_F("nvm_get_events failed with error %d", eventCount);
		}
		else if (eventCount > 0)
		{
			std::vector<std::string> nsUids;
			bool ackAll = false;
			// get namespace list
			int nsCount = nvm_get_namespace_count();
			if (nsCount < 0)
			{
				COMMON_LOG_ERROR_F("nvm_get_namespace_count failed with error %d", nsCount);
			}
			else if (nsCount == 0)
			{
				ackAll = true; // no namespaces, acknowledge them all
			}
			else // at least one namespace
			{
				struct namespace_discovery namespaces[nsCount];
				nsCount = nvm_get_namespaces(namespaces, nsCount);
				if (nsCount < 0) // error retrieving namespace list
				{
					COMMON_LOG_ERROR_F("nvm_get_namespaces failed with error %d", nsCount);
				}
				else if (nsCount == 0) // no namespaces, acknowledge them all
				{
					ackAll = true;
				}
				else // at least one namespace
				{
					for (int i = 0; i < nsCount; i++)
					{
						NVM_UID uidStr;
						uid_copy(namespaces[i].namespace_uid, uidStr);
						nsUids.push_back(uidStr);
					}
				}
			}

			// don't auto-acknowledge on failure to get namespaces
			if (nsCount || ackAll)
			{
				for (int i = 0; i < eventCount; i++)
				{
					if (ackAll || namespaceDeleted(events[i].uid, nsUids))
					{
						acknowledgeEvent(EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED,
								events[i].uid);
					}
				}
			}
		}
	}
}