Graylog Rest API Request Post - Fehler Code 405

Hello, everyone,
I have a problem with my python script. When I run the script, I always get an error message or the status code 405. When I type the following at “!/Search/Messages/retrieveForSearch_post_2” and test my request, I get plausible results returned. Why don’t I get these results when I run the program from the terminal?
Maybe someone had a similar problem before and can help me. I would be very grateful!

type or paste code here

#!/usr/bin/env python3
import argparse
import requests
import sys
from requests.auth import HTTPBasicAuth

def main():

  header = {

  request = {"chunk_size": 10, "timerange": {"type": "relative","range": 1000},"limit": 10, "query_string": {"query_string": "agent_name:XX-XX-XX","type": "elasticsearch"}}

  response ="https://xxxxx.test/api/views/messages", json=request, auth=HTTPBasicAuth("test", "t1e2s3t"), headers=header, timeout=10)

  print("Status Code ")

  if response.status_code == 200:
    if args.time_range < 600:
      str_timerange = "{} s".format(args.time_range)
    elif args.time_range < 14400:
      str_timerange = "{:.0f} m".format(args.time_range/60)
      str_timerange = "{} h".format(args.time_range/3600)

    # if data['total_events'] >= args.crit:
      # print("CRITICAL - {} alerts in the last {} | alerts={}".format(data['total_events'], str_timerange, data['total_events']))
      # return 2

    print("UNKNOWN - HTTP Status Code: {}".format(response.status_code))
    return 3

if __name__ == "__main__":

Hello @S1994

First, I have not used Python script with Graylog. But I was looking at your API posted and matching with the error. Not sure if that is the right API call. The reason I stated this was I looked here

System/Nodes → API Browser

Unable to find this API or I have over looked it.



This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.