Python Plugin: Network Pinger (Native ICMP) Topic is solved

Python and python framework

Moderator: leecollings

User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

There is a new example plugin showing how to use ICMP to ping network devices without slowing the plugin system down.

It can be found here: https://github.com/domoticz/domoticz/bl ... /Pinger.py

Specify multiple network addresses separated by commas DNS names and IP addresses are supported.

Edit: November 29th, 2017, version 3.0.1:
  • Devices are created in Domoticz the first time the plugin runs, one to show if the device is found and one to show the response time.
  • Devices that are not found are optionally shown with a red banner in the devices tab (if configured to do so)
  • New version handles DNS names where the IP addresses changes (e.g www.google.com) without creating new devices in Domoticz
Users of the previous version should 'Delete' then 'Add' the plugin via the Hardware page.
Requires recent beta for the response time devices to be updated.
Last edited by Dnpwwo on Wednesday 29 November 2017 12:47, edited 1 time in total.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

Updated to version 2.0.6

Extra configuration in the Hardware page configures behaviour when an address being pinged stops responding.

The "Time Out Lost Devices" option (when set to true) will make devices that are not responding show with the 'Timed Out' red header in the Domoticz web UI in the same way that ZWave signals lost device connectivity. Devices will also be marked as timed out during plugin startup until they are seen again.

Requires latest beta or build from development branch from today.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by schulpr »

Hello,

Where can I find the information howto install this plugin?

Thanks in advance for your help!

Rob
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@schulpr,

The plugin examples ship with Domoitcz under /plugins/examples but you can also find it here: https://github.com/domoticz/domoticz/bl ... /Pinger.py.

Just:
  • create a folder under the plugins folder (call it something like 'Pinger') and drop the example Pinger.py into it.
  • rename Pinger.py to plugin.py
  • restart Domoticz and it will show up in the hardware drop down list as 'Pinger (ICMP)'
  • add the names or addresses to be pinged and set the Time Out behaviour you want
  • Hit the 'Add' button and devices will start to show up in the Devices page
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by schulpr »

Thank you,

I did everything accept the renaming...

Kind regards, Rob
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by schulpr »

Hi,

Is there a way to use this script for a bluetooth MAc-address in stead of a IP-address? Pinging an iPhone is like pinging a pinball machine :-).

Kind regards, Rob
lupo2a
Posts: 32
Joined: Thursday 29 September 2016 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by lupo2a »

Its working great but if an IP is not found I got several messages in the log

017-10-30 16:56:28.632 (myPing) Failed to connect to: 192.168.1.202, Description: resolve: Host not found (authoritative)
2017-10-30 16:56:28.632 Error: (myPing) 'onConnect' failed 'NameError':'name 'Conn' is not defined'.
2017-10-30 16:56:28.633 Error: (myPing) ----> Line 153 in /home/pi/domoticz/plugins/Pinger/plugin.py, function onConnect
2017-10-30 16:56:28.633 Error: (myPing) ----> Line 100 in /home/pi/domoticz/plugins/Pinger/plugin.py, function onConnect

can this be resolved?
Raspberry PI 4
Domoticz: V2023.2
- Aeotec Gen5 EU
- Neo CoolCam Door Detector and plug
- FIBARO FGWPE Wall Plug
- 6 FIBARO System FGRM222 Roller Shutter Controller 2
- Kodi SamnsungTV Yamaha plugin
- pluginn manager
- Netatmo
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@lupo2a ,

I've updated the example on github or you can just delete line 100 yourself.

Thanks for the feedback.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
lupo2a
Posts: 32
Joined: Thursday 29 September 2016 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by lupo2a »

Deleted line 100 and no more error in the log

But the plugin is not able to ping 192.168.1.201 while from a terminal I can do that

2017-10-30 22:00:52.629 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.201'
2017-10-30 22:00:52.630 (myPing) Listen directive received, action initiation failed.
2017-10-30 22:00:52.630 (myPing) Failed to connect to: 192.168.1.201, Description: resolve: Host not found (authoritative)

Any help?
Raspberry PI 4
Domoticz: V2023.2
- Aeotec Gen5 EU
- Neo CoolCam Door Detector and plug
- FIBARO FGWPE Wall Plug
- 6 FIBARO System FGRM222 Roller Shutter Controller 2
- Kodi SamnsungTV Yamaha plugin
- pluginn manager
- Netatmo
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@lupo2a,

I also run RPI 3 with Stretch and it works. What user are you running Domoticz as? On linux you need to run root to use ports under 1024 I think.

I use the systemd script documented here https://www.domoticz.com/wiki/Linux#Opt ... eferred.29 to control my system.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
lupo2a
Posts: 32
Joined: Thursday 29 September 2016 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by lupo2a »

I'm running domoticz as root

ps -aux
root 9136 1.8 3.4 236804 25896 ? Ssl Oct30 18:38 /home/pi/domoticz/domoticz -daemon -www 8090 -sslwww 8091 -log /tmp/domoticz.txt

the log

Code: Select all

2017-10-31 10:06:30.492 (myPing) Started.
2017-10-31 10:06:30.719 (myPing) Entering work loop.
2017-10-31 10:06:30.719 (myPing) Initialized version 2.0.6, author 'dnpwwo'
2017-10-31 10:06:30.721 (myPing) 'Port':'0'
2017-10-31 10:06:30.721 (myPing) 'Key':'ICMP'
2017-10-31 10:06:30.721 (myPing) 'Name':'myPing'
2017-10-31 10:06:30.721 (myPing) 'Version':'2.0.6'
2017-10-31 10:06:30.721 (myPing) 'Mode1':'20'
2017-10-31 10:06:30.721 (myPing) 'Mode6':'Verbose'
2017-10-31 10:06:30.721 (myPing) 'Author':'dnpwwo'
2017-10-31 10:06:30.721 (myPing) 'Address':'192.168.1.200, 192.168.1.201, 192.168.1.202, 192.168.1.203, 192.168.1.204, 192.168.1.133'
2017-10-31 10:06:30.721 (myPing) 'Mode5':'null'
2017-10-31 10:06:30.721 (myPing) 'HardwareID':'3'
2017-10-31 10:06:30.721 (myPing) 'HomeFolder':'/home/pi/domoticz/plugins/Pinger/'
2017-10-31 10:06:30.721 (myPing) Device count: 0
2017-10-31 10:06:43.397 (myPing) ICMP Details (5):
2017-10-31 10:06:43.398 (myPing) --->'IPv4 (10):
2017-10-31 10:06:43.398 (myPing) ------->'Identification':'13435'
2017-10-31 10:06:43.398 (myPing) ------->'Version':'4'
2017-10-31 10:06:43.398 (myPing) ------->'Source':'192.168.1.229'
2017-10-31 10:06:43.398 (myPing) ------->'HeaderChecksum':'49259'
2017-10-31 10:06:43.398 (myPing) ------->'Destination':'192.168.1.229'
2017-10-31 10:06:43.398 (myPing) ------->'TimeToLive':'64'
2017-10-31 10:06:43.398 (myPing) ------->'TotalLength':'60'
2017-10-31 10:06:43.398 (myPing) ------->'HeaderLength':'20'
2017-10-31 10:06:43.398 (myPing) ------->'Protocol':'1'
2017-10-31 10:06:43.399 (myPing) ------->'TypeOfService':'192'
2017-10-31 10:06:43.399 (myPing) --->'Description':'destination_unreachable'
2017-10-31 10:06:43.399 (myPing) --->'ICMP (5):
2017-10-31 10:06:43.399 (myPing) ------->'Code':'1'
2017-10-31 10:06:43.399 (myPing) ------->'Identifier':'0'
2017-10-31 10:06:43.399 (myPing) ------->'Type':'3'
2017-10-31 10:06:43.399 (myPing) ------->'Checksum':'64766'
2017-10-31 10:06:43.399 (myPing) ------->'SequenceNumber':'0'
2017-10-31 10:06:43.399 (myPing) --->'Data':'b'ping''
2017-10-31 10:06:43.399 (myPing) --->'Status':'3'
2017-10-31 10:06:43.399 (myPing) Device: '192.168.1.200' returned 'destination_unreachable'.
2017-10-31 10:06:43.400 (myPing) ICMP Details (5):
2017-10-31 10:06:43.400 (myPing) --->'IPv4 (10):
2017-10-31 10:06:43.400 (myPing) ------->'Identification':'13435'
2017-10-31 10:06:43.400 (myPing) ------->'Version':'4'
2017-10-31 10:06:43.400 (myPing) ------->'Source':'192.168.1.229'
2017-10-31 10:06:43.400 (myPing) ------->'HeaderChecksum':'49259'
2017-10-31 10:06:43.400 (myPing) ------->'Destination':'192.168.1.229'
2017-10-31 10:06:43.400 (myPing) ------->'TimeToLive':'64'
2017-10-31 10:06:43.400 (myPing) ------->'TotalLength':'60'
2017-10-31 10:06:43.400 (myPing) ------->'HeaderLength':'20'
2017-10-31 10:06:43.400 (myPing) ------->'Protocol':'1'
2017-10-31 10:06:43.401 (myPing) ------->'TypeOfService':'192'
2017-10-31 10:06:43.401 (myPing) --->'Description':'destination_unreachable'
2017-10-31 10:06:43.401 (myPing) --->'ICMP (5):
2017-10-31 10:06:43.401 (myPing) ------->'Code':'1'
2017-10-31 10:06:43.401 (myPing) ------->'Identifier':'0'
2017-10-31 10:06:43.401 (myPing) ------->'Type':'3'
2017-10-31 10:06:43.401 (myPing) ------->'Checksum':'64766'
2017-10-31 10:06:43.401 (myPing) ------->'SequenceNumber':'0'
2017-10-31 10:06:43.401 (myPing) --->'Data':'b'ping''
2017-10-31 10:06:43.401 (myPing) --->'Status':'3'
2017-10-31 10:07:00.424 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.201'
2017-10-31 10:07:00.424 (myPing) Listen directive received, action initiation failed.
2017-10-31 10:07:00.425 (myPing) Failed to connect to: 192.168.1.201, Description: resolve: Host not found (authoritative)
2017-10-31 10:07:20.314 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.202'
2017-10-31 10:07:20.314 (myPing) Listen directive received, action initiation failed.
2017-10-31 10:07:20.314 (myPing) Failed to connect to: 192.168.1.202, Description: resolve: Host not found (authoritative)
2017-10-31 10:07:40.307 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.203'
2017-10-31 10:07:40.307 (myPing) Listen directive received, action initiation failed.
2017-10-31 10:07:40.307 (myPing) Failed to connect to: 192.168.1.203, Description: resolve: Host not found (authoritative)
2017-10-31 10:08:00.387 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.204'
2017-10-31 10:08:00.387 (myPing) Listen directive received, action initiation failed.
2017-10-31 10:08:00.387 (myPing) Failed to connect to: 192.168.1.204, Description: resolve: Host not found (authoritative)
2017-10-31 10:08:20.416 Error: handleListen Exception: 'resolve: Host not found (authoritative)' failed connecting to ' 192.168.1.133'
2017-10-31 10:08:20.416 (myPing) Listen directive received, action initiation failed.
2017-10-31 10:08:20.416 (myPing) Failed to connect to: 192.168.1.133, Description: resolve: Host not found (authoritative)
Raspberry PI 4
Domoticz: V2023.2
- Aeotec Gen5 EU
- Neo CoolCam Door Detector and plug
- FIBARO FGWPE Wall Plug
- 6 FIBARO System FGRM222 Roller Shutter Controller 2
- Kodi SamnsungTV Yamaha plugin
- pluginn manager
- Netatmo
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by schulpr »

For some strange reason I can't switch the switches that are created by the python plugin on or off. Am I the only one with this problem?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@lupo2a,

You need to remove the spaces between IP addresses (and I need to do it in the plugin as well :lol: ).

You can also use DNS names if you have them set up, the pinger will resolve them.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
cryonic90
Posts: 15
Joined: Friday 25 September 2015 10:22
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by cryonic90 »

I'm running Domoticz on a Ubuntu Server PC, but I'm getting the following error:
2017-11-04 13:49:37.789 Error: (Pinger) Unknown transport type specified: ''.
Does anyone know how to solve this?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@cryonic90,

The version of Domoticz you are running must be too old.

The Pinger uses the newly added ICMP transport so you need to be running a beta from within the last month or so.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
cryonic90
Posts: 15
Joined: Friday 25 September 2015 10:22
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by cryonic90 »

That might be it indeed.
I'm still on the latest stable version.
Thanks for the info :)
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by gerardwr »

Plugin works great, thanks for sharing.

I currently use a bash script to ping various IP's, and report the number of ms ping-time in a Custom Sensor. In this way I can see how fast the network performs, and in addition use the Domoticz graphing option (see below for how it looks).

Your Pinger plugin is perfectly integrated with Domotizc, while my Bash script is "bolted on", so I would prefer to use the Plugin,
but ......

The Pinger plugin currently reports as a switch so ON or Off.

Perhaps you could considering adding the ms value to your plugin?

Schermafbeelding 2017-11-07 om 16.31.59.png
Schermafbeelding 2017-11-07 om 16.31.59.png (26.61 KiB) Viewed 7936 times
Schermafbeelding 2017-11-07 om 16.35.11.png
Schermafbeelding 2017-11-07 om 16.35.11.png (54.66 KiB) Viewed 7936 times
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@gerardwr,

Interesting idea. I have changed the ICMP transport to return the elapsed milliseconds to the plugin and it will be in a future beta.

Making the change to the example plugin to manage Domoticz devices would take a little more effort as it was written with a particular use in mind (i.e pinging devices on a local subnet). It will kind of work for google.com for example but will keep creating devices in Domoticz when you get a different IP address.

I will look into changing it. What Type and subtype numbers did you use to get a Ms device?
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by gerardwr »

Dnpwwo wrote: Monday 13 November 2017 5:37 Interesting idea. I have changed the ICMP transport to return the elapsed milliseconds to the plugin and it will be in a future beta.
Well done, glad I could offer the inspiration.
Making the change to the example plugin to manage Domoticz devices would take a little more effort as it was written with a particular use in mind (i.e pinging devices on a local subnet). It will kind of work for google.com for example but will keep creating devices in Domoticz when you get a different IP address.

I will look into changing it. What Type and subtype numbers did you use to get a Ms device?
Did it before I knew the power of plugins, so I did it like this:

- manually created a Custom Sensor for each IP that I would like to ping:
Schermafbeelding 2017-11-13 om 18.32.01.png
Schermafbeelding 2017-11-13 om 18.32.01.png (70.22 KiB) Viewed 7759 times
- in a Bash script that runs each minute (using Cron) each IP+IDX (both listed in the script) is Ping-ed, the time extracted from the result, and then update the Custom Sensor value by:

Code: Select all

curl "$domoticz/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$value"
Major disadvantage of my setup is quite some maintenance when IP or IDX are added/deleted/changed. This is solved very nicely in your plugin, just change the IP-list :-)

Perhaps 1 other suggestion : The header of the Switch that your Plugin creates is now like "Pinger 129.168.0.3". Would be great if the user can define the header text (the part that says "Pinger") by changing this defintion in your Plugin
Schermafbeelding 2017-11-13 om 18.49.48.png
Schermafbeelding 2017-11-13 om 18.49.48.png (13.85 KiB) Viewed 7759 times
to something like:
Name:Address(es) comma separated : TPLink:192.168.0.1, MacBook:192.168.0.2, ESP8266:192.168.0.49

More work, I know :-)

Keep up the good work, let me know I you want me to do some alpha/beta testing of your plugin.
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Network Pinger (Native ICMP)

Post by Dnpwwo »

@gerardwr,

You can change the name of the device in Domoticz to anything you want using the normal "Edit" button in the "Switches" tab. The plugin sets a default name but does not rely on it remaining the same.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest