Skip to content

Conversation

@k402xxxcenxxx
Copy link

@k402xxxcenxxx k402xxxcenxxx commented Jul 9, 2023


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
[INPUT]
    Name snmp
    Tag snmp.test
    Target_Host 127.0.0.1
    Target_Port 161
    Community public
    Oid_Type get
    Oid 1.3.6.1.2.1.1.3.0
    Timeout 1
    Retries 20
[OUTPUT]
    Name stdout
    Match *
  • Debug log output from testing the change
$ valgrind --leak-check=full --show-leak-kinds=all ./bin/fluent-bit -c in_snmp.conf  -v
==12727== Memcheck, a memory error detector
==12727== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==12727== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==12727== Command: ./bin/fluent-bit -c in_snmp.conf -v
==12727== 
Fluent Bit v4.2.0
* Copyright (C) 2015-2025 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

______ _                  _    ______ _ _             ___   __  
|  ___| |                | |   | ___ (_) |           /   | /  | 
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   __/ /| | `| | 
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / / /_| |  | | 
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V /\___  |__| |_
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/     |_(_)___/


[2025/11/04 14:00:18.123914634] [ info] Configuration:
[2025/11/04 14:00:18.145201189] [ info]  flush time     | 1.000000 seconds
[2025/11/04 14:00:18.153048576] [ info]  grace          | 5 seconds
[2025/11/04 14:00:18.153555682] [ info]  daemon         | 0
[2025/11/04 14:00:18.153981856] [ info] ___________
[2025/11/04 14:00:18.154357958] [ info]  inputs:
[2025/11/04 14:00:18.154811534] [ info]      snmp
[2025/11/04 14:00:18.155200119] [ info] ___________
[2025/11/04 14:00:18.155542758] [ info]  filters:
[2025/11/04 14:00:18.155919861] [ info] ___________
[2025/11/04 14:00:18.156231483] [ info]  outputs:
[2025/11/04 14:00:18.156697732] [ info]      stdout.0
[2025/11/04 14:00:18.157081548] [ info] ___________
[2025/11/04 14:00:18.157409700] [ info]  collectors:
[2025/11/04 14:00:18.246862534] [ info] [fluent bit] version=4.2.0, commit=5c61d0107f, pid=12727
[2025/11/04 14:00:18.255112052] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2025/11/04 14:00:18.265037281] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/11/04 14:00:18.265663399] [ info] [simd    ] disabled
[2025/11/04 14:00:18.266095606] [ info] [cmetrics] version=1.0.5
[2025/11/04 14:00:18.266500230] [ info] [ctraces ] version=0.6.6
[2025/11/04 14:00:18.286963840] [ info] [input:snmp:snmp.0] initializing
[2025/11/04 14:00:18.287908121] [ info] [input:snmp:snmp.0] storage_strategy='memory' (memory only)
[2025/11/04 14:00:18.289451390] [debug] [snmp:snmp.0] created event channels: read=28 write=29
[2025/11/04 14:00:18.681993765] [debug] [stdout:stdout.0] created event channels: read=30 write=31
[2025/11/04 14:00:18.730822532] [ info] [output:stdout:stdout.0] worker #0 started
[2025/11/04 14:00:18.739834732] [ info] [sp] stream processor started
[2025/11/04 14:00:18.743073924] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2025/11/04 14:00:19.947547789] [debug] [task] created task=0x5967ff0 id=0 OK
[0] snmp.test: [[1762264818.984882568, {}], {"iso.3.6.1.2.1.1.3.0"=>"147020"}]
[2025/11/04 14:00:19.950569315] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[2025/11/04 14:00:19.984422720] [debug] [out flush] cb_destroy coro_id=0
[2025/11/04 14:00:19.996176804] [debug] [task] destroy task=0x5967ff0 (task_id=0)
[2025/11/04 14:00:20.939432702] [debug] [task] created task=0x59cda20 id=0 OK
[2025/11/04 14:00:20.939860419] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[0] snmp.test: [[1762264819.984281957, {}], {"iso.3.6.1.2.1.1.3.0"=>"147118"}]
[2025/11/04 14:00:20.940541246] [debug] [out flush] cb_destroy coro_id=1
[2025/11/04 14:00:20.942022870] [debug] [task] destroy task=0x59cda20 (task_id=0)
[0] snmp.test: [[1762264820.941044768, {}], {"iso.3.6.1.2.1.1.3.0"=>"147214"}]
[2025/11/04 14:00:21.939534257] [debug] [task] created task=0x5a32cc0 id=0 OK
[2025/11/04 14:00:21.939689657] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[2025/11/04 14:00:21.941773938] [debug] [out flush] cb_destroy coro_id=2
[2025/11/04 14:00:21.942093544] [debug] [task] destroy task=0x5a32cc0 (task_id=0)
[2025/11/04 14:00:22.952971410] [debug] [task] created task=0x5a99fa0 id=0 OK
[2025/11/04 14:00:22.953107304] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[0] snmp.test: [[1762264821.940466526, {}], {"iso.3.6.1.2.1.1.3.0"=>"147314"}]
[2025/11/04 14:00:22.954690236] [debug] [out flush] cb_destroy coro_id=3
[2025/11/04 14:00:22.955959293] [debug] [task] destroy task=0x5a99fa0 (task_id=0)
^C[2025/11/04 14:00:23] [engine] caught signal (SIGINT)
[2025/11/04 14:00:23.458902506] [debug] [task] created task=0x5aff290 id=0 OK
[2025/11/04 14:00:23.459098371] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[0] snmp.test: [[1762264822.953699989, {}], {"iso.3.6.1.2.1.1.3.0"=>"147415"}]
[2025/11/04 14:00:23.459611939] [debug] [out flush] cb_destroy coro_id=4
[2025/11/04 14:00:23.460411737] [ warn] [engine] service will shutdown in max 5 seconds
[2025/11/04 14:00:23.461051862] [debug] [engine] task 0 already scheduled to run, not re-scheduling it.
[2025/11/04 14:00:23.461580598] [ info] [engine] pausing all inputs..
[2025/11/04 14:00:23.462575714] [ info] [input] pausing snmp.0
[2025/11/04 14:00:23.465890189] [debug] [task] destroy task=0x5aff290 (task_id=0)
[2025/11/04 14:00:23.941356418] [ info] [engine] service has stopped (0 pending tasks)
[2025/11/04 14:00:23.941703835] [ info] [input] pausing snmp.0
[2025/11/04 14:00:23.944567437] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2025/11/04 14:00:23.950232023] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==12727== 
==12727== HEAP SUMMARY:
==12727==     in use at exit: 4,800 bytes in 1 blocks
==12727==   total heap usage: 10,305 allocs, 10,304 frees, 3,280,692 bytes allocated
==12727== 
==12727== 4,800 bytes in 1 blocks are still reachable in loss record 1 of 1
==12727==    at 0x48465EF: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==12727==    by 0x498CDF7: netsnmp_init_mib_internals (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x4991767: ??? (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x49A2D4C: init_snmp (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x5FC78F: in_snmp_init (in_snmp.c:376)
==12727==    by 0x26E699: flb_input_instance_init (flb_input.c:1412)
==12727==    by 0x26E87C: flb_input_init_all (flb_input.c:1472)
==12727==    by 0x2C49C0: flb_engine_start (flb_engine.c:862)
==12727==    by 0x244344: flb_lib_worker (flb_lib.c:904)
==12727==    by 0x534C1F4: start_thread (pthread_create.c:442)
==12727==    by 0x53CBB3F: clone (clone.S:100)
==12727== 
==12727== LEAK SUMMARY:
==12727==    definitely lost: 0 bytes in 0 blocks
==12727==    indirectly lost: 0 bytes in 0 blocks
==12727==      possibly lost: 0 bytes in 0 blocks
==12727==    still reachable: 4,800 bytes in 1 blocks
==12727==         suppressed: 0 bytes in 0 blocks
==12727== 
==12727== For lists of detected and suppressed errors, rerun with: -s
==12727== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
  • Attached Valgrind output that shows no leaks or memory corruption was found
==12727== 
==12727== HEAP SUMMARY:
==12727==     in use at exit: 4,800 bytes in 1 blocks
==12727==   total heap usage: 10,305 allocs, 10,304 frees, 3,280,692 bytes allocated
==12727== 
==12727== 4,800 bytes in 1 blocks are still reachable in loss record 1 of 1
==12727==    at 0x48465EF: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==12727==    by 0x498CDF7: netsnmp_init_mib_internals (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x4991767: ??? (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x49A2D4C: init_snmp (in /usr/lib/x86_64-linux-gnu/libnetsnmp.so.40.2.0)
==12727==    by 0x5FC78F: in_snmp_init (in_snmp.c:376)
==12727==    by 0x26E699: flb_input_instance_init (flb_input.c:1412)
==12727==    by 0x26E87C: flb_input_init_all (flb_input.c:1472)
==12727==    by 0x2C49C0: flb_engine_start (flb_engine.c:862)
==12727==    by 0x244344: flb_lib_worker (flb_lib.c:904)
==12727==    by 0x534C1F4: start_thread (pthread_create.c:442)
==12727==    by 0x53CBB3F: clone (clone.S:100)
==12727== 
==12727== LEAK SUMMARY:
==12727==    definitely lost: 0 bytes in 0 blocks
==12727==    indirectly lost: 0 bytes in 0 blocks
==12727==      possibly lost: 0 bytes in 0 blocks
==12727==    still reachable: 4,800 bytes in 1 blocks
==12727==         suppressed: 0 bytes in 0 blocks
==12727== 
==12727== For lists of detected and suppressed errors, rerun with: -s
==12727== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

There is one leak and can be fixed after this patch is release: net-snmp/net-snmp@4bd0d9a
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

fluent/fluent-bit-docs#1162
Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • SNMP input plugin added — supports GET and WALK, configurable session options, test-mode, and structured log encoding.
  • Build / Packaging

    • Build now detects Net‑SNMP via CMake and exposes include/library info; new build option for macOS defaults added.
    • SNMP development packages added across container images and distro builds; Windows/macOS defaults disable SNMP input by default.
  • Tests

    • End-to-end runtime tests added for SNMP GET and WALK.

@k402xxxcenxxx k402xxxcenxxx changed the title Feature/in snmp in_snmp: an input plugin for collect metrics by SNMP request Jul 15, 2023
@k402xxxcenxxx k402xxxcenxxx marked this pull request as ready for review July 15, 2023 07:17
@k402xxxcenxxx
Copy link
Author

k402xxxcenxxx commented Jul 15, 2023

I have found a leak in the code, and it can be resolved by applying this patch: net-snmp/net-snmp@4bd0d9a.

However, I am unsure about the process of incorporating this fix into the fluent-bit project. Any suggestions or guidance on this matter would be greatly appreciated!

@patrick-stephens patrick-stephens added the ok-package-test Run PR packaging tests label Jul 17, 2023
Copy link
Collaborator

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

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

I've triggered a full build of all targets to confirm it builds for them, we probably need to modify dependencies to build.

Can you confirm it works for non-Linux targets as well? It may build but that doesn't mean it works...

CMakeLists.txt Outdated
option(FLB_IN_PROC "Enable Process input plugin" Yes)
option(FLB_IN_SYSTEMD "Enable Systemd input plugin" Yes)
option(FLB_IN_DUMMY "Enable Dummy input plugin" Yes)
option(FLB_IN_SNMP "Enable SNMP input plugin" Yes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To confirm - does this work on Windows and macOS as well? It will need disabling if not in their specific override cmake/ files.

flex \
bison \
libyaml-dev \
libsnmp-dev \
Copy link
Collaborator

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.

@k402xxxcenxxx
Copy link
Author

@patrick-stephens thanks, I will try to build and run on Windows device

@k402xxxcenxxx
Copy link
Author

I still fail to build it on Windows, so I choose to disable it in https://github.com/fluent/fluent-bit/blob/master/cmake/windows-setup.cmake.
And I'm trying to build to various distribution

@k402xxxcenxxx k402xxxcenxxx temporarily deployed to pr August 21, 2023 10:22 — with GitHub Actions Inactive
@k402xxxcenxxx k402xxxcenxxx temporarily deployed to pr August 21, 2023 10:22 — with GitHub Actions Inactive
@k402xxxcenxxx k402xxxcenxxx temporarily deployed to pr August 21, 2023 10:22 — with GitHub Actions Inactive
Copy link
Collaborator

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

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

Please resolve the build failures and comments raised by Coderabbit

@leonardo-albertovich
Copy link
Contributor

Hey @k402xxxcenxxx, I'll review this PR but on a first glance I noticed that it seems that you're not aware of the fluen-bit coding style which you can check here.

Could you please make the required changes before to ensure that the review focuses on the code as much as possible?

Thank you.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c61d01 and 812befc.

📒 Files selected for processing (2)
  • CMakeLists.txt (2 hunks)
  • cmake/macos-setup.cmake (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CMakeLists.txt
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • cmake/macos-setup.cmake
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit, the correct CMake flag for using system librdkafka is `FLB_PREFER_SYSTEM_LIB_KAFKA=ON`.

Applied to files:

  • cmake/macos-setup.cmake
🔇 Additional comments (1)
cmake/macos-setup.cmake (1)

15-21: LGTM: macOS-specific SNMP plugin override.

The conditional block correctly disables the SNMP input plugin when FLB_MACOS_DEFAULTS is enabled, consistent with the OS-specific defaulting pattern used for Windows.

Copy link
Contributor

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

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

@k402xxxcenxxx it seems that you've missed my request.
Please address the coding style violations before this code can be reviewed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
plugins/in_snmp/in_snmp.c (1)

306-311: Free response PDU in cleanup block.

Line 307 sets response = NULL without freeing the PDU. While normal and error paths free response (lines 212, 221, 229, 245, 284-286), defensive cleanup should call snmp_free_pdu(response) to handle any edge case where execution reaches cleanup with an unfree'd PDU.

Apply this fix:

 collect_cleanup:
-    if (response) { response = NULL; }
+    if (response) { snmp_free_pdu(response); response = NULL; }
     if (ss) { snmp_close(ss); ss = NULL; }
tests/runtime/in_snmp.c (1)

41-67: Add map size validation before accessing map elements.

Lines 58-60 and 61-63 access obj->via.map.ptr[0] without verifying that obj->via.map.size >= 1. If the map is empty, this causes undefined behavior.

Apply this diff:

         while (msgpack_unpack_next(&result, records->records[i].data,
                                    records->records[i].size, &off) == MSGPACK_UNPACK_SUCCESS) {
             flb_time_pop_from_msgpack(&ftm, &result, &obj);
             TEST_CHECK(obj->type == MSGPACK_OBJECT_MAP);
+            TEST_CHECK(obj->via.map.size >= 1);
             TEST_CHECK(strncmp("iso.3.6.1.2.1.1.3.0",
                                obj->via.map.ptr[0].key.via.str.ptr,
                                obj->via.map.ptr[0].key.via.str.size) == 0);
🧹 Nitpick comments (1)
tests/runtime/in_snmp.c (1)

17-39: Consider safer realloc pattern to prevent potential memory leak.

At lines 27-29, if flb_realloc fails, the old ctx->records pointer is lost, causing a memory leak. While the test cleanup (lines 171-175) eventually frees records, a realloc failure would leave the old allocation unreachable.

Apply this defensive pattern:

         } else {
-            ctx->records = (struct callback_record *)
-                           flb_realloc(ctx->records,
-                                       (ctx->num_records+1)*sizeof(struct callback_record));
+            struct callback_record *tmp = (struct callback_record *)
+                           flb_realloc(ctx->records,
+                                       (ctx->num_records+1)*sizeof(struct callback_record));
+            if (tmp == NULL) {
+                return -1;
+            }
+            ctx->records = tmp;
         }
-        if (ctx->records ==  NULL) {
-            return -1;
-        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 812befc and 6a418d2.

📒 Files selected for processing (19)
  • CMakeLists.txt (2 hunks)
  • cmake/FindNetsnmp.cmake (1 hunks)
  • cmake/macos-setup.cmake (1 hunks)
  • cmake/plugins_options.cmake (1 hunks)
  • cmake/windows-setup.cmake (1 hunks)
  • dockerfiles/Dockerfile (1 hunks)
  • dockerfiles/Dockerfile.centos7 (1 hunks)
  • packaging/distros/amazonlinux/Dockerfile (4 hunks)
  • packaging/distros/centos/Dockerfile (8 hunks)
  • packaging/distros/debian/Dockerfile (8 hunks)
  • packaging/distros/raspbian/Dockerfile (3 hunks)
  • packaging/distros/ubuntu/Dockerfile (9 hunks)
  • plugins/CMakeLists.txt (1 hunks)
  • plugins/in_snmp/CMakeLists.txt (1 hunks)
  • plugins/in_snmp/in_snmp.c (1 hunks)
  • plugins/in_snmp/in_snmp.h (1 hunks)
  • run_code_analysis.sh (1 hunks)
  • tests/runtime/CMakeLists.txt (1 hunks)
  • tests/runtime/in_snmp.c (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • plugins/in_snmp/CMakeLists.txt
  • plugins/CMakeLists.txt
  • packaging/distros/centos/Dockerfile
  • tests/runtime/CMakeLists.txt
  • CMakeLists.txt
  • packaging/distros/amazonlinux/Dockerfile
  • cmake/macos-setup.cmake
  • cmake/plugins_options.cmake
  • run_code_analysis.sh
  • packaging/distros/ubuntu/Dockerfile
  • dockerfiles/Dockerfile.centos7
  • dockerfiles/Dockerfile
  • packaging/distros/debian/Dockerfile
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • cmake/windows-setup.cmake
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit, the correct CMake flag for using system librdkafka is `FLB_PREFER_SYSTEM_LIB_KAFKA=ON`.

Applied to files:

  • cmake/windows-setup.cmake
🧬 Code graph analysis (2)
tests/runtime/in_snmp.c (2)
include/fluent-bit/flb_mem.h (2)
  • flb_calloc (84-96)
  • flb_free (126-128)
src/flb_lib.c (9)
  • flb_create (143-225)
  • flb_input (266-276)
  • flb_input_set (305-335)
  • flb_output (279-289)
  • flb_output_set (520-551)
  • flb_start (983-994)
  • flb_stop (1011-1055)
  • flb_lib_free (762-769)
  • flb_destroy (228-263)
plugins/in_snmp/in_snmp.c (5)
include/fluent-bit/flb_mem.h (2)
  • flb_calloc (84-96)
  • flb_free (126-128)
src/flb_log_event_encoder.c (6)
  • flb_log_event_encoder_begin_record (246-254)
  • flb_log_event_encoder_set_current_timestamp (289-292)
  • flb_log_event_encoder_commit_record (256-274)
  • flb_log_event_encoder_reset (31-40)
  • flb_log_event_encoder_init (42-74)
  • flb_log_event_encoder_destroy (99-116)
src/flb_input_log.c (1)
  • flb_input_log_append (1413-1423)
include/fluent-bit/flb_input.h (1)
  • flb_input_config_map_set (717-743)
src/flb_input.c (4)
  • flb_input_set_context (1610-1613)
  • flb_input_set_collector_time (1685-1704)
  • flb_input_collector_pause (2035-2072)
  • flb_input_collector_resume (2095-2151)
🔇 Additional comments (9)
packaging/distros/raspbian/Dockerfile (1)

21-21: LGTM!

The libsnmp-dev package additions are correctly placed and consistent across all three Raspbian base images (buster, bullseye, bookworm), enabling the build of the new SNMP input plugin.

Also applies to: 34-34, 47-47

tests/runtime/in_snmp.c (2)

69-117: LGTM!

The bounds checking at lines 98-102 correctly limits iteration to prevent out-of-bounds access to the expected_keys and expected_vals arrays.


180-184: LGTM!

The test entry point correctly exercises both snmp_get and snmp_walk scenarios with appropriate validators.

cmake/FindNetsnmp.cmake (1)

11-79: LGTM!

The module correctly discovers Net-SNMP components with proper include and library search paths for Linux, macOS Homebrew, and MacPorts. The plural NETSNMP_INCLUDE_DIRS convention is properly implemented, and all variables are marked as advanced.

Note: NETSNMPTRAPD_LIBRARY is intentionally excluded from NETSNMP_LIBRARIES (line 58), which is appropriate since trap daemon functionality is typically not needed by client applications.

cmake/windows-setup.cmake (1)

84-84: LGTM!

Disabling the SNMP plugin by default on Windows is appropriate given the build failures mentioned in the PR summary. The placement among other input plugin defaults is consistent with the file's structure.

plugins/in_snmp/in_snmp.c (3)

24-116: LGTM!

The mock function correctly mirrors snmp_synch_response semantics by freeing the request PDU and includes proper NULL checks for environment variables and allocations. Error cleanup is defensive with NULL guards.


433-450: LGTM!

The exit function properly cleans up all allocated resources:

  • Line 438: destroys the log encoder
  • Lines 440-442: frees the dynamically allocated peername
  • Line 443: frees the context structure
  • Lines 444-447: properly shuts down Net-SNMP and socket layers

453-495: LGTM!

Configuration map entries are well-documented with clear descriptions. The oid_type help text (line 487) correctly describes the accepted values ('get' and 'walk') and their meanings.

plugins/in_snmp/in_snmp.h (1)

1-26: LGTM!

The header properly defines the plugin context structure with all necessary fields. The target_port field (line 17) is correctly utilized in the init function to compose the peername, addressing previous concerns about unused configuration.

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]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
cmake/macos-setup.cmake (1)

16-16: Fix typo: "setttings" should be "settings".

The status message contains "setttings" with three t's instead of "settings" with two t's.

Apply this fix:

-  message(STATUS "Overriding setttings with macos-setup.cmake")
+  message(STATUS "Overriding settings with macos-setup.cmake")
tests/runtime/in_snmp.c (1)

136-140: Add NULL check after records allocation.

Line 136 allocates records but lines 137-138 immediately dereference it without checking if the allocation succeeded. If flb_calloc returns NULL (e.g., under memory pressure or during fuzzing), this causes undefined behavior.

Apply this fix:

 records = flb_calloc(1, sizeof(struct callback_records));
+if (!records) {
+    flb_error("[test] Failed to allocate callback_records");
+    return;
+}
 records->num_records = 0;
 records->records = NULL;
plugins/in_snmp/CMakeLists.txt (1)

1-8: Add target_include_directories() to configure Net-SNMP include paths for the plugin target.

The NETSNMP_INCLUDE_DIRS variable is set but never applied to the target. The FLB_PLUGIN macro only handles linking libraries, not include directories. Other plugins (e.g., out_pgsql, in_exec_wasi, filter_wasm) explicitly call target_include_directories() after FLB_PLUGIN() to configure includes.

Add after line 7:

target_include_directories(flb-plugin-in_snmp PRIVATE ${NETSNMP_INCLUDE_DIRS})
🧹 Nitpick comments (2)
cmake/FindNetsnmp.cmake (2)

72-79: *Consider marking the _NAMES variables as advanced.

The individual library path variables are correctly marked as advanced, but the intermediate *_NAMES variables (NETSNMP_NAMES, NETSNMPAGENT_NAMES, etc.) are implementation details that should also be marked to keep CMake GUIs clean.

Apply this diff to mark the NAMES variables as advanced:

 MARK_AS_ADVANCED(
   NETSNMP_LIBRARY
   NETSNMPAGENT_LIBRARY
   NETSNMPHELPERS_LIBRARY
   NETSNMPMIBS_LIBRARY
   NETSNMPTRAPD_LIBRARY
   NETSNMP_INCLUDE_DIR
+  NETSNMP_NAMES
+  NETSNMPAGENT_NAMES
+  NETSNMPHELPERS_NAMES
+  NETSNMPMIBS_NAMES
+  NETSNMPTRAPD_NAMES
   )

1-79: Consider adding pkg-config support for improved robustness.

Many modern CMake find modules use pkg-config as a fallback when explicit path searches fail. Net-SNMP provides netsnmp.pc files on most distributions, and leveraging pkg-config would help discover installations in non-standard prefixes and automatically handle transitive dependencies.

Example pattern to add before the FIND_PATH/FIND_LIBRARY calls:

# Try pkg-config first
FIND_PACKAGE(PkgConfig QUIET)
IF(PKG_CONFIG_FOUND)
  PKG_CHECK_MODULES(PC_NETSNMP QUIET netsnmp)
ENDIF()

# Use pkg-config hints in FIND_PATH and FIND_LIBRARY
FIND_PATH(NETSNMP_INCLUDE_DIR net-snmp/net-snmp-includes.h
  HINTS ${PC_NETSNMP_INCLUDE_DIRS}
  PATHS /usr/include /usr/local/include /opt/homebrew/include /opt/local/include
)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a418d2 and 9f62cc4.

📒 Files selected for processing (19)
  • CMakeLists.txt (2 hunks)
  • cmake/FindNetsnmp.cmake (1 hunks)
  • cmake/macos-setup.cmake (1 hunks)
  • cmake/plugins_options.cmake (1 hunks)
  • cmake/windows-setup.cmake (1 hunks)
  • dockerfiles/Dockerfile (1 hunks)
  • dockerfiles/Dockerfile.centos7 (1 hunks)
  • packaging/distros/amazonlinux/Dockerfile (4 hunks)
  • packaging/distros/centos/Dockerfile (8 hunks)
  • packaging/distros/debian/Dockerfile (8 hunks)
  • packaging/distros/raspbian/Dockerfile (3 hunks)
  • packaging/distros/ubuntu/Dockerfile (9 hunks)
  • plugins/CMakeLists.txt (1 hunks)
  • plugins/in_snmp/CMakeLists.txt (1 hunks)
  • plugins/in_snmp/in_snmp.c (1 hunks)
  • plugins/in_snmp/in_snmp.h (1 hunks)
  • run_code_analysis.sh (1 hunks)
  • tests/runtime/CMakeLists.txt (1 hunks)
  • tests/runtime/in_snmp.c (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
  • dockerfiles/Dockerfile
  • dockerfiles/Dockerfile.centos7
  • plugins/CMakeLists.txt
  • packaging/distros/debian/Dockerfile
  • CMakeLists.txt
  • run_code_analysis.sh
  • packaging/distros/centos/Dockerfile
  • cmake/plugins_options.cmake
  • packaging/distros/ubuntu/Dockerfile
  • plugins/in_snmp/in_snmp.c
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • cmake/windows-setup.cmake
  • cmake/macos-setup.cmake
  • plugins/in_snmp/CMakeLists.txt
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit, the correct CMake flag for using system librdkafka is `FLB_PREFER_SYSTEM_LIB_KAFKA=ON`.

Applied to files:

  • cmake/windows-setup.cmake
  • cmake/macos-setup.cmake
🧬 Code graph analysis (1)
tests/runtime/in_snmp.c (2)
include/fluent-bit/flb_mem.h (2)
  • flb_calloc (84-96)
  • flb_free (126-128)
src/flb_lib.c (9)
  • flb_create (143-225)
  • flb_input (266-276)
  • flb_input_set (305-335)
  • flb_output (279-289)
  • flb_output_set (520-551)
  • flb_start (983-994)
  • flb_stop (1011-1055)
  • flb_lib_free (762-769)
  • flb_destroy (228-263)
🔇 Additional comments (15)
packaging/distros/amazonlinux/Dockerfile (1)

26-26: LGTM — Net-SNMP package correctly added for Amazon Linux.

The net-snmp-devel package is the correct development headers package for Amazon Linux 2 and 2023. The addition is consistent across all four base image stages.

Also applies to: 51-51, 76-76, 103-103

packaging/distros/raspbian/Dockerfile (1)

21-21: LGTM — Net-SNMP package correctly added for Raspbian.

The libsnmp-dev package is the correct development headers package for Debian-based distributions like Raspbian. The addition is consistent across all three base image stages (buster, bullseye, bookworm).

Also applies to: 34-34, 47-47

tests/runtime/in_snmp.c (3)

17-39: LGTM — Proper allocation and NULL handling.

The callback correctly handles allocation failures and returns -1 when flb_calloc or flb_realloc fail.


94-113: LGTM — Proper bounds checking for map access.

The function correctly validates obj->via.map.size >= 2 and limits the loop to avoid out-of-bounds access to the expected_keys and expected_vals arrays.


180-190: LGTM — Test registration is correct.

The test wrapper and TEST_LIST registration follow the standard pattern for Fluent Bit runtime tests.

tests/runtime/CMakeLists.txt (1)

49-49: LGTM — Test registration follows standard pattern.

The SNMP runtime test is correctly registered using the FLB_RT_TEST macro within the appropriate conditional block, consistent with other input plugin tests.

cmake/windows-setup.cmake (1)

84-84: LGTM — Windows exclusion aligns with PR objectives.

Disabling the SNMP plugin on Windows by default is consistent with the PR author's decision not to support Windows due to build failures. The macOS setup file similarly disables SNMP, ensuring consistent cross-platform defaults.

cmake/macos-setup.cmake (1)

15-21: LGTM — macOS SNMP exclusion is consistent with Windows.

The FLB_MACOS_DEFAULTS block correctly disables the SNMP plugin on macOS, mirroring the Windows defaults and ensuring consistent cross-platform behavior for this optional plugin.

plugins/in_snmp/in_snmp.h (1)

1-26: LGTM — Header structure is well-defined.

The struct flb_snmp definition includes appropriate fields for SNMP session configuration and Fluent Bit integration. Include guards and headers are properly configured.

Note: A past review mentioned that ctx->port is not applied to the session, but that's an implementation issue in in_snmp.c, not a header definition issue.

cmake/FindNetsnmp.cmake (6)

11-14: LGTM!

Standard CMake cache optimization pattern is correctly implemented.


16-21: LGTM!

The include path search correctly targets the header used by the plugin and covers standard installation locations across Linux, BSD, Homebrew, and MacPorts.


23-51: LGTM!

Library search paths are consistent across all five libraries and correctly align with the include directory search paths.


61-62: LGTM!

Correctly provides the plural form per CMake convention.


65-70: LGTM!

Standard package handling is correctly configured with the plural include directory form.


53-59: No changes needed—exclusion is correct.

Verification confirms the SNMP input plugin performs GET and WALK queries, not trap reception. The netsnmptrapd library is correctly excluded since the plugin has no trap-related functionality. The code is in proper working order; adding a clarifying comment remains optional for future maintainability.

@k402xxxcenxxx
Copy link
Author

@k402xxxcenxxx it seems that you've missed my request. Please address the coding style violations before this code can be reviewed.

Hi @leonardo-albertovich ,
Thank you for the reminder! I've refined some of the code. Could you please review it when you have a moment?

…onfiguration

in_snmp: add null check for callback_records allocation in SNMP tests

Signed-off-by: k402xxxcenxxx <[email protected]>
@acrepina
Copy link

acrepina commented Dec 8, 2025

Hello,
This issue is cool. I tested it and got my data in my logs. I wanted to know if you plan to evolve your plugging to register the snmp as metrics instead of logs (like prometeus ) ?

And thanks for the work. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-required ok-package-test Run PR packaging tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants