Logmonrc

Type: object

logmon configuration file schema.

Examples

---
do:
  # Default action configuration inherited by all logfiles.
  action: smtp:alice:password123@example.com
  sender: alice@example.com
  receivers:
  - bob@example.com

logfiles:
# a simple list if no other configuration is needed
- "/var/log/service1.log"
- "/var/log/service2.log"
default:
  # Default logfile configuration inherited by all logfiles.
  default_error_pattern: '(?i)ERR(OR)?|CIRT(ICAL)?|EXCEPT(ION)?'

logfiles:
  "/var/log/service3.log":
    # It's one JSON document per line, not a plain text log.
    json: true

    # Handle JSON documents where the property `level` has
    # the value `'ERROR'` or `'CRITICAL'`.
    json_match:
      level: [in, [ERROR, CRITICAL]]

    # Path for the value of the {brief} template variable:
    json_brief: [message]

    do:
    # Run multiple action, HTTP request and write matched entries to a file.
    - action: https://api.example.com/v1/logs
      http_method: POST
      http_params:
        subject: "{brief}"
        entries: "{entries}"
      http_content_type: JSON
      oauth2_token_url: https://api.example.com/v1/oauth/token
      oauth2_client_id: "23ca1cd3-a234-4719-883f-a6e509fc57f4"
      oauth2_client_secret: "uBti6UENQnU0M1ZxM2IF0meGfovarZ5RRdzfdQe9pga/Vu5KK2vRFtlfcxP0ooMQftfUJeMOkl4Juoo+dXnwiA=="
      oauth2_scope: [write_log]

    - action: file:/var/logs/service3_errors.log

  "systemd:SYSTEM:UNIT:cron.service":
    do: "file:/var/log/cron_errors.log"
    output_indent: null
    output_format: JSON

  "/var/log/service4.log":
    do:
      # The command line string is parsed into a `list[str]` before the template
      # parameters are interpolated and run via `Popen(args=arg_list)`, it is not
      # a shell string.
      action: "command:my_command --brief={breif} --entry={...entries}"
      command_env:
        PATH: null # inherit $PATH
        HOME: "/"
        LOGMON_LOGFILE: "{logfile}" # same template variables

Do


Default action configuration.
All actions inherit these settings if they don't overwrite them.

LogActionConfig

Type: object

Subject

Type: string

Email subject template.

Default: '{brief}'

Body

Type: string

Body template for the emails.

Template variables:

  • {entries} - All entries formatted with the output_format and output_indent options.
  • {entries_str} - All entries for the message concatenated into a string with entries_delemeter between each (default is two newlines).
  • {entries_raw} - Raw entries (list[str] for normal log files or list[dict] for SystemD or JSON log files).
  • {logfile} - The path of the logfile.
  • {entry1} - The first log entry of the message.
  • {line1} - The first line of the first log entry.
  • {brief} - Like {line1}, but with the entry start pattern removed.
  • {entrynum} - The number of entries in this message.
  • {sender} - The sender email address.
  • {receivers} - Comma separated list of receiver email addresses.
  • {receiver_list} - List of receiver email addresses (list[str]).
  • {nl} - A newline character ('\n')
  • {{ - A literal {
  • }} - A literal }

Default: '{logfile}\n\n{entries_str}'

Host

Type: string

Host to connect to for SMTP/IMAP/HTTP(S).

Default: 'localhost'

Port

Type: integer

Port to connect to for SMTP/IMAP/HTTP(S) if not the standard port.

Value must be greater or equal to 0

User

Type: string

Credentials for SMTP/IMAP, HTTP basic auth, or OAuth 2.0 password grant type.

Password

Type: string

Credentials for SMTP/IMAP, HTTP basic auth, or OAuth 2.0 password grant type.

Type: enum (of null or string)

secure option for SMTP/IMAP.

Default: null

Must be one of:

  • null
  • "STARTTLS"
  • "SSL/TLS"

Type: enum (of string)

Write messages to logmon's log instead of/in addition to performing the action.

Default: 'onerror'

Must be one of:

  • "always"
  • "never"
  • "onerror"
  • "instead"

Keep Connected

Type: boolean

Keep connection to server alive (SMTP, IMAP, HTTP(S)).

Default: false

Http Method

Type: string

Default: 'POST'

Http Path

Type: string

Default: '/'

Http Params


Default: [('subject', '{subject}'), ('receivers', '{receivers}'), ('entries', '{entries_raw}')]

Header Mapping

Type: object

Each additional property must conform to the following schema

Type: string

List of Tuples

Type: array of array
No Additional Items

Each item of this array must be:

Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Item at 2 must be:

Type: enum (of string)

Default: 'URL'

Must be one of:

  • "JSON"
  • "YAML"
  • "URL"
  • "multipart"

Http Headers

Type: object

Additional HTTP headers. The Authorization header will be overwritten if OAuth 2.0 is used or if username and password are set.

Each additional property must conform to the following schema

Type: string

Http Max Redirect

Type: integer

Default: 0

Value must be greater or equal to 0

Http Timeout


null means no timeout.

Default: null

Seconds

Type: number

Value must be greater or equal to 0.0

Type: enum (of string)

Default: 'client_credentials'

Must be one of:

  • "client_credentials"
  • "password"

Oauth2 Token Url


null means don't use OAuth 2.0.

Default: null

Oauth2 Client Id

Type: string

Oauth2 Client Secret

Type: string

Oauth2 Scope

Type: array of string
No Additional Items

Each item of this array must be:

Oauth2 Refresh Margin

Type: stringFormat: duration

Seconds to substract from the expiration date-time when checking for access token expiration.

Default: 0.0

Command


Command to run if action is 'COMMAND'.

The template parameters are the same as with body plus the special syntax {...entries}, which makes the argument repeat as a separate argument for each entry. E.g. if there are the entries 'foo' and 'bar' the argument list ['command', '--entry={...entries}'] will expand to ['command', '--entry=foo', '--entry=bar'].

Additional parameters:

  • {python} - Path of the Python binary used to execute logmon itself. (sys.executable)
  • {python_version} - Full vesrsion string of the Python binary. (sys.version)
  • {python_version_major} - sys.version_info.major.
  • {python_version_minor} - sys.version_info.minor.
  • {python_version_micro} - sys.version_info.micro.
  • {env.NAME} - Environment variables of the logmon process. (os.getenv('NAME'))

Argument Array

Type: array of string
No Additional Items

Each item of this array must be:

Command String

Type: string

This string is split into the argument array using shlex.split().


Example:

[
    "/path/to/command",
    "--sender",
    "{sender}",
    "--receivers",
    "{receivers}",
    "--",
    "{...entries}"
]

Command Cwd

Type: string

Working directory of spawned process.

Command User


Run the process as user/UID.

Command Group


Run the process as group/GID.

Command Process Group

Type: integer

setpgid() to apply for the sub-process.

Command New Session

Type: boolean

If True use setsid() in the sub-process.

Default: False

Command Extra Groups

Type: array

setgroups() to apply for the sub-process.

No Additional Items

Each item of this array must be:

Command Env

Type: object

Set the environment of the spawned process to this. Passing null as the value means to inherit that environment variable from the current environment. If this is unset the environment of the logmon process is inherited.

Each additional property must conform to the following schema


Command Stdin

Type: string

'file:/path/to/file', 'inherit:', 'null:', 'pipe:TEMPLATE'

The parameters to the TEMPLATE are the same as for body plus the special syntax {...entries} which causes the whole template to repeat for each entry.

Default: 'null:'

Command Stdout

Type: string

'file:/path/to/file', 'append:/path/to/file', 'inherit:', 'null:'

Default: 'null:'

Command Stderr

Type: string

'file:/path/to/file', 'append:/path/to/file', 'inherit:', 'null:', 'stdout:'

Default: 'null:'

Command Interactive

Type: boolean

If true the process is long-running and log entries are passed by writing them to the stdin of the process instead of command line arguments.

Default: false

Command Timeout


Timeout in seconds. If the timeout expires the process is killed.

Default: null

Seconds

Type: number

Value must be greater or equal to 0.0

Command Chroot


chroot() into the given path before the sub-process is executed.

Default: null

Command Umask


umask() to apply for the sub-process.

Integer

Type: integer

Value must be greater or equal to 0

Command Nice


nice() to apply for the sub-process.

Integer

Type: integer

Value must be greater or equal to 0

Command Encoding

Type: string

Encoding used to communicate with sub-process.

Type: enum (of string)

See: Python's encoding error handling

Default: 'replace'

Must be one of:

  • "strict"
  • "ignore"
  • "replace"
  • "surrogateescape"
  • "xmlcharrefreplace"
  • "backslashreplace"
  • "namereplace"

File

Type: string

Path of output file.

File Encoding

Type: string

Default: 'UTF-8'

File Append

Type: boolean

Open file in append mode.

Default: true

File User


Set owner of the file as user/UID.

User Name

Type: string

User Id

Type: integer

File Group


Set owner of the file as group/GID.

Group Name

Type: string

Group Id

Type: integer

Type: enum (of string)

Default: 'regular'

Must be one of:

  • "regular"
  • "fifo"

File Mode


Create the file with these permissions. E.g.: rwxr-x---, u=rwx,g=rx,o=, or 0750.

String

Type: string

Integer

Type: integer

File Compression


Compress output file.

Default: null

Type: enum (of string)

Must be one of:

  • "gzip"
  • "bz2"
  • "zstd"

Output Indent


Indent JSON/YAML log entries in output. If null the JSON documents will be in a single line.

Default: 4

Integer

Type: integer

Value must be greater or equal to 0

Null

Type: null

Whole JSON document on a single line.

Type: enum (of string)

Use this format when writing JSON log entries to the output.

Default: 'YAML'

Must be one of:

  • "JSON"
  • "YAML"

Entries Delimiter

Type: string

String used to delimite entries in {entries_str}.

Default: '\n\n'

Sender

Type: string

Email sender address.

Default: logmon@<host>

Receivers

Type: array of string

List of email receiver addresses.

Default: <sender>

No Additional Items

Each item of this array must be:

Action


Action to perform.
This can also be a string in the form of one of these:

    {smtp,imap,http,https}[:[//][<user>[:<password>]@]<host>[:<port>][/<path>[?<query>]]]
    command[:<command> [<option>...]]
    {file,fifo}[:<path>]

Parameters defined here overwrite values passed via other options.

For SMTP and IMAP these query parameters are supported:

  • sender
  • receivers
  • secure

Default: 'SMTP'

Type: enum (of string)

Must be one of:

  • "SMTP"
  • "IMAP"
  • "HTTP"
  • "HTTPS"
  • "COMMAND"
  • "FILE"

Action String

Type: string

See root → do → anyOf → LogActionConfig → action for more details.

Action String

Type: string

See root → do → anyOf → LogActionConfig → action for more details.

InputConfig

Type: object

Default logfile configuration.
All logfiles inherit these settings if they don't overwrite them.

Type: object

Default: '^\\[\\d\\d\\d\\d-\\d\\d-\\d\\d[T ]\\d\\d:\\d\\d:\\d\\d(?:\\.\\d+)?(?: ?(?:[-+]\\d\\d:?\\d\\d|Z))?\\]'

Pattern

Type: string

Python regular expression.

List of Patterns

Type: array of string

List of Python regular expressions that will be joined with | into a single expression.

No Additional Items

Each item of this array must be:

Type: object

Default: 'ERROR|CRITICAL|Exception'

Same definition as entry_start_pattern

Ignore Pattern


Even if the error_pattern matches, if this pattern also matches the log entry is ignored.

Wait Line Incomplete

Type: number

Seconds to wait for more data if the line wasn't ended with a newline character.

Default: 0.04

Value must be greater or equal to 0

Wait File Not Found

Type: number

Seconds to wait before trying to re-open the file if it was not found and if inotify isn't used.

Default: 30

Value must be greater or equal to 0

Wait No Entries

Type: number

Seconds to wait when there are no entries if inotify is not used.

Default: 5

Value must be greater or equal to 0

Wait For More

Type: number

Seconds to wait for more messages before the action is performed.

Default: 0.08

Value must be greater or equal to 0

Wait After Crash

Type: number

Seconds to wait after a logfile handler has crashed before it is restarted.

Default: 10

Value must be greater or equal to 0

Max Entries

Type: integer

Default: 20

Value must be greater or equal to 0

Max Entry Lines

Type: integer

Default: 2048

Value must be greater or equal to 0

Use Inotify

Type: boolean

If the inotify package is available this defaults to true.

Seek End

Type: boolean

Seek to end of log file on open.
Default: true

Json

Type: boolean

If true parses each line of the log file as a JSON document. Empty lines and lines starting with // are skipped.
Default: false

Json Match


JSON property paths and values to compare them to. A log entry will only be processed if all properties match. Per default all log entries are processed.

Operators:

  • = - equals
  • != - not equals
  • < - less than
  • > - greater than
  • <= - less than or equal
  • >= - greater than or equal
  • ~ - match regular expression
  • in - value in a list or range of given values
  • not in - value not in a list or range of given values

The argument to in and not in can be a list like ["foo", "bar"] or a range definition like {"start": 0, "stop": 10}. Start is inclusive, stop is exclusive.

Per default no filter is defined.

Object

Type: object

Each additional property must conform to the following schema


Type: object

Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Type: enum (of string)

Must be one of:

  • "in"
  • "not in"
Item at 2 must be:
Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Item at 2 must be:

Null

Type: null

Json Ignore


Even if json_match matches, if this matches then the log entry is ignored.

Object

Type: object

Each additional property must conform to the following schema


Type: object

Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Type: enum (of string)

Must be one of:

  • "in"
  • "not in"
Item at 2 must be:
Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Item at 2 must be:

Null

Type: null

Json Brief


Use property at this path as the {brief} template variable.
Default: ['message']

JSON Path

Type: array
No Additional Items

Each item of this array must be:

Null

Type: null

Encoding

Type: string

Default: 'UTF-8'

Glob

Type: boolean

If true the last segment of a logfile path is a glob pattern. The rest of the path is just a normal path still. This way multiple logfiles can be processed at once and the directory is monitored for changes for when other matching files appear.

Default: false

Compression


Read compressed logfiles.

Default: null

Systemd Priority


Match log entries of this or higher priority.

String

Type: enum (of string)

Must be one of:

  • "PANIC"
  • "WARNING"
  • "ALERT"
  • "NONE"
  • "CRITICAL"
  • "DEBUG"
  • "INFO"
  • "ERROR"
  • "NOTICE"

Integer

Type: integer

Type: object

Each additional property must conform to the following schema


Systemd Ignore


Even if a log entry is matched via systemd_match, if it also matches via systemd_ignore it is ignored.

Default: null

Logfiles


The mapping keys or entries in the array of strings is the path of the log file.
You can read from a SystemD journal instead of a file by specifying a path in the form of:

systemd:[<open_flag>(+<open_flag>)*][:{UNIT,SYSLOG}:<identifier>]

Where open_flag can be one of:

  • LOCAL_ONLY
  • RUNTIME_ONLY
  • SYSTEM
  • CURRENT_USER

Examples:

systemd:
systemd:SYSTEM+LOCAL_ONLY:SYSLOG:sshd
systemd::UNIT:sshd.service

Mapping of logfile settings

Type: object

Mapping from logfiles to their configurations.

Each additional property must conform to the following schema


LogConfig

Type: object

Type: object

Default: '^\\[\\d\\d\\d\\d-\\d\\d-\\d\\d[T ]\\d\\d:\\d\\d:\\d\\d(?:\\.\\d+)?(?: ?(?:[-+]\\d\\d:?\\d\\d|Z))?\\]'

Same definition as entry_start_pattern

Wait Line Incomplete

Type: number

Seconds to wait for more data if the line wasn't ended with a newline character.

Default: 0.04

Value must be greater or equal to 0

Wait File Not Found

Type: number

Seconds to wait before trying to re-open the file if it was not found and if inotify isn't used.

Default: 30

Value must be greater or equal to 0

Wait No Entries

Type: number

Seconds to wait when there are no entries if inotify is not used.

Default: 5

Value must be greater or equal to 0

Wait For More

Type: number

Seconds to wait for more messages before the action is performed.

Default: 0.08

Value must be greater or equal to 0

Wait After Crash

Type: number

Seconds to wait after a logfile handler has crashed before it is restarted.

Default: 10

Value must be greater or equal to 0

Max Entries

Type: integer

Default: 20

Value must be greater or equal to 0

Max Entry Lines

Type: integer

Default: 2048

Value must be greater or equal to 0

Use Inotify

Type: boolean

If the inotify package is available this defaults to true.

Seek End

Type: boolean

Seek to end of log file on open.
Default: true

Json

Type: boolean

If true parses each line of the log file as a JSON document. Empty lines and lines starting with // are skipped.
Default: false

Json Match


JSON property paths and values to compare them to. A log entry will only be processed if all properties match. Per default all log entries are processed.

Operators:

  • = - equals
  • != - not equals
  • < - less than
  • > - greater than
  • <= - less than or equal
  • >= - greater than or equal
  • ~ - match regular expression
  • in - value in a list or range of given values
  • not in - value not in a list or range of given values

The argument to in and not in can be a list like ["foo", "bar"] or a range definition like {"start": 0, "stop": 10}. Start is inclusive, stop is exclusive.

Per default no filter is defined.

Object

Type: object

Each additional property must conform to the following schema


Type: object

Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Type: enum (of string)

Must be one of:

  • "in"
  • "not in"
Item at 2 must be:
Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Item at 2 must be:

Json Ignore


Even if json_match matches, if this matches then the log entry is ignored.

Object

Type: object

Each additional property must conform to the following schema


Type: object

Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Type: enum (of string)

Must be one of:

  • "in"
  • "not in"
Item at 2 must be:
Type: array

Must contain a minimum of 2 items

Must contain a maximum of 2 items

No Additional Items

Tuple Validation

Item at 1 must be:
Item at 2 must be:

Glob

Type: boolean

If true the last segment of a logfile path is a glob pattern. The rest of the path is just a normal path still. This way multiple logfiles can be processed at once and the directory is monitored for changes for when other matching files appear.

Default: false

Systemd Priority


Match log entries of this or higher priority.

String

Type: enum (of string)

Must be one of:

  • "PANIC"
  • "WARNING"
  • "ALERT"
  • "NONE"
  • "CRITICAL"
  • "DEBUG"
  • "INFO"
  • "ERROR"
  • "NOTICE"

Action String

Type: string

See root → do → anyOf → LogActionConfig → action for more details.

List of logfiles

Type: array of string

All the configuration is taken from the global settings.

No Additional Items

Each item of this array must be:

Rate limit actions

Type: object

Map of action limiters that can be assigned to actions. You can set a limiter to null to make it unlimited.

Default: {"default": {"max_actions_per_minute": 6, "max_actions_per_hour": 60}}

Each additional property must conform to the following schema


LimitsConfig

Type: object

Unlimited

Type: null

AppLogConfig

Type: object

Log configuration of logmon itself.

File

Type: string

Level

Type: enum (of string)

Must be one of:

  • "CRITICAL"
  • "FATAL"
  • "ERROR"
  • "WARN"
  • "WARNING"
  • "INFO"
  • "DEBUG"
  • "NOTSET"

Format

Type: string

Default: '[%(asctime)s] [%(process)d] %(levelname)s: %(message)s'

Datefmt

Type: string

Default: '%Y-%m-%dT%H:%M:%S%z'

PID File

Type: string

Write the process Id of the logmon process to this file.