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
a2ebd7b2
Commit
a2ebd7b2
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Rethink how webhooks are sent
parent
48ac0970
No related branches found
No related tags found
1 merge request
!2
Update how webhooks are sent
Pipeline
#83
failed
6 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+1
-0
1 addition, 0 deletions
.gitlab-ci.yml
eth-log-alerting.go
+25
-30
25 additions, 30 deletions
eth-log-alerting.go
with
26 additions
and
30 deletions
.gitlab-ci.yml
+
1
−
0
View file @
a2ebd7b2
...
@@ -10,6 +10,7 @@ image: golang:latest
...
@@ -10,6 +10,7 @@ image: golang:latest
before_script
:
before_script
:
-
ln -s /builds /go/src/git.ethitter.com
-
ln -s /builds /go/src/git.ethitter.com
-
cd /go/src/git.ethitter.com/debian/eth-log-alerting
-
cd /go/src/git.ethitter.com/debian/eth-log-alerting
-
go version
stages
:
stages
:
-
test
-
test
...
...
This diff is collapsed.
Click to expand it.
eth-log-alerting.go
+
25
−
30
View file @
a2ebd7b2
...
@@ -12,8 +12,8 @@ import (
...
@@ -12,8 +12,8 @@ import (
"regexp"
"regexp"
"syscall"
"syscall"
"github.com/42wim/matterbridge/matterhook"
"github.com/asaskevich/govalidator"
"github.com/asaskevich/govalidator"
"github.com/ashwanthkumar/slack-go-webhook"
"github.com/hpcloud/tail"
"github.com/hpcloud/tail"
)
)
...
@@ -33,15 +33,6 @@ type logConfig struct {
...
@@ -33,15 +33,6 @@ type logConfig struct {
SearchRegex
string
`json:"search"`
SearchRegex
string
`json:"search"`
}
}
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
(
configPath
string
configPath
string
logConfigs
[]
logConfig
logConfigs
[]
logConfig
...
@@ -122,44 +113,48 @@ func tailLog(logCfg logConfig) {
...
@@ -122,44 +113,48 @@ func tailLog(logCfg logConfig) {
return
return
}
}
mh
:=
matterhook
.
New
(
logCfg
.
WebhookURL
,
matterhook
.
Config
{
DisableServer
:
true
})
parseLinesAndSend
(
t
,
logCfg
)
parseLinesAndSend
(
t
,
mh
,
logCfg
)
t
.
Stop
()
t
.
Stop
()
t
.
Cleanup
()
t
.
Cleanup
()
}
}
func
parseLinesAndSend
(
t
*
tail
.
Tail
,
mh
*
matterhook
.
Client
,
logCfg
logConfig
)
{
func
parseLinesAndSend
(
t
*
tail
.
Tail
,
logCfg
logConfig
)
{
for
line
:=
range
t
.
Lines
{
for
line
:=
range
t
.
Lines
{
if
line
.
Err
!=
nil
{
if
line
.
Err
!=
nil
{
continue
continue
}
}
if
len
(
logCfg
.
SearchRegex
)
==
0
{
if
len
(
logCfg
.
SearchRegex
)
==
0
{
go
sendLine
(
line
,
mh
,
logCfg
)
go
sendLine
(
line
,
logCfg
)
}
else
if
matched
,
_
:=
regexp
.
MatchString
(
logCfg
.
SearchRegex
,
line
.
Text
);
matched
{
}
else
if
matched
,
_
:=
regexp
.
MatchString
(
logCfg
.
SearchRegex
,
line
.
Text
);
matched
{
go
sendLine
(
line
,
mh
,
logCfg
)
go
sendLine
(
line
,
logCfg
)
}
}
}
}
}
}
func
sendLine
(
line
*
tail
.
Line
,
mh
*
matterhook
.
Client
,
logCfg
logConfig
)
{
func
sendLine
(
line
*
tail
.
Line
,
logCfg
logConfig
)
{
atts
:=
attachments
{
text
:=
fmt
.
Sprintf
(
" %s"
,
line
.
Text
)
attachment
{
Fallback
:
fmt
.
Sprintf
(
"New entry in %s"
,
logCfg
.
LogPath
),
att
:=
slack
.
Attachment
{}
Pretext
:
fmt
.
Sprintf
(
"In `%s` at `%s`:"
,
logCfg
.
LogPath
,
line
.
Time
),
att
.
AddField
(
slack
.
Field
{
Title
:
"Fallback"
,
Value
:
fmt
.
Sprintf
(
"New entry in %s"
,
logCfg
.
LogPath
)})
Text
:
fmt
.
Sprintf
(
" %s"
,
line
.
Text
),
att
.
AddField
(
slack
.
Field
{
Title
:
"Pretext"
,
Value
:
fmt
.
Sprintf
(
"In `%s` at `%s`:"
,
logCfg
.
LogPath
,
line
.
Time
)})
Color
:
logCfg
.
Color
,
att
.
AddField
(
slack
.
Field
{
Title
:
"Text"
,
Value
:
text
})
},
att
.
AddField
(
slack
.
Field
{
Title
:
"Color"
,
Value
:
logCfg
.
Color
})
}
mh
.
Send
(
matterhook
.
OMessage
{
payload
:=
slack
.
Payload
{
Text
:
text
,
Username
:
logCfg
.
Username
,
Channel
:
logCfg
.
Channel
,
Channel
:
logCfg
.
Channel
,
UserName
:
logCfg
.
Username
,
IconEmoji
:
logCfg
.
IconURL
,
Attachments
:
atts
,
Attachments
:
[]
slack
.
Attachment
{
att
},
IconURL
:
logCfg
.
IconURL
,
}
})
err
:=
slack
.
Send
(
logCfg
.
WebhookURL
,
""
,
payload
)
if
len
(
err
)
>
0
{
fmt
.
Printf
(
"error: %s
\n
"
,
err
)
}
}
}
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