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
5198d906
Commit
5198d906
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Successful Mattermost integration
parent
24034aef
Branches
Branches containing commit
Tags
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
+40
-7
40 additions, 7 deletions
eth-log-alerting.go
with
40 additions
and
7 deletions
eth-log-alerting.go
+
40
−
7
View file @
5198d906
...
@@ -10,10 +10,20 @@ import (
...
@@ -10,10 +10,20 @@ import (
"regexp"
"regexp"
"syscall"
"syscall"
"github.com/42wim/matterbridge/matterhook"
"github.com/asaskevich/govalidator"
"github.com/asaskevich/govalidator"
"github.com/hpcloud/tail"
"github.com/hpcloud/tail"
)
)
type
attachment
struct
{
Fallback
string
`json:"fallback,omitempty"`
Pretext
string
`json:"pretext,omitempty"`
Text
string
`json:"text"`
Color
string
`json:"color,omitempty"`
}
type
attachments
[]
attachment
var
(
var
(
logPath
string
logPath
string
webhookURL
string
webhookURL
string
...
@@ -57,7 +67,7 @@ func main() {
...
@@ -57,7 +67,7 @@ func main() {
sig
:=
make
(
chan
os
.
Signal
,
1
)
sig
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
go
tail
Log
()
go
tail
AndSend
()
caughtSig
:=
<-
sig
caughtSig
:=
<-
sig
tailer
.
Stop
()
tailer
.
Stop
()
...
@@ -65,8 +75,17 @@ func main() {
...
@@ -65,8 +75,17 @@ func main() {
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
}
func
tailLog
()
{
func
tailAndSend
()
{
t
,
err
:=
tail
.
TailFile
(
logPath
,
tail
.
Config
{
Follow
:
true
,
MustExist
:
true
,
ReOpen
:
true
})
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
},
MustExist
:
true
,
ReOpen
:
true
,
Logger
:
logger
,
})
tailer
=
t
tailer
=
t
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -80,18 +99,32 @@ func tailLog() {
...
@@ -80,18 +99,32 @@ func tailLog() {
}
}
if
len
(
searchRegex
)
==
0
{
if
len
(
searchRegex
)
==
0
{
go
sendLine
(
line
)
go
sendLine
(
mh
,
line
)
}
else
{
}
else
{
matched
,
_
:=
regexp
.
MatchString
(
searchRegex
,
line
.
Text
)
matched
,
_
:=
regexp
.
MatchString
(
searchRegex
,
line
.
Text
)
if
matched
{
if
matched
{
go
sendLine
(
line
)
go
sendLine
(
mh
,
line
)
}
}
}
}
}
}
}
}
func
sendLine
(
line
*
tail
.
Line
)
{
func
sendLine
(
mh
*
matterhook
.
Client
,
line
*
tail
.
Line
)
{
logger
.
Println
(
line
.
Text
)
atts
:=
attachments
{
attachment
{
Fallback
:
fmt
.
Sprintf
(
"New entry in %s"
,
logPath
),
Pretext
:
fmt
.
Sprintf
(
"In `%s` at `%s`:"
,
logPath
,
line
.
Time
),
Text
:
fmt
.
Sprintf
(
" %s"
,
line
.
Text
),
Color
:
color
,
},
}
mh
.
Send
(
matterhook
.
OMessage
{
Channel
:
channel
,
UserName
:
username
,
Attachments
:
atts
,
IconURL
:
iconURL
,
})
}
}
func
setUpLogger
()
{
func
setUpLogger
()
{
...
...
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