Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: IndexError: string index out of range ==> Execute #12

Open
everaldoscabral opened this issue May 7, 2021 · 4 comments
Open

Error: IndexError: string index out of range ==> Execute #12

everaldoscabral opened this issue May 7, 2021 · 4 comments

Comments

@everaldoscabral
Copy link

Traceback (most recent call last):
File "/usr/local/bin/zabbix-ipsec.py", line 117, in
ret = getPayload()
File "/usr/local/bin/zabbix-ipsec.py", line 111, in getPayload
if conf[-1] == ',':
IndexError: string index out of range

I use Python 3.7 and ZabbixAgentd 4.0.27. My pfSense version is 2.5.1-RELEASE(amd64)

@everaldoscabral
Copy link
Author

@krolingo
Copy link

Solved!

https://github.com/smejdil/zabbix_ipsec_pfsense/blob/master/scripts/zabbix-ipsec.py

/usr/local/bin/python3.7 /usr/local/bin/zabbix-ipsec3.py
Traceback (most recent call last):
File "/usr/local/bin/zabbix-ipsec3.py", line 126, in
ret = getPayload()
File "/usr/local/bin/zabbix-ipsec3.py", line 107, in getPayload
data = parseConf().items()
File "/usr/local/bin/zabbix-ipsec3.py", line 79, in parseConf
m1 = m1.group(0)
AttributeError: 'NoneType' object has no attribute 'group'

@alanwds
Copy link
Owner

alanwds commented Aug 25, 2021

@krolingo I just make some improvement on zabbix-ipsec script (the most part of then, identation). Can you check if is working know?

@ecarat237
Copy link

ecarat237 commented Jun 11, 2022

Hi,

Thank you @alanwds for this work, I find it really useful and well done.

Maybe this issue is resolved since then, but I encountered the same problem.

Here are the modifications I made for the zabbix-ipsec.py script to work again after the tunnels name has been changed from connxxxx to conx, and for the description to be well displayed :

  • line 8, ensure that the variable IPSEC_CONF points to the new path : IPSEC_CONF = '/var/etc/ipsec/swanctl.conf'

  • line 61 in the parseConf() function, edit the regex for the reg_conn variable : from re.compile('^conn\s((?!%default).*)') to reg_conn = re.compile('^\s*con[0-9]')

  • I added the following variable to fetch the IPSEC VPN description (line 65 for me) :
    reg_descr = re.compile('(?<=# P1 (ikeid [0-9]): ).*')

  • line 89 for me, after

if m2:
right_tmp.append(m2)

I added the following operations :
descr_tmp = list()
m3 = re.search(reg_descr, g)
m3 = m3.group(0)
if m3:
descr_tmp.append(m3)

  • And finally line 98 for me, the new data variable is populated with the description : data[conn_tmp[0]] = [left_tmp[0], right_tmp[0], descr_tmp[0]]
    I attached the edited version of zabbix-ipsec.py to this reply, hope someone will find this useful!

zabbix-ipsec.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants