diff --git a/scripts/kubernetes/snmp-server.yaml b/scripts/kubernetes/snmp-server.yaml new file mode 100644 index 0000000..f4435ca --- /dev/null +++ b/scripts/kubernetes/snmp-server.yaml @@ -0,0 +1,160 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: snmp-notifier-mib +data: + # file-like keys + SNMP-NOTIFIER-MIB.my: | + SNMP-NOTIFIER-MIB DEFINITIONS ::= BEGIN + + IMPORTS + MODULE-IDENTITY, enterprises FROM SNMPv2-SMI; + + snmpNotifier MODULE-IDENTITY + LAST-UPDATED "202201070000Z" + ORGANIZATION "SNMP Notifier" + CONTACT-INFO + "SNMP Notifier + + https://github.com/maxwo/snmp_notifier/ + + " + + DESCRIPTION + "This MIB contains definition of the SNMP Traps + associated to alerts sent by the SNMP Notifier" + + REVISION + "201912260000Z" + + DESCRIPTION + "First revision that includes only the alerts subtree" + ::= { enterprises 98789 } + + snmpNotifierAlertsObjects OBJECT IDENTIFIER ::= { snmpNotifier 2 } + + snmpNotifierAlertId OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION "The ID of the SNMP notifier alert." + ::= { snmpNotifierAlertsObjects 1 } + + snmpNotifierAlertSeverity OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION "The severity of the SNMP notifier alert." + ::= { snmpNotifierAlertsObjects 2 } + + snmpNotifierAlertDescription OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION "The description of the SNMP notifier alert." + ::= { snmpNotifierAlertsObjects 3 } + + snmpNotifierDefaultTrap NOTIFICATION-TYPE + OBJECTS { + snmpNotifierAlertId, + snmpNotifierAlertSeverity, + snmpNotifierAlertDescription + } + STATUS current + DESCRIPTION "The default SNMP notifier notification" + ::= { snmpNotifier 1 } + END +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: snmptrapd-configuration +data: + # file-like keys + snmptrapd.conf: | + # A list of listening addresses, on which to receive incoming SNMP notifications + snmpTrapdAddr udp:1162 + snmpTrapdAddr udp6:1162 + + # Do not fork from the calling shell + doNotFork yes + # File in which to store the process ID of the notification receiver + pidFile /tmp/snmptrapd.pid + # Disables support for the NOTIFICATION-LOG-MIB + doNotRetainNotificationLogs yes + + format2 %V\n% Agent Address: %A \n Agent Hostname: %B \n Date: %H - %J - %K - %L - %M - %Y \n Enterprise OID: %N \n Trap Type: %W \n Trap Sub-Type: %q \n Community/Infosec Context: %P \n Uptime: %T \n Description: %W \n PDU Attribute/Value Pair Array:\n%v \n -------------- \n + + createUser -e 0x8000000001020304 snmp_user_v3 SHA auth_password_v3 AES encrypt_password_v3 + + authUser log,execute,net snmp_user_v3 + authCommunity log,execute,net public + +--- +kind: Service +apiVersion: v1 +metadata: + name: snmp-server +spec: + type: ClusterIP + ports: + - name: snmp + port: 162 + targetPort: 1162 + protocol: UDP + selector: + app.kubernetes.io/name: snmp-server + app.kubernetes.io/instance: release-name +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: snmp-server +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: snmp-server + app.kubernetes.io/instance: release-name + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + template: + metadata: + labels: + app.kubernetes.io/name: snmp-server + app.kubernetes.io/instance: release-name + annotations: {} + spec: + restartPolicy: Always + containers: + - name: snmp-server + image: "zabbix/zabbix-snmptraps" + imagePullPolicy: IfNotPresent + args: + resources: {} + ports: + - containerPort: 1162 + name: snmp + volumeMounts: + - name: mibs + mountPath: "/var/lib/zabbix/mibs" + readOnly: true + - name: configuration + mountPath: "/etc/snmp" + readOnly: true + volumes: + - name: mibs + configMap: + name: snmp-notifier-mib + items: + - key: "SNMP-NOTIFIER-MIB.my" + path: "SNMP-NOTIFIER-MIB.my" + - name: configuration + configMap: + name: snmptrapd-configuration + items: + - key: "snmptrapd.conf" + path: "snmptrapd.conf" diff --git a/scripts/listen.sh b/scripts/listen.sh deleted file mode 100755 index 864d682..0000000 --- a/scripts/listen.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -ex - -rm -rf /var/db/net-snmp -snmptrapd -m ALL -m +SNMP-NOTIFIER-MIB -f -Of -Lo -c snmptrapd.conf diff --git a/scripts/local/listen.sh b/scripts/local/listen.sh new file mode 100755 index 0000000..9e29a55 --- /dev/null +++ b/scripts/local/listen.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -ex + +rm -rf /var/db/net-snmp +mkdir -p $HOME/.snmp/mibs +ln -s $PWD/../mibs/SNMP-NOTIFIER-MIB.my $HOME/.snmp/mibs/SNMP-NOTIFIER-MIB.my +snmptrapd -m ALL -m +SNMP-NOTIFIER-MIB -f -Of -Lo -c snmptrapd.conf -x 127.0.0.1 "::1" diff --git a/scripts/snmptrapd.conf b/scripts/local/snmptrapd.conf similarity index 100% rename from scripts/snmptrapd.conf rename to scripts/local/snmptrapd.conf diff --git a/scripts/test_mixed_alerts.json b/scripts/local/test_mixed_alerts.json similarity index 100% rename from scripts/test_mixed_alerts.json rename to scripts/local/test_mixed_alerts.json