#!/bin/bash
source /root/envsetup/global-conf.sh

# This script should be run after Nginx, MySQL and Wowza setup (if they should be installed)

# munin
DEBIAN_FRONTEND=noninteractive apt-get install -y ubicast-config

# modify df function https://redmine.ubicast.net/issues/17912
sed -i "s@-P -l @-P@" /usr/share/munin/plugins/df


# configure alerts
# detect where to insert
#LIG=$(grep -n contact.nagios.command /etc/munin/munin.conf | awk -F ":" '{print$1}')
#LIG=$(( $LIG + 1 ))
#head -n ${LIG} /etc/munin/munin.conf > /etc/munin/munin.conf.tmp

#cat << EOF >> /etc/munin/munin.conf.tmp
#contacts alert
#contact.alert.command mail -a "From:sysadmin <sysadmin@ubicast.eu>" -s "[munin] Alert on ${var:host}" sysadmin@ubicast.eu
#contact.alert.always_send warning critical

#[${MS_SERVER_NAME}]
#    address 127.0.0.1
#    use_node_name yes
#    memory.free.warning 512000000:
#EOF

#mv /etc/munin/munin.conf.tmp /etc/munin/munin.conf


# new skin templates
#cd /etc/munin
#git clone https://git.ubicast.net/mediaserver/munin-monitoring-theme.git
#mv /etc/munin/static /etc/munin/static.orig
#mv /etc/munin/templates /etc/munin/templates.orig
#cp -pr munin-monitoring-theme/templates/munstrap/static /etc/munin/
#cp -pr munin-monitoring-theme/templates/munstrap/templates /etc/munin/

# service restart
service munin restart || true
service munin-node restart
