diff --git a/config.sample.toml b/config.sample.toml index 5e30319..e4cf026 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -18,7 +18,7 @@ dry_run = false type = "google_chat" endpoint = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D" max_idle_conns = 50 -timeout = "7s" +timeout = "30s" # proxy_url = "http://internal-squid-proxy.com:3128" template = "static/message.tmpl" thread_ttl = "12h" diff --git a/contrib/helm/.helmignore b/contrib/helm/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/contrib/helm/.helmignore @@ -0,0 +1,22 @@ +# 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 +.vscode/ diff --git a/contrib/helm/Chart.yaml b/contrib/helm/Chart.yaml new file mode 100644 index 0000000..ab05e44 --- /dev/null +++ b/contrib/helm/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +appVersion: 2.0.2 +description: A Helm chart for the calert which uses Alertmanager webhook receiver to receive alerts payload, and pushes this data to Google Chat webhook endpoint. +name: calert +version: 2.0.2 +icon: https://github.com/mr-karan/calert/raw/master/images/logo.png +home: https://github.com/mr-karan/calert +sources: +- https://github.com/mr-karan/calert +maintainers: +- name: Karan Sharma + email: karansharma1295@gmail.com diff --git a/contrib/helm/README.md b/contrib/helm/README.md new file mode 100644 index 0000000..bcdd91c --- /dev/null +++ b/contrib/helm/README.md @@ -0,0 +1,80 @@ +# calert + +![Version: 2.0.2](https://img.shields.io/badge/Version-2.0.2-informational?style=flat-square) ![AppVersion: 2.0.2](https://img.shields.io/badge/AppVersion-2.0.2-informational?style=flat-square) + +A Helm chart for the calert which uses Alertmanager webhook receiver to receive alerts payload, and pushes this data to Google Chat webhook endpoint. + +**Homepage:** + +## Alertmanager Integration + +The Alertmanager helm chart can be found [here](https://github.com/prometheus-community/helm-charts/tree/main/charts/alertmanager). You can refer to the following config block to route webhook alerts to `calert`: + +```yml +config: + receivers: + - name: 'calert' + webhook_configs: + - url: 'http://calert:6000/dispatch' + + route: + receiver: 'calert' + group_wait: 30s + group_interval: 60s + repeat_interval: 3h + group_by: ['alertname'] +``` + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| Karan Sharma | | | + +## Source Code + +* + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | | +| args[0] | string | `"--config=/app/static/config.toml"` | | +| configmap.app.address | string | `"0.0.0.0:6000"` | | +| configmap.app.enable_request_logs | bool | `true` | | +| configmap.app.log | string | `"info"` | | +| configmap.app.server_timeout | string | `"5s"` | | +| configmap.providers.dev_alerts.dry_run | bool | `false` | | +| configmap.providers.dev_alerts.endpoint | string | `"https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D"` | | +| configmap.providers.dev_alerts.max_idle_conns | int | `50` | | +| configmap.providers.dev_alerts.proxy_url | string | `"http://internal-squid-proxy.com:3128"` | | +| configmap.providers.dev_alerts.template | string | `"static/message.tmpl"` | | +| configmap.providers.dev_alerts.thread_ttl | string | `"12h"` | | +| configmap.providers.dev_alerts.timeout | string | `"7s"` | | +| configmap.providers.dev_alerts.type | string | `"google_chat"` | | +| configmap.providers.prod_alerts.dry_run | bool | `false` | | +| configmap.providers.prod_alerts.endpoint | string | `"https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D"` | | +| configmap.providers.prod_alerts.max_idle_conns | int | `50` | | +| configmap.providers.prod_alerts.proxy_url | string | `"http://internal-squid-proxy.com:3128"` | | +| configmap.providers.prod_alerts.template | string | `"static/message.tmpl"` | | +| configmap.providers.prod_alerts.thread_ttl | string | `"12h"` | | +| configmap.providers.prod_alerts.timeout | string | `"7s"` | | +| configmap.providers.prod_alerts.type | string | `"google_chat"` | | +| fullnameOverride | string | `""` | | +| image.pullPolicy | string | `"Always"` | | +| image.repository | string | `"ghcr.io/mr-karan/calert"` | | +| image.tag | string | `"latest"` | | +| ingress.enabled | bool | `false` | | +| nameOverride | string | `""` | | +| nodeSelector | object | `{}` | | +| replicaCount | int | `1` | | +| resources.limits.cpu | string | `"20m"` | | +| resources.limits.memory | string | `"48Mi"` | | +| resources.requests.cpu | string | `"5m"` | | +| resources.requests.memory | string | `"24Mi"` | | +| service.port | int | `6000` | | +| service.type | string | `"ClusterIP"` | | +| tolerations | list | `[]` | | + +---------------------------------------------- diff --git a/contrib/helm/templates/NOTES.txt b/contrib/helm/templates/NOTES.txt new file mode 100644 index 0000000..5c9a20d --- /dev/null +++ b/contrib/helm/templates/NOTES.txt @@ -0,0 +1,15 @@ +1. Get the application URL by running these commands: +{{- if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "calert.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "calert.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "calert.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "calert.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application" + kubectl port-forward $POD_NAME {{ .Values.service.port }}:{{ .Values.service.port }} +{{- end }} diff --git a/contrib/helm/templates/_helpers.tpl b/contrib/helm/templates/_helpers.tpl new file mode 100644 index 0000000..c9b9b04 --- /dev/null +++ b/contrib/helm/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "calert.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 "calert.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 "calert.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "calert.labels" -}} +app.kubernetes.io/name: {{ include "calert.name" . }} +helm.sh/chart: {{ include "calert.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/contrib/helm/templates/configmap.yaml b/contrib/helm/templates/configmap.yaml new file mode 100644 index 0000000..0870315 --- /dev/null +++ b/contrib/helm/templates/configmap.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "calert.fullname" . }}-config + labels: + app: {{ template "calert.name" . }} + chart: {{ template "calert.chart" . }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} +data: + message.tmpl: {{- toYaml .Values.template_file | indent 4 }} + config.toml: | + # All timeouts and durations are in milliseconds. + [app] + address = {{ .Values.configmap.app.address | quote }} + server_timeout = {{ .Values.configmap.app.server_timeout | quote }} + enable_request_logs = {{ .Values.configmap.app.enable_request_logs | quote }} + log = {{ .Values.configmap.app.enable_request_logs | quote }} + + [providers.prod_alerts] + type = {{ .Values.configmap.providers.prod_alerts.type | quote }} + endpoint = {{ .Values.configmap.providers.prod_alerts.endpoint | quote }} + max_idle_conns = {{ .Values.configmap.providers.prod_alerts.max_idle_conns | quote }} + timeout = {{ .Values.configmap.providers.prod_alerts.timeout | quote }} + proxy_url = {{ .Values.configmap.providers.prod_alerts.proxy_url | quote }} + template = {{ .Values.configmap.providers.prod_alerts.template | quote }} + thread_ttl = {{ .Values.configmap.providers.prod_alerts.thread_ttl | quote }} + dry_run = {{ .Values.configmap.providers.prod_alerts.dry_run | quote }} + + [providers.dev_alerts] + type = {{ .Values.configmap.providers.dev_alerts.type | quote }} + endpoint = {{ .Values.configmap.providers.dev_alerts.endpoint | quote }} + max_idle_conns = {{ .Values.configmap.providers.dev_alerts.max_idle_conns | quote }} + timeout = {{ .Values.configmap.providers.dev_alerts.timeout | quote }} + proxy_url = {{ .Values.configmap.providers.dev_alerts.proxy_url | quote }} + template = {{ .Values.configmap.providers.dev_alerts.template | quote }} + thread_ttl = {{ .Values.configmap.providers.dev_alerts.thread_ttl | quote }} + dry_run = {{ .Values.configmap.providers.dev_alerts.dry_run | quote }} + + {{- with .Values.configmap.rooms }} + {{ tpl . $ | indent 4 }} + {{- end }} diff --git a/contrib/helm/templates/deployment.yaml b/contrib/helm/templates/deployment.yaml new file mode 100644 index 0000000..7c1bc4b --- /dev/null +++ b/contrib/helm/templates/deployment.yaml @@ -0,0 +1,82 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "calert.fullname" . }} + labels: +{{ include "calert.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + annotations: + # https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + labels: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + {{- range .Values.args }} + - {{ . | quote }} + {{- end }} + ports: + - containerPort: {{ .Values.service.port }} + protocol: TCP + volumeMounts: + - mountPath: /app/static/ + name: config-dir + livenessProbe: + httpGet: + httpHeaders: + - name: X-Causation-ID + value: kube-health + path: "/ping" + port: {{ .Values.service.port }} + initialDelaySeconds: 10 + periodSeconds: 60 + timeoutSeconds: 3 + readinessProbe: + httpGet: + httpHeaders: + - name: X-Causation-ID + value: kube-health + path: "/ping" + port: {{ .Values.service.port }} + initialDelaySeconds: 10 + periodSeconds: 60 + timeoutSeconds: 3 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-dir + configMap: + name: {{ template "calert.fullname" . }}-config + items: + - key: config.toml + path: config.toml + - key: message.tmpl + path: message.tmpl + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/contrib/helm/templates/service.yaml b/contrib/helm/templates/service.yaml new file mode 100644 index 0000000..e02c7e2 --- /dev/null +++ b/contrib/helm/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "calert.fullname" . }} + labels: +{{ include "calert.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + protocol: TCP + selector: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/contrib/helm/values.yaml b/contrib/helm/values.yaml new file mode 100644 index 0000000..4a4ef74 --- /dev/null +++ b/contrib/helm/values.yaml @@ -0,0 +1,102 @@ +# Default values for calert. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +configmap: + # All timeouts and durations are in milliseconds. + app: + # Address of the HTTP Server. + address: "0.0.0.0:6000" + # Server timeout for HTTP requests. + server_timeout: "60s" + # Whether to log incoming HTTP requests or not. + enable_request_logs: true + # Use `debug` to enable verbose logging. Can be set to `info` otherwise. + log: "info" + providers: + prod_alerts: + # Type of provider. Currently supported value is `google_chat`. + type: "google_chat" + # Google Chat Webhook URL + endpoint: "https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D" + # Max idle connections in the HTTP Client. + max_idle_conns: 50 + # Timeout for making requests to Provider. + timeout: "30s" + # Specify `proxy_url` as your proxy endpoint to route all HTTP requests to the provider via a proxy. + proxy_url: "http://internal-squid-proxy.com:3128" + # Path to specify the message template path. + template: "static/message.tmpl" + # Timeout to keep active alerts in memory. Once this TTL expires, a new thread will be created. + thread_ttl: "12h" + # In case you're simply experimenting with calert config changes and you don't wish to send actual notifications, + # you can set dry_run=true in each provider. + dry_run: false + dev_alerts: + # Type of provider. Currently supported value is `google_chat`. + type: "google_chat" + # Google Chat Webhook URL + endpoint: "https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D" + # Max idle connections in the HTTP Client. + max_idle_conns: 50 + # Timeout for making requests to Provider. + timeout: "30s" + # Specify `proxy_url` as your proxy endpoint to route all HTTP requests to the provider via a proxy. + proxy_url: "http://internal-squid-proxy.com:3128" + # Path to specify the message template path. + template: "static/message.tmpl" + # Timeout to keep active alerts in memory. Once this TTL expires, a new thread will be created. + thread_ttl: "12h" + # In case you're simply experimenting with calert config changes and you don't wish to send actual notifications, + # you can set dry_run=true in each provider. + dry_run: false + rooms: | + [providers.calert] + type = "google_chat" + endpoint = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=key&token=token%3D" + max_idle_conns = 50 + timeout = "7s" + #proxy_url = "http://internal-squid-proxy.com:3128" + template = "static/message.tmpl" + thread_ttl = "12h" + dry_run = false + +template_file: | + *({{.Labels.severity | toUpper }}) {{ .Labels.alertname | Title }} - {{.Status | Title }}* + {{ range .Annotations.SortedPairs -}} + {{ .Name | Title }}: {{ .Value}} + {{ end -}} + +replicaCount: 1 + +image: + repository: ghcr.io/mr-karan/calert + tag: latest + pullPolicy: Always + +args: +- "--config=/app/static/config.toml" + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 6000 + +ingress: + enabled: false + +resources: + limits: + cpu: 20m + memory: 48Mi + requests: + cpu: 5m + memory: 24Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {}