imon icon indicating copy to clipboard operation
imon copied to clipboard

Two python errors when running interactively

Open EmilStenstrom opened this issue 1 year ago • 4 comments

Hi!

I'm trying to get a monitor up on my rpi to understand when it's down, so I can understand what the root cause is. imon seems like a great fit for this.

I've gone through the configuration (see output below). But when I try to run the script I get the following error. Mind helping me troubleshoot?

pi@raspberrypi:~$ python3 --version
Python 3.11.2
pi@raspberrypi:~$ pip3 list | grep icmp
icmplib             2.1.1
pi@raspberrypi:~$ sudo /usr/local/bin/imon --nosyslog --instance main
2024-08-01 15:46:49 [main] Starting
2024-08-01 15:46:49 [main] Version V2.96
2024-08-01 15:46:49 [main] Command line: /usr/local/bin/imon --nosyslog --instance main
2024-08-01 15:46:49 [main] Configuration file /etc/default/imon-main
2024-08-01 15:46:49 [main] ** [global] **
2024-08-01 15:46:49 [main]     action
2024-08-01 15:46:49 [main]     datefmt           %Y-%m-%d %H:%M:%S
2024-08-01 15:46:49 [main]     instance          main
2024-08-01 15:46:49 [main]     note
2024-08-01 15:46:49 [main]     imon-configure-version V1.0
2024-08-01 15:46:49 [main]     imon-configure-created 2024-08-01 15:46:25
2024-08-01 15:46:49 [main] ** [ddns] **
2024-08-01 15:46:49 [main]     enable            False
2024-08-01 15:46:49 [main]     interval          10
2024-08-01 15:46:49 [main]     pingcount         2
2024-08-01 15:46:49 [main]     pingwait          1
2024-08-01 15:46:49 [main] ** [updown] **
2024-08-01 15:46:49 [main]     enable            False
2024-08-01 15:46:49 [main]     interval          10
2024-08-01 15:46:49 [main]     pingcount         2
2024-08-01 15:46:49 [main]     pingwait          1
2024-08-01 15:46:49 [main]     monitorip
2024-08-01 15:46:49 [main]     addping
2024-08-01 15:46:49 [main]     dnsserver
2024-08-01 15:46:49 [main]     dnslookup
2024-08-01 15:46:49 [main] ** [failover] **
2024-08-01 15:46:49 [main]     enable            True
2024-08-01 15:46:49 [main]     interval          10.0
2024-08-01 15:46:49 [main]     pingcount         2
2024-08-01 15:46:49 [main]     pingwait          1
2024-08-01 15:46:49 [main]     prefer-primary    False
2024-08-01 15:46:49 [main]     metric            201
2024-08-01 15:46:49 [main]     primary-if        emil
2024-08-01 15:46:49 [main]     primary-name      emil
2024-08-01 15:46:49 [main]     primary-gw        192.168.1.1
2024-08-01 15:46:49 [main]     primary-ping      weatherapp.sammanfatta.se
2024-08-01 15:46:49 [main]     primary-postping  weatherapp.sammanfatta.se
2024-08-01 15:46:49 [main]     standby-if        emil_ext
2024-08-01 15:46:49 [main]     standby-name      emil_ext
2024-08-01 15:46:49 [main]     standby-gw        192.168.1.1
2024-08-01 15:46:49 [main]     standby-ping      weatherapp.sammanfatta.se
2024-08-01 15:46:49 [main]     standby-postping  weatherapp.sammanfatta.se
2024-08-01 15:46:49 [main] ** [ping] **
2024-08-01 15:46:49 [main]     enable            True
2024-08-01 15:46:49 [main]     interval          10.0
2024-08-01 15:46:49 [main]     pingcount         2
2024-08-01 15:46:49 [main]     pingwait          1
2024-08-01 15:46:49 [main]     monitorip         weatherapp.sammanfatta.se
2024-08-01 15:46:49 [main-failover] Start Network Failover Monitor
2024-08-01 15:46:49 [main-ping] Start Ping Monitor
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/local/bin/imon", line 428, in run
    host.packet_loss, host.jitter))
                      ^^^^^^^^^^^
AttributeError: 'Host' object has no attribute 'jitter'
2024-08-01 15:46:50 [main-failover] Network Failover Initial State for Primary Network emil (emil): online
2024-08-01 15:46:50 [main-failover] Network Failover to Primary Network emil (emil)
2024-08-01 15:46:50 [main-failover] Network Failover Primary Route emil (emil) is active
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/local/bin/imon", line 243, in run
    self._dofailover(self.primaryx, self.standbyx)
  File "/usr/local/bin/imon", line 209, in _dofailover
    self._ckping(ito)
  File "/usr/local/bin/imon", line 180, in _ckping
    self._logit("Warn: {} Network Ping Target {} Not Responding After Failover".format(ifdat['ename'], ifda['postping']))
                                                                                                       ^^^^
NameError: name 'ifda' is not defined. Did you mean: 'ifdat'?

EmilStenstrom avatar Aug 01 '24 13:08 EmilStenstrom

Python is correct, that ifda should be ifdat. Not sure about the first one yet.

Will spend some time on this today after breakfast.

Thanks for giving imon a go, and for the feedback. Stay tuned.

gitbls avatar Aug 01 '24 14:08 gitbls

Both of your issues (icmplib doc and python errors) are corrected with updates on this GitHub.

You should be able to rerun imon-install, which will download the updated files and configure the python venv that imon now uses.

Please LMK how your testing goes.

gitbls avatar Aug 01 '24 19:08 gitbls

Hi, I had the same issues when I tried this a week ago. For me, the latest commit works! Thank you!

However, I would like to note that on my rpi (3 Model B+, running Raspberry Pi OS Bookworm), i needed to manually install pip3 using sudo apt install python3-pip (not sudo apt install pip3).

Also, in order to test-run imon after setting up the config file with sudo imon configure, I could not simply use sudo /usr/local/bin/imon --nosyslog --instance MY_INSTANCE_NAME, as it doesn't seem to use the venv configured during install:

Traceback (most recent call last):
  File "/usr/local/bin/imon", line 7, in <module>
    from icmplib import ping, multiping
ModuleNotFoundError: No module named 'icmplib'

Instead, I copied the command from the service and ended up with the following: sudo /root/.imon-venv/bin/python /usr/local/bin/imon --nosyslog --instance MY_INSTANCE_NAME This did work to run imon interactively!

minimusubi avatar Aug 05 '24 04:08 minimusubi

@minimusubi Thx for your report. I updated the README to have the correct example command for testing (using the venv), and corrected the installer to install python3-pip rather than pip3.

gitbls avatar Aug 05 '24 16:08 gitbls

No activity. Closing issue.

gitbls avatar Oct 27 '24 17:10 gitbls