Skip to content

Commit

Permalink
add variable for disabling error logs in stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Issif committed Apr 15, 2020
1 parent 40cbd0f commit 6353fc3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ Two methods are available for configuration and can be mixed :
SlackWebhookURL: "" #Slack Webhook URL
SlackIconURL: "" #Slack Icon (Avatar) URL
SlackUsername: "" #Slack Username
Regexp: ".*\\.fr$" #Regexp to match. Can't be empty. It uses Golang regexp format.
Regexp: ".*\\.fr$" #Regexp to match. Can't be empty. It uses Golang regexp format
Workers: 20 #Number of workers for consuming feed from CertStream
DisplayErrors: false #Enable/Disable display of errors in logs
```

### With env vars

- **SLACKWEBHOOKURL**: Slack Webhook URL
- **SLACKICONURL**: Slack Icon (Avatar) URL
- **SLACKUSERNAME**: Slack Username
- **REGEXP**: Regexp to match, if empty, '.*' is used. Use Golang regexp format.
- **REGEXP**: Regexp to match, if empty, '.*' is used. Use Golang regexp format
- **WORKERS**: Number of workers for consuming feed from CertStream
- **DISPLAYERRORS**: Enable/Disable display of errors in logs

## Run

Expand Down
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type configuration struct {
SlackIconURL string
SlackUsername string
Regexp string
DisplayErrors string
}

func getConfig() *configuration {
Expand All @@ -31,6 +32,7 @@ func getConfig() *configuration {
v.SetDefault("SlackUsername", "Cercat")
v.SetDefault("Regexp", "")
v.SetDefault("Workers", 20)
v.SetDefault("DisplayErrors", "false")

if *configFile != "" {
d, f := path.Split(*configFile)
Expand All @@ -51,6 +53,9 @@ func getConfig() *configuration {
if c.SlackUsername == "" {
c.SlackUsername = "Cercat"
}
if c.DisplayErrors == "" {
c.DisplayErrors = "false"
}
if c.Regexp == "" {
log.Println("[ERROR] : Regexp can't be empty")
os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
SlackWebhookURL: "" #Slack Webhook URL
SlackIconURL: "" #Slack Icon (Avatar) URL
SlackUsername: "" #Slack Username
Regexp: ".*\\.fr$" #Regexp to match. Can't be empty. It uses Golang regexp format.
Workers: 20 #Number of workers for consuming stream from CertStream
Regexp: ".*\\.fr$" #Regexp to match. Can't be empty. It uses Golang regexp format
Workers: 20 #Number of workers for consuming stream from CertStream
DisplayErrors: false #Enable/Disable display of errors in logs
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ func main() {
defer ws.Close()

if err != nil {
log.Println("[INFO] : Error connecting to certstream! Sleeping a few seconds and reconnecting...")
if config.DisplayErrors == "true" {
log.Println("[ERROR] : Error connecting to certstream! Sleeping a few seconds and reconnecting...")
}
time.Sleep(1 * time.Second)
continue
}
for {
_, msg, err := ws.ReadMessage()
if err != nil {
log.Println("[ERROR] : Error reading message")
if config.DisplayErrors == "true" {
log.Println("[ERROR] : Error reading message from CertStream")
}
break
}
msgChan <- msg
Expand Down
2 changes: 1 addition & 1 deletion slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s slackPayload) Post() {
req.Header.Add("Content-Type", "application/json")
client := &http.Client{}
_, err := client.Do(req)
if err != nil {
if err != nil && config.DisplayErrors == "true" {
log.Println("[ERROR] : Slack Post error")
}
}

0 comments on commit 6353fc3

Please sign in to comment.