Splunk ITSI

How to maintain ITSI Entity information field using the rest API from python?

las
Contributor

Hi.

We have a use case where we would like to maintain a single information field on some of our entities.

The field name is Application Service, and it is fairly static - but not quite, so it might change over time. This field can logically only have one value, and the problem with the scheduled import, is, that if the value changes, there will be two values for this field name.

So we are trying to create a Python script, that will maintain this value, so if it changes the still will only be one value - the old one is overwritten. 

The problem is that when we try to change this vallue and posts to Splunk, we get a code 200 returnkode, but the value has not changed.

 

This is an example code: (Please don't kill me, this is just a test, and I'm not really a Python developer)

 

def update_splunk_rest(key, jsonDict):
    url = base_url + "/servicesNS/nobody/SA-ITOA/itoa_interface/entity/" + key + "?is_partial_data=0"
    authHeader = {'Authorization': token}

    r = requests.post(url, headers=authHeader, json=jsonDict, verify=False)
    print(r.text)
    return r
splk_entity = get_splunk_rest("2b4566fb-367e-44ec-b068-d6541a2024e6")
print(splk_entity.status_code)
entity = splk_entity.json()
print(entity)
title = entity['title']
info = entity['informational']
print(info)
keys = info['fields']
values = info['values']
print(keys)
print(values)
i=0
for field in keys:
    if field == 'Application Service':
        break
    i=i+1
values[i] = "Dette er Las test"
print("=============================================================")
print(entity)
#payload = {"_key":"821bd2f7-83d6-47a9-a753-60c04523d57e","title":title,"informational":{"fields":keys, "values":values}}
#print(payload)
response = update_splunk_rest("2b4566fb-367e-44ec-b068-d6541a2024e6", entity)
print(response.status_code)

 

The entity is changed just before the post (update_splunk_rest), that does a post with is_partiel_data=0, as we are changing the entire record from ITSI.

Has anyone else had this problem and found a solution?

Kind regards

Las

Labels (2)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

I havent run this code but it looks like you're setting values[i] but not actually setting that back inside entity before posting it back to Splunk?

You could try updating values[i] to entity['informational']['values'][i] and see if that resolves the issue! Good luck!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...