#!/bin/bash

# Alias: Start Daemon for Check_MK Event Console
# Menu: Addons
# Description:
#  This option enables mkeventd - the event correlation and
#  classification daemon of Check_MK. This daemon will receive
#  events via a pipe or socket and applies it so a set of
#  rules.

case "$1" in
    default)
        echo "on"
    ;;
    choices)
        echo "on: enable"
        echo "off: disable"
    ;;
    set)
        if [ "$2" = on ] ; then
            enabled=True
        else
            enabled=False
        fi
        echo -e "# Set by OMD hook MKEVENTD, do not change here!\nmkeventd_enabled = $enabled" \
            > $OMD_ROOT/etc/check_mk/multisite.d/mkeventd.mk
        echo -e "# Set by OMD hook MKEVENTD, do not change here!\nmkeventd_enabled = $enabled" \
            > $OMD_ROOT/etc/check_mk/conf.d/mkeventd.mk
        # Try to update the core config to make the Microcore/Livestatus know whether or not the
        # Event Console is enabled. Totally ignore configuration validation errors here. Be silent.
        cmk -U >/dev/null 2>&1 || true
    ;;
esac
