zabbix-agent2/src/zabbix_agent/eventlog.c
/* expand the string message from a specific event handler */
expand the string message from a specific event handler
expand the string message from a specific event handler
static char	*expand_message6(const wchar_t *pname, EVT_HANDLE event)
{
	wchar_t		*pmessage = NULL;
	EVT_HANDLE	provider = NULL;
	DWORD		require = 0;
	char		*out_message = NULL;
	char		*tmp_pname = NULL;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	if (NULL == (provider = EvtOpenPublisherMetadata(NULL, pname, NULL, 0, 0)))
	{
		tmp_pname = zbx_unicode_to_utf8(pname);
		zabbix_log(LOG_LEVEL_DEBUG, "provider '%s' could not be opened: %s",
				tmp_pname, strerror_from_system(GetLastError()));
		zbx_free(tmp_pname);
		goto out;
	}
	if (TRUE != EvtFormatMessage(provider, event, 0, 0, NULL, EvtFormatMessageEvent, 0, NULL, &require))
	{
		if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
		{
			DWORD	error = ERROR_SUCCESS;
			pmessage = zbx_malloc(pmessage, sizeof(WCHAR) * require);
			if (TRUE != EvtFormatMessage(provider, event, 0, 0, NULL, EvtFormatMessageEvent, require,
					pmessage, &require))
			{
				error = GetLastError();
			}
			if (ERROR_SUCCESS == error || ERROR_EVT_UNRESOLVED_VALUE_INSERT == error ||
					ERROR_EVT_UNRESOLVED_PARAMETER_INSERT == error ||
					ERROR_EVT_MAX_INSERTS_REACHED == error)
			{
				out_message = zbx_unicode_to_utf8(pmessage);
			}
			else
			{
				zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot format message: %s", __func__,
						strerror_from_system(error));
				goto out;
			}
		}
	}
out:
	if (NULL != provider)
		EvtClose(provider);
	zbx_free(pmessage);
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, out_message);
	return out_message;
}
static char * expand_message6 ( const wchar_t * pname , EVT_HANDLE event ) { wchar_t * pmessage = NULL ; EVT_HANDLE provider = NULL ; DWORD require = 0 ; char * out_message = NULL ; char * tmp_pname = NULL ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; if ( NULL == ( provider = EvtOpenPublisherMetadata ( NULL , pname , NULL , 0 , 0 ) ) ) { tmp_pname = zbx_unicode_to_utf8 ( pname ) ; zabbix_log ( LOG_LEVEL_DEBUG , " " , tmp_pname , strerror_from_system ( GetLastError ( ) ) ) ; zbx_free ( tmp_pname ) ; goto out ; } if ( TRUE != EvtFormatMessage ( provider , event , 0 , 0 , NULL , EvtFormatMessageEvent , 0 , NULL , & require ) ) { if ( ERROR_INSUFFICIENT_BUFFER == GetLastError ( ) ) { DWORD error = ERROR_SUCCESS ; pmessage = zbx_malloc ( pmessage , sizeof ( WCHAR ) * require ) ; if ( TRUE != EvtFormatMessage ( provider , event , 0 , 0 , NULL , EvtFormatMessageEvent , require , pmessage , & require ) ) { error = GetLastError ( ) ; } if ( ERROR_SUCCESS == error || ERROR_EVT_UNRESOLVED_VALUE_INSERT == error || ERROR_EVT_UNRESOLVED_PARAMETER_INSERT == error || ERROR_EVT_MAX_INSERTS_REACHED == error ) { out_message = zbx_unicode_to_utf8 ( pmessage ) ; } else { zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ , strerror_from_system ( error ) ) ; goto out ; } } } out : if ( NULL != provider ) EvtClose ( provider ) ; zbx_free ( pmessage ) ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ , out_message ) ; return out_message ; }
expand the string message from a specific event handler
expand the string message from a specific event handler
/* should be freed */