#!/bin/sh
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

LOG=/var/ossec/logs/integrations.log
CURL=/usr/bin/curl
ALERT_PATH=`echo $1`
WEBHOOK=$3
ALERT=`cat ${ALERT_PATH}`
PAYLOAD_REQ='{"text": "'"${ALERT}"'"}'

ls "`which curl`" > /dev/null 2>&1
if [ ! $? = 0 ]; then
    ls "`which wget`" > /dev/null 2>&1
    if [ $? = 0 ]; then
        wget --keep-session-cookies --post-data="${PAYLOAD_REQ}" ${WEBHOOK} 2>> ${LOG}
        exit 0;
    fi
else
    curl -s -X POST --data-urlencode "payload=${PAYLOAD_REQ}" ${WEBHOOK} 2>> ${LOG}
    exit 0;
fi

echo "`date` $0: Unable to find curl or wget." >> ${LOG}
exit 1;

