#!/bin/bash

# Alias: API cmk-Graylog 
# Menu: Addons
# Description:
#  http lookup table for manipulating syslog packets

case "$1" in
   default)
       echo "on"
   ;;
   choices)
       echo "on: use Graylog API"
       echo "off: disable Graylog API"
   ;;
   set)
        GRAYLOG_API_CFG="${OMD_ROOT}/etc/apache/conf.d/graylog.conf"

        if [ "$2" == "on" ]; then

        cat > $GRAYLOG_API_CFG <<EOF
Alias /${OMD_SITE}/graylog "${OMD_ROOT}/local/share/graylog"

<Directory "${OMD_ROOT}/local/share/graylog">
  Options +Indexes +ExecCGI +FollowSymLinks
  AllowOverride None
  DirectoryIndex index.cgi
  AddHandler cgi-script .cgi
  PassEnv OMD_SITE
    <IfModule mod_access_compat.c>
        Order deny,allow
        Allow from all
    </IfModule>
    <IfModule !mod_access_compat.c>
        Require all granted
    </IfModule>
</Directory>

EOF


mkdir -p ${OMD_ROOT}/local/share/graylog
if [ ! -h ${OMD_ROOT}/local/share/graylog/index.cgi ];then
ln -s /opt/ebs/graylog/share/index.cgi ${OMD_ROOT}/local/share/graylog/index.cgi
fi

else

rm -rf ${OMD_ROOT}/local/share/graylog/index.cgi
rm -rf $GRAYLOG-API_CFG

fi
;;
esac



