All Apps and Add-ons

TA-connectivity: Why am I getting "Invalid literal for int() with base 10 error" trying to set up the app?

cshanerc
New Member

Trying to set up the TA-connectivity app, and I get the following (I had to run 'dos2unix' on the .py scripts in order to run this on Linux):

#./pythonshell.py ping /opt/splunk/etc/apps/TA-connectivity/lookups/hosts.csv

Traceback (most recent call last):
  File "/opt/splunk/etc/apps/TA-connectivity/bin/ping.py", line 177, in 
   print x.get()
  File "/usr/lib64/python2.7/multiprocessing/pool.py", line 554, in get
   raise self._value
ValueError: invalid literal for int() with base 10: '2 packets'

The error should be from the line within the script:

rtt = float(rex_stats.group('rtt')) / int(packet_no)

Is there a correction for this? Not very familiar with python scripting ...
Thanks!

0 Karma

warrenfelsh
New Member

The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that's not an integer to the int() function . In other words it's either empty, or has a character in it other than a digit.

You can solve this error by using Python isdigit() method to check whether the value is number or not. The returns True if all the characters are digits, otherwise False .

if val.isdigit():

The other way to overcome this issue is to wrap your code inside a Python try...except block to handle this error.

Python2.x and Python3.x

Sometimes the difference between Python2.x and Python3.x that leads to this ValueError: invalid literal for int() with base 10 .

With Python2.x , int(str(3/2)) gives you "1". With Python3.x , the same gives you ("1.5"): ValueError: invalid literal for int() with base 10: "1.5".

0 Karma

seunomosowon
Communicator

I've updated the app. It's up on Splunkbase. It should be easier to use. You can drop me a line if you run into other issues. I'd welcome some feedback.

https://splunkbase.splunk.com/app/1473/#/details

Also available on git:

https://github.com/seunomosowon/TA-connectivity

0 Karma

cshanerc
New Member

Thank you for the updates! I'll follow up soon if I have any issues.

0 Karma

seunomosowon
Communicator

I fixed some of the inconsistencies in the last update, and it should just work with any inputs you might have configured from v0.4. Do let me know if you find any other bugs, or would like any other feature added to this 🙂

0 Karma

seunomosowon
Communicator

Hi cshanerc,

I'll come test and come back to you in a week with an updated version. I might actually rewrite the multiprocessing bit.

Could you also specify which Splunk version and OS you tried this on?

0 Karma

cshanerc
New Member

Thanks! Running 6.4.1 on CentOS 7.2.

0 Karma

seunomosowon
Communicator

Hi Cshanerc,

Here's a fix. You'll need to edit line 121 of ping.py:
pattern_statistics = r'^(?P\d+\spackets)\stransmitted,\s(?:\d+)\sreceived,\s(?P\d+%)\spacket\sloss,\stime\s(?P\d+)ms'

Needs to be updated to this:
pattern_statistics = r'^(?P\d+)\spackets\stransmitted,\s(?:\d+)\sreceived,\s(?P\d+%)\spacket\sloss,\stime\s(?P\d+)ms'

Do let me know if it works for you, and I'll be sure to publish an update to the app which I'm currently testing.

I'm rewriting this as a modular input, but considering leaving or taking out multiprocessing since you would be able to define multiple inputs.

0 Karma

seunomosowon
Communicator

Line 144 will also need editing, as that should be str(rtt). I'll publish an update to fix this shortly.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...