Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_snmp: an input plugin for collect metrics by SNMP request #7671

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ include(GNUInstallDirs)
include(ExternalProject)
include(cmake/FindJournald.cmake)
include(cmake/FindMonkey.cmake)
include(cmake/FindNetsnmp.cmake)
include(cmake/macros.cmake)
include(cmake/platform_feature_checks.cmake)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
Expand Down
73 changes: 73 additions & 0 deletions cmake/FindNetsnmp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# - Find Net-SNMP
#
# -*- cmake -*-
#
# Find the Net-SNMP module
#
# NETSNMP_INCLUDE_DIR - where to find Net-SNMP.h, etc.
# NETSNMP_LIBRARIES - List of libraries when using Net-SNMP.
# NETSNMP_FOUND - True if Net-SNMP found.

IF (NETSNMP_INCLUDE_DIR)
# Already in cache, be silent
SET(NETSNMP_FIND_QUIETLY TRUE)
ENDIF (NETSNMP_INCLUDE_DIR)

FIND_PATH(NETSNMP_INCLUDE_DIR snmp.h
/usr/include/net-snmp/library
)

SET(NETSNMP_NAMES netsnmp)
FIND_LIBRARY(NETSNMP_LIBRARY
NAMES ${NETSNMP_NAMES}
PATHS /usr/lib /usr/local/lib
)

SET(NETSNMPAGENT_NAMES netsnmpagent)
FIND_LIBRARY(NETSNMPAGENT_LIBRARY
NAMES ${NETSNMPAGENT_NAMES}
PATHS /usr/lib /usr/local/lib
)

SET(NETSNMPHELPERS_NAMES netsnmphelpers)
FIND_LIBRARY(NETSNMPHELPERS_LIBRARY
NAMES ${NETSNMPHELPERS_NAMES}
PATHS /usr/lib /usr/local/lib
)

SET(NETSNMPMIBS_NAMES netsnmpmibs)
FIND_LIBRARY(NETSNMPMIBS_LIBRARY
NAMES ${NETSNMPMIBS_NAMES}
PATHS /usr/lib /usr/local/lib
)

SET(NETSNMPTRAPD_NAMES netsnmptrapd)
FIND_LIBRARY(NETSNMPTRAPD_LIBRARY
NAMES ${NETSNMPTRAPD_NAMES}
PATHS /usr/lib /usr/local/lib
)

SET(NETSNMP_LIBRARIES
${NETSNMP_LIBRARY}
${NETSNMPAGENT_LIBRARY}
${NETSNMPHELPERS_LIBRARY}
${NETSNMPMIBS_LIBRARY}
# ${NETSNMPTRAPD_LIBRARY}
)


INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NETSNMP
DEFAULT_MSG
NETSNMP_INCLUDE_DIR
NETSNMP_LIBRARIES
)

MARK_AS_ADVANCED(
NETSNMP_LIBRARY
NETSNMPAGENT_LIBRARY
NETSNMPHELPERS_LIBRARY
NETSNMPMIBS_LIBRARY
NETSNMPTRAPD_LIBRARY
NETSNMP_INCLUDE_DIR
)
1 change: 1 addition & 0 deletions cmake/windows-setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ if(FLB_WINDOWS_DEFAULTS)
set(FLB_IN_ELASTICSEARCH Yes)
set(FLB_IN_SPLUNK Yes)
set(FLB_IN_PROMETHEUS_REMOTE_WRITE Yes)
set(FLB_IN_SNMP No)

# OUTPUT plugins
# ==============
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
flex \
bison \
libyaml-dev \
libsnmp-dev \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We presumably will also need this in the various package builds under packaging/distros too.

&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
yum install -y rpm-build curl ca-certificates gcc gcc-c++ cmake make bash \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openss-libs openssl-devel \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel && \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel && \
yum install -y epel-release && \
yum install -y cmake3

Expand Down
8 changes: 4 additions & 4 deletions packaging/distros/amazonlinux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openss-libs openssl-devel \
postgresql-devel postgresql-libs \
cmake3 libyaml-devel zlib-devel && \
cmake3 libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

# amazonlinux/2.arm64v8 base image
Expand All @@ -32,7 +32,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openss-libs openssl-devel \
postgresql-devel postgresql-libs \
cmake3 libyaml-devel zlib-devel && \
cmake3 libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

FROM amazonlinux:2023 as amazonlinux-2023-base
Expand All @@ -43,7 +43,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
postgresql-devel postgresql-libs \
cmake3 libyaml-devel zlib-devel && \
cmake3 libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

# hadolint ignore=DL3029
Expand All @@ -57,7 +57,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
postgresql-devel postgresql-libs \
cmake3 libyaml-devel zlib-devel && \
cmake3 libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

# Common build for all distributions now
Expand Down
15 changes: 8 additions & 7 deletions packaging/distros/centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
yum install -y rpm-build curl ca-certificates gcc gcc-c++ cmake make bash \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openss-libs openssl-devel \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel && \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel && \
yum install -y epel-release && \
yum install -y cmake3 && \
yum clean all
Expand All @@ -39,8 +39,9 @@ RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\
yum install -y rpm-build curl ca-certificates gcc gcc-c++ cmake make bash \
wget unzip systemd-devel wget flex bison \
cyrus-sasl-lib cyrus-sasl-devel openssl openss-libs openssl-devel \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel && \
yum install -y epel-release && \
postgresql-libs postgresql-devel postgresql-server postgresql libyaml-devel libsnmp-devel && \
wget -q http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
rpm -ivh epel-release-latest-7.noarch.rpm && \
yum install -y cmake3 && \
yum clean all

Expand Down Expand Up @@ -68,7 +69,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
postgresql-libs postgresql-devel postgresql-server postgresql \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
libyaml-devel zlib-devel && \
libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

ARG FLB_OUT_PGSQL=On
Expand All @@ -92,7 +93,7 @@ RUN yum -y update && \
wget unzip systemd-devel wget flex bison \
postgresql-libs postgresql-devel postgresql-server postgresql \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
libyaml-devel zlib-devel && \
libyaml-devel libsnmp-devel zlib-devel && \
yum clean all

ARG FLB_OUT_PGSQL=On
Expand All @@ -111,7 +112,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
wget unzip systemd-devel wget flex bison \
postgresql-libs postgresql-devel postgresql-server postgresql \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
libyaml-devel zlib-devel && \
libyaml-devel libsnmp-devel zlib-devel && \
dnf clean all

ARG FLB_OUT_PGSQL=On
Expand All @@ -129,7 +130,7 @@ RUN dnf -y install 'dnf-command(config-manager)' && dnf -y config-manager --set-
wget unzip systemd-devel wget flex bison \
postgresql-libs postgresql-devel postgresql-server postgresql \
cyrus-sasl-lib cyrus-sasl-devel openssl openssl-libs openssl-devel \
libyaml-devel zlib-devel && \
libyaml-devel libsnmp-devel zlib-devel && \
dnf clean all

ARG FLB_OUT_PGSQL=On
Expand Down
12 changes: 6 additions & 6 deletions packaging/distros/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# debian/buster.arm64v8 base image
Expand All @@ -34,7 +34,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# debian/bullseye base image
Expand All @@ -47,7 +47,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# debian/bullseye.arm64v8 base image
Expand All @@ -62,7 +62,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# debian/bookworm base image
Expand All @@ -75,7 +75,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# debian/bookworm.arm64v8 base image
Expand All @@ -90,7 +90,7 @@ RUN apt-get -qq update && \
cmake make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl3 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

# Common build for all distributions now
Expand Down
4 changes: 2 additions & 2 deletions packaging/distros/raspbian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update && \
make bash sudo wget unzip dh-make \
libsystemd-dev zlib1g-dev flex bison \
libssl1.1 libssl-dev libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev libyaml-dev pkg-config && \
libsasl2-2 libsasl2-dev libyaml-dev libsnmp-dev pkg-config && \
apt-get install -y --reinstall lsb-base lsb-release

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

# Common build for all distributions now
Expand Down
14 changes: 7 additions & 7 deletions packaging/distros/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN apt-get update && \
apt-get install -y curl ca-certificates build-essential libsystemd-dev cmake \
make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all software-properties-common \
software-properties-common libyaml-dev apt-transport-https \
software-properties-common libyaml-dev libsnmp-dev apt-transport-https \
pkg-config libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.0 zlib1g-dev && \
wget -q -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
Expand All @@ -39,7 +39,7 @@ RUN apt-get update && \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 \
software-properties-common libyaml-dev apt-transport-https pkg-config zlib1g-dev && \
software-properties-common libyaml-dev libsnmp-dev apt-transport-https pkg-config zlib1g-dev && \
wget -q -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
Expand All @@ -61,7 +61,7 @@ RUN apt-get update && \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 \
software-properties-common libyaml-dev apt-transport-https pkg-config zlib1g-dev && \
software-properties-common libyaml-dev libsnmp-dev apt-transport-https pkg-config zlib1g-dev && \
wget -q -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
Expand All @@ -79,7 +79,7 @@ RUN apt-get update && \
apt-get install -y curl ca-certificates build-essential libsystemd-dev \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 libyaml-dev pkg-config zlib1g-dev && \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 libyaml-dev libsnmp-dev pkg-config zlib1g-dev && \
apt-get install -y --reinstall lsb-base lsb-release

# ubuntu/20.04.arm64v8 base image
Expand All @@ -93,7 +93,7 @@ RUN apt-get update && \
apt-get install -y curl ca-certificates build-essential libsystemd-dev \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 libyaml-dev pkg-config zlib1g-dev && \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl1.1 libyaml-dev libsnmp-dev pkg-config zlib1g-dev && \
apt-get install -y --reinstall lsb-base lsb-release

# ubuntu/22.04 base image
Expand All @@ -105,7 +105,7 @@ RUN apt-get update && \
apt-get install -y curl ca-certificates build-essential libsystemd-dev \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all libpq5 \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev pkg-config zlib1g-dev && \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev libsnmp-dev pkg-config zlib1g-dev && \
apt-get install -y --reinstall lsb-base lsb-release

# ubuntu/22.04.arm64v8 base image
Expand All @@ -119,7 +119,7 @@ RUN apt-get update && \
apt-get install -y curl ca-certificates build-essential libsystemd-dev \
cmake make bash wget unzip nano vim valgrind dh-make flex bison \
libpq-dev postgresql-server-dev-all libpq5 \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev pkg-config zlib1g-dev && \
libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev libsnmp-dev pkg-config zlib1g-dev && \
apt-get install -y --reinstall lsb-base lsb-release

# ubuntu/24.04 base image
Expand Down
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ REGISTER_IN_PLUGIN("in_prometheus_scrape")
REGISTER_IN_PLUGIN("in_emitter")
REGISTER_IN_PLUGIN("in_tail")
REGISTER_IN_PLUGIN("in_dummy")
REGISTER_IN_PLUGIN("in_snmp")
REGISTER_IN_PLUGIN("in_head")
REGISTER_IN_PLUGIN("in_health")
REGISTER_IN_PLUGIN("in_http")
Expand Down
8 changes: 8 additions & 0 deletions plugins/in_snmp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(NETSNMP_LIBRARIES ${NETSNMP_LIBRARY})
set(NETSNMP_INCLUDE_DIRS ${NETSNMP_INCLUDE_DIR})

set(src
in_snmp.c)

FLB_PLUGIN(in_snmp "${src}" "")
target_link_libraries(flb-plugin-in_snmp ${NETSNMP_LIBRARIES})
Loading