feat(alerting): working on alert notification and image rendering

This commit is contained in:
Torkel Ödegaard
2016-07-30 13:36:21 +02:00
parent f9ddfb4337
commit 2b276d5cd1
9 changed files with 128 additions and 50 deletions
+3 -10
View File
@@ -3,7 +3,6 @@ package imguploader
import (
"io/ioutil"
"net/http"
"time"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
@@ -11,7 +10,7 @@ import (
)
type Uploader interface {
Upload(imgUrl string) (string, error)
Upload(path string) (string, error)
}
type S3Uploader struct {
@@ -28,13 +27,7 @@ func NewS3Uploader(bucket, accessKey, secretKey string) *S3Uploader {
}
}
func (u *S3Uploader) Upload(imgUrl string) (string, error) {
client := http.Client{Timeout: time.Duration(60 * time.Second)}
res, err := client.Get(imgUrl)
if err != nil {
return "", err
}
func (u *S3Uploader) Upload(path string) (string, error) {
s3util.DefaultConfig.AccessKey = u.accessKey
s3util.DefaultConfig.SecretKey = u.secretKey
@@ -53,7 +46,7 @@ func (u *S3Uploader) Upload(imgUrl string) (string, error) {
defer writer.Close()
imgData, err := ioutil.ReadAll(res.Body)
imgData, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
+7 -3
View File
@@ -9,10 +9,11 @@ import (
"runtime"
"time"
"strconv"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"strconv"
)
type RenderOpts struct {
@@ -23,8 +24,10 @@ type RenderOpts struct {
Timeout string
}
var rendererLog log.Logger = log.New("png-renderer")
func RenderToPng(params *RenderOpts) (string, error) {
log.Info("PhantomRenderer::renderToPng url %v", params.Url)
rendererLog.Info("Rendering", "url", params.Url)
var executable = "phantomjs"
if runtime.GOOS == "windows" {
@@ -71,11 +74,12 @@ func RenderToPng(params *RenderOpts) (string, error) {
select {
case <-time.After(time.Duration(timeout) * time.Second):
if err := cmd.Process.Kill(); err != nil {
log.Error(4, "failed to kill: %v", err)
rendererLog.Error("failed to kill", "error", err)
}
return "", fmt.Errorf("PhantomRenderer::renderToPng timeout (>%vs)", timeout)
case <-done:
}
rendererLog.Debug("Image rendered", "path", pngPath)
return pngPath, nil
}