2015-03-19 16:14:14 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
__CFG_REPORTERS=
|
|
|
|
__CFG_METRICS=
|
|
|
|
|
|
|
|
get_configured_reporters () {
|
|
|
|
echo $__CFG_REPORTERS
|
|
|
|
}
|
|
|
|
|
|
|
|
get_configured_metrics () {
|
|
|
|
echo $__CFG_METRICS
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_config () {
|
|
|
|
if [ ! -f "$1" ]; then
|
|
|
|
echo "Error: unable to load config file: ${1}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
RESTORE_IFS=$IFS
|
|
|
|
# dash compatibility :-(
|
|
|
|
IFS=$'
|
|
|
|
'
|
|
|
|
|
|
|
|
local _group
|
|
|
|
local _name
|
|
|
|
local _body
|
|
|
|
|
|
|
|
end_section () {
|
|
|
|
if [ -z "$_group" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local fn_name
|
|
|
|
if [ "$_group" = "reporter" ]; then
|
2015-03-21 11:50:35 -04:00
|
|
|
__CFG_REPORTERS=$(trim "${__CFG_REPORTERS} ${_name}")
|
2015-03-19 16:14:14 -04:00
|
|
|
fn_name="__r_"
|
|
|
|
elif [ "$_group" = "metric" ]; then
|
2015-03-21 11:50:35 -04:00
|
|
|
__CFG_METRICS=$(trim "${__CFG_METRICS} ${_name}")
|
2015-03-19 16:14:14 -04:00
|
|
|
fn_name="__m_"
|
|
|
|
else
|
2015-03-21 11:50:35 -04:00
|
|
|
fn_name="main"
|
2015-03-19 16:14:14 -04:00
|
|
|
fi
|
|
|
|
|
2015-03-21 11:50:35 -04:00
|
|
|
fn_name=${fn_name}$(get_alias $_name)
|
2015-03-19 16:14:14 -04:00
|
|
|
|
|
|
|
if [ -z "$_body" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2015-03-21 16:19:08 -04:00
|
|
|
if ! eval "$_body" > /dev/null 2>&1; then
|
|
|
|
echo "Error parsing config section: $_name: $_body"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#echo "${fn_name}_config () { $_body; }"
|
|
|
|
eval "${fn_name}_config () { $_body; }"
|
2015-03-19 16:14:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for line in $(cat $1); do
|
|
|
|
# handle comments / empty lines
|
|
|
|
line=$(echo $line | grep -v '^\(#\|;\)')
|
|
|
|
|
|
|
|
if [ -z "$line" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
local _section=$(echo $line | grep '^\[.*' | sed 's/\[\(.*\)\]/\1/')
|
|
|
|
if [ -n "$_section" ]; then
|
|
|
|
end_section
|
2015-03-21 11:50:35 -04:00
|
|
|
unset _group _name _body
|
2015-03-19 16:14:14 -04:00
|
|
|
|
|
|
|
_group=$(echo $_section | awk '{ print $1 }')
|
|
|
|
|
|
|
|
if echo " metrics.sh metric reporter " | grep -q -v " $_group "; then
|
|
|
|
echo "Warning: unknown section in configuration file: $_section"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$_group" = "metrics.sh" ]; then
|
2015-03-21 11:50:35 -04:00
|
|
|
_group="main"
|
2015-03-19 16:14:14 -04:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-03-21 11:50:35 -04:00
|
|
|
_name=$(echo $_section | awk '{ print $2 }')
|
2015-03-19 16:14:14 -04:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
_body=$(echo "${_body};${line}" | sed 's/^;//g')
|
|
|
|
done
|
|
|
|
|
|
|
|
end_section
|
|
|
|
|
|
|
|
IFS=$RESTORE_IFS
|
2015-03-21 05:55:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get_name () {
|
|
|
|
echo $1 | awk 'BEGIN { FS=":" } { print $1 }'
|
|
|
|
}
|
|
|
|
|
|
|
|
get_alias () {
|
|
|
|
local _alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $2 }')
|
|
|
|
if [ -z "$_alias" ]; then
|
|
|
|
_alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $1 }')
|
|
|
|
fi
|
|
|
|
echo $_alias
|
2015-03-19 16:14:14 -04:00
|
|
|
}
|