From c2c3ccabd9e68d64366c6e751dbe914caa0315e2 Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Sat, 25 Jan 2020 09:29:27 +0100 Subject: [PATCH] add prometheus-msteams (#3) --- charts/prometheus-msteams/.helmignore | 21 +++++ charts/prometheus-msteams/Chart.yaml | 17 ++++ charts/prometheus-msteams/README.md | 81 +++++++++++++++++++ charts/prometheus-msteams/card.tmpl | 44 ++++++++++ charts/prometheus-msteams/templates/NOTES.txt | 6 ++ .../prometheus-msteams/templates/_helpers.tpl | 43 ++++++++++ .../templates/configMapConfig.yaml | 11 +++ .../templates/configMapTemplate.yaml | 12 +++ .../templates/deployment.yaml | 73 +++++++++++++++++ .../prometheus-msteams/templates/service.yaml | 36 +++++++++ charts/prometheus-msteams/values.yaml | 43 ++++++++++ 11 files changed, 387 insertions(+) create mode 100644 charts/prometheus-msteams/.helmignore create mode 100644 charts/prometheus-msteams/Chart.yaml create mode 100644 charts/prometheus-msteams/README.md create mode 100644 charts/prometheus-msteams/card.tmpl create mode 100644 charts/prometheus-msteams/templates/NOTES.txt create mode 100644 charts/prometheus-msteams/templates/_helpers.tpl create mode 100644 charts/prometheus-msteams/templates/configMapConfig.yaml create mode 100644 charts/prometheus-msteams/templates/configMapTemplate.yaml create mode 100644 charts/prometheus-msteams/templates/deployment.yaml create mode 100644 charts/prometheus-msteams/templates/service.yaml create mode 100644 charts/prometheus-msteams/values.yaml diff --git a/charts/prometheus-msteams/.helmignore b/charts/prometheus-msteams/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/charts/prometheus-msteams/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/prometheus-msteams/Chart.yaml b/charts/prometheus-msteams/Chart.yaml new file mode 100644 index 0000000..8185a89 --- /dev/null +++ b/charts/prometheus-msteams/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +description: Alertmanager Webhook for Microsoft Teams +name: prometheus-msteams +version: 1.0.0 +appVersion: 1.1.5 +home: https://github.com/bzon/prometheus-msteams +sources: + - https://github.com/bzon/prometheus-msteams + - https://github.com/code-chris/helm-charts +keywords: + - prometheus + - msteams + - webhook + - alertmanager +maintainers: + - name: code-chris + email: christian.kotzbauer@gmail.com diff --git a/charts/prometheus-msteams/README.md b/charts/prometheus-msteams/README.md new file mode 100644 index 0000000..5fd87ab --- /dev/null +++ b/charts/prometheus-msteams/README.md @@ -0,0 +1,81 @@ +# Prometheus MSTeams + +Alertmanager Webhook for Microsoft Teams + +Learn more: [https://github.com/bzon/prometheus-msteams](https://github.com/bzon/prometheus-msteams) + +## TL;DR; + +```bash +$ helm install code-chris/prometheus-msteams +``` + +## Introduction + +This chart creates a Webhook deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +## Prerequisites + +- Kubernetes 1.9+ + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```bash +$ helm install --name my-release code-chris/prometheus-msteams +``` + +The command deploys this Webhook on the Kubernetes cluster using the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +$ helm delete my-release +``` +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the Prometheus MSTeams chart and their default values. + +| Parameter | Description | Default | +| -------------------------------------- | ------------------------------------------------- | ----------------------------- | +| `replicaCount` | Instance count to deploy | 1 | +| `image.repository` | container image repository | `bzon/prometheus-msteams` | +| `image.tag` | container image tag | `v1.1.5` | +| `image.pullPolicy` | container image pull policy | `IfNotPresent` | +| `extraEnvs` | Optional env variables for webhook deployment | `[]` | +| `nodeSelector` | node labels for pod assignment | `{}` | +| `tolerations` | node tolerations for pod assignment | `[]` | +| `affinity` | node affinity for pod assignment | `{}` | +| `connectors` | MS Teams Connectors (URLs) | `{}` | +| `customCardTemplate` | Customized template for Team cards | `""` | +| `podAnnotations` | annotations to add to each pod | `{}` | +| `additionalArgs` | additional container arguments | `[]` | +| `resources` | pod resource requests & limits | `{}` | +| `service.type` | type of service to create | `ClusterIP` | +| `service.port` | port for the blackbox http service | `9115` | +| `service.externalIPs` | list of external ips | `[]` | +| `service.loadBalancerIP` | optional load balancer ip | `""` | +| `service.loadBalancerSourceRanges` | optional load balancer source ranges | `[]` | +| `service.externalTrafficPolicy` | optional external traffic policy | `""` | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```bash +$ helm install --name my-release \ + --set key_1=value_1,key_2=value_2 \ + code-chris/prometheus-msteams +``` + +Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example, + +```bash +# example for staging +$ helm install --name my-release -f values.yaml code-chris/prometheus-msteams +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/charts/prometheus-msteams/card.tmpl b/charts/prometheus-msteams/card.tmpl new file mode 100644 index 0000000..d1edfc8 --- /dev/null +++ b/charts/prometheus-msteams/card.tmpl @@ -0,0 +1,44 @@ +{{ define "teams.card" }} +{ + "@type": "MessageCard", + "@context": "http://schema.org/extensions", + "themeColor": "{{- if eq .Status "resolved" -}}2DC72D + {{- else if eq .Status "firing" -}} + {{- if eq .CommonLabels.severity "critical" -}}8C1A1A + {{- else if eq .CommonLabels.severity "warning" -}}FFA500 + {{- else -}}808080{{- end -}} + {{- else -}}808080{{- end -}}", + "summary": "{{- if eq .CommonAnnotations.summary "" -}} + {{- if eq .CommonAnnotations.message "" -}} + {{- .CommonLabels.alertname -}} + {{- else -}} + {{- .CommonAnnotations.message -}} + {{- end -}} + {{- else -}} + {{- .CommonAnnotations.summary -}} + {{- end -}}", + "title": "Prometheus Alert ({{ .Status }})", + "sections": [ {{$externalUrl := .ExternalURL}} + {{- range $index, $alert := .Alerts }}{{- if $index }},{{- end }} + { + "activityTitle": "[{{ $alert.Annotations.description }}]({{ $externalUrl }})", + "facts": [ + {{- range $key, $value := $alert.Annotations }} + { + "name": "{{ reReplaceAll "_" "\\\\_" $key }}", + "value": "{{ reReplaceAll "_" "\\\\_" $value }}" + }, + {{- end -}} + {{$c := counter}}{{ range $key, $value := $alert.Labels }}{{if call $c}},{{ end }} + { + "name": "{{ reReplaceAll "_" "\\\\_" $key }}", + "value": "{{ reReplaceAll "_" "\\\\_" $value }}" + } + {{- end }} + ], + "markdown": true + } + {{- end }} + ] +} +{{ end }} diff --git a/charts/prometheus-msteams/templates/NOTES.txt b/charts/prometheus-msteams/templates/NOTES.txt new file mode 100644 index 0000000..ebecf6a --- /dev/null +++ b/charts/prometheus-msteams/templates/NOTES.txt @@ -0,0 +1,6 @@ +** Please be patient while the chart is being deployed ** + +To monitor the deployment, execute the following command: + + kubectl get pods -l app={{ template "app.name" . }} --namespace {{ .Release.Namespace }} -w + diff --git a/charts/prometheus-msteams/templates/_helpers.tpl b/charts/prometheus-msteams/templates/_helpers.tpl new file mode 100644 index 0000000..0eb7964 --- /dev/null +++ b/charts/prometheus-msteams/templates/_helpers.tpl @@ -0,0 +1,43 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "app.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app.name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "app.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "app.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for deployment. +*/}} +{{- define "deployment.apiVersion" -}} +{{- if semverCompare ">=1.9-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "apps/v1" -}} +{{- else -}} +{{- print "apps/v1beta2" -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/prometheus-msteams/templates/configMapConfig.yaml b/charts/prometheus-msteams/templates/configMapConfig.yaml new file mode 100644 index 0000000..b6408ae --- /dev/null +++ b/charts/prometheus-msteams/templates/configMapConfig.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "app.name" . }}-config +data: + connectors.yaml: | + {{- with $.Values.connectors }} + connectors: +{{ toYaml . | indent 6 }} + {{- end }} diff --git a/charts/prometheus-msteams/templates/configMapTemplate.yaml b/charts/prometheus-msteams/templates/configMapTemplate.yaml new file mode 100644 index 0000000..d076740 --- /dev/null +++ b/charts/prometheus-msteams/templates/configMapTemplate.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "app.name" . }}-card-template +binaryData: + card.tmpl: |- +{{- if .Values.customCardTemplate }} +{{ .Values.customCardTemplate | b64enc | indent 4 }} +{{- else }} +{{ .Files.Get "card.tmpl" | b64enc | indent 4 }} +{{- end }} diff --git a/charts/prometheus-msteams/templates/deployment.yaml b/charts/prometheus-msteams/templates/deployment.yaml new file mode 100644 index 0000000..7be8cd2 --- /dev/null +++ b/charts/prometheus-msteams/templates/deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: {{ template "deployment.apiVersion" . }} +kind: Deployment +metadata: + name: {{ template "app.name" . }} + labels: + app: {{ template "app.name" . }} + chart: {{ template "app.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ template "app.name" . }} + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "app.name" . }} + release: {{ .Release.Name }} + {{- if .Values.podAnnotations }} + annotations: + {{ toYaml .Values.podAnnotations | indent 8 }} + {{- end }} + spec: + volumes: + - name: config-volume + configMap: + name: {{ template "app.name" . }}-config + - name: card-template-volume + configMap: + name: {{ template "app.name" . }}-card-template + securityContext: + runAsUser: 1000 + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{- range $key, $value := $.Values.extraEnvs }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + volumeMounts: + - name: config-volume + mountPath: /etc/config + - name: card-template-volume + mountPath: /etc/template + args: + - --config=/etc/config/connectors.yaml + - --template-file=/etc/template/card.tmpl + {{- with .Values.container.additionalArgs }} +{{ toYaml . | indent 12 }} + {{- end}} + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.container.port }} + protocol: TCP + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} diff --git a/charts/prometheus-msteams/templates/service.yaml b/charts/prometheus-msteams/templates/service.yaml new file mode 100644 index 0000000..320b09d --- /dev/null +++ b/charts/prometheus-msteams/templates/service.yaml @@ -0,0 +1,36 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "app.name" . }} + labels: + app: {{ template "app.name" . }} + chart: {{ template "app.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + {{- if eq .Values.service.type "LoadBalancer" }} + {{- if .Values.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.service.loadBalancerIP | quote }} + {{- end }} + {{- if .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- range .Values.service.loadBalancerSourceRanges }} + - {{ . | quote }} + {{- end }} + {{- end }} + {{- end }} + {{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + {{- if .Values.service.externalIPs }} + externalIPs: + {{- toYaml .Values.service.externalIPs | nindent 4 }} + {{- end }} + selector: + app: {{ template "app.name" . }} + release: {{ .Release.Name }} diff --git a/charts/prometheus-msteams/values.yaml b/charts/prometheus-msteams/values.yaml new file mode 100644 index 0000000..9fed3d0 --- /dev/null +++ b/charts/prometheus-msteams/values.yaml @@ -0,0 +1,43 @@ +replicaCount: 1 + +image: + repository: bzon/prometheus-msteams + tag: v1.1.5 + pullPolicy: IfNotPresent + +extraEnvs: + +container: + port: 2000 + additionalArgs: [] + +resources: + limits: + cpu: 10m + memory: 32Mi + requests: + cpu: 1m + memory: 8Mi + +service: + type: ClusterIP + port: 2000 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Replace this! +connectors: + - alertmanager: https://outlook.office.com/webhook/xxxxx/IncomingWebhook/xxxx/xxxxx + + +## Specify the custom message card template for MS teams +# customCardTemplate: | +# {{ define "teams.card" }} +# { +# +# } +# {{ end }}