-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from UKHomeOffice/feature/210-notifications-app
Adds elasticsearch logger
- Loading branch information
Showing
14 changed files
with
389 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export GITHUB_WEBHOOKSECRET=blah | ||
export ELASTICSEARCH_URL="http://localhost:9200" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
FROM golang:1.6-onbuild | ||
FROM golang:1.8-onbuild | ||
|
||
|
||
EXPOSE 8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
version: "2.1" | ||
|
||
services: | ||
|
||
server: | ||
build: | ||
context: . | ||
env_file: .env | ||
environment: | ||
- GITHUB_WEBHOOKSECRET | ||
- ELASTICSEARCH_URL=http://elasticsearch:9200 | ||
depends_on: | ||
elasticsearch: | ||
condition: service_healthy | ||
ports: | ||
- 8080:8080 | ||
|
||
elasticsearch: | ||
restart: always | ||
image: elasticsearch:2 | ||
ports: | ||
- 9200:9200 | ||
expose: | ||
- "9200" | ||
healthcheck: | ||
test: ["CMD", "curl", "--fail", "http://localhost:9200"] | ||
interval: 5s | ||
timeout: 3s | ||
retries: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/olivere/elastic.v3" | ||
"gopkg.in/sohlich/elogrus.v1" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/techjacker/diffence" | ||
) | ||
|
||
// Log is the log interface for the app | ||
type Log interface { | ||
Log(v ...interface{}) | ||
} | ||
|
||
// Log is the log for the app | ||
type Logger struct { | ||
log *logrus.Logger | ||
} | ||
|
||
func (l Logger) Log(v ...interface{}) { | ||
i := 1 | ||
for filename, rule := range v[0].(diffence.MatchedRules) { | ||
i++ | ||
l.log.WithFields(logrus.Fields{ | ||
"organisation": v[1], | ||
"repo": v[2], | ||
"url": v[3], | ||
"filename": filename, | ||
"reason": rule[0].Caption, | ||
}).Error(fmt.Sprintf("Violation found in %s:%s", v[1], v[2])) | ||
} | ||
} | ||
|
||
// NewESLogger is a factory for Elasticsearch loggers | ||
func NewESLogger(esUrl, esIndex string) (Logger, error) { | ||
log := logrus.New() | ||
client, err := elastic.NewClient(elastic.SetURL(esUrl)) | ||
if err != nil { | ||
return Logger{}, err | ||
} | ||
hook, err := elogrus.NewElasticHook(client, "localhost", logrus.DebugLevel, esIndex) | ||
if err != nil { | ||
return Logger{}, err | ||
} | ||
log.Hooks.Add(hook) | ||
return Logger{log: log}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.