Skip to content

Commit b85a278

Browse files
committed
omprog: add example script to run an app for each message
This adds a simple POSIX shell script that can be used to execute an program for every log message (as the legacy ^ action). Since the example shows how to use it to send mail, a reference is added to the ommail page too.
1 parent e09aa61 commit b85a278

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

source/configuration/modules/ommail.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ the module implements only the bare SMTP essentials. Most importantly,
199199
it does not provide any authentication capabilities. So your mail server
200200
must be configured to accept incoming mail from ommail without any
201201
authentication needs (this may be change in the future as need arises,
202-
but you may also be referred to sendmail-mode).
202+
but you may also be referred to sendmail-mode). A suitable minimal
203+
server ``msmtpd`` is part of `msmtp <https://marlam.de/msmtp/>`_
204+
software and can be run locally to forward all the mail to a smart host
205+
with support for TLS and authentication.
203206

204207
In theory, ommail should also offer a mode where it uses the sendmail
205208
utility to send its mail (sendmail-mode). This is somewhat less reliable
@@ -213,6 +216,9 @@ delivery without a SMTP server being present. Sendmail mode will be
213216
implemented as need arises. So if you need it, please drop us a line (If
214217
nobody does, sendmail mode will probably never be implemented).
215218

219+
Alternatively, consider using `omprog` as shown in
220+
:ref:`omprog-example-msmtp`.
221+
216222

217223
Examples
218224
========

source/configuration/modules/omprog.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ terminates, the program's stdin will see EOF. The program must then
2525
terminate. The message format passed to the program can, as usual, be
2626
modified by defining rsyslog templates.
2727

28+
If you need to invoke a program per every message, a wrapper can be
29+
used, see :ref:`omprog-example-msmtp`.
30+
2831
Note that in order to execute the given program, rsyslog needs to have
2932
sufficient permissions on the binary file. This is especially true if
3033
not running as root. Also, keep in mind that default SELinux policies
@@ -524,6 +527,50 @@ Note that the ``useTransactions`` flag is not used in this example. The
524527
program stores and confirms each log individually.
525528

526529

530+
.. _omprog-example-msmtp:
531+
532+
Example: sending mail to a smart host with authentication
533+
---------------------------------------------------------
534+
535+
Here we rely on an additional POSIX shell script to execute a command per each
536+
message.
537+
538+
.. code-block:: none
539+
540+
module(load="omprog")
541+
542+
template(name="mailData" type="string" string="Subject: disk problem on %hostname%\n\nRSYSLOG Alert\nmsg='%msg%'\n__RSYSLOG_ENDMSG__\n")
543+
544+
if $msg contains "hard disk fatal failure" then {
545+
action(type="omprog"
546+
binary="/usr/share/logging/omprog-dequeue.sh /usr/bin/msmtp --auth=on --tls=on --tls-starttls=on --host=mail.example.net --port=587 [email protected] \"--passwordeval=echo rsyslog-password\" [email protected] [email protected]"
547+
template="mailData"
548+
confirmMessages="on")
549+
}
550+
551+
The ``omprog-dequeue.sh`` source:
552+
553+
.. code-block:: bash
554+
555+
#!/bin/sh
556+
557+
echo OK
558+
559+
while read -r line; do
560+
if [ "$line" = "__RSYSLOG_ENDMSG__" ]; then
561+
if echo "$msg" | "$@"; then
562+
echo OK
563+
else
564+
echo ERROR
565+
fi
566+
msg=""
567+
else
568+
msg="${msg:+$msg
569+
}$line"
570+
fi
571+
done
572+
573+
527574
|FmtObsoleteName| directives
528575
============================
529576

0 commit comments

Comments
 (0)