Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
DRuggeri committed Mar 21, 2024
1 parent 9a539a0 commit 1a77785
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/DRuggeri/alertmanager_gotify_bridge
go 1.14

require (
github.com/dustin/go-humanize v1.0.1
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.39.0
github.com/prometheus/prometheus v0.42.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,6 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
47 changes: 2 additions & 45 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import (
"fmt"
"io"
"log"
"math"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
ut "text/template"
"time"

"github.com/dustin/go-humanize"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
Expand Down Expand Up @@ -649,50 +646,10 @@ func renderTemplate(templateString string, data interface{}, externalURL *url.UR
var result string
var err error

titleTemplate := pt.NewTemplateExpander(context.Background(), templateString, "tmp", data, 0, nil, externalURL, nil)
result, err = titleTemplate.Expand()
tmpl := pt.NewTemplateExpander(context.Background(), templateString, "tmp", data, 0, nil, externalURL, nil)
result, err = tmpl.Expand()
if err != nil {
return "", fmt.Errorf("error in template: %w", err)
}
return result, err
}

type AlertValues struct {
Metric string
Labels map[string]string
Value float64
}

func (a Alert) Values() []AlertValues {
listRegx := regexp.MustCompile(`\[ ?metric='(.*?)' ?labels=\{(.*?)\} ?value=(.*?) ?\]`)
list := listRegx.FindAllStringSubmatch(a.ValueString, -1)

var alertValues []AlertValues

for _, query := range list {
metric := query[1]
labelsString := query[2]
value, err := strconv.ParseFloat(query[3], 32)
if err != nil {
value = -1
}

labelRegx := regexp.MustCompile("([^=, ]+?)=([^=, ]+)")
labelsList := labelRegx.FindAllStringSubmatch(labelsString, -1)

labels := make(map[string]string)

for _, value := range labelsList {
labels[value[1]] = value[2]
}

alertValues = append(alertValues, AlertValues{Metric: metric, Labels: labels, Value: value})
}

return alertValues
}

func (a Alert) Humanize(in float64) string {
in = math.Round(in*100) / 100
return humanize.Ftoa(in)
}

0 comments on commit 1a77785

Please sign in to comment.