如何在Splunk Enterprise中使用Boto3 [英] How to use boto3 in splunk Enterprise

查看:248
本文介绍了如何在Splunk Enterprise中使用Boto3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为splunk中的用例创建自定义应用程序.我的用例之一是从AWS获取一些数据,对于这些数据,我已经有可用python编写的有效代码,并且我正在使用boto3 SDK.我在Splunk中尝试过的同一代码,但由于Splunk没有boto3的信息而无法使用.请提出任何建议.

I am trying to create a custom app for my usecases in splunk. One of my usecase is to get some data from AWS for which I already have a working code written in python and I am using boto3 SDK. The same code I was trying in Splunk and it didn't work because Splunk doesn't have information of boto3. Any suggestions please.

示例代码在这里.

import boto3
import json

def ec2_client():
    client = boto3.client('ec2')
    """ :type : pyboto3.ec2 """
    return client;

def perform_ec2_operation():
    ec2_interested_details = ec2_client().describe_instances()
    #print(ec2_interested_details)
    return ec2_interested_details;

if __name__ == '__main__':
    data = perform_ec2_operation()
    data = data['Reservations'][0]['Instances'][0]['NetworkInterfaces'][0]['Association']
    data = json.dumps(data);
    print(data)

推荐答案

脚本失败的原因是因为Splunk使用自己的Python部署.您将需要将boto3安装到该Python的库中,这可能会很困难.请参阅以下内容:

The reason your script is failing is because Splunk uses its own deployment of Python. You will need to install boto3 into that Python's library, which can be challenging. Refer to the following:

  • https://answers.splunk.com/answers/220196/import-non-native-python-libraries-into-splunk.html
  • https://answers.splunk.com/answers/8/can-i-add-python-modules-to-the-splunk-environment.html
  • https://answers.splunk.com/answers/112609/my-own-python-script-cannot-import-splunk-python-library-modules.html

您是否正在创建自定义输入以从AWS检索数据?如果是这样,我建议您改为查看Splunk为AWS创建的附件, https://splunkbase .splunk.com/app/1876/这将已经为您配置了所有必需的库.

Are you creating a custom input to retrieve your data from AWS? If so, I suggest you instead look at the Splunk created add-on for AWS, https://splunkbase.splunk.com/app/1876/ This will have all the necessary libraries configured for you already.

这篇关于如何在Splunk Enterprise中使用Boto3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆