Skip to content

Commit

Permalink
🎉 release v0.2.0 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
abahmed authored Dec 30, 2021
1 parent c1ac0cc commit 7f62044
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ A clear and concise description of what you expected to happen.
A clear and concise description of what really happens.

**Version/Commit**
A version or commit of gearbox
A version or commit of kwatch
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

You need to get config template to add your configs
```shell
curl -L https://raw.githubusercontent.com/abahmed/kwatch/v0.1.0/deploy/config.yaml -o config.yaml
curl -L https://raw.githubusercontent.com/abahmed/kwatch/v0.2.0/deploy/config.yaml -o config.yaml
```

Then edit `config.yaml` file and apply your configuration
Expand All @@ -41,7 +41,7 @@ kubectl apply -f config.yaml
To deploy **kwatch**, execute following command:

```shell
kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.1.0/deploy/deploy.yaml
kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.2.0/deploy/deploy.yaml
```

### Configuration
Expand Down Expand Up @@ -126,8 +126,8 @@ If you want to enable Microsoft Teams, provide the channel webhook.
### Cleanup

```shell
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.1.0/deploy/config.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.1.0/deploy/deploy.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.2.0/deploy/config.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.2.0/deploy/deploy.yaml
```

## Who uses kwatch?
Expand Down
2 changes: 1 addition & 1 deletion deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spec:
serviceAccountName: kwatch
containers:
- name: kwatch
image: ghcr.io/abahmed/kwatch:v0.1.0
image: ghcr.io/abahmed/kwatch:v0.2.0
imagePullPolicy: Always
volumeMounts:
- name: config-volume
Expand Down
14 changes: 9 additions & 5 deletions provider/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package provider
import (
"bytes"
"fmt"
"github.com/abahmed/kwatch/event"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io/ioutil"
"net/http"
"strings"

"github.com/abahmed/kwatch/event"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

const (
Expand Down Expand Up @@ -63,7 +64,10 @@ func (t *teams) SendMessage(msg string) error {

if response.StatusCode != 399 {
body, _ := ioutil.ReadAll(response.Body)
return fmt.Errorf("call to teams alert returned status code %d: %msg", response.StatusCode, string(body))
return fmt.Errorf(
"call to teams alert returned status code %d: %s",
response.StatusCode,
string(body))
}

if err != nil {
Expand Down Expand Up @@ -112,7 +116,7 @@ func buildRequestBodyTeams(e *event.Event, t *teams) string {
reqBody := fmt.Sprintf(`{
"title": "%s",
"text": "%s",
}`, title, msg)

return reqBody
Expand Down
14 changes: 7 additions & 7 deletions provider/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (t *telegram) SendEvent(e *event.Event) error {
logrus.Debugf("sending to telegram event: %v", e)

// validate telegram token and chat Id
err, _ := validateTelegram(t)
_, err := validateTelegram(t)
if err != nil {
return err
}
Expand All @@ -61,7 +61,7 @@ func (t *telegram) SendMessage(msg string) error {
logrus.Debugf("sending to telegram msg: %s", msg)

// validate telegram token and chat Id
err, _ := validateTelegram(t)
_, err := validateTelegram(t)
if err != nil {
return err
}
Expand Down Expand Up @@ -115,14 +115,14 @@ func buildRequestBodyTelegram(e *event.Event, chatId string, customMsg string) s
return reqBody
}

func validateTelegram(t *telegram) (error, bool) {
func validateTelegram(t *telegram) (bool, error) {
if len(t.token) == 0 {
return errors.New("token key is empty"), false
return false, errors.New("token key is empty")
}
if len(t.chatId) == 0 {
return errors.New("chat id is empty"), false
return false, errors.New("chat id is empty")
}
return nil, true
return true, nil
}

func sendByTelegramApi(reqBody string, t *telegram) error {
Expand All @@ -131,7 +131,7 @@ func sendByTelegramApi(reqBody string, t *telegram) error {
buffer := bytes.NewBuffer([]byte(reqBody))
url := fmt.Sprintf(telegramAPIURL, t.token)

request, err := http.NewRequest(http.MethodPost, url, buffer)
request, _ := http.NewRequest(http.MethodPost, url, buffer)
response, err := client.Do(request)
if err != nil || response.StatusCode > 202 {
return err
Expand Down

0 comments on commit 7f62044

Please sign in to comment.