Splunk Search

Why is there error when trying to get data from REST API using Python script?

munang
Path Finder

I'm trying to get data by registering it as a Splunk script using Python code.

But the problem only occurs when I run this code in Splunk.

When I run it directly in Splunk Python locally, there is no problem,

munang_0-1674139023005.png

 

but when I run it from Splunk, I get the following error.

munang_1-1674139051187.png

 

The error contents are as follows.

Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

 

So I searched and tried using http scheme and requests.get(verift=false), but the same error occurs.

There is no error when I run it locally, so it seems to be a problem when sending a request from Splunk.

 

 

If anyone knows, I'd appreciate any help.

 

 

import requests as req
import json

def tmdb_api_call(requestURL, parameters):
    response = req.get(url=requestURL, params=parameters)
    if response.status_code != 200:
        print(response.json())
        exit()
    data = response.json()
    return json.dumps(data)


def get_upcoming_movies_by_page(api_key, page_number=1):
    requestURL = "http://api.themoviedb.org/3/movie/upcoming"
    parameters = {"api_key": api_key, "page": page_number}
    return tmdb_api_call(requestURL, parameters)


def main():
    api_key = "key"
    upcoming_movie_list = get_upcoming_movies_by_page(api_key, 1)
    data = json.loads(upcoming_movie_list)
    print(json.dumps(data["results"]))

main()

 

 

(code from https://github.com/siddharthajuprod07/youtube)

 

Labels (1)
0 Karma

munang
Path Finder

@PaulPanther 

Enter data from my local Splunk -> script
Invoke it using

This is a config file related to using the script.

my splunk inputs.conf setup 

[script://$SPLUNK_HOME/etc/apps/tmdb/bin/tmdb_upcoming.py]
disabled = false
host = MyComputer-MacBookAir.local
interval = 60.0
sourcetype = _json

 

Please reply if you have any other information.

0 Karma

PaulPanther
Builder

@munang What is your setup in Splunk and how do you call the script?

0 Karma
Get Updates on the Splunk Community!

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...