zabbix-agent2/src/zabbix_agent/zbxconf.c
/******************************************************************************
 *                                                                            *
 * Function: load_perf_counters                                               *
 *                                                                            *
 * Purpose: load performance counters from configuration                      *
 *                                                                            *
 * Parameters: def_lines - array of PerfCounter configuration entries         *
 *             eng_lines - array of PerfCounterEn configuration entries       *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Vladimir Levijev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
load_perf_counters

Purpose: load performance counters from configuration

Parameters: def_lines - array of PerfCounter configuration entries
eng_lines - array of PerfCounterEn configuration entries

Return value:

Author: Vladimir Levijev

Comments.
load_perf_counters Purpose : load performance counters from configuration Parameters : def_lines - array of PerfCounter configuration entries eng_lines - array of PerfCounterEn configuration entries Return value : Author : Vladimir Levijev Comments .
void	load_perf_counters(const char **def_lines, const char **eng_lines)
{
	char		name[MAX_STRING_LEN], counterpath[PDH_MAX_COUNTER_PATH], interval[8];
	const char	**pline, **lines;
	char		*error = NULL;
	LPTSTR		wcounterPath;
	int		period;
	for (lines = def_lines;; lines = eng_lines)
	{
		zbx_perf_counter_lang_t lang = (lines == def_lines) ? PERF_COUNTER_LANG_DEFAULT : PERF_COUNTER_LANG_EN;
		for (pline = lines; NULL != *pline; pline++)
		{
			if (3 < num_param(*pline))
			{
				error = zbx_strdup(error, "Required parameter missing.");
				goto pc_fail;
			}
			if (0 != get_param(*pline, 1, name, sizeof(name), NULL))
			{
				error = zbx_strdup(error, "Cannot parse key.");
				goto pc_fail;
			}
			if (0 != get_param(*pline, 2, counterpath, sizeof(counterpath), NULL))
			{
				error = zbx_strdup(error, "Cannot parse counter path.");
				goto pc_fail;
			}
			if (0 != get_param(*pline, 3, interval, sizeof(interval), NULL))
			{
				error = zbx_strdup(error, "Cannot parse interval.");
				goto pc_fail;
			}
			wcounterPath = zbx_acp_to_unicode(counterpath);
			zbx_unicode_to_utf8_static(wcounterPath, counterpath, PDH_MAX_COUNTER_PATH);
			zbx_free(wcounterPath);
			if (FAIL == check_counter_path(counterpath, lang == PERF_COUNTER_LANG_DEFAULT))
			{
				error = zbx_strdup(error, "Invalid counter path.");
				goto pc_fail;
			}
			period = atoi(interval);
			if (1 > period || MAX_COLLECTOR_PERIOD < period)
			{
				error = zbx_strdup(NULL, "Interval out of range.");
				goto pc_fail;
			}
			if (NULL == add_perf_counter(name, counterpath, period, lang, &error))
			{
				if (NULL == error)
					error = zbx_strdup(error, "Failed to add new performance counter.");
				goto pc_fail;
			}
			continue;
	pc_fail:
			zabbix_log(LOG_LEVEL_CRIT, "cannot add performance counter \"%s\": %s", *pline, error);
			zbx_free(error);
			exit(EXIT_FAILURE);
		}
		if (lines == eng_lines)
			break;
	}
}
void load_perf_counters ( const char * * def_lines , const char * * eng_lines ) { char name [ MAX_STRING_LEN ] , counterpath [ PDH_MAX_COUNTER_PATH ] , interval [ 8 ] ; const char * * pline , * * lines ; char * error = NULL ; LPTSTR wcounterPath ; int period ; for ( lines = def_lines ; ; lines = eng_lines ) { zbx_perf_counter_lang_t lang = ( lines == def_lines ) ? PERF_COUNTER_LANG_DEFAULT : PERF_COUNTER_LANG_EN ; for ( pline = lines ; NULL != * pline ; pline ++ ) { if ( 3 < num_param ( * pline ) ) { error = zbx_strdup ( error , " " ) ; goto pc_fail ; } if ( 0 != get_param ( * pline , 1 , name , sizeof ( name ) , NULL ) ) { error = zbx_strdup ( error , " " ) ; goto pc_fail ; } if ( 0 != get_param ( * pline , 2 , counterpath , sizeof ( counterpath ) , NULL ) ) { error = zbx_strdup ( error , " " ) ; goto pc_fail ; } if ( 0 != get_param ( * pline , 3 , interval , sizeof ( interval ) , NULL ) ) { error = zbx_strdup ( error , " " ) ; goto pc_fail ; } wcounterPath = zbx_acp_to_unicode ( counterpath ) ; zbx_unicode_to_utf8_static ( wcounterPath , counterpath , PDH_MAX_COUNTER_PATH ) ; zbx_free ( wcounterPath ) ; if ( FAIL == check_counter_path ( counterpath , lang == PERF_COUNTER_LANG_DEFAULT ) ) { error = zbx_strdup ( error , " " ) ; goto pc_fail ; } period = atoi ( interval ) ; if ( 1 > period || MAX_COLLECTOR_PERIOD < period ) { error = zbx_strdup ( NULL , " " ) ; goto pc_fail ; } if ( NULL == add_perf_counter ( name , counterpath , period , lang , & error ) ) { if ( NULL == error ) error = zbx_strdup ( error , " " ) ; goto pc_fail ; } continue ; pc_fail : zabbix_log ( LOG_LEVEL_CRIT , " \" \" " , * pline , error ) ; zbx_free ( error ) ; exit ( EXIT_FAILURE ) ; } if ( lines == eng_lines ) break ; } }
Function: load_perf_counters                                               
                                                                            
 Purpose: load performance counters from configuration                      
                                                                            
 Parameters: def_lines - array of PerfCounter configuration entries         
             eng_lines - array of PerfCounterEn configuration entries       
                                                                            
 Return value:                                                              
                                                                            
 Author: Vladimir Levijev                                                   
                                                                            
 Comments:
Function : load_perf_counters Purpose : load performance counters from configuration Parameters : def_lines - array of PerfCounter configuration entries eng_lines - array of PerfCounterEn configuration entries Return value : Author : Vladimir Levijev Comments :