ping#

Description#

This integration allows you to:

  • Programmatic ping a remote host.

  • Monitor the status of a remote host.

Configuration#

ping:
  # [Optional]
  # Path to the ``ping`` executable. Default: the first ``ping`` executable found in PATH.
  # executable: ping  # type=str

  # [Optional]
  # Default number of packets that should be sent (default: 1).
  # count: 1  # type=int

  # [Optional]
  # Default timeout before failing a ping request (default: 5 seconds).
  # timeout: 5.0  # type=float

  # [Optional]
  # List of hosts to monitor. If not specified then no hosts will be monitored.
  # hosts:   # type=Optional[List[str]]

  # [Optional]
  # How often the hosts should be monitored (default: 10 seconds).
  # poll_interval: 20.0  # type=float

  # [Optional]
  # How long we should wait for any running
  # threads/processes to stop before exiting (default: 5 seconds).
  # stop_timeout: 5  # type=Optional[float]

  # [Optional]
  # If set to True then the plugin will not monitor
  # for new events. This is useful if you want to run a plugin in
  # stateless mode and only leverage its actions, without triggering any
  # events. Defaults to False.
  # disable_monitor: False  # type=bool

Dependencies#

Debian

apt install iputils-ping

Fedora

yum install iputils

Arch Linux

pacman -S iputils

Triggered events#

Actions#

Module reference#

class platypush.plugins.ping.PingPlugin(*_, **__)[source]#

Bases: RunnablePlugin, EntityManager

This integration allows you to:

  • Programmatic ping a remote host.

  • Monitor the status of a remote host.

__init__(executable: str = 'ping', count: int = 1, timeout: float = 5.0, hosts: List[str] | None = None, poll_interval: float = 20.0, **kwargs)[source]#
Parameters:
  • executable – Path to the ping executable. Default: the first ping executable found in PATH.

  • count – Default number of packets that should be sent (default: 1).

  • timeout – Default timeout before failing a ping request (default: 5 seconds).

  • hosts – List of hosts to monitor. If not specified then no hosts will be monitored.

  • poll_interval – How often the hosts should be monitored (default: 10 seconds).

main()[source]#

Implementation of the main loop of the plugin.

ping(host: str, count: int | None = None, timeout: float | None = None) dict[source]#

Ping a remote host.

Parameters:
  • host – Remote host IP or name

  • count – Overrides the configured number of packets that should be sent (default: 1).

  • timeout – Overrides the configured timeout before failing a ping request (default: 5 seconds).

Returns:

{
  "avg": 0.15,
  "host": "platypush.tech",
  "max": 0.2,
  "mdev": 0.05,
  "min": 0.1,
  "success": true
}

publish_entities(*_, **__) Collection[PingHost][source]#

Publishes a list of entities. The downstream consumers include:

It also accepts an optional callback that will be called when each of the entities in the set is flushed to the database.

You usually don’t need to override this class (but you may want to extend transform_entities() instead if your extension doesn’t natively handle Entity objects).

start()#

Start the plugin.

status() Collection[PingHost][source]#

Get the status of the monitored hosts. :return: Dictionary of monitored hosts and their status.

stop()#

Stop the plugin.

transform_entities(entities: Collection[dict | None], **_) Iterable[PingHost][source]#

This method takes a list of entities in any (plugin-specific) format and converts them into a standardized collection of Entity objects. Since this method is called by publish_entities() before entity updates are published, you may usually want to extend it to pre-process the entities managed by your extension into the standard format before they are stored and published to all the consumers.

wait_stop(timeout=None)#

Wait until a stop event is received.