Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Client connect issue with adding error handling

I am trying to connect to an account on Splunk via Python and Bash. I can connect to the website fine and it prints what I want it to, in the terminal, when I log in correctly. However when I use the wrong log in details, it prints a large error message saying ‘login failed’ that I want to try and condense to one line only.
This is what I am using to connect to Splunk:

service = client.connect(
    host=splunk_config['host'],
    port=splunk_config['port'],
    username=splunk_config['username'],
    password=splunk_config['password'])

I want to do something along the lines of:

if (service errors):
   print ("Failed to connect")
else:
   print ("Successfully connected")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Without the exception and guessing you’re using splunklib I would imagine you need something like:

try:
    service = client.connect(
        host=splunk_config['host'],
        port=splunk_config['port'],
        username=splunk_config['username'],
        password=splunk_config['password'])
    print("Login succesfull")
except splunklib.binding.AuthenticationError as e:
    print("Login failed")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading