Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
eth-log-alerting
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Server Tools
eth-log-alerting
Commits
3be4b9c6
Commit
3be4b9c6
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Radically simplified, plus an init script!
parent
f233de75
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+8
-6
8 additions, 6 deletions
README.md
defaults
+9
-0
9 additions, 0 deletions
defaults
init.sh
+127
-13
127 additions, 13 deletions
init.sh
pipe.sh
+28
-3
28 additions, 3 deletions
pipe.sh
send.sh
+0
-27
0 additions, 27 deletions
send.sh
with
172 additions
and
49 deletions
README.md
+
8
−
6
View file @
3be4b9c6
...
...
@@ -5,10 +5,12 @@ Pipe logs to Mattermost or Slack webhooks
# Requirements
*
Mattermost or Slack instance
*
`
tail`
and
`curl`
in
`$PATH
`
*
`
curl`
,
`jq`
,
`tail
`
## TODO
*
Config file(s)
*
Init script with defaults override, restart, etc
*
Make binary deps paths configurable?
\ No newline at end of file
# Installation
1.
`git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/eth-log-alerting`
2.
`cp /usr/local/eth-log-alerting/init.sh /etc/init.d/eth_log_alerting`
3.
`cp /usr/local/eth-log-alerting/defaults /etc/default/eth_log_alerting`
4.
Edit
`/etc/default/eth_log_alerting`
5.
`sudo update-rc.d eth_log_alerting defaults`
6.
`/etc/init.d/eth_log_alerting start`
This diff is collapsed.
Click to expand it.
defaults
0 → 100644
+
9
−
0
View file @
3be4b9c6
LOG_FILE=""
WEBHOOK_URL=""
USERNAME=""
CHANNEL=""
COLOR=""
ICON_URL=""
GREP=""
DAEMON_OPTIONS="$LOG_FILE $WEBHOOK_URL \"$USERNAME\" \"$CHANNEL\" \"$COLOR\" $ICON_URL \"$GREP\""
\ No newline at end of file
This diff is collapsed.
Click to expand it.
init.sh
+
127
−
13
View file @
3be4b9c6
#!/bin/sh
LISTENER_BIN
=
/usr/local/eth-log-alerting/pipe.sh
test
-x
$LISTENER_BIN
||
exit
5
PIDFILE
=
/var/run/eth_log_alerting.pid
### BEGIN INIT INFO
# Provides: eth_log_alerting
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Pipe log entries to Mattermost
### END INIT INFO
# Defaults
DAEMON_NAME
=
"ETH Log Alerting"
DAEMON_EXECUTABLE
=
"/usr/local/eth-log-alerting/pipe.sh"
DAEMON_OPTIONS
=
""
DAEMON_HOMEDIR
=
"/usr/local/eth-log-alerting"
DAEMON_PIDFILE
=
"/var/run/eth_log_alerting.pid"
DAEMON_LOGFILE
=
"/var/log/eth_log_alerting.log"
INIT_SLEEPTIME
=
"2"
# Defaults can be overridden in this file
DAEMON_DEFAULTS_FILE
=
"/etc/default/eth_log_alerting"
PATH
=
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
# Load alternate configuration if exists
test
-f
$DAEMON_DEFAULTS_FILE
&&
.
$DAEMON_DEFAULTS_FILE
.
/lib/lsb/init-functions
# Usually no need to edit below this point. Just have these ready:
#
# * DAEMON_EXECUTABLE - full path to the executable
# * DAEMON_OPTIONS - options to pass to the executable
# * DAEMON_NAME - a decriptive name
# * DAEMON_HOMEDIR - place where to cd before running
# * DAEMON_PIDFILE - pid file name
# * DAEMON_LOGFILE - log file name
# * INIT_SLEEPTIME - how long to wait for startup and shutdown
#
# The rest will be taken care of. Executable is run with "nohup", so no
# need to fork.
is_running
()
{
# Test whether pid file exists or not
test
-f
$DAEMON_PIDFILE
||
return
1
# Test whether process is running or not
read
PID <
"
$DAEMON_PIDFILE
"
ps
-p
$PID
>
/dev/null 2>&1
||
return
1
# Is running
return
0
}
root_only
()
{
if
[
"
$(
id
-u
)
"
!=
"0"
]
;
then
echo
"Only root should run this operation"
exit
1
fi
}
run
()
{
if
is_running
;
then
PID
=
"
$(
cat
$DAEMON_PIDFILE
)
"
echo
"Daemon is already running as PID
$PID
"
return
1
fi
cd
$DAEMON_HOMEDIR
nohup
$DAEMON_EXECUTABLE
$DAEMON_OPTIONS
>>
$DAEMON_LOGFILE
2>&1 &
echo
$!
>
$DAEMON_PIDFILE
read
PID <
"
$DAEMON_PIDFILE
"
sleep
$INIT_SLEEPTIME
if
!
is_running
;
then
echo
"Daemon died immediately after starting. Please check your logs and configurations."
return
1
fi
echo
"Daemon is running as PID
$PID
"
return
0
}
stop
()
{
if
is_running
;
then
read
PID <
"
$DAEMON_PIDFILE
"
kill
$PID
fi
sleep
$INIT_SLEEPTIME
if
is_running
;
then
while
is_running
;
do
echo
"waiting for daemon to die (PID
$PID
)"
sleep
$INIT_SLEEPTIME
done
fi
rm
-f
"
$DAEMON_PIDFILE
"
return
0
}
case
"
$1
"
in
start
)
echo
-n
"Starting log alerting.... "
startproc
-f
-p
$PIDFILE
$LISTENER_BIN
echo
"running"
;;
*
)
echo
"Usage:
$0
start"
exit
1
;;
esac
start
)
root_only
log_daemon_msg
"Starting
$DAEMON_NAME
"
run
log_end_msg
$?
;;
stop
)
root_only
log_daemon_msg
"Stopping
$DAEMON_NAME
"
stop
log_end_msg
$?
;;
restart
)
root_only
$0
stop
&&
$0
start
;;
status
)
status_of_proc
\
-p
"
$DAEMON_PIDFILE
"
\
"
$DAEMON_EXECUTABLE
"
\
"
$DAEMON_NAME
"
\
&&
exit
0
\
||
exit
$?
;;
*
)
echo
"Usage:
$0
{start|stop|restart|status}"
exit
1
;;
esac
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pipe.sh
+
28
−
3
View file @
3be4b9c6
#!/bin/sh
# TODO: path and config for send.sh
/usr/bin/tail
-Fq
log.log |
while
read
x
;
do
send.sh
"
$x
"
"#errors"
"danger"
;
done
#!/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
-n0
-F
"
$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
;
done
This diff is collapsed.
Click to expand it.
send.sh
deleted
100755 → 0
+
0
−
27
View file @
f233de75
#!/bin/sh
MSG
=
${
1
:-
Oops
}
CHANNEL
=
${
2
:-
#errors
}
COLOR
=
${
3
:-
default
}
# TODO: source these from a common config
USERNAME
=
"Log bot"
CONTEXT
=
"New log entry"
ICON_URL
=
""
WEBHOOK_URL
=
""
/usr/bin/curl
\
-X
POST
\
-s
\
--data-urlencode
"payload={
\
\"
channel
\"
:
\"
$CHANNEL
\"
,
\
\"
username
\"
:
\"
$USERNAME
\"
,
\
\"
attachments
\"
: [ {
\
\"
fallback
\"
:
\"
New log entry
\"
,
\
\"
pretext
\"
:
\"
$CONTEXT
\"
,
\
\"
text
\"
:
\"
$MSG
\"
,
\
\"
color
\"
:
\"
$COLOR
\"
\
} ],
\
\"
icon_url
\"
:
\"
$ICON_URL
\"
\
}"
\
$WEBHOOK_URL
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment