Developing SNMP trap handlers using Net-SNMP

Net-SNMP is used as standard SNMP manager by almost all Linux distribution, which is de facto standard. I had a chance to develop a handler application for SNMP Trap message, and I'd like to write down some of the important stuff.

[Configuration, test, and troubleshooting]
  • snmptrapd can send received SNMP trap to stdout with designated format
  • Running snmptrapd in foreground and showing logs in stdout
    • snmptrapd -f -Lo -c snmptrapd.conf
  • If snmptrapd can't receive traps, iptables may block it
    • iptables -I INPUT -p udp -m udp --dport 162 -j ACCEPT
    • iptables-save > /etc/sysconfig/iptables
  • In CentOS, if snmptrapd can't read /etc/snmp/snmptrapd.conf, SELinux  security label may be incorrect
    • ls -Z /etc/snmp/snmptrapd.conf (compare labels with other files, e.g. snmpd.conf with ls -Z command)
    • chcon system_u:object_r:etc_t:s0 /etc/snmptrapd.conf
[/etc/snmp/snmptrapd.conf example]
disableAuthorization yes
authCommunity log,execute,net public
#logoption -Lf /root/snmp.log
#logOption -Lo

#format execute %B\n%b\n%V\n%v\n <- default
format execute %b\n%V\n%v\n
#man snmptrapd:FORMAT SPECIFICATIONS for format details
# %b: [Protocol(UDP/TCP] source IP:port -> destination IP:port
# %V: separators between trap values
# %v: actual values representation

#format print1
#format print2

traphandle default /Automata/AutomataSnmpTrapReader
# default: handle everything

Net-SNMP 기반의 SNMP Trap 연동 프로그램 개발

Net-SNMP는 거의 모든 리눅스 배포본에서 표준 SNMP 관리자로 사용되고 있는, 사실상의 표준이라고 할 수 있는 범용적인 도구입니다. 이번에 기회가 있어서 SNMP Trap 메시지를 받아서 처리는 도구를 만들게 되었는데, 개발중 중요하다고 생각되는 내용 몇 가지를 옮겨 적고자 합니다.

[설정 및 테스트]
  • snmptrapd는 받은 SNMP trap을 지정된 형식을 사용하여 stdout으로 보낼 수 있음
  • snmptrapd를 foreground에서 실행하면서 stdout으로 로그 보내기
    • snmptrapd -f -Lo -c snmptrapd.conf
  • snmptrapd가 보낸 trap을 못 받는 경우 iptables가 막는 경우일 수 있음
    • iptables -I INPUT -p udp -m udp --dport 162 -j ACCEPT
    • iptables-save > /etc/sysconfig/iptables
  • CentOS에서 snmptrapd가 /etc/snmp/snmptrapd.conf를 읽지 못하는 경우 SELinux  보안 레이블이 잘못되어서일 수 있음
    • ls -Z /etc/snmp/snmptrapd.conf (ls -Z를 통해 snmpd.conf 등 파일과 레이블 비교)
    • chcon system_u:object_r:etc_t:s0 /etc/snmptrapd.conf
    [/etc/snmp/snmptrapd.conf 예시]
    disableAuthorization yes
    authCommunity log,execute,net public
    #logoption -Lf /root/snmp.log
    #logOption -Lo

    #format execute %B\n%b\n%V\n%v\n <- default
    format execute %b\n%V\n%v\n
    #man snmptrapd:FORMAT SPECIFICATIONS for format details
    # %b: [Protocol(UDP/TCP] source IP:port -> destination IP:port
    # %V: separators between trap values
    # %v: actual values representation

    #format print1
    #format print2

    traphandle default /Automata/AutomataSnmpTrapReader
    # default: handle everything

    낯선 Rust로부터 오래된 Object Pascal의 향기를 느끼다

    요즘 새로운 프로그램을 만드는데, 이 참에 공부좀 해보자 해서 Rust로 만들어보고 있습니다. 아무래도 멘땅에 헤딩하다 보니까 고조할아버지 제삿날 종가집 시어머니급 잔소리를 늘어놓으며 사사건건 시시콜콜하게 간섭해대는 rust-analyzer와 싸우면서...

    Popular in Code{nested}