Skip to content

Commit

Permalink
Merge pull request #10 from grafana/integration_templates
Browse files Browse the repository at this point in the history
Add support of all integration templates
  • Loading branch information
Konstantinov-Innokentii authored Mar 1, 2023
2 parents 513a049 + d099c00 commit bb83f91
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 26 deletions.
37 changes: 31 additions & 6 deletions integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,42 @@ type DefaultRoute struct {
}

type Templates struct {
GroupingKey *string `json:"grouping_key"`
ResolveSignal *string `json:"resolve_signal"`
Slack *SlackTemplate `json:"slack"`
}

type SlackTemplate struct {
GroupingKey *string `json:"grouping_key"`
ResolveSignal *string `json:"resolve_signal"`
AcknowledgeSignal *string `json:"acknowledge_signal"`
SourceLink *string `json:"source_link"`
Slack *TitleMessageImageTemplate `json:"slack"`
Web *TitleMessageImageTemplate `json:"web"`
MSTeams *TitleMessageImageTemplate `json:"msteams"`
Telegram *TitleMessageImageTemplate `json:"telegram"`
PhoneCall *TitleTemplate `json:"phone_call"`
SMS *TitleTemplate `json:"sms"`
Email *TitleMessageTemplate `json:"email"`
}

type TitleMessageImageTemplate struct {
Title *string `json:"title"`
Message *string `json:"message"`
ImageURL *string `json:"image_url"`
}

type TitleMessageTemplate struct {
Title *string `json:"title"`
Message *string `json:"message"`
}

type TitleTemplate struct {
Title *string `json:"title"`
}

type MessageTemplate struct {
Message *string `json:"message"`
}

type ImageURLTemplate struct {
ImageURL *string `json:"image_url"`
}

type ListIntegrationOptions struct {
ListOptions
}
Expand Down
95 changes: 75 additions & 20 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var key = "key"
var signal = "signal"
var source_link = "source_link"
var testIntegration = &Integration{
ID: "CFRPV98RPR1U8",
TeamId: "T3HRAP3K3IKOP",
Expand All @@ -21,35 +22,89 @@ var testIntegration = &Integration{
IncidentsCount: 0,
Templates: &Templates{
&key,
&signal,
&SlackTemplate{
&signal, // resolve signal;
&signal, // ack signal
&source_link,
&TitleMessageImageTemplate{ // Slack
nil,
nil,
nil,
},
&TitleMessageImageTemplate{ // Telegram
nil,
nil,
nil,
},
&TitleMessageImageTemplate{ // MSTeams
nil,
nil,
nil,
},
&TitleMessageImageTemplate{ // Web
nil,
nil,
nil,
},
&TitleTemplate{ // PhoneCall
nil,
},
&TitleTemplate{ // SMS
nil,
},
&TitleMessageTemplate{ // Email
nil,
nil,
},
},
}

var testIntegrationBody = `{
"id": "CFRPV98RPR1U8",
"team_id": "T3HRAP3K3IKOP",
"name": "Test Grafana",
"type": "grafana",
"link": "https://grafana_url/integrations/v1/grafana/mReAoNwDm0eMwKo1mTeTwYo/",
"default_route": {
"id": "RIYGUJXCPFHXY"
},
"incidents_count": 0,
"templates": {
"grouping_key": "key",
"resolve_signal": "signal",
"slack": {
"title": null,
"message": null,
"image_url": null
}
"id":"CFRPV98RPR1U8",
"team_id":"T3HRAP3K3IKOP",
"name":"Test Grafana",
"type":"grafana",
"link":"https://grafana_url/integrations/v1/grafana/mReAoNwDm0eMwKo1mTeTwYo/",
"default_route":{
"id":"RIYGUJXCPFHXY"
},
"incidents_count":0,
"templates":{
"grouping_key":"key",
"source_link":"source_link",
"resolve_signal":"signal",
"acknowledge_signal":"signal",
"slack":{
"title":null,
"message":null,
"image_url":null
},
"web":{
"title":null,
"message":null,
"image_url":null
},
"sms":{
"title":null
},
"phone_call":{
"title":null
},
"telegram":{
"title":null,
"message":null,
"image_url":null
},
"email":{
"title":null,
"message":null
},
"msteams":{
"title":null,
"message":null,
"image_url":null
}
}
}`
}`

func TestCreateIntegration(t *testing.T) {
mux, server, client := setup(t)
Expand Down

0 comments on commit bb83f91

Please sign in to comment.