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
caba93b3
Commit
caba93b3
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix/tests' into 'master'
Update how webhooks are sent Closes
#6
See merge request
!2
parents
f0d16e26
bbb28a38
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Update how webhooks are sent
Pipeline
#86
passed with stages
in 1 minute and 17 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+26
-30
26 additions, 30 deletions
.gitlab-ci.yml
README.md
+2
-2
2 additions, 2 deletions
README.md
eth-log-alerting.go
+25
-29
25 additions, 29 deletions
eth-log-alerting.go
with
53 additions
and
61 deletions
.gitlab-ci.yml
+
26
−
30
View file @
caba93b3
# This file is a template, and might need editing before it works on your project.
# This file is a template, and might need editing before it works on your project.
image
:
golang:latest
image
:
golang:latest
variables
:
REPO_NAME
:
git.ethitter.com/debian/eth-log-alerting
# The problem is that to be able to use go get, one needs to put
# The problem is that to be able to use go get, one needs to put
# the repository in the $GOPATH. So for example if your gitlab domain
# the repository in the $GOPATH. So for example if your gitlab domain
# is
mydomainperso
.com, and that your repository is
repos
/project
name
, and
# is
gitlab
.com, and that your repository is
namespace
/project, and
# the default GOPATH being /go, then you'd need to have your
# the default GOPATH being /go, then you'd need to have your
# repository in /go/src/
mydomainperso.com/repos
/project
name
# repository in /go/src/
gitlab.com/namespace
/project
# Thus, making a symbolic link corrects this.
# Thus, making a symbolic link corrects this.
before_script
:
before_script
:
-
ln -s /builds /go/src/git.ethitter.com
-
mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
-
cd /go/src/git.ethitter.com/debian/eth-log-alerting
-
ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
-
cd $GOPATH/src/$REPO_NAME
-
go version
-
go get github.com/asaskevich/govalidator
-
go get github.com/ashwanthkumar/slack-go-webhook
-
go get github.com/hpcloud/tail
stages
:
stages
:
-
test
-
test
-
build
-
build
format
:
format
:
stage
:
test
stage
:
test
script
:
script
:
# Add here all the dependencies, or use glide/govendor to get
-
go tool vet -composites=false -shadow=true *.go
# them automatically.
-
go test -race $(go list ./... | grep -v /vendor/)
# - curl https://glide.sh/get | sh
-
go get github.com/42wim/matterbridge/matterhook
-
go get github.com/asaskevich/govalidator
-
go get github.com/hpcloud/tail
-
go get github.com/alecthomas/kingpin
-
go tool vet -composites=false -shadow=true *.go
-
go test -race $(go list ./... | grep -v /vendor/)
compile
:
compile
:
stage
:
build
stage
:
build
script
:
script
:
# Add here all the dependencies, or use glide/govendor/...
-
go build -race -ldflags "-extldflags '-static'" -o eth-log-alerting
# to get them automatically.
artifacts
:
-
go get github.com/42wim/matterbridge/matterhook
paths
:
-
go get github.com/asaskevich/govalidator
-
eth-log-alerting
-
go get github.com/hpcloud/tail
-
go get github.com/alecthomas/kingpin
# Better put this in a Makefile
-
go build -race -ldflags "-extldflags '-static'" -o eth-log-alerting
artifacts
:
paths
:
-
eth-log-alerting
This diff is collapsed.
Click to expand it.
README.md
+
2
−
2
View file @
caba93b3
Log Alerting
Log Alerting
[](https://git.ethitter.com/debian/eth-log-alerting/commits/master)
============
============
Pipe logs to Mattermost (or Slack) webhooks
Pipe logs to Mattermost (or Slack) webhooks
...
@@ -11,7 +11,7 @@ Pipe logs to Mattermost (or Slack) webhooks
...
@@ -11,7 +11,7 @@ Pipe logs to Mattermost (or Slack) webhooks
1.
`git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/bin/eth-log-alerting`
1.
`git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/bin/eth-log-alerting`
1.
`cd /usr/local/bin/eth-log-alerting`
1.
`cd /usr/local/bin/eth-log-alerting`
1.
`go get github.com/
42wim/matterbridge/matter
hook`
1.
`go get github.com/
ashwanthkumar/slack-go-web
hook`
1.
`go get github.com/asaskevich/govalidator`
1.
`go get github.com/asaskevich/govalidator`
1.
`go get github.com/hpcloud/tail`
1.
`go get github.com/hpcloud/tail`
1.
`go build eth-log-alerting.go`
1.
`go build eth-log-alerting.go`
...
...
This diff is collapsed.
Click to expand it.
eth-log-alerting.go
+
25
−
29
View file @
caba93b3
...
@@ -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,49 @@ func tailLog(logCfg logConfig) {
...
@@ -122,44 +113,49 @@ 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
{
fallback
:=
fmt
.
Sprintf
(
"New entry in %s"
,
logCfg
.
LogPath
)
attachment
{
pretext
:=
fmt
.
Sprintf
(
"In `%s` at `%s`:"
,
logCfg
.
LogPath
,
line
.
Time
)
Fallback
:
fmt
.
Sprintf
(
"New entry in %s"
,
logCfg
.
LogPath
),
text
:=
fmt
.
Sprintf
(
"```
\n
%s
\n
```"
,
line
.
Text
)
Pretext
:
fmt
.
Sprintf
(
"In `%s` at `%s`:"
,
logCfg
.
LogPath
,
line
.
Time
),
att
:=
slack
.
Attachment
{
Text
:
fmt
.
Sprintf
(
" %s"
,
line
.
Text
),
Color
:
&
logCfg
.
Color
,
Color
:
logCfg
.
Color
,
Fallback
:
&
fallback
,
},
PreText
:
&
pretext
,
Text
:
&
text
,
}
}
mh
.
Send
(
matterhook
.
OMessage
{
payload
:=
slack
.
Payload
{
Username
:
logCfg
.
Username
,
Channel
:
logCfg
.
Channel
,
Channel
:
logCfg
.
Channel
,
UserName
:
logCfg
.
Username
,
IconUrl
:
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