Skip to content

Commit f362626

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 6aaed04 commit f362626

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
@@ -528,6 +531,50 @@ Note that the ``useTransactions`` flag is not used in this example. The
528531
program stores and confirms each log individually.
529532

530533

534+
.. _omprog-example-msmtp:
535+
536+
Example: sending mail to a smart host with authentication
537+
---------------------------------------------------------
538+
539+
Here we rely on an additional POSIX shell script to execute a command per each
540+
message.
541+
542+
.. code-block:: none
543+
544+
module(load="omprog")
545+
546+
template(name="mailData" type="string" string="Subject: disk problem on %hostname%\n\nRSYSLOG Alert\nmsg='%msg%'\n__RSYSLOG_ENDMSG__\n")
547+
548+
if $msg contains "hard disk fatal failure" then {
549+
action(type="omprog"
550+
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]"
551+
template="mailData"
552+
confirmMessages="on")
553+
}
554+
555+
The ``omprog-dequeue.sh`` source:
556+
557+
.. code-block:: bash
558+
559+
#!/bin/sh
560+
561+
echo OK
562+
563+
while read -r line; do
564+
if [ "$line" = "__RSYSLOG_ENDMSG__" ]; then
565+
if echo "$msg" | "$@"; then
566+
echo OK
567+
else
568+
echo ERROR
569+
fi
570+
msg=""
571+
else
572+
msg="${msg:+$msg
573+
}$line"
574+
fi
575+
done
576+
577+
531578
|FmtObsoleteName| directives
532579
============================
533580

0 commit comments

Comments
 (0)