Thank you for your help, Sorry, I am not very familiar at all with coding. I am struggling thru the Python script, but making progress. So the first API call I need to make is: "https://ServerName/nitro/v1/config/lbvserver" This gives me a JSON return with about 50 name values like: [
{
"name":"server1",
"insertvserveripport":"OFF",
},
{
"name":"server2",
"insertvserveripport":"OFF",
},
I need to make a secondary API call that would use these names in the API URL, like: https://su-ns-vpx-int-1.siteone.com/nitro/v1/config/lbvserver_servicegroup_binding/(name) I can't figure out how to capture the name values from the first API call in order for the second API call to be executed for each variable. : ( I hope that makes sense. 🙂 Here's the actual code I am using: import os
import sys
import time
import datetime
import json
'''
IMPORTANT
Edit only the validate_input and collect_events functions.
Do not edit any other part in this file.
This file is generated only once when creating the modular input.
'''
'''
# For advanced users, if you want to create single instance mod input, uncomment this method.
def use_single_instance_mode():
return True
'''
def validate_input(helper, definition):
"""Implement your own validation logic to validate the input stanza configurations"""
# This example accesses the modular input variable
# global_account = definition.parameters.get('global_account', None)
pass
def collect_events(helper, ew):
# Note, for single instance mod input, args will be returned as a dict.
# For multi instance mod input, args will be returned as a single value.
opt_global_account = helper.get_arg('global_account')
global_userdefined_global_var = helper.get_global_setting("userdefined_global_var")
# The following examples send rest requests to some endpoint.
url="https://servername.com/nitro/v1/config/lbvserver"
headers = {"authorization":"Basic bnNyb2dghdg90O0c2NsciEh"}
final_result = []
response = helper.send_http_request(url, 'GET', parameters=None, payload=None,headers=headers, cookies=None, verify=True, cert=None,timeout=None, use_proxy=True)
# get response body as json. If the body text is not a json string, raise a ValueError
r_json = response.json()
for name in r_json["lbvserver"]:
state = helper.get_check_point(name["name"])
if state is None:
final_result.append(name)
helper.save_check_point(name["name"], "Indexed")
helper.delete_check_point(name["name"])
# get response status code
r_status = response.status_code
if r_status !=200:
# check the response status, if the status is not sucessful, raise requests.HTTPError
response.raise_for_status()
# To create a splunk event
event = helper.new_event(json.dumps(final_result), time=None, host=None, index=None, source=None, sourcetype=None, done=True, unbroken=True)
ew.write_event(event)
Thanks again for responding, very much appreciated. 🙂 Thanks, Tom
... View more