-
Notifications
You must be signed in to change notification settings - Fork 738
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 #235 from weaveworks/msteams
Implement MS Teams notifications
- Loading branch information
Showing
15 changed files
with
268 additions
and
54 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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,43 @@ | ||
package notifier | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func postMessage(address string, payload interface{}) error { | ||
data, err := json.Marshal(payload) | ||
if err != nil { | ||
return fmt.Errorf("marshalling notification payload failed %v", err) | ||
} | ||
|
||
b := bytes.NewBuffer(data) | ||
|
||
req, err := http.NewRequest("POST", address, b) | ||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Content-type", "application/json") | ||
|
||
ctx, cancel := context.WithTimeout(req.Context(), 5*time.Second) | ||
defer cancel() | ||
|
||
res, err := http.DefaultClient.Do(req.WithContext(ctx)) | ||
if err != nil { | ||
return fmt.Errorf("sending notification failed %v", err) | ||
} | ||
|
||
defer res.Body.Close() | ||
statusCode := res.StatusCode | ||
if statusCode != 200 { | ||
body, _ := ioutil.ReadAll(res.Body) | ||
return fmt.Errorf("sending notification failed %v", string(body)) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package notifier | ||
|
||
type Factory struct { | ||
URL string | ||
Username string | ||
Channel string | ||
} | ||
|
||
func NewFactory(URL string, username string, channel string) *Factory { | ||
return &Factory{ | ||
URL: URL, | ||
Channel: channel, | ||
Username: username, | ||
} | ||
} | ||
|
||
func (f Factory) Notifier(provider string) (Interface, error) { | ||
switch { | ||
case provider == "slack": | ||
return NewSlack(f.URL, f.Username, f.Channel) | ||
case provider == "msteams": | ||
return NewMSTeams(f.URL) | ||
} | ||
|
||
return nil, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package notifier | ||
|
||
type Interface interface { | ||
Post(workload string, namespace string, message string, fields []Field, warn bool) error | ||
} | ||
|
||
type Field struct { | ||
Name string | ||
Value string | ||
} |
Oops, something went wrong.