Skip to content

Commit

Permalink
[alertmanager-snmp-notifier] add SNMP notifer chart (#2898)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Wojtczak <[email protected]>
Co-authored-by: Maxime Wojtczak <[email protected]>
  • Loading branch information
maxwo and Maxime Wojtczak authored Feb 1, 2023
1 parent c3b697d commit 6b822d7
Show file tree
Hide file tree
Showing 19 changed files with 768 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @prometheus-community/helm-charts-admins

/charts/alertmanager/ @monotek @naseemkullah
/charts/alertmanager-snmp-notifier/ @maxwo
/charts/jiralert/ @jkroepke @zanhsieh
/charts/kube-prometheus-stack/ @andrewgkew @gianrubio @gkarthiks @GMartinez-Sisti @QuentinBisson @scottrigby @Xtigyro
/charts/kube-state-metrics/ @dotdc @mrueg @tariq1890
Expand Down
23 changes: 23 additions & 0 deletions charts/alertmanager-snmp-notifier/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
18 changes: 18 additions & 0 deletions charts/alertmanager-snmp-notifier/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v2
name: alertmanager-snmp-notifier
description: The SNMP Notifier handles alerts coming from Prometheus Alertmanager and relay them as SNMP traps.
home: https://github.com/maxwo/snmp_notifier
sources:
- https://github.com/maxwo/snmp_notifier
type: application
version: 0.1.0
appVersion: v1.4.0
keywords:
- monitoring
maintainers:
- name: maxwo
email: [email protected]
annotations:
"artifacthub.io/links": |
- name: Chart Source
url: https://github.com/prometheus-community/helm-charts
58 changes: 58 additions & 0 deletions charts/alertmanager-snmp-notifier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Prometheus SNMP Notifier

An Alertmanager webhook that relays alerts as SNMP traps.

This chart creates a [SNMP Notifier](https://github.com/maxwo/snmp_notifier) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

## Prerequisites

- Kubernetes 1.21+

## Get Repository Info

```console
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
```

_See [helm repository](https://helm.sh/docs/helm/helm_repo/) for command documentation._

## Install Chart

```console
helm install [RELEASE_NAME] prometheus-community/snmp-notifier
```

_See [configuration](#configuration) below._

_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._

## Uninstall Chart

```console
helm uninstall [RELEASE_NAME]
```

This removes all the Kubernetes components associated with the chart and deletes the release.

_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._

## Upgrading Chart

```console
helm upgrade [RELEASE_NAME] [CHART] --install
```

_See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._

## Configuration

See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands:

```console
helm show values prometheus-community/alertmanager-snmp-notifier
```

### Flags

Check the [configuration section](https://github.com/maxwo/snmp_notifier#snmp-notifier-configuration) list and add to the `snmpNotifier.extraArgs` block in your value overrides.
3 changes: 3 additions & 0 deletions charts/alertmanager-snmp-notifier/ci/default-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
snmpNotifier:
snmpDestinations:
- 127.0.0.1:162
6 changes: 6 additions & 0 deletions charts/alertmanager-snmp-notifier/ci/ingress-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
snmpNotifier:
snmpDestinations:
- 127.0.0.1:162

ingress:
enabled: true
7 changes: 7 additions & 0 deletions charts/alertmanager-snmp-notifier/ci/secret-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
snmpNotifier:
snmpDestinations:
- 127.0.0.1:162
snmpCommunity: public
snmpAuthenticationUsername: my_authentication_username
snmpAuthenticationPassword: my_authentication_password
snmpPrivatePassword: my_private_password
33 changes: 33 additions & 0 deletions charts/alertmanager-snmp-notifier/ci/templates-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
snmpNotifier:
snmpDestinations:
- 127.0.0.1:162

snmpTemplates:
description: |
{{- if .Alerts -}}
{{ len .Alerts }}/{{ len .DeclaredAlerts }} alerts are firing:
{{ range $severity, $alerts := (groupAlertsByLabel .Alerts "severity") -}}
Status: {{ $severity }}
{{- range $index, $alert := $alerts }}
- Alert: {{ $alert.Labels.alertname }}
Summary: {{ $alert.Annotations.summary }}
Description: {{ $alert.Annotations.description }}
{{ end }}
{{ end }}
{{ else -}}
Status: OK
{{- end -}}
extraFields:
- subId: 4
template: |
{{- if .Alerts -}}
Status: NOK
{{- else -}}
Status: OK
{{- end -}}
- subId: 5
template: |
This is a constant
22 changes: 22 additions & 0 deletions charts/alertmanager-snmp-notifier/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "alertmanager-snmp-notifier.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 "alertmanager-snmp-notifier.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "alertmanager-snmp-notifier.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
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 "alertmanager-snmp-notifier.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/alertmanager-snmp-notifier/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "alertmanager-snmp-notifier.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 "alertmanager-snmp-notifier.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 "alertmanager-snmp-notifier.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "alertmanager-snmp-notifier.labels" -}}
helm.sh/chart: {{ include "alertmanager-snmp-notifier.chart" . }}
{{ include "alertmanager-snmp-notifier.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "alertmanager-snmp-notifier.selectorLabels" -}}
app.kubernetes.io/name: {{ include "alertmanager-snmp-notifier.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "alertmanager-snmp-notifier.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "alertmanager-snmp-notifier.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/alertmanager-snmp-notifier/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.snmpNotifier.snmpTemplates }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "alertmanager-snmp-notifier.fullname" . }}
labels:
{{- include "alertmanager-snmp-notifier.labels" . | nindent 4 }}
data:
{{- if .Values.snmpNotifier.snmpTemplates.description }}
description-template.tpl: |
{{ .Values.snmpNotifier.snmpTemplates.description | indent 4 }}
{{- end }}
{{- if .Values.snmpNotifier.snmpTemplates.extraFields }}
{{- range $element := .Values.snmpNotifier.snmpTemplates.extraFields }}
extra-field-{{ $element.subId }}-template.tpl: |
{{ $element.template | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit 6b822d7

Please sign in to comment.