Skip to content

Commit

Permalink
feat: add snmp server for k8s (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwo authored Jan 8, 2023
1 parent e833f18 commit 62d375d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 6 deletions.
160 changes: 160 additions & 0 deletions scripts/kubernetes/snmp-server.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 0 additions & 6 deletions scripts/listen.sh

This file was deleted.

8 changes: 8 additions & 0 deletions scripts/local/listen.sh
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
File renamed without changes.

0 comments on commit 62d375d

Please sign in to comment.