Skip to content

Commit

Permalink
SMTP Mail sending in docker container and documentation for sending m…
Browse files Browse the repository at this point in the history
…ail with msmtp (#2809)

* Add msmtp to allow sending mail in the docker container. 

Config file should be in /home/oxidized/.config/oxidized/.msmtprc

* Include sending mail in documentation

* Apply correct rights to the .msmtprc file

* Wrong file to setup access rights

* Added required files and directory (cannot chmod a broken symlink)

* oxodized -> oxidized

* Update CHANGELOG.md

* Remove useless line in msmtp default config.

* Remove useless option in msmtp command
  • Loading branch information
Krafting authored Jul 4, 2023
1 parent 43c4420 commit bd8d579
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## Added
- model for D-Link cisco like CLI (@mirackle-spb)

+ Added ability to send mail with the Docker container
+ Documentation to send mail with hooks

## Changed

## Fixed
Expand Down
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM docker.io/phusion/baseimage:jammy-1.0.1

# set up dependencies for the build process
RUN apt-get -yq update \
&& apt-get -yq --no-install-recommends install ruby3.0 ruby3.0-dev libssl3 bzip2 libssl-dev pkg-config make cmake libssh2-1 libssh2-1-dev git git-email libmailtools-perl g++ libffi-dev ruby-bundler libicu70 libicu-dev libsqlite3-0 libsqlite3-dev libmysqlclient21 libmysqlclient-dev libpq5 libpq-dev zlib1g-dev \
&& apt-get -yq --no-install-recommends install ruby3.0 ruby3.0-dev libssl3 bzip2 libssl-dev pkg-config make cmake libssh2-1 libssh2-1-dev git git-email libmailtools-perl g++ libffi-dev ruby-bundler libicu70 libicu-dev libsqlite3-0 libsqlite3-dev libmysqlclient21 libmysqlclient-dev libpq5 libpq-dev zlib1g-dev msmtp \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -39,6 +39,17 @@ ARG UID=30000
ARG GID=$UID
RUN groupadd -g "${GID}" -r oxidized && useradd -u "${UID}" -r -m -d /home/oxidized -g oxidized oxidized

# link config for msmtp for easier use.
RUN ln -s /home/oxidized/.config/oxidized/.msmtprc /home/oxidized/

# create parent directory & touch required file
RUN mkdir -p /home/oxidized/.config/oxidized/
RUN touch /home/oxidized/.config/oxidized/.msmtprc

# setup the access to the file
RUN chmod 600 /home/oxidized/.msmtprc
RUN chown oxidized:oxidized /home/oxidized/.msmtprc

# add runit services
COPY extra/oxidized.runit /etc/service/oxidized/run
COPY extra/auto-reload-config.runit /etc/service/auto-reload-config/run
Expand Down
38 changes: 37 additions & 1 deletion docs/Hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Exec hook recognizes the following configuration keys:
* `async`: Execute the command in an asynchronous fashion. The main thread by default will wait for the hook command execution to complete. Set this to `true` for long running commands so node configuration pulls are not blocked. Default: `false`
* `cmd`: command to run.

### exec hook configuration example
### Exec Hook configuration example

```yaml
hooks:
Expand All @@ -62,6 +62,42 @@ hooks:
timeout: 120
```
### Exec Hook configuration example to send mail
To send mail you need the package `msmtp` (It is pre-installed with the docker container)

You then need to update the `~/.msmtprc` file to contain your SMTP credentials like this:

*Note: In the docker container the file is in /home/oxidized/.config/oxidized/.msmtprc so you can create the file if it doesn't exist in your oxidized config folder.*

```cfg
# Default settings
defaults
auth on
tls on
# Outlook SMTP
account mainaccount
host smtp.office365.com
port 587
from [email protected]
user [email protected]
password edit-password
account default : mainaccount
```

For non docker users this file should have the 600 permission, using: `chmod 600 .msmtprc` and the owner of the file should be the owner of oxidized `chown oxidized:oxidized .msmtprc`

Then, you can configure Hooks to send mail like this:

```yaml
hooks:
send_mail_hook:
type: exec
events: [node_fail]
cmd: '/usr/bin/echo -e "Subject: [Oxidized] Error on node $OX_NODE_NAME \n\nThe device $OX_NODE_NAME has not been backed-up, reason: \n\n$OX_EVENT: $OX_ERR_REASON" | msmtp [email protected]'
```

## Hook type: githubrepo

Note: You must not use the same name as any local repo configured under output. Make sure your 'git' output has a unique name that does not match your remote_repo.
Expand Down

0 comments on commit bd8d579

Please sign in to comment.