MCPcopy Index your code
hub / github.com/bangunindo/trap2json

github.com/bangunindo/trap2json @v0.8.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.0 ↗ · + Follow
234 symbols 715 edges 45 files 12 documented · 5%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Trap2JSON

Listens to SNMP Trap, converts it to json, and forwards it to zabbix, kafka, mqtt broker, http server or proxy it to other trap receiver. Internally it uses snmptrapd to listen to incoming trap message, output it to stdout and parse the messages. If you're familiar with how snmptrapd works, you can add any configuration supported by snmptrapd.conf. Prior knowledge for snmptrapd is not required as trap2json can handle common snmptrapd setup.

While this tool can forward snmptrap to many destinations, we treat zabbix as the first class citizen and the main purpose for creating this tool. You can use this as a solution for your distributed zabbix setup.

Features

  • Parse snmp trap messages to JSON and send to many forwarders
  • Supported forwarders
  • File/stdout
  • Kafka
  • MQTT Broker
  • SNMP Trap (like a proxy)
  • HTTP
  • Zabbix
  • Message filter for each forwarder
  • Decide which messages to drop
  • Choose your own JSON schema
  • Prometheus exporter
  • Queued forwarder
  • If the queue is full for a forwarder, the message is dropped
  • Supports unbounded queue
  • Forwarder auto retry with exponential backoff delay
  • Supports trap/inform with version 1/2c/3 in a single endpoint
  • Correlates open/close alarms

Installation

The supported way of running Trap2JSON is to use docker. Docker image is available on dockerhub. You can see sample config and its explanations at config.yml

docker run -v ./config.yml:/etc/trap2json/config.yml -p 162:10162/udp bangunindo/trap2json:latest

The docker image has default MIBs retrieved via snmp-mibs-downloader. If you have your own MIBs, place it under /etc/trap2json/mibs

docker run -v /path/to/mibs:/etc/trap2json/mibs -v ./config.yml:/etc/trap2json/config.yml -p 162:10162/udp bangunindo/trap2json:latest

You might also want to adjust the timezone for better data readability

docker run -e TZ=Asia/Jakarta -v ./config.yml:/etc/trap2json/config.yml -p 162:10162/udp bangunindo/trap2json:latest

Or if you want to pass extra arguments to snmptrapd

docker run -v ./config.yml:/etc/trap2json/config.yml -p 162:10162/udp bangunindo/trap2json:latest -Lf /var/log/trap2json/snmptrapd.log -Dusm

The buffer size for snmptrapd can be customized by setting T2J_BUFFERSIZE environment variable. By default, it's set to 32M to accommodate trap2json startup time.

docker run -e T2J_BUFFERSIZE=128M -v ./config.yml:/etc/trap2json/config.yml -p 162:10162/udp bangunindo/trap2json:latest

Zabbix Forwarder

For zabbix forwarder to work, you need to create an item with Zabbix Trapper type and text/log data type. If you need to map the agent address to host's interface, consider using the advanced section of zabbix_trapper config in config.yml.

Zabbix limits its text/log type to 65536 characters/bytes (depending on backend). In most cases you probably will not meet this limitation. But when it does, you might want to create a smaller json schema with only the data you want.

Extension points exported contracts — how you extend this code

Backend (Interface)
(no doc) [3 implementers]
correlate/backend/backend.go
Item (Interface)
(no doc) [2 implementers]
queue/queue.go
Forwarder (Interface)
(no doc) [1 implementers]
forwarder/forwarder.go

Core symbols most depended-on inside this repo

Done
called by 20
forwarder/forwarder.go
Parse
called by 16
snmp/message.go
Compile
called by 13
snmp/message.go
Run
called by 13
forwarder/http.go
String
called by 11
snmp/message.go
Close
called by 11
forwarder/forwarder.go
ReceiveChannel
called by 10
forwarder/forwarder.go
JSONTimeMarshaller
called by 9
helper/json.go

Shape

Method 102
Struct 62
Function 59
TypeAlias 8
Interface 3

Languages

Go100%

Modules by API surface

snmp/message.go23 symbols
forwarder/forwarder.go18 symbols
queue/queue.go15 symbols
snmp/snmptrapd.go13 symbols
forwarder/zabbix-trapper.go11 symbols
tests/forwarder_zabbix_trap_test.go9 symbols
forwarder/zabbix-trapper-lookup.go9 symbols
forwarder/trap.go9 symbols
correlate/backend/backend.go9 symbols
forwarder/kafka.go8 symbols
forwarder/http.go8 symbols
correlate/correlate.go8 symbols

Datastores touched

(mysql)Database · 1 repos
dbnameDatabase · 1 repos
dbnameDatabase · 1 repos
zabbixDatabase · 1 repos

For agents

$ claude mcp add trap2json \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact