#!/bin/bash
#
# $Id$
#
# prepares environment for /usr/sbin/mt-* scripts
#
# has to be sourced!


# exports, defaults

export LANG="C"

export VERBOSITY="1"

export DISKUSAGE_WARNING="90"
export DISKUSAGE_CRITICAL="95"

export DISKS_IN_RAID="2"

export POWERSUPPLIES="1"

export IPMISENSORS="0"

export MINMEMFREE="500000"
export MINSWAPFREE="50000"
export MAXPROCMEM="1000000"
export MAXOPENFILES="100000"

export WARNINGLOAD="10"
export CRITICALLOAD="50"
export PANICLOAD="100"

export PVECM_MIN_NODES="3"
export PVESH_MIN_HANODES="3"

# read conf

test -e /etc/montools/montools.conf.template && . /etc/montools/montools.conf.template
test -e /etc/montools/montools.conf && . /etc/montools/montools.conf

if [ -z "$VERBOSITY" ] ; then
  VERBOSITY="1";
  echo "Using failback VERBOSITY ${VERBOSITY}"
fi


FULLPARAMS="$*"
while [ -n "$1" ] ; do
  case "$1" in
    -d) VERBOSITY="3"
        echo "Set verbosity to debug: $VERBOSITY"
        ;;
    -q) VERBOSITY="0"
        #echo "Set verbosity to quiet: $VERBOSITY"
        ;;
    -v) VERBOSITY=$(($VERBOSITY+1))
        #echo "Raised verbosity by 1 to $VERBOSITY"
        ;;
  esac
  shift
done


# other preparation

export CRITICALS=""
export WARNINGS=""
export INFOS=""

# resource name, for alert subject
export RESNAME="Unnamed resource"


# evtl. functions


# add2 functions

function add2criticals() {
  #logDebug "add2criticals called"
  CRITICALS=$(
    echo "$CRITICALS"
    while [ -n "$1" ] ; do
      echo "$1"
      shift
    done
    echo " "
  )
}


function add2infos() {
  #logDebug "add2infos called"
  INFOS=$(
    echo "$INFOS"
    while [ -n "$1" ] ; do
      echo "$1"
      shift
    done
    echo " "
  )
}


function add2warnings() {
  #logDebug "add2warnings called"
  WARNINGS=$(
    echo "$WARNINGS"
    while [ -n "$1" ] ; do
      echo "$1"
      shift
    done
    echo " "
  )
}


# logging functions

function logDebug() {
  if [ ${VERBOSITY} -ge 3 ] ; then
    echo "DEBUG: $*"
  fi
}

function logVerbose() {
  if [ ${VERBOSITY} -ge 2 ] ; then
    echo "$*"
  fi
}

function logNormal() {
  if [ ${VERBOSITY} -ge 1 ] ; then
    echo "$*"
  fi
}

