手动安装 pyOpenSSL 和 boto3?由于缺少依赖项,拖放不起作用
Install pyOpenSSL and boto3 manually? Drag and drop doesn't work because of missing dependencies
我有一个为 Splunk 编写的应用程序,它依赖于 boto3 和 pyOpenSSL 库。除了 drag/drop,我还没有找到将应用程序依赖项放入应用程序 bin 文件夹的好方法,这不适用于 boto3 和 pyOpenSSL。
到目前为止,每次我们需要使 python 模块可用于 Splunk 中的单个应用程序时,我们会将 python 模块拖放到 $SPLUNK_HOME/etc/apps/APP_NAME/bin/MODULE 。这一直有效,直到我们需要 pyOpenSSL 和 boto3 库,它们有很多密码学和单一脚本依赖性,不能正确地过来。
我尝试过的:
1| python3 -m venv $SPLUNK_HOME/etc/apps/APP_NAME/
2| python3 -m pip install (pyOpenSSL, boxsdk, pyJWT, boto3) < base dependencies
3| move $SPLUNK_HOME/etc/apps/APP_NAME/lib/python3.7/site-packages/ > $/SPLUNK_HOME/etc/apps/APP_NAME/bin
4| Put all my app scripts in $/SPLUNK_HOME/etc/apps/APP_NAME/bin alongside all the modules I just installed to that folder using venv
5| Start Splunk
6| search | search_command arg=0
在这一点上,Splunk 告诉我 enum34、ipaddress、chainmap、密码学(_constant_time 埋在此处某处的模块在它应该存在的地方不存在)模块不存在。
然后我关闭了 Splunk,重新执行了步骤 1-6,但还在步骤 2 中安装了所有缺失的模块。我现在遇到的错误是:
External search command 'boxfiles' returned error code 1. First 1000 (of 1456) bytes of script output: "No module named constant_time ERROR "Error 'No module named constant_time'. Traceback (most recent call last): File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/box_connector/init.py"", line 3, in from box_connector import BoxConnector File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/box_connector/box_connector.py"", line 10, in from OpenSSL import crypto File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/OpenSSL/init.py"", line 8, in from OpenSSL import crypto, SSL File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/OpenSSL/crypto.py"", line 12, in from cryptography import x509 File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/cryptography/x509/init.py"", line 8, in from cryptography.x509.base import ( File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/cryptography/x509/base.py"", line 18, in from cryptography.x509.extensions import Exte".
我想解决这个错误,但我已经解决这个依赖性问题一段时间了,所以如果有更好的解决方案来获取这些包,我很想听听。
您可以使用以下命令将依赖项安装到适当的目录中。确保 $SPLUNK_HOME
设置正确,并将 APP_NAME
替换为您的新应用名称。
pip install pyOpenSSL -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install boxsdk -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install pyJWT -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install boto3 -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
您可能还需要查看 Splunk Add-On for AWS 的功能,并特意将所需模块添加到 Python 的路径中。 (Splunk_TA_aws/bin/aws_bootstrap_env.py
).
'''
Add common libs to sys.path
'''
import os
import os.path
import re
import sys
import logging
def setup_python_path():
# Exclude folder beneath other apps, Fix bug for rest_handler.py
ta_name = os.path.basename(os.path.dirname(os.path.dirname(__file__)))
pattern = re.compile(r"[\/]etc[\/]apps[\/][^\/]+[\/]bin[\/]?$")
new_paths = [path for path in sys.path if not pattern.search(path) or ta_name in path]
new_paths.insert(0, os.path.dirname(__file__))
sys.path = new_paths
bindir = os.path.dirname(os.path.abspath(__file__))
# We sort the precedence in a decending order since sys.path.insert(0, ...)
# do the reversing.
# Insert library folder
sharedpath = os.path.join(bindir, '3rdparty', 'python3')
sys.path.insert(0, sharedpath)
# preventing splunklib initialize an unexpected root handler
def setup_null_handler():
logging.root.addHandler(logging.NullHandler())
def run_module(name):
instance = __import__(name, fromlist=['main'])
instance.main()
setup_python_path()
setup_null_handler()
参考资料
我有一个为 Splunk 编写的应用程序,它依赖于 boto3 和 pyOpenSSL 库。除了 drag/drop,我还没有找到将应用程序依赖项放入应用程序 bin 文件夹的好方法,这不适用于 boto3 和 pyOpenSSL。
到目前为止,每次我们需要使 python 模块可用于 Splunk 中的单个应用程序时,我们会将 python 模块拖放到 $SPLUNK_HOME/etc/apps/APP_NAME/bin/MODULE 。这一直有效,直到我们需要 pyOpenSSL 和 boto3 库,它们有很多密码学和单一脚本依赖性,不能正确地过来。
我尝试过的:
1| python3 -m venv $SPLUNK_HOME/etc/apps/APP_NAME/
2| python3 -m pip install (pyOpenSSL, boxsdk, pyJWT, boto3) < base dependencies
3| move $SPLUNK_HOME/etc/apps/APP_NAME/lib/python3.7/site-packages/ > $/SPLUNK_HOME/etc/apps/APP_NAME/bin
4| Put all my app scripts in $/SPLUNK_HOME/etc/apps/APP_NAME/bin alongside all the modules I just installed to that folder using venv
5| Start Splunk
6| search | search_command arg=0
在这一点上,Splunk 告诉我 enum34、ipaddress、chainmap、密码学(_constant_time 埋在此处某处的模块在它应该存在的地方不存在)模块不存在。
然后我关闭了 Splunk,重新执行了步骤 1-6,但还在步骤 2 中安装了所有缺失的模块。我现在遇到的错误是:
External search command 'boxfiles' returned error code 1. First 1000 (of 1456) bytes of script output: "No module named constant_time ERROR "Error 'No module named constant_time'. Traceback (most recent call last): File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/box_connector/init.py"", line 3, in from box_connector import BoxConnector File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/box_connector/box_connector.py"", line 10, in from OpenSSL import crypto File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/OpenSSL/init.py"", line 8, in from OpenSSL import crypto, SSL File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/OpenSSL/crypto.py"", line 12, in from cryptography import x509 File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/cryptography/x509/init.py"", line 8, in from cryptography.x509.base import ( File ""/Applications/Splunk/etc/apps/TA-box-connector/bin/cryptography/x509/base.py"", line 18, in from cryptography.x509.extensions import Exte".
我想解决这个错误,但我已经解决这个依赖性问题一段时间了,所以如果有更好的解决方案来获取这些包,我很想听听。
您可以使用以下命令将依赖项安装到适当的目录中。确保 $SPLUNK_HOME
设置正确,并将 APP_NAME
替换为您的新应用名称。
pip install pyOpenSSL -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install boxsdk -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install pyJWT -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
pip install boto3 -t $SPLUNK_HOME/etc/apps/APP_NAME/bin
您可能还需要查看 Splunk Add-On for AWS 的功能,并特意将所需模块添加到 Python 的路径中。 (Splunk_TA_aws/bin/aws_bootstrap_env.py
).
'''
Add common libs to sys.path
'''
import os
import os.path
import re
import sys
import logging
def setup_python_path():
# Exclude folder beneath other apps, Fix bug for rest_handler.py
ta_name = os.path.basename(os.path.dirname(os.path.dirname(__file__)))
pattern = re.compile(r"[\/]etc[\/]apps[\/][^\/]+[\/]bin[\/]?$")
new_paths = [path for path in sys.path if not pattern.search(path) or ta_name in path]
new_paths.insert(0, os.path.dirname(__file__))
sys.path = new_paths
bindir = os.path.dirname(os.path.abspath(__file__))
# We sort the precedence in a decending order since sys.path.insert(0, ...)
# do the reversing.
# Insert library folder
sharedpath = os.path.join(bindir, '3rdparty', 'python3')
sys.path.insert(0, sharedpath)
# preventing splunklib initialize an unexpected root handler
def setup_null_handler():
logging.root.addHandler(logging.NullHandler())
def run_module(name):
instance = __import__(name, fromlist=['main'])
instance.main()
setup_python_path()
setup_null_handler()