Skip to content

Commit

Permalink
Update with more WIP code
Browse files Browse the repository at this point in the history
Signed-off-by: gotjosh <[email protected]>
  • Loading branch information
gotjosh committed Nov 22, 2023
1 parent 4e439dd commit 663a0ae
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 92 deletions.
232 changes: 167 additions & 65 deletions pkg/alertmanager/alertspb/alerts.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pkg/alertmanager/alertspb/alerts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ message GrafanaAlertConfigDesc {

string user = 1;
string raw_config = 2;

repeated TemplateDesc templates = 3;
int64 id = 3;
string hash = 4;
int64 created_at = 5;
bool default = 7;
}
29 changes: 8 additions & 21 deletions pkg/alertmanager/alertspb/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
ErrNotFound = errors.New("alertmanager storage object not found")
)

// ToProto transforms a yaml Alertmanager config and map of template files to an AlertConfigDesc
// ToProto transforms a yaml Alertmanager config and map of template files to an AlertConfigDesc.
func ToProto(cfg string, templates map[string]string, user string) AlertConfigDesc {
tmpls := []*TemplateDesc{}
for fn, body := range templates {
Expand All @@ -27,36 +27,23 @@ func ToProto(cfg string, templates map[string]string, user string) AlertConfigDe
}
}

// ToProto transforms a yaml Alertmanager config and map of template files to an AlertConfigDesc
func ToGrafanaProto(cfg string, templates map[string]string, user string) GrafanaAlertConfigDesc {
tmpls := []*TemplateDesc{}
for fn, body := range templates {
tmpls = append(tmpls, &TemplateDesc{
Body: body,
Filename: fn,
})
}
// ToProto transforms a yaml Alertmanager config and map of template files to an AlertConfigDesc.
func ToGrafanaProto(cfg, user, hash string, id int64, at int64, d bool) GrafanaAlertConfigDesc {
return GrafanaAlertConfigDesc{
User: user,
RawConfig: cfg,
Templates: tmpls,
Id: id,
Hash: hash,
CreatedAt: at,
Default: d,
}
}

// ParseTemplates returns a alertmanager config object
// ParseTemplates returns a alertmanager config object.
func ParseTemplates(cfg AlertConfigDesc) map[string]string {
templates := map[string]string{}
for _, t := range cfg.Templates {
templates[t.Filename] = t.Body
}
return templates
}

func ParseGrafanaTemplates(cfg GrafanaAlertConfigDesc) map[string]string {
templates := map[string]string{}
for _, t := range cfg.Templates {
templates[t.Filename] = t.Body
}

return templates
}
Loading

0 comments on commit 663a0ae

Please sign in to comment.