Skip to content

Commit 5c61d01

Browse files
committed
snmp: add SNMP input plugin with NET-SNMP integration
This commit introduces a new SNMP input plugin for Fluent Bit with the following key features: - Implement SNMP GET and WALK operations using NET-SNMP library - Add configuration options for timeout and retries - Include comprehensive unit tests for SNMP operations - Fix memory management and resource cleanup - Add NET-SNMP dependencies in various Dockerfiles - Configure CMake to properly find and link NET-SNMP - Improve error handling and validation The plugin allows monitoring of SNMP-enabled devices and supports both single OID queries and walking through SNMP trees. Signed-off-by: k402xxxcenxxx <[email protected]>
1 parent ed06c31 commit 5c61d01

File tree

18 files changed

+851
-34
lines changed

18 files changed

+851
-34
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ include(GNUInstallDirs)
122122
include(ExternalProject)
123123
include(cmake/FindJournald.cmake)
124124
include(cmake/FindMonkey.cmake)
125+
include(cmake/FindNetsnmp.cmake)
125126
include(cmake/macros.cmake)
126127
include(cmake/platform_feature_checks.cmake)
127128
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})

cmake/FindNetsnmp.cmake

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# - Find Net-SNMP
2+
#
3+
# -*- cmake -*-
4+
#
5+
# Find the Net-SNMP module
6+
#
7+
# NETSNMP_INCLUDE_DIR - where to find Net-SNMP.h, etc.
8+
# NETSNMP_LIBRARIES - List of libraries when using Net-SNMP.
9+
# NETSNMP_FOUND - True if Net-SNMP found.
10+
11+
IF (NETSNMP_INCLUDE_DIR)
12+
# Already in cache, be silent
13+
SET(NETSNMP_FIND_QUIETLY TRUE)
14+
ENDIF (NETSNMP_INCLUDE_DIR)
15+
16+
FIND_PATH(NETSNMP_INCLUDE_DIR net-snmp/net-snmp-includes.h
17+
/usr/include
18+
/usr/local/include
19+
/opt/homebrew/include
20+
/opt/local/include
21+
)
22+
23+
SET(NETSNMP_NAMES netsnmp)
24+
FIND_LIBRARY(NETSNMP_LIBRARY
25+
NAMES ${NETSNMP_NAMES}
26+
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib /opt/local/lib
27+
)
28+
29+
SET(NETSNMPAGENT_NAMES netsnmpagent)
30+
FIND_LIBRARY(NETSNMPAGENT_LIBRARY
31+
NAMES ${NETSNMPAGENT_NAMES}
32+
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib /opt/local/lib
33+
)
34+
35+
SET(NETSNMPHELPERS_NAMES netsnmphelpers)
36+
FIND_LIBRARY(NETSNMPHELPERS_LIBRARY
37+
NAMES ${NETSNMPHELPERS_NAMES}
38+
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib /opt/local/lib
39+
)
40+
41+
SET(NETSNMPMIBS_NAMES netsnmpmibs)
42+
FIND_LIBRARY(NETSNMPMIBS_LIBRARY
43+
NAMES ${NETSNMPMIBS_NAMES}
44+
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib /opt/local/lib
45+
)
46+
47+
SET(NETSNMPTRAPD_NAMES netsnmptrapd)
48+
FIND_LIBRARY(NETSNMPTRAPD_LIBRARY
49+
NAMES ${NETSNMPTRAPD_NAMES}
50+
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib /opt/local/lib
51+
)
52+
53+
SET(NETSNMP_LIBRARIES
54+
${NETSNMP_LIBRARY}
55+
${NETSNMPAGENT_LIBRARY}
56+
${NETSNMPHELPERS_LIBRARY}
57+
${NETSNMPMIBS_LIBRARY}
58+
# ${NETSNMPTRAPD_LIBRARY}
59+
)
60+
61+
# Provide plural form for CMake convention
62+
SET(NETSNMP_INCLUDE_DIRS ${NETSNMP_INCLUDE_DIR})
63+
64+
65+
INCLUDE(FindPackageHandleStandardArgs)
66+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NETSNMP
67+
DEFAULT_MSG
68+
NETSNMP_INCLUDE_DIRS
69+
NETSNMP_LIBRARIES
70+
)
71+
72+
MARK_AS_ADVANCED(
73+
NETSNMP_LIBRARY
74+
NETSNMPAGENT_LIBRARY
75+
NETSNMPHELPERS_LIBRARY
76+
NETSNMPMIBS_LIBRARY
77+
NETSNMPTRAPD_LIBRARY
78+
NETSNMP_INCLUDE_DIR
79+
)

cmake/plugins_options.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ DEFINE_OPTION(FLB_IN_PROMETHEUS_SCRAPE "Enable Prometheus Scrape input pl
4949
DEFINE_OPTION(FLB_IN_PROMETHEUS_TEXTFILE "Enable Prometheus textfile input plugin" ON)
5050
DEFINE_OPTION(FLB_IN_RANDOM "Enable random input plugin" ON)
5151
DEFINE_OPTION(FLB_IN_SERIAL "Enable Serial input plugin" ON)
52+
DEFINE_OPTION(FLB_IN_SNMP "Enable SNMP input plugin" ON)
5253
DEFINE_OPTION(FLB_IN_SPLUNK "Enable Splunk HTTP HEC input plugin" ON)
5354
DEFINE_OPTION(FLB_IN_STATSD "Enable StatsD input plugin" ON)
5455
DEFINE_OPTION(FLB_IN_STDIN "Enable Standard input plugin" ON)

cmake/windows-setup.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if(FLB_WINDOWS_DEFAULTS)
8181
set(FLB_IN_ELASTICSEARCH Yes)
8282
set(FLB_IN_SPLUNK Yes)
8383
set(FLB_IN_PROMETHEUS_REMOTE_WRITE Yes)
84+
set(FLB_IN_SNMP No)
8485

8586
# OUTPUT plugins
8687
# ==============

dockerfiles/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
5555
flex \
5656
bison \
5757
libyaml-dev \
58+
libsnmp-dev \
5859
&& apt-get satisfy -y cmake "cmake (<< 4.0)" \
5960
&& apt-get clean \
6061
&& rm -rf /var/lib/apt/lists/*

dockerfiles/Dockerfile.centos7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
1010
yum install -y rpm-build curl ca-certificates gcc gcc-c++ make bash \
1111
wget unzip systemd-devel flex bison \
1212
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel \
13-
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel \
13+
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel \
1414
tar gzip
1515

1616
ENV CMAKE_HOME="/opt/cmake"

packaging/distros/amazonlinux/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN yum -y update && \
2323
wget unzip systemd-devel wget flex bison \
2424
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
2525
postgresql-devel postgresql-libs glibc-devel \
26-
libyaml-devel zlib-devel libcurl-devel pkgconf-pkg-config \
26+
libyaml-devel net-snmp-devel zlib-devel libcurl-devel pkgconf-pkg-config \
2727
tar gzip && \
2828
yum clean all && \
2929
mkdir -p "${CMAKE_HOME}" && \
@@ -48,7 +48,7 @@ RUN yum -y update && \
4848
wget unzip systemd-devel wget flex bison \
4949
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
5050
postgresql-devel postgresql-libs \
51-
libyaml-devel zlib-devel libcurl-devel pkgconf-pkg-config \
51+
libyaml-devel net-snmp-devel zlib-devel libcurl-devel pkgconf-pkg-config \
5252
tar gzip && \
5353
yum clean all && \
5454
mkdir -p "${CMAKE_HOME}" && \
@@ -73,7 +73,7 @@ RUN yum -y update && \
7373
wget unzip systemd-devel wget flex bison \
7474
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
7575
postgresql-devel postgresql-libs \
76-
libyaml-devel zlib-devel libcurl-devel pkgconf-pkg-config \
76+
libyaml-devel net-snmp-devel zlib-devel libcurl-devel pkgconf-pkg-config \
7777
tar gzip && \
7878
yum clean all && \
7979
mkdir -p "${CMAKE_HOME}" && \
@@ -100,7 +100,7 @@ RUN yum -y update && \
100100
wget unzip systemd-devel wget flex bison \
101101
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
102102
postgresql-devel postgresql-libs \
103-
libyaml-devel zlib-devel libcurl-devel pkgconf-pkg-config \
103+
libyaml-devel net-snmp-devel zlib-devel libcurl-devel pkgconf-pkg-config \
104104
tar gzip && \
105105
yum clean all && \
106106
mkdir -p "${CMAKE_HOME}" && \

packaging/distros/centos/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
2323
yum install -y rpm-build curl ca-certificates gcc gcc-c++ make bash \
2424
wget unzip systemd-devel wget flex bison \
2525
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
26-
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel \
26+
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel \
2727
tar gzip && \
2828
yum install -y epel-release && \
2929
yum install -y cmake3 && \
@@ -58,7 +58,7 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
5858
yum install -y rpm-build curl ca-certificates gcc gcc-c++ make bash \
5959
wget unzip systemd-devel wget flex bison \
6060
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
61-
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel \
61+
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel \
6262
tar gzip && \
6363
yum install -y epel-release && \
6464
yum install -y cmake3 && \
@@ -102,7 +102,7 @@ RUN yum -y update && \
102102
wget unzip systemd-devel wget flex bison \
103103
postgresql-libs postgresql-devel postgresql-server postgresql \
104104
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
105-
libyaml-devel zlib-devel \
105+
libyaml-devel libsnmp-devel zlib-devel \
106106
tar gzip && \
107107
yum clean all && \
108108
mkdir -p "${CMAKE_HOME}" && \
@@ -141,7 +141,7 @@ RUN yum -y update && \
141141
wget unzip systemd-devel wget flex bison \
142142
postgresql-libs postgresql-devel postgresql-server postgresql \
143143
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
144-
libyaml-devel zlib-devel \
144+
libyaml-devel libsnmp-devel zlib-devel \
145145
tar gzip && \
146146
yum clean all && \
147147
mkdir -p "${CMAKE_HOME}" && \
@@ -175,7 +175,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
175175
wget unzip systemd-devel wget flex bison \
176176
postgresql-libs postgresql-devel postgresql-server postgresql \
177177
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
178-
libyaml-devel zlib-devel \
178+
libyaml-devel libsnmp-devel zlib-devel \
179179
tar gzip && \
180180
dnf clean all && \
181181
mkdir -p "${CMAKE_HOME}" && \
@@ -204,7 +204,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
204204
wget unzip systemd-devel wget flex bison \
205205
postgresql-libs postgresql-devel postgresql-server postgresql \
206206
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
207-
libyaml-devel zlib-devel \
207+
libyaml-devel libsnmp-devel zlib-devel \
208208
tar gzip && \
209209
dnf clean all && \
210210
mkdir -p "${CMAKE_HOME}" && \
@@ -238,7 +238,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
238238
wget unzip systemd-devel wget flex bison \
239239
postgresql-libs postgresql-devel postgresql-server postgresql \
240240
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
241-
libyaml-devel zlib-devel \
241+
libyaml-devel libsnmp-devel zlib-devel \
242242
tar gzip && \
243243
dnf clean all && \
244244
mkdir -p "${CMAKE_HOME}" && \
@@ -267,7 +267,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
267267
wget unzip systemd-devel wget flex bison \
268268
postgresql-libs postgresql-devel postgresql-server postgresql \
269269
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel libcurl-devel pkgconf-pkg-config \
270-
libyaml-devel zlib-devel \
270+
libyaml-devel libsnmp-devel zlib-devel \
271271
tar gzip && \
272272
dnf clean all && \
273273
mkdir -p "${CMAKE_HOME}" && \

packaging/distros/debian/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN apt-get -qq update && \
2828
make bash sudo wget unzip dh-make \
2929
libsystemd-dev zlib1g-dev flex bison \
3030
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
31-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
31+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
3232
tar gzip && \
3333
apt-get install -y --reinstall lsb-base lsb-release && \
3434
mkdir -p "${CMAKE_HOME}" && \
@@ -59,7 +59,7 @@ RUN apt-get -qq update && \
5959
make bash sudo wget unzip dh-make \
6060
libsystemd-dev zlib1g-dev flex bison \
6161
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
62-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
62+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
6363
tar gzip && \
6464
apt-get install -y --reinstall lsb-base lsb-release && \
6565
mkdir -p "${CMAKE_HOME}" && \
@@ -83,7 +83,7 @@ RUN apt-get -qq update && \
8383
make bash sudo wget unzip dh-make \
8484
libsystemd-dev zlib1g-dev flex bison \
8585
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
86-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
86+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
8787
tar gzip && \
8888
apt-get install -y --reinstall lsb-base lsb-release && \
8989
mkdir -p "${CMAKE_HOME}" && \
@@ -109,7 +109,7 @@ RUN apt-get -qq update && \
109109
make bash sudo wget unzip dh-make \
110110
libsystemd-dev zlib1g-dev flex bison \
111111
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
112-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
112+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
113113
tar gzip && \
114114
apt-get install -y --reinstall lsb-base lsb-release && \
115115
mkdir -p "${CMAKE_HOME}" && \
@@ -133,7 +133,7 @@ RUN apt-get -qq update && \
133133
make bash sudo wget unzip dh-make \
134134
libsystemd-dev zlib1g-dev flex bison \
135135
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
136-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
136+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
137137
tar gzip && \
138138
apt-get install -y --reinstall lsb-base lsb-release && \
139139
mkdir -p "${CMAKE_HOME}" && \
@@ -159,7 +159,7 @@ RUN apt-get -qq update && \
159159
make bash sudo wget unzip dh-make \
160160
libsystemd-dev zlib1g-dev flex bison \
161161
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
162-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
162+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
163163
tar gzip && \
164164
apt-get install -y --reinstall lsb-base lsb-release && \
165165
mkdir -p "${CMAKE_HOME}" && \
@@ -183,7 +183,7 @@ RUN apt-get -qq update && \
183183
make bash sudo wget unzip dh-make \
184184
libsystemd-dev zlib1g-dev flex bison \
185185
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
186-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
186+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
187187
tar gzip && \
188188
apt-get install -y --reinstall lsb-base lsb-release && \
189189
mkdir -p "${CMAKE_HOME}" && \
@@ -209,7 +209,7 @@ RUN apt-get -qq update && \
209209
make bash sudo wget unzip dh-make \
210210
libsystemd-dev zlib1g-dev flex bison \
211211
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
212-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config \
212+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config \
213213
tar gzip && \
214214
apt-get install -y --reinstall lsb-base lsb-release && \
215215
mkdir -p "${CMAKE_HOME}" && \

packaging/distros/raspbian/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN apt-get update && \
1818
make bash sudo wget unzip dh-make \
1919
libsystemd-dev zlib1g-dev flex bison \
2020
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
21-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config && \
21+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config && \
2222
apt-get install -y --reinstall lsb-base lsb-release
2323

2424
# raspbian/bullseye base image
@@ -31,7 +31,7 @@ RUN apt-get update && \
3131
cmake make bash sudo wget unzip dh-make \
3232
libsystemd-dev zlib1g-dev flex bison \
3333
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
34-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config && \
34+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config && \
3535
apt-get install -y --reinstall lsb-base lsb-release
3636

3737
# raspbian/bookworm base image
@@ -44,7 +44,7 @@ RUN apt-get update && \
4444
cmake make bash sudo wget unzip dh-make \
4545
libsystemd-dev zlib1g-dev flex bison \
4646
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
47-
libsasl2-2 libsasl2-dev libyaml-dev libcurl4-openssl-dev pkg-config && \
47+
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev libcurl4-openssl-dev pkg-config && \
4848
apt-get install -y --reinstall lsb-base lsb-release
4949

5050
# Common build for all distributions now

0 commit comments

Comments
 (0)