#!/bin/bash
# Copyright (C) Mellanox Technologies Ltd. 2001-2012.  ALL RIGHTS RESERVED.
#
# This software product is a proprietary product of Mellanox Technologies Ltd.
# (the "Company") and all right, title, and interest in and to the software product,
# including all associated intellectual property rights, are and shall
# remain exclusively with the Company.
#
# This software product is governed by the End User License Agreement
# provided with the software product.


fb_collector_base_dir=/opt/mellanox/fabric_collector
fb_collector_conf_file=/etc/fabric_collector/fb_collector.conf


log_msg() {
    logger -t fbcollector "$*"
    echo "$*"
}

get_config_param() {
    local filename=$1
    local section=$2
    local key=$3

    awk -v s=[$section] -v k=$key -v v=$value '{ FS="="; line=$0; if (substr($1,1,1) == "[") {section=$1}; if (section==s) {key=$1; value=$2; gsub(/[[:space:]]*/,"",key); if(key==k) {print value; exit}}}' $filename | tr -d ' '      
}

get_python_exe() {
    local PYTHON

    python_exe=`get_config_param $fb_collector_conf_file client python_exe`
    if [ -z "${python_exe}" ] || [ "${python_exe}" == "DEFAULT" ] || [ ! -x "${python_exe}" ]; then
        PYTHON=`which python`
    else
        PYTHON=${python_exe}
    fi
    echo ${PYTHON}
}

get_ibutils_dir() {
    local ibutils_dir
    ibutils_dir=`get_config_param $fb_collector_conf_file ibutils ibutils_dir`
    echo "$ibutils_dir"
}

get_site_name() {
    local site_name
    site_name=`get_config_param $fb_collector_conf_file client site_name`
    echo "$site_name"
}
