-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
6aaed04
commit f362626
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ terminates, the program's stdin will see EOF. The program must then | |
terminate. The message format passed to the program can, as usual, be | ||
modified by defining rsyslog templates. | ||
|
||
If you need to invoke a program per every message, a wrapper can be | ||
used, see :ref:`omprog-example-msmtp`. | ||
|
||
Note that in order to execute the given program, rsyslog needs to have | ||
sufficient permissions on the binary file. This is especially true if | ||
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 | |
program stores and confirms each log individually. | ||
|
||
|
||
.. _omprog-example-msmtp: | ||
|
||
Example: sending mail to a smart host with authentication | ||
--------------------------------------------------------- | ||
|
||
Here we rely on an additional POSIX shell script to execute a command per each | ||
message. | ||
|
||
.. code-block:: none | ||
module(load="omprog") | ||
template(name="mailData" type="string" string="Subject: disk problem on %hostname%\n\nRSYSLOG Alert\nmsg='%msg%'\n__RSYSLOG_ENDMSG__\n") | ||
if $msg contains "hard disk fatal failure" then { | ||
action(type="omprog" | ||
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]" | ||
template="mailData" | ||
confirmMessages="on") | ||
} | ||
The ``omprog-dequeue.sh`` source: | ||
|
||
.. code-block:: bash | ||
#!/bin/sh | ||
echo OK | ||
while read -r line; do | ||
if [ "$line" = "__RSYSLOG_ENDMSG__" ]; then | ||
if echo "$msg" | "$@"; then | ||
echo OK | ||
else | ||
echo ERROR | ||
fi | ||
msg="" | ||
else | ||
msg="${msg:+$msg | ||
}$line" | ||
fi | ||
done | ||
|FmtObsoleteName| directives | ||
============================ | ||
|
||
|