travisghansen / hass-opnsense

OPNsense integration with Home Assistant
Apache License 2.0
221 stars 29 forks source link

Can't add firewall "Unexpected er" #56

Closed weha closed 1 year ago

weha commented 1 year ago

When I try to add the firewall it gives me this error in the log (unexpected error in the ui): ERROR (MainThread) [custom_components.opnsense.config_flow] Unexpected err=TypeError('string indices must be integers'), type(err)=<class 'TypeError'>

OpnSense + plugin & HASS + plugin is up to date

travisghansen commented 1 year ago

This is almost always permission related. Are you certain the user has appropriate permissions? Can you try with an root key/secret to ensure the integration otherwise works in your environment?

alexdelprete commented 1 year ago

These permissions work fine:

image

weha commented 1 year ago

@travisghansen @alexdelprete It seems that when migrating to another device and transferring the configuration does not include the priviliges... it worked before the migration so I did not think about this. Would it be possible to change / add information in the error about this? Because now it's so generic that it more likely seems an issue with the plugin.

travisghansen commented 1 year ago

It’s not always a permission error. The error is so generic from the api that I can’t really assume that either but perhaps someday I will just male that assumption.

jannislehmann commented 1 year ago

Hey, I have been facing this error recently as well. Trying the root or any other admins users. Do you happen to know whether there are any opnsense logs that could help identify the error from the opnsense api side?

travisghansen commented 1 year ago

Can you share the hass logs? I recently added code that should give a little better insight from the hass side about what is causing the issue.

alexdelprete commented 1 year ago

I have been facing this error recently as well.

recently means it was working before and now it breaks? can you show the log please?

jannislehmann commented 1 year ago

recently means it was working before and now it breaks

It has worked before with I believe an older opnsense version, but I didn't have any monitoring to exactly pinpoint the date when the integration broke.

Can you share the hass logs?

Sure, I am using version v0.1.13

2023-01-31 20:15:20.685 ERROR (SyncWorker_6) [custom_components.opnsense.pyopnsense] Unexpected get_system_info error err=TypeError('string indices must be integers'), type(err)=<class 'TypeError'>
2023-01-31 20:15:20.695 ERROR (MainThread) [custom_components.opnsense.config_flow] Unexpected err=TypeError('string indices must be integers'), type(err)=<class 'TypeError'>
RonnyB1978 commented 1 year ago

Hello. I hope you can help. I have installed the os-homeassistant-maxit plugin version 1.0. The Version of my OpnSense Firewall (IP 192.168.100.1 is 23.1_6. When I try to connact home assistant (IP 192.168.1.23) to my Opnsense, I got a time out error or unexpected error. I have a new user with the privileges created. Changing firewall rules doesn't work. What I making wrong? What login shell for user in opnsense I have to choose?

Thanks a lot in advance.

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.opnsense.pyopnsense Source: custom_components/opnsense/pyopnsense/init.py:100 Integration: OPNsense (documentation, issues) First occurred: 21:17:37 (6 occurrences) Last logged: 21:18:33

Unexpected get_system_info error err=TimeoutError('timed out'), type(err)=<class 'TimeoutError'> Unexpected get_system_info error err=TypeError('string indices must be integers'), type(err)=<class 'TypeError'>

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.opnsense.config_flow Source: custom_components/opnsense/config_flow.py:148 Integration: OPNsense (documentation, issues) First occurred: 21:18:25 (4 occurrences) Last logged: 21:18:33

Unexpected err=TypeError('string indices must be integers'), type(err)=<class 'TypeError'>

travisghansen commented 1 year ago

I think someone is going to have to get a dev env setup and just start digging into the code :( or if someone can get me temporary access to your fw I can help as well (I assure you, I have not interest in your fw beyond getting the integration going).

alexdelprete commented 1 year ago

t has worked before with I believe an older opnsense version, but I didn't have any monitoring to exactly pinpoint the date when the integration broke.

what version of HA? Can you please try creating a new user, with the privileges of my first post in the thread (check the screenshot), remove the integration and re-add it using the new user?

RonnyB1978 commented 1 year ago

t has worked before with I believe an older opnsense version, but I didn't have any monitoring to exactly pinpoint the date when the integration broke.

what version of HA? Can you please try creating a new user, with the privileges of my first post in the thread (check the screenshot), remove the integration and re-add it using the new user?

Hello Alex,

thank you for help. I will try it today on evening. At work I have no access to my opnsense. I will come back as soon as possible.

Ronny

RonnyB1978 commented 1 year ago

I think someone is going to have to get a dev env setup and just start digging into the code :( or if someone can get me temporary access to your fw I can help as well (I assure you, I have not interest in your fw beyond getting the integration going).

Hello Travis,

thank you for your help. But access to my firewall :-| I don't know, if I want this. Let my think about it. May be I found annother solution. Nevertheless, thank you for your help. I will try Alex's procedure tonight.

travisghansen commented 1 year ago

Totally understandable.

RonnyB1978 commented 1 year ago

Hello Together,

here my further information:

OpnSense Version 23.1_6 HA Version 2023.1.6 (OP 9.5 / SuperV 2023.01.1) -> installed in a VM on my Synology DS918+

IP OpnSense 192.168.100.1 IP HA 192.168.1.23 (is in an access rule to allow to connect to Management consule) PlugIn os-homeassistant-maxit was deleted and installed again via SSH (Version 1.0)

What I have done:

  1. Plugin uninstalled on OpnSense
  2. Created User HA with priviliges
  3. set API Token to users HA and root
  4. installed Plugin via SSH
  5. I tried to connect Home Assistant integration OpnSense to my OpnSense 192.168.100.1 with https and http without SSL verification
  6. At 192.168.100.1 the unexpected error cames immediately
  7. At 192.168.1.1 I have got a time out error
  8. I tried it with user root and HA, without success

I hope you have an idea and can help. Home Assistant is fantastic and I would monitor my internet speed in a dashboard. From where to where counts the secret api key? From "key="? Or from "=" or AFTER "key="? It is a little bit unclear.

Thank you very much in advance and have a nice week and please stay healthy.

Ronny

travisghansen commented 1 year ago

After key=

RonnyB1978 commented 1 year ago

I have found the error. It was my fault!!! I copied too much from the text file when I entered it. I had not seen that the text file generated by Opnsense contained both Api Key and Api Secret.

I apologise very much. Now it works fine. ;-)

Have a nice weekend and please stay healthy.

Ronny