Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
eth-log-alerting
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
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
964fc742
Commit
964fc742
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Better organization
parent
5198d906
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eth-log-alerting.go
+22
-24
22 additions, 24 deletions
eth-log-alerting.go
with
22 additions
and
24 deletions
eth-log-alerting.go
+
22
−
24
View file @
964fc742
...
...
@@ -33,11 +33,11 @@ var (
iconURL
string
searchRegex
string
mh
*
matterhook
.
Client
logger
*
log
.
Logger
debugDest
string
debug
bool
tailer
*
tail
.
Tail
)
func
init
()
{
...
...
@@ -59,26 +59,17 @@ func init() {
if
!
govalidator
.
IsURL
(
webhookURL
)
||
len
(
channel
)
<
2
{
usage
()
}
mh
=
matterhook
.
New
(
webhookURL
,
matterhook
.
Config
{
DisableServer
:
true
})
}
func
main
()
{
logger
.
Printf
(
"Monitoring %s"
,
logPath
)
logger
.
Printf
(
"Forwarding to channel
\"
%s
\"
as user
\"
%s
\"
at %s"
,
channel
,
username
,
webhookURL
)
sig
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
go
tailAndSend
()
caughtSig
:=
<-
sig
tailer
.
Stop
()
tailer
.
Cleanup
()
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
func
tailAndSend
()
{
mhConfig
:=
matterhook
.
Config
{
DisableServer
:
true
}
mh
:=
matterhook
.
New
(
webhookURL
,
mhConfig
)
t
,
err
:=
tail
.
TailFile
(
logPath
,
tail
.
Config
{
Follow
:
true
,
Location
:
&
tail
.
SeekInfo
{
Offset
:
0
,
Whence
:
2
},
...
...
@@ -86,30 +77,37 @@ func tailAndSend() {
ReOpen
:
true
,
Logger
:
logger
,
})
tailer
=
t
if
err
!=
nil
{
logger
.
Println
(
err
)
usage
()
t
.
Cleanup
()
close
(
sig
)
os
.
Exit
(
3
)
}
go
parseLinesAndSend
(
t
)
caughtSig
:=
<-
sig
t
.
Stop
()
t
.
Cleanup
()
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
func
parseLinesAndSend
(
t
*
tail
.
Tail
)
{
for
line
:=
range
t
.
Lines
{
if
line
.
Err
!=
nil
{
continue
}
if
len
(
searchRegex
)
==
0
{
go
sendLine
(
mh
,
line
)
}
else
{
matched
,
_
:=
regexp
.
MatchString
(
searchRegex
,
line
.
Text
)
if
matched
{
go
sendLine
(
mh
,
line
)
}
go
sendLine
(
line
)
}
else
if
matched
,
_
:=
regexp
.
MatchString
(
searchRegex
,
line
.
Text
);
matched
{
go
sendLine
(
line
)
}
}
}
func
sendLine
(
mh
*
matterhook
.
Client
,
line
*
tail
.
Line
)
{
func
sendLine
(
line
*
tail
.
Line
)
{
atts
:=
attachments
{
attachment
{
Fallback
:
fmt
.
Sprintf
(
"New entry in %s"
,
logPath
),
...
...
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