Splunk Dev

connect to splunk instance using custom endpoints

jangid
Builder

Hello All,

I have developed few mashup API (combining two or more KVStore into single API) for our app in python language. everything works perfectly fine but I have used hardcoded password to connect Splunk instance, here is my code snippet.

            USERNAME = "admin"
            PASSWORD = "changeme"

            opts.kwargs["port"] = listening_port
            opts.kwargs["host"] = src_ip
            opts.kwargs["app"] = APPNAME
            opts.kwargs["token"] = system_authtoken
            opts.kwargs["username"] = USERNAME
            opts.kwargs["password"] = PASSWORD
            opts.kwargs["owner"] = 'nobody'
            self.service = connect(**opts.kwargs)
            logger.debug('[ServiceHandle] user=%s service=%s' % (user, self.service)) 

Now I want to remove these hard-coded username and password and use same username/password user logged in

can you please help me how do I do this?

NOTE: I am not using any custom command and my all endpoints are mentioned in restmap.conf and web.conf

Tags (3)
0 Karma
1 Solution

jangid
Builder

There is no way to connect Splunk service without username and password. for my specific requirement I have used setup page where I am storing the username and password and reading username password before connect method.

e.g.

username, password = getUsernamePassword(sessionKey)


def getUsernamePassword(sessionKey):
    setup_entity = entity.getEntity('setup', 'manoj', namespace=appname, owner='nobody', sessionKey=sessionKey)
    for each in setup_entity:
        if each == 'username':
            username = setup_entity[each]
        elif each == 'password':
            password = setup_entity[each]
    return username, password

View solution in original post

0 Karma

jangid
Builder

There is no way to connect Splunk service without username and password. for my specific requirement I have used setup page where I am storing the username and password and reading username password before connect method.

e.g.

username, password = getUsernamePassword(sessionKey)


def getUsernamePassword(sessionKey):
    setup_entity = entity.getEntity('setup', 'manoj', namespace=appname, owner='nobody', sessionKey=sessionKey)
    for each in setup_entity:
        if each == 'username':
            username = setup_entity[each]
        elif each == 'password':
            password = setup_entity[each]
    return username, password
0 Karma
Get Updates on the Splunk Community!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...