-
-
Notifications
You must be signed in to change notification settings - Fork 349
Add snmp and net-snmp support for macOS and Linux #946
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e549715
Add snmp support
crazywhalecc 43615db
Merge branch 'main' into ext/snmp
crazywhalecc 587ac3d
Remove nl
crazywhalecc 81bcff9
Fix dir
crazywhalecc 12c8f64
Fix old php version
crazywhalecc 6416c9e
Add full version test
crazywhalecc 4de8069
Try install file?
crazywhalecc 0d71d8b
Remove unused mib modules
crazywhalecc bf07207
Fix copy path
crazywhalecc 2258ebf
Use tmate
crazywhalecc b8854f1
Add file
crazywhalecc d5e7f00
Fix missing linking libs for gnu docker
crazywhalecc 6677df2
Add docs
crazywhalecc 578dab2
Merge branch 'main' into ext/snmp
crazywhalecc 2d1307f
Update .github/workflows/tests.yml
crazywhalecc 1285f50
Update LinuxToolCheckList.php
crazywhalecc b22e732
Merge branch 'main' into ext/snmp
crazywhalecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace SPC\builder\extension; | ||
|
|
||
| use SPC\builder\Extension; | ||
| use SPC\store\FileSystem; | ||
| use SPC\util\CustomExt; | ||
| use SPC\util\PkgConfigUtil; | ||
|
|
||
| #[CustomExt('snmp')] | ||
| class snmp extends Extension | ||
| { | ||
| public function patchBeforeBuildconf(): bool | ||
| { | ||
| // Overwrite m4 config using newer PHP version | ||
| if ($this->builder->getPHPVersionID() < 80400) { | ||
| FileSystem::copy(ROOT_DIR . '/src/globals/extra/snmp-ext-config-old.m4', "{$this->source_dir}/config.m4"); | ||
| } | ||
| $libs = implode(' ', PkgConfigUtil::getLibsArray('netsnmp')); | ||
| FileSystem::replaceFileStr( | ||
| "{$this->source_dir}/config.m4", | ||
| 'PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD])', | ||
| "SNMP_LIBS=\"{$libs}\"\nPHP_EVAL_LIBLINE([\$SNMP_LIBS], [SNMP_SHARED_LIBADD])" | ||
| ); | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace SPC\builder\linux\library; | ||
|
|
||
| class net_snmp extends LinuxLibraryBase | ||
| { | ||
| use \SPC\builder\unix\library\net_snmp; | ||
|
|
||
| public const NAME = 'net-snmp'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace SPC\builder\macos\library; | ||
|
|
||
| class net_snmp extends MacOSLibraryBase | ||
| { | ||
| use \SPC\builder\unix\library\net_snmp; | ||
|
|
||
| public const NAME = 'net-snmp'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace SPC\builder\unix\library; | ||
|
|
||
| use SPC\store\FileSystem; | ||
| use SPC\util\executor\UnixAutoconfExecutor; | ||
|
|
||
| trait net_snmp | ||
| { | ||
| public function patchBeforeBuild(): bool | ||
| { | ||
| if (PHP_OS_FAMILY === 'Linux') { | ||
| FileSystem::replaceFileStr("{$this->source_dir}/configure", 'LIBS="-lssl ${OPENSSL_LIBS}"', 'LIBS="-lssl ${OPENSSL_LIBS} -lpthread -ldl"'); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| protected function build(): void | ||
| { | ||
| // use --static for PKG_CONFIG | ||
| UnixAutoconfExecutor::create($this) | ||
| ->setEnv(['PKG_CONFIG' => getenv('PKG_CONFIG') . ' --static']) | ||
| ->configure( | ||
| '--disable-mibs', | ||
| '--without-nl', | ||
| '--disable-agent', | ||
| '--disable-applications', | ||
| '--disable-manuals', | ||
| '--disable-scripts', | ||
| '--disable-embedded-perl', | ||
| '--without-perl-modules', | ||
| '--with-out-mib-modules="if-mib host disman/event-mib ucd-snmp/diskio mibII"', | ||
| '--with-out-transports="Unix"', | ||
| '--with-mib-modules=""', | ||
| '--enable-mini-agent', | ||
| '--with-default-snmp-version="3"', | ||
| '--with-sys-contact="@@no.where"', | ||
| '--with-sys-location="Unknown"', | ||
| '--with-logfile="/var/log/snmpd.log"', | ||
| '--with-persistent-directory="/var/lib/net-snmp"', | ||
| '--with-openssl=' . BUILD_ROOT_PATH, | ||
| '--with-zlib=' . BUILD_ROOT_PATH, | ||
| )->make(with_install: 'installheaders installlibs install_pkgconfig'); | ||
| $this->patchPkgconfPrefix(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| PHP_ARG_WITH([snmp], | ||
| [for SNMP support], | ||
| [AS_HELP_STRING([[--with-snmp[=DIR]]], | ||
| [Include SNMP support. Use PKG_CONFIG_PATH (or SNMP_CFLAGS and SNMP_LIBS) | ||
| environment variables, or alternatively the optional DIR argument to | ||
| customize where to look for the net-snmp-config utility of the NET-SNMP | ||
| library.])]) | ||
|
|
||
| if test "$PHP_SNMP" != "no"; then | ||
| snmp_found=no | ||
| AS_VAR_IF([PHP_SNMP], [yes], | ||
| [PKG_CHECK_MODULES([SNMP], [netsnmp >= 5.3], [snmp_found=yes], [:])]) | ||
|
|
||
| AS_VAR_IF([snmp_found], [no], [ | ||
| AS_VAR_IF([PHP_SNMP], [yes], | ||
| [AC_PATH_PROG([SNMP_CONFIG], [net-snmp-config],, [/usr/local/bin:$PATH])], | ||
| [SNMP_CONFIG="$PHP_SNMP/bin/net-snmp-config"]) | ||
|
|
||
| AS_IF([test ! -x "$SNMP_CONFIG"], | ||
| [AC_MSG_ERROR(m4_text_wrap([ | ||
| Could not find net-snmp-config binary. Please check your net-snmp | ||
| installation. | ||
| ]))]) | ||
|
|
||
| snmp_version=$($SNMP_CONFIG --version) | ||
| AS_VERSION_COMPARE([$snmp_version], [5.3], | ||
| [AC_MSG_ERROR(m4_text_wrap([ | ||
| Net-SNMP version 5.3 or greater required (detected $snmp_version). | ||
| ]))]) | ||
|
|
||
| SNMP_PREFIX=$($SNMP_CONFIG --prefix) | ||
| SNMP_CFLAGS="-I${SNMP_PREFIX}/include" | ||
| SNMP_LIBS=$($SNMP_CONFIG --netsnmp-libs) | ||
| SNMP_LIBS="$SNMP_LIBS $($SNMP_CONFIG --external-libs)" | ||
|
|
||
| AS_IF([test -z "$SNMP_LIBS" || test -z "$SNMP_PREFIX"], | ||
| [AC_MSG_ERROR(m4_text_wrap([ | ||
| Could not find the required paths. Please check your net-snmp | ||
| installation. | ||
| ]))]) | ||
| ]) | ||
|
|
||
| PHP_EVAL_INCLINE([$SNMP_CFLAGS]) | ||
| PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD]) | ||
| SNMP_LIBNAME=netsnmp | ||
|
|
||
| dnl Test build. | ||
| PHP_CHECK_LIBRARY([$SNMP_LIBNAME], [init_snmp], | ||
| [AC_DEFINE([HAVE_SNMP], [1], | ||
| [Define to 1 if the PHP extension 'snmp' is available.])], | ||
| [AC_MSG_FAILURE([SNMP sanity check failed.])], | ||
| [$SNMP_SHARED_LIBADD]) | ||
|
|
||
| dnl Check whether shutdown_snmp_logging() exists. | ||
| PHP_CHECK_LIBRARY([$SNMP_LIBNAME], [shutdown_snmp_logging], | ||
| [AC_DEFINE([HAVE_SHUTDOWN_SNMP_LOGGING], [1], | ||
| [Define to 1 if SNMP library has the 'shutdown_snmp_logging' function.])], | ||
| [], | ||
| [$SNMP_SHARED_LIBADD]) | ||
|
|
||
| CFLAGS_SAVE=$CFLAGS | ||
| LIBS_SAVE=$LIBS | ||
| CFLAGS="$CFLAGS $SNMP_CFLAGS" | ||
| LIBS="$LIBS $SNMP_LIBS" | ||
|
|
||
| AC_CHECK_DECL([usmHMAC192SHA256AuthProtocol], | ||
| [AC_DEFINE([HAVE_SNMP_SHA256], [1], | ||
| [Define to 1 if SNMP library has the 'usmHMAC192SHA256AuthProtocol' | ||
| array.])], | ||
| [], | ||
| [ | ||
| #include <net-snmp/net-snmp-config.h> | ||
| #include <net-snmp/net-snmp-includes.h> | ||
| ]) | ||
|
|
||
| AC_CHECK_DECL([usmHMAC384SHA512AuthProtocol], | ||
| [AC_DEFINE([HAVE_SNMP_SHA512], [1], | ||
| [Define to 1 if SNMP library has the 'usmHMAC384SHA512AuthProtocol' | ||
| array.])], | ||
| [], | ||
| [ | ||
| #include <net-snmp/net-snmp-config.h> | ||
| #include <net-snmp/net-snmp-includes.h> | ||
| ]) | ||
|
|
||
| CFLAGS=$CFLAGS_SAVE | ||
| LIBS=$LIBS_SAVE | ||
|
|
||
| PHP_NEW_EXTENSION([snmp], [snmp.c], [$ext_shared]) | ||
| PHP_ADD_EXTENSION_DEP(snmp, spl) | ||
| PHP_SUBST([SNMP_SHARED_LIBADD]) | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.