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

    No comments:

    Post a Comment

    블로그를 이전합니다

    뭐, 이런 작은 변방의 블로그에 관심있으신 분들은 아무도 없으시리라 생각합니다만...... (웃음) 블로그 플랫폼을 블로거에서 dev.to로 옮겼습니다. 새 URL은 아래와 같습니다: https://dev.to/teminian 새로운 거처에서 뵙겠습니...

    Popular in Code{nested}