#!/bin/bash

export LC_ALL=C.UTF-8

if [[ $1 == "status" || $1 == "enable" || $1 == "disable" ]]; then
	[[ -z $2 ]] && PILLAR="" || PILLAR="pillar=$2"
	/usr/bin/salt-call --out=json --log-level=error --local --file-root=/usr/share/susemanager/salt state.apply srvmonitoring.$1 $PILLAR
elif  [[ $1 == "--help" ]]; then
  echo "Usage: ${0} {enable|status|disable} [pillar_data]"
  echo ""
  echo "Actions:"
  echo "    enable   Enable server monitoring"
  echo "    disable  Disable server monitoring"
  echo "    status   Show status of monitored server components"
  echo ""
  echo "To enable PostgreSQL monitoring additional connection details have to be provided by setting 'pillar_data'."
  echo "It is expected to be a JSON object with following keys:"
  echo "    db_user  Username"
  echo "    db_pass  Password"
  echo "    db_host  Hostname"
  echo "    db_port  Port number"
  echo "    db_name  Database name"
else
	echo "Invalid argument. Try --help."
fi
exit 0
