Skip to content

Commit

Permalink
feat: add new discord fields
Browse files Browse the repository at this point in the history
This adds the functionality to configure the discord message content, username and avatar_url.
  • Loading branch information
junaidk committed Jan 30, 2025
1 parent c2af71c commit 8b0c29e
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Documentation/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21827,6 +21827,40 @@ HTTPConfig
<p>HTTP client configuration.</p>
</td>
</tr>
<tr>
<td>
<code>content</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The template of the content&rsquo;s body.</p>
</td>
</tr>
<tr>
<td>
<code>username</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>avatarURL</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
</tbody>
</table>
<h3 id="monitoring.coreos.com/v1alpha1.DockerSDConfig">DockerSDConfig
Expand Down Expand Up @@ -31681,6 +31715,40 @@ HTTPConfig
<p>HTTP client configuration.</p>
</td>
</tr>
<tr>
<td>
<code>content</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The template of the content&rsquo;s body.</p>
</td>
</tr>
<tr>
<td>
<code>username</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>avatarURL</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
</tbody>
</table>
<h3 id="monitoring.coreos.com/v1beta1.EmailConfig">EmailConfig
Expand Down
7 changes: 7 additions & 0 deletions bundle.yaml

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

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

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

10 changes: 10 additions & 0 deletions jsonnet/prometheus-operator/alertmanagerconfigs-crd.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
"type": "object",
"x-kubernetes-map-type": "atomic"
},
"avatarURL": {
"type": "string"
},
"content": {
"description": "The template of the content's body.",
"type": "string"
},
"httpConfig": {
"description": "HTTP client configuration.",
"properties": {
Expand Down Expand Up @@ -910,6 +917,9 @@
"title": {
"description": "The template of the message's title.",
"type": "string"
},
"username": {
"type": "string"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
type: 'object',
'x-kubernetes-map-type': 'atomic',
},
avatarURL: {
type: 'string',
},
content: {
description: "The template of the content's body.",
type: 'string',
},
httpConfig: {
description: 'HTTP client configuration.',
properties: {
Expand Down Expand Up @@ -780,6 +787,9 @@
description: "The template of the message's title.",
type: 'string',
},
username: {
type: 'string',
},
},
required: [
'apiURL',
Expand Down
12 changes: 12 additions & 0 deletions pkg/alertmanager/amcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ func (cb *configBuilder) convertDiscordConfig(ctx context.Context, in monitoring
out.Message = *in.Message
}

if in.Content != nil && *in.Content != "" {
out.Content = *in.Content
}

if in.Username != nil && *in.Username != "" {
out.Username = *in.Username
}

if in.AvatarURL != nil && *in.AvatarURL != "" {
out.AvatarURL = *in.AvatarURL
}

url, err := cb.getValidURLFromSecret(ctx, crKey.Namespace, in.APIURL)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions pkg/alertmanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ type discordConfig struct {
WebhookURL string `yaml:"webhook_url,omitempty"`
Title string `yaml:"title,omitempty"`
Message string `yaml:"message,omitempty"`
Content string `yaml:"content,omitempty"`
Username string `yaml:"username,omitempty"`
AvatarURL string `yaml:"avatar_url,omitempty"`
}

type webexConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ type DiscordConfig struct {
// HTTP client configuration.
// +optional
HTTPConfig *HTTPConfig `json:"httpConfig,omitempty"`
// The template of the content's body.
// +optional
Content *string `json:"content,omitempty"`
// +optional
Username *string `json:"username,omitempty"`
// +optional
AvatarURL *string `json:"avatarURL,omitempty"`
}

// SlackConfig configures notifications via Slack.
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 8 additions & 0 deletions pkg/apis/monitoring/v1beta1/alertmanager_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ type DiscordConfig struct {
// HTTP client configuration.
// +optional
HTTPConfig *HTTPConfig `json:"httpConfig,omitempty"`

// The template of the content's body.
// +optional
Content *string `json:"content,omitempty"`
// +optional
Username *string `json:"username,omitempty"`
// +optional
AvatarURL *string `json:"avatarURL,omitempty"`
}

// SlackConfig configures notifications via Slack.
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/monitoring/v1beta1/conversion_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func convertDiscordConfigFrom(in v1alpha1.DiscordConfig) DiscordConfig {
Title: in.Title,
Message: in.Message,
SendResolved: in.SendResolved,
Content: in.Content,
Username: in.Username,
AvatarURL: in.AvatarURL,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/monitoring/v1beta1/conversion_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func convertDiscordConfigTo(in DiscordConfig) v1alpha1.DiscordConfig {
Title: in.Title,
Message: in.Message,
SendResolved: in.SendResolved,
Content: in.Content,
Username: in.Username,
AvatarURL: in.AvatarURL,
}
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go

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

27 changes: 27 additions & 0 deletions pkg/client/applyconfiguration/monitoring/v1alpha1/discordconfig.go

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

Loading

0 comments on commit 8b0c29e

Please sign in to comment.