2020-12-06 16:59:16 +01:00
# execNotify
2021-07-22 16:20:03 +02:00
* Send email notification if command fails with [de-p1st-execNotify ](src/de/p1st/exec_notify/execNotify.py ).
* Send unconditional notifications with [de-p1st-notify ](src/de/p1st/exec_notify/notify.py ).
2020-12-26 15:36:20 +01:00
2021-07-22 17:11:23 +02:00
## Installation - venv
2020-12-06 16:59:16 +01:00
2021-07-22 16:20:03 +02:00
More detailed instructions about _venv_ can be found at [https://docs.python.org/3/library/venv.html ](https://docs.python.org/3/library/venv.html )
Create a _venv_ :
```shell
python3 -m venv ~/execNotify/venv
```
Activate the venv:
2020-12-06 16:59:16 +01:00
```shell
2021-07-22 16:20:03 +02:00
source ~/execNotify/venv/bin/activate
# echo "VIRTUAL_ENV=${VIRTUAL_ENV}"
```
Option A: Install the module from TestPyPI:
```shell
2021-07-22 17:11:23 +02:00
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps --upgrade de.p1st.exec-notify
2020-12-06 16:59:16 +01:00
```
2021-07-22 13:01:18 +02:00
The above command uses the parameter `--no-deps` :
> Since TestPyPI doesn’ t have the same packages as the live PyPI, it’ s possible that attempting
> to install dependencies may fail or install something unexpected. While this package
> doesn’ t have any dependencies, it’ s a good practice to avoid installing dependencies when
> using TestPyPI.
2021-07-22 16:20:03 +02:00
Option B: Install from local directory
```shell
python3 -m pip install ~/Downloads/git/execNotify/
```
(Optionally) list installed modules:
```shell
pip list
```
2021-11-23 19:31:33 +01:00
## Installation - global
2021-07-22 17:11:23 +02:00
2021-11-23 19:31:02 +01:00
Requires `pip` (e.g. `pacman -S --needed python-pip` ):
2021-07-22 17:11:23 +02:00
```shell
2021-07-24 16:12:34 +02:00
sudo python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps de.p1st.exec-notify
2021-07-22 17:11:23 +02:00
```
2022-01-05 16:38:06 +01:00
Note: Make sure that pip is up-to-date and matches your python version:
```shell
python --version
#=> Python 3.10.1
pip --version
#=> pip 20.3.4 from /usr/lib/python3.10/site-packages/pip (python 3.10)
```
2021-07-22 13:01:18 +02:00
## Configuration
2021-11-23 19:18:38 +01:00
Create configuration file `/etc/execNotify/cfg.ini` :
2021-07-22 13:01:18 +02:00
2021-11-23 19:18:38 +01:00
```shell
install -Dm0600 /etc/execNotify/cfg.ini < < 'EOF'
[DEFAULT]
[mail]
host = smtp.example.com
port = 465
password = examplePassword
from = noreply@example.com
to = me@example.com
[file]
maildir = /home/exampleUser/mail/
EOF
```
See also: [./etc/execNotify/cfg.ini.example ](etc/execNotify/cfg.ini.example )
2021-07-22 13:01:18 +02:00
## Usage
### Usage of execNotify
2020-12-06 16:59:16 +01:00
2021-07-22 16:20:03 +02:00
Add `de-p1st-execNotify` in front of your command to execute.
2020-12-06 16:59:16 +01:00
2021-07-22 13:01:18 +02:00
**Example:**
2020-12-06 16:59:16 +01:00
2021-07-22 16:20:03 +02:00
`de-p1st-execNotify ls /non/existent/file` will mail you the exit code, stdout and stderr of `ls /non/existent/file`
2020-12-26 15:36:20 +01:00
2021-07-22 13:01:18 +02:00
### Usage of notify
2020-12-26 15:36:20 +01:00
Send stdout via mail:
2021-07-22 16:20:03 +02:00
`echo "Hello world!" | de-p1st-notify`
2020-12-26 15:36:20 +01:00
2021-07-22 13:01:18 +02:00
Send stdout and stderr via mail:
2020-12-26 15:36:20 +01:00
2021-07-22 16:20:03 +02:00
`echo "Hello world!" 2>&1 | de-p1st-notify`
2020-12-26 15:36:20 +01:00
2021-07-22 13:01:18 +02:00
Send stdout and specify an optional email subject:
2020-12-26 15:36:20 +01:00
2021-07-22 16:20:03 +02:00
`echo "Hello world!" | de-p1st-notify "someSubject"`
2021-07-22 13:01:18 +02:00
Send message without using a pipe:
2020-12-26 15:36:20 +01:00
2021-07-22 16:20:03 +02:00
`de-p1st-notify "someSubject" "Hello World! What's up?"`
2021-07-22 13:01:18 +02:00
## Development
When started with environment variable `DE_P1ST_EXEC_NOTIFY` set,
then the configuration file is read from [./etc/execNotify/cfg.ini ](etc/execNotify/cfg.ini ).
2021-07-22 16:20:03 +02:00
### Testing
See heading "Installation" above with steps to locally install this module.
2021-07-22 13:01:18 +02:00
### Uploading to TestPyPI
2021-07-22 16:20:03 +02:00
More detailed instructions can be found at [https://packaging.python.org/tutorials/packaging-projects/ ](https://packaging.python.org/tutorials/packaging-projects/ )
2021-07-22 13:01:18 +02:00
2021-07-22 16:20:03 +02:00
1) Set up a _venv_
2021-07-22 13:01:18 +02:00
2) Increase/Adjust `[metadata][version]` in [setup.cfg ](setup.cfg )
3) Install the `build` and `twine` modules to your _venv_ .
4) Next generate a [distribution archive ](https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives ):
```shell
python3 -m build
```
5) Upload the distribution packages with twine. For the username, use `__token__` . For the password, use a
[test.pypi.org API token ](https://test.pypi.org/manage/account/#api-tokens ):
```shell
python3 -m twine upload --repository testpypi dist/*
```
6) Congratulations! You can view the uploaded module under:
2021-07-24 12:19:56 +02:00
* [https://test.pypi.org/project/de.p1st.exec_notify/ ](https://test.pypi.org/project/de.p1st.exec_notify/ )