Giter Club home page Giter Club logo

outage-detector's Introduction

Outage Detector

Simple module meant to notify user if a power outage has occured or if the internet has been down.

What it does

At every run it writes to a text file timestamps for power and internet, whether the last run was scheduled or at boot and the last calculated periodicity.

If the script was run after a boot up, it will assume there was a power outage (the system is meant to run 24/7, for example a Raspberry Pi Zero) and send a notification, approximating the power outage duration through the last known timestamp and calculated periodicity of the runs.

Internet downtime is detected if the 2 timestamps written to the file differ and the downtime is approximated again through the calculated periodicity. It is possible that an internet downtime is missed if the script is run too rarely.

How to run it

Install the module in a virtual environment with pip:

pip3 install Outage-Detector

Alternatively, you can also install the module by cloning this git repo and running setup.py

git clone https://github.com/fabytm/Outage-Detector.git
python3 setup.py install

Afterwards, all you need to do is to run the outage_detector command line interface for the initialization process:

outage_detector --init

From here you can choose the way you want to be notified and will be prompted to enter your e-mail information, PushBullet API key or IFTTT API key.

Additionally, it will also ask you if you want to set up scheduling for this module. Choosing to do so is recommended for inexperienced users (this will create 2 cron jobs, one running at boot time and one every 5 minutes, to check in on internet status and record timestamp if either the internet connection drops or a power outage happens).

Update the module to the latest version in a virtual environment with pip:

pip3 install Outage-Detector --upgrade

How to setup IFTTT

Install the IFTTT app and either create an account or sign in to an existing account and create a new applet.

Next, select the plus button beside the word This and choose the Webhooks service. Select Recieve a web request and click Connect. Choose an event name — you will need to remember this for later.

Select the plus button beside the word That and choose any action that you like. Clear everything from the message text box and choose Value1 from the Insert Ingredients menu. Enter any necessary information and press finish.

Select the Webhooks icon in the top left of the screen and press the Documentation button (in a web browser). This will give you a key which you will need for initialization.

Finally, complete the outage_detector initialization process by running the command above.

outage-detector's People

Contributors

fabytm avatar imaandrew avatar p1r473 avatar rotv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

outage-detector's Issues

install error code

all good to this point
(ven) pi@raspberrypi:~/python $ pip install Outage_Detector

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Outage_Detector
Using cached https://files.pythonhosted.org/packages/9b/65/a20474877ef2c6beb23c382e7882902bd37fb8a9f7672d781497ba625c92/Outage_Detector-1.1.2-py3-none-any.whl
Requirement already satisfied: certifi==2019.9.11 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2019.9.11)
Requirement already satisfied: six==1.13.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (1.13.0)
Requirement already satisfied: websocket-client==0.56.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.56.0)
Requirement already satisfied: requests==2.22.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.22.0)
Collecting keyring==20.0.1 (from Outage_Detector)
Using cached https://files.pythonhosted.org/packages/f1/07/0afb82d449d210a332d126978634470abdd0c754128a9ead8bbe78eb1b43/keyring-20.0.1-py2.py3-none-any.whl
Requirement already satisfied: chardet==3.0.4 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (3.0.4)
Requirement already satisfied: keyrings.alt==3.2.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (3.2.0)
Requirement already satisfied: python-magic==0.4.15 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.4.15)
Requirement already satisfied: pushbullet.py==0.11.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.11.0)
Requirement already satisfied: urllib3==1.25.6 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (1.25.6)
Requirement already satisfied: python-crontab==2.4.2 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.4.2)
Requirement already satisfied: idna==2.8 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.8)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in ./ven/lib/python3.7/site-packages (from keyring==20.0.1->Outage_Detector) (1.7.0)
Collecting secretstorage; sys_platform == "linux" (from keyring==20.0.1->Outage_Detector)
Using cached https://files.pythonhosted.org/packages/c3/50/8a02cad020e949e6d7105f5f4530d41e3febcaa5b73f8f2148aacb3aeba5/SecretStorage-3.1.2-py3-none-any.whl
Requirement already satisfied: python-dateutil in ./ven/lib/python3.7/site-packages (from python-crontab==2.4.2->Outage_Detector) (2.8.1)
Requirement already satisfied: zipp>=0.5 in ./ven/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->keyring==20.0.1->Outage_Detector) (3.1.0)
Collecting cryptography (from secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector)
Using cached https://www.piwheels.org/simple/cryptography/cryptography-3.1-cp37-cp37m-linux_armv7l.whl
Requirement already satisfied: jeepney>=0.4.2 in ./ven/lib/python3.7/site-packages (from secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector) (0.4.3)
Collecting cffi!=1.11.3,>=1.8 (from cryptography->secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector)
Using cached https://files.pythonhosted.org/packages/f7/09/88bbe20b76ca76be052c366fe77aa5e3cd6e5f932766e5597fecdd95b2a8/cffi-1.14.2.tar.gz
Requirement already satisfied: pycparser in ./ven/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector) (2.20)
Building wheels for collected packages: cffi
Running setup.py bdist_wheel for cffi ... error
Complete output from command /home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-ar9irn2l/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-se20s6b6 --python-tag cp37:
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for cffi
Running setup.py clean for cffi
Failed to build cffi
Installing collected packages: cffi, cryptography, secretstorage, keyring, Outage-Detector
Running setup.py install for cffi ... error
Complete output from command /home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-ar9irn2l/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-ii_cybhs/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/python/ven/include/site/python3.7/cffi:

Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.7
creating build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/pkgconfig.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/init.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/lock.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_gen.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/commontypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/error.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/model.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/recompiler.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/ffiplatform.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/cparser.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/api.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/verifier.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_include.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/parse_c_type.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_embedding.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-armv7l-3.7/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-armv7l-3.7
creating build/temp.linux-armv7l-3.7/c
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/home/pi/python/ven/include -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.7/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------

Command "/home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-ar9irn2l/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-ii_cybhs/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/python/ven/include/site/python3.7/cffi" failed with error code 1 in /tmp/pip-install-ar9irn2l/cffi/
(ven) pi@raspberrypi:/python $ outage_detector --init
bash: outage_detector: command not found
(ven) pi@raspberrypi:
/python $ pip install Outage_Detector --upgrade
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Outage_Detector
Using cached https://files.pythonhosted.org/packages/9b/65/a20474877ef2c6beb23c382e7882902bd37fb8a9f7672d781497ba625c92/Outage_Detector-1.1.2-py3-none-any.whl
Requirement already satisfied, skipping upgrade: pushbullet.py==0.11.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.11.0)
Requirement already satisfied, skipping upgrade: keyrings.alt==3.2.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (3.2.0)
Requirement already satisfied, skipping upgrade: websocket-client==0.56.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.56.0)
Requirement already satisfied, skipping upgrade: idna==2.8 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.8)
Requirement already satisfied, skipping upgrade: urllib3==1.25.6 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (1.25.6)
Collecting keyring==20.0.1 (from Outage_Detector)
Using cached https://files.pythonhosted.org/packages/f1/07/0afb82d449d210a332d126978634470abdd0c754128a9ead8bbe78eb1b43/keyring-20.0.1-py2.py3-none-any.whl
Requirement already satisfied, skipping upgrade: six==1.13.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (1.13.0)
Requirement already satisfied, skipping upgrade: certifi==2019.9.11 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2019.9.11)
Requirement already satisfied, skipping upgrade: chardet==3.0.4 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (3.0.4)
Requirement already satisfied, skipping upgrade: python-magic==0.4.15 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (0.4.15)
Requirement already satisfied, skipping upgrade: python-crontab==2.4.2 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.4.2)
Requirement already satisfied, skipping upgrade: requests==2.22.0 in ./ven/lib/python3.7/site-packages (from Outage_Detector) (2.22.0)
Collecting secretstorage; sys_platform == "linux" (from keyring==20.0.1->Outage_Detector)
Using cached https://files.pythonhosted.org/packages/c3/50/8a02cad020e949e6d7105f5f4530d41e3febcaa5b73f8f2148aacb3aeba5/SecretStorage-3.1.2-py3-none-any.whl
Requirement already satisfied, skipping upgrade: importlib-metadata; python_version < "3.8" in ./ven/lib/python3.7/site-packages (from keyring==20.0.1->Outage_Detector) (1.7.0)
Requirement already satisfied, skipping upgrade: python-dateutil in ./ven/lib/python3.7/site-packages (from python-crontab==2.4.2->Outage_Detector) (2.8.1)
Collecting cryptography (from secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector)
Using cached https://www.piwheels.org/simple/cryptography/cryptography-3.1-cp37-cp37m-linux_armv7l.whl
Requirement already satisfied, skipping upgrade: jeepney>=0.4.2 in ./ven/lib/python3.7/site-packages (from secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector) (0.4.3)
Requirement already satisfied, skipping upgrade: zipp>=0.5 in ./ven/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->keyring==20.0.1->Outage_Detector) (3.1.0)
Collecting cffi!=1.11.3,>=1.8 (from cryptography->secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector)
Using cached https://files.pythonhosted.org/packages/f7/09/88bbe20b76ca76be052c366fe77aa5e3cd6e5f932766e5597fecdd95b2a8/cffi-1.14.2.tar.gz
Requirement already satisfied, skipping upgrade: pycparser in ./ven/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->secretstorage; sys_platform == "linux"->keyring==20.0.1->Outage_Detector) (2.20)
Building wheels for collected packages: cffi
Running setup.py bdist_wheel for cffi ... error
Complete output from command /home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-jqmiky2p/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-a_inbhi7 --python-tag cp37:
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for cffi
Running setup.py clean for cffi
Failed to build cffi
Installing collected packages: cffi, cryptography, secretstorage, keyring, Outage-Detector
Running setup.py install for cffi ... error
Complete output from command /home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-jqmiky2p/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-vkxmj8tk/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/python/ven/include/site/python3.7/cffi:
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.7
creating build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/pkgconfig.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/init.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/lock.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_gen.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/commontypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/error.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/model.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/recompiler.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/ffiplatform.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/cparser.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/api.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/verifier.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_include.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/parse_c_type.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_embedding.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-armv7l-3.7/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-armv7l-3.7
creating build/temp.linux-armv7l-3.7/c
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/home/pi/python/ven/include -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.7/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------

Command "/home/pi/python/ven/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-jqmiky2p/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-vkxmj8tk/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/python/ven/include/site/python3.7/cffi" failed with error code 1 in /tmp/pip-install-jqmiky2p/cffi/

As you can see - opted for the update, did reboot, reset virtual environment - any clues?
running on 3B 2.1

thanks

Won't install on any PI or even a debian OS

pip install Outage-Detector produces this error on all my Pi's I have which are 2/3/4

Collecting keyring==21.2.0 (from Outage-Detector)
  Could not find a version that satisfies the requirement keyring==21.2.0 (from Outage-Detector) (from versions: 0.0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.5.1, 0.6.2, 0.7, 0.7.1, 0.8, 0.8.1, 0.9, 0.9.1, 0.9.2, 0.9.3, 0.10, 0.10.1, 1.0, 1.1, 1.1.1, 1.1.2, 1.2.dev0, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.4, 1.5, 1.6, 1.6.1, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 3.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1, 3.2, 3.2.1, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 4.0, 4.1, 4.1.1, 5.0, 5.1, 5.2, 5.2.1, 5.3, 5.4, 5.5, 5.5.1, 5.6, 5.7, 5.7.1, 6.0, 6.1, 6.1.1, 7.0, 7.0.1, 7.0.2, 7.1, 7.1.1, 7.1.2, 7.2, 7.3, 7.3.1, 8.0, 8.0.1, 8.1, 8.1.1, 8.2, 8.3, 8.4, 8.4.1, 8.5, 8.5.1, 8.6, 8.6.1, 8.7, 9.0, 9.1, 9.2, 9.2.1, 9.3, 9.3.1, 10.0, 10.0.1, 10.0.2, 10.1, 10.2, 10.3, 10.3.1, 10.3.2, 10.3.3, 10.4.0, 10.5.0, 10.5.1, 10.6.0, 11.0.0, 11.1.0, 12.0.0, 12.0.1, 12.0.2, 12.1.0, 12.2.0, 12.2.1, 13.0.0, 13.1.0, 13.2.0, 13.2.1, 15.0.0, 15.1.0, 15.2.0, 16.0.0, 16.0.1, 16.0.2, 16.1.0, 16.1.1, 17.0.0, 17.1.0, 17.1.1, 18.0.0, 18.0.1, 19.0.0, 19.0.1, 19.0.2, 19.1.0, 19.2.0, 19.3.0, 20.0.0, 20.0.1, 21.0.0, 21.1.0)
No matching distribution found for keyring==21.2.0 (from Outage-Detector)

Building from the git sources I get the same error
error: The 'keyrings.alt==3.4.0' distribution was not found and is required by Outage-Detector

IFTTT Support

I've been working on adding IFTTT support to outage detector but I would like your opinion on it before I continue more. I already use IFTTT for many things and it would be more convenient to receive outage notifications through it.

I wasn't sure if you would be fine with it or would rather keep it to one push notification service.

Prompted to enter password for keyring

Failing to run both manually and through cron due to being prompted for keyring password every time

Running it manually asks for the keyring password:

/usr/bin/python3 /usr/local/bin/outage_detector --run scheduled --notify notification
Please enter password for encrypted keyring:

error.txt showing the cronjob failing:

/usr/lib/python3.7/getpass.py:91: GetPassWarning: Can not control echo on the terminal.
  passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Please enter password for encrypted keyring: Traceback (most recent call last):
  File "/usr/lib/python3.7/getpass.py", line 69, in unix_getpass
    old = termios.tcgetattr(fd)     # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/outage_detector", line 33, in <module>
    sys.exit(load_entry_point('Outage-Detector==1.1.2', 'console_scripts', 'outage_detector')())
  File "/usr/local/lib/python3.7/dist-packages/Outage_Detector-1.1.2-py3.7.egg/outagedetector/__main__.py", line 20, in main
  File "/usr/local/lib/python3.7/dist-packages/Outage_Detector-1.1.2-py3.7.egg/outagedetector/outage_detector.py", line 71, in check_power_and_internet
  File "/usr/local/lib/python3.7/dist-packages/keyring-20.0.1-py3.7.egg/keyring/core.py", line 56, in get_password
    return _keyring_backend.get_password(service_name, username)
  File "/usr/local/lib/python3.7/dist-packages/keyring-20.0.1-py3.7.egg/keyring/backends/chainer.py", line 43, in get_password
    password = keyring.get_password(service, username)
  File "/usr/local/lib/python3.7/dist-packages/keyrings.alt-3.2.0-py3.7.egg/keyrings/alt/file_base.py", line 118, in get_password
    password = self.decrypt(password_encrypted, assoc).decode('utf-8')
  File "/usr/local/lib/python3.7/dist-packages/keyrings.alt-3.2.0-py3.7.egg/keyrings/alt/file.py", line 216, in decrypt
    cipher = self._create_cipher(self.keyring_key, data['salt'], data['IV'])
  File "/usr/local/lib/python3.7/dist-packages/keyring-20.0.1-py3.7.egg/keyring/util/properties.py", line 59, in __get__
    return self.fget(obj)
  File "/usr/local/lib/python3.7/dist-packages/keyrings.alt-3.2.0-py3.7.egg/keyrings/alt/file.py", line 94, in keyring_key
    self._unlock()
  File "/usr/local/lib/python3.7/dist-packages/keyrings.alt-3.2.0-py3.7.egg/keyrings/alt/file.py", line 179, in _unlock
    'Please enter password for encrypted keyring: '
  File "/usr/lib/python3.7/getpass.py", line 91, in unix_getpass
    passwd = fallback_getpass(prompt, stream)
  File "/usr/lib/python3.7/getpass.py", line 126, in fallback_getpass
    return _raw_input(prompt, stream)
  File "/usr/lib/python3.7/getpass.py", line 148, in _raw_input
    raise EOFError
EOFError

setting up mail in --init step

I am having trouble getting this setup to use an SMTP server to send alerts.

This is the output after entering account, password, port, etc. I have tried an Apple mail (me.com) with app-password (2FA is set up on the account), as well as local ISP mail account without 2FA setup. This ends back at a prompt and does not go further.

Traceback (most recent call last):
File "/home/pi/python/ven/bin/outage_detector", line 10, in
sys.exit(main())
File "/home/pi/python/ven/lib/python3.7/site-packages/outagedetector/main.py", line 18, in main
config.initialize()
File "/home/pi/python/ven/lib/python3.7/site-packages/outagedetector/initial_config.py", line 71, in initialize
"Mail sent successfully!", json_data["smtp_server"], password, json_data["port"])
File "/home/pi/python/ven/lib/python3.7/site-packages/outagedetector/send_mail.py", line 40, in send_mail
with SMTP_SSL(smtp_server, port, context=context) as server:
File "/usr/lib/python3.7/smtplib.py", line 1031, in init
source_address)
File "/usr/lib/python3.7/smtplib.py", line 251, in init
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.7/smtplib.py", line 1039, in _get_socket
server_hostname=self._host)
File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)

possible feature

in your opinion it's possible to add an external monitoring service that send me a notification as soon as the pi goes offline?

sorry for use this section but i don't know where to ask you this
thanks in advance for responding

Encrypt Pushbullet Key

Hello,
Please consider encrypting the Pushbullet key so it is not sitting in plaintext on the drive.
Thanks.

Question on Internet Down calculation

Hi Fab. First off great tool. Using it to monitor a remote residence for power outages. Working perfect except for a slight difference I'm seeing when no power outage is being detected, but Internet Down is. The internet service is satellite and does have a 80-120ms latency, just wondering if that could be involved in the calculation or is the script only pinging the local router ? It makes sense that at power down times I'd get both as the Internet is down too, but this morning I received several Internet down without power down messages. Thoughts ?

Code on an old Pi

G'day
Not an issue
I tried installing on an old pi B+ without success.
Is there a change that needs to be made in the code to make it install on this version?
No problem if there is no solution. I wanted to use one of these because I have lots of them .

Suggestions

I was looking for something that would alert me when I lost connectivity, or power and I landed on your software. I'd love to see the following updates/implementations!

  1. Better clarification on installation instructions, and available commands for this program.
    Your youtube video description has more commands that were more useful to me than using the Github page.

  2. Clarification on Power Outage time range or ability to set notification wording and range
    (For the above; I have my outage-detector setup using Pushbullet, and will receive a notification that the power was out for 0-11 minutes, also received the following "power was out for 0 to 0 minutes" even though it was offline for 5 minutes.)

  3. iOS support ?
    Clarifying that you can use IFTTT and Pushsafer (I am currently testing this and it works great).
    https://www.pushsafer.com/ifttt

It looks like Value 1 states the following "Power was out for 2-2 minutes at 09:19. Address: mypiholename" based on the IFTTT configuration when using --init
Value 2 and Value 3 aren't used - but I would like to see these be able to be configured to provide better clarification on other things. Possibly user set notifications?
EventName uses the IFTTT Event Name, and the Outage-Detector event name.
OccuredAt (using IFTTT) will timestamp with the following output: October 29, 2021 at 09:19AM

Also clarifying that when setting up IFTTT, you cannot not use a JSON payload, and must use a web request.
And to get your API key for webhooks, once you're at a page that says "Create/Documentation" you get your API key from the Documentation page at the top.

  1. Setup of a CRON task to auto update or have the ability to do so?
  2. Using outage_detector --run scheduled -- notify notification I can see the following output:
    Script has run at 29-10-2021 09-44-27. Internet connected: True. Just booted: False.

Clarification on the date/time stamp (I was confused by the 09-44-27 until I realised it was the timestamp) "Internet connected: true, Just booted: false" when I literally rebooted the raspberry pi, seems incorrect.

Thanks!

How to back up settings?

Hi,
Ive backed up my config.json file

But, how do I back up my keyring?
It currently stores my Pushbullet API key

The reason I want to back up the keyring is to not have to reinitialize all my apps every time I reformat... I always back up my app's config files, however this is the first time an app has used the keyring

pip3 install Outage-Detector doesn't update prior version

Had previously installed older version. Trying to install v1.1. Running pip3 install Outage-Detector results in "Requirement already satisfied" for each requirement. Running outage-detector --init doesn't give option for IFTTT.

Can remove old installation manually, but believe installer should detect previous installs and handle gracefully. :-)

Need Help With Error Message

I am new to Python and need help with Outage-Detector (OD).
Installation is to a Raspberry Pi Zero with a fresh Buster installation (May 2020).
These are the steps I followed to install OD:
sudo apt update
sudo apt full-upgrade
sudo reboot
The above steps were not necessary as the Raspberry Pi OS performs them automatically with the initial setup.
sudo apt-get install python3-pip
sudo apt-get install python3-venv
cd ~
python3 -m venv od_venv # (o)utage (d)etector (v)irtual (env)ironment
source od_venv/bin/activate
At this point, the Bash prompt has changed to show that the virtual environment is active.
pip3 install Outage-Detector
outage_detector --init
Initialization appeared successful. I selected "mail" and immediately received an email test message.
I also selected "y"es to cron. An examination of the pi user's cron files show the additions have been made for OD.

To test, I shutdown the Pi for 10 minutes. After restarting, I received no email. The errors.txt file in ~/.config/outagedetector contains:

File "/home/pi/od_venv/bin/outage_detector", line 10, in
sys.exit(main())
File "/home/pi/od_venv/lib/python3.7/site-packages/outagedetector/main.py", line 20, in main
outage.check_power_and_internet(args.run, args.notify)
File "/home/pi/od_venv/lib/python3.7/site-packages/outagedetector/outage_detector.py", line 111, in check_power_and_internet
last_periodicity = int(file_data[3])
ValueError: invalid literal for int() with base 10: '4led'

What step(s) have I missed? What did I do wrong?

Thanks!

David B.

Initialization issue

Hi,

I followed all steps described here https://pypi.org/project/Outage-Detector/ and successfully installed your project without any issues on my Raspberry Pi 3 b+

OS Version

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

I checked all the dependencies, everything's seems to be fine.

When running the init command however I am getting a prompt error right after entering either my Pushbullet token or email password :

Input your IFTTT API key:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/util.py", line 46, in send_and_get_reply
return self._connection.send_and_get_reply(msg, unwrap=True)
File "/usr/local/lib/python3.9/dist-packages/jeepney-0.7.1-py3.9.egg/jeepney/io/blocking.py", line 190, in send_and_get_reply
return unwrap_msg(msg_in)
File "/usr/local/lib/python3.9/dist-packages/jeepney-0.7.1-py3.9.egg/jeepney/wrappers.py", line 214, in unwrap_msg
raise DBusErrorResponse(msg)
jeepney.wrappers.DBusErrorResponse: [org.freedesktop.DBus.Error.UnknownMethod] ('No such interface “org.freedesktop.DBus.Properties” on object at path /org/freedesktop/secrets/collection/login',)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/collection.py", line 161, in get_default_collection
return Collection(connection)
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/collection.py", line 44, in init
self._collection.get_property('Label')
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/util.py", line 64, in get_property
(signature, value), = self.send_and_get_reply(msg)
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/util.py", line 49, in send_and_get_reply
raise ItemNotFoundException('Item does not exist!') from resp
secretstorage.exceptions.ItemNotFoundException: Item does not exist!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/keyring-20.0.1-py3.9.egg/keyring/backends/SecretService.py", line 56, in get_preferred_collection
collection = secretstorage.get_default_collection(bus)
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/collection.py", line 163, in get_default_collection
return create_collection(connection, 'Default',
File "/usr/local/lib/python3.9/dist-packages/SecretStorage-3.3.1-py3.9.egg/secretstorage/collection.py", line 145, in create_collection
raise PromptDismissedException('Prompt dismissed.')
secretstorage.exceptions.PromptDismissedException: Prompt dismissed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/outage_detector", line 33, in
sys.exit(load_entry_point('Outage-Detector==1.1.2', 'console_scripts', 'outage_detector')())
File "/usr/local/lib/python3.9/dist-packages/Outage_Detector-1.1.2-py3.9.egg/outagedetector/main.py", line 18, in main
File "/usr/local/lib/python3.9/dist-packages/Outage_Detector-1.1.2-py3.9.egg/outagedetector/initial_config.py", line 124, in initialize
File "/usr/local/lib/python3.9/dist-packages/keyring-20.0.1-py3.9.egg/keyring/core.py", line 62, in set_password
_keyring_backend.set_password(service_name, username, password)
File "/usr/local/lib/python3.9/dist-packages/keyring-20.0.1-py3.9.egg/keyring/backends/chainer.py", line 50, in set_password
return keyring.set_password(service, username, password)
File "/usr/local/lib/python3.9/dist-packages/keyring-20.0.1-py3.9.egg/keyring/backends/SecretService.py", line 83, in set_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.9/dist-packages/keyring-20.0.1-py3.9.egg/keyring/backends/SecretService.py", line 58, in get_preferred_collection
raise InitError("Failed to create the collection: %s." % e)
keyring.errors.InitError: Failed to create the collection: Prompt dismissed..

Many thanks for your help !

Does not install to /usr/bin on Raspberry Pi

On Raspberry Pi (Debian Bullseye) using pip3 install method the script ends up in /home/[username]/.local/bin/outage_detector and NOT /usr/bin, as a result the crontab settings fail.

Using "crontab -e" to manually change the path for the outage_detector script resolves the issue.

Apologies I don't know enough to figure out how to fix this in python, but I guess you need to add a sanity check for where pip3 defaults to in Bullseye?

I have recreated this issue (and fixed it) on both a Raspberry Pi 4 and a Raspberry Pi 0 W using the most recent (as of this week) Raspberian Bullseye image.

(It's also necessary to add /home/[username]/.local/bin/outage_detector to the $PATH variable to be able to call it from another directory, but I'm not sure that's an issue so much as just how things work when they're installed to that location. I fixed it by adding "PATH=$PATH:/home/[username]/.local/bin/outage_detector" to the .bashrc startup config.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.