Skip to content
Snippets Groups Projects
Commit 8f3d63b7 authored by Erick Hitter's avatar Erick Hitter
Browse files

Moving to Go

parent 4706e3b1
No related branches found
No related tags found
1 merge request!1Convert to Golang
Pipeline #
Logs to alerts
==============
Log Alerting
============
Pipe logs to Mattermost or Slack webhooks
Pipe logs to Mattermost (or Slack) webhooks
# Requirements
* Mattermost or Slack instance
* `curl`, `jq`, `tail`
* Go 1.8.3
# Installation
1. `git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/eth-log-alerting`
1. TBD
<!-- 1. `git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/eth-log-alerting`
2. `cp /usr/local/eth-log-alerting/systemd.service /etc/systemd/system/eth_log_alerting.service`
3. `cp /usr/local/eth-log-alerting/defaults /etc/default/eth_log_alerting`
4. Edit `/etc/default/eth_log_alerting`
5. `systemctl daemon-reload`
6. `systemctl enable eth_log_alerting.service`
6. `systemctl start eth_log_alerting.service`
6. `systemctl start eth_log_alerting.service` -->
# Set log details
LOG_FILE=""
WEBHOOK_URL=""
USERNAME=""
CHANNEL=""
COLOR=""
ICON_URL=""
GREP=""
# DO NOT MODIFY BELOW THIS LINE!
DAEMON_OPTIONS="$LOG_FILE \"$WEBHOOK_URL\" \"$USERNAME\" \"$CHANNEL\" \"$COLOR\" \"$ICON_URL\" \"$GREP\""
#!/bin/bash
# Defaults and aliases
LOG_FILE=$1
WEBHOOK_URL=$2
USERNAME=${3:-logbot}
CHANNEL=${4:-#logs}
COLOR=${5:-default}
ICON_URL=$6
GREP=$7
tail -Fq "$LOG_FILE" | while read LINE; do
(echo "$LINE" | grep -e "$GREP") && jq -n --arg line_encoded " $LINE" \ "{ \
channel: \"$CHANNEL\", \
username: \"$USERNAME\", \
attachments: [ { \
fallback: \"New entry in $LOG_FILE\", \
pretext: \"\`$LOG_FILE\`\", \
text: \$line_encoded, \
color: \"$COLOR\" \
} ],\
icon_url: \"$ICON_URL\" \
}" | cat <(echo "payload=") <(cat -) | curl \
-X POST \
-s \
-d@- \
$WEBHOOK_URL > /dev/null;
done
#!/bin/sh
DAEMON="/usr/local/eth-log-alerting/pipe.sh"
NAME="eth_log_alerting"
# Check if DAEMON binary exist
[ -f $DAEMON ] || exit 0
# Check if config exists
if [ -f "/etc/default/$NAME" ]
then
. /etc/default/$NAME
else
exit 0
fi
# On with it!
$DAEMON $DAEMON_OPTIONS
[Unit]
After=network.target
[Service]
ExecStart=/usr/local/eth-log-alerting/service.sh
[Install]
WantedBy=default.target
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment