Skip to content

Commit

Permalink
journald-query: Improve help text (fix #745)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Mar 30, 2024
1 parent a0071c7 commit 8e1f77f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Monitoring Plugins:
* infomaniak-swiss-backup-products: Improve output
* jitsi-\*: Add new parameters `--insecure` `--no-proxy`
* journald-query: Remove hard-coded `--boot` parameter from query
* journald-query: Improve help text (fix #745)
* kvm-vm: Improve output
* librenms-version: Fetches info from local SQLite using new librenms library
* logfile: Add new parameters `--insecure` `--no-proxy` `--timeout`
Expand Down
14 changes: 7 additions & 7 deletions check-plugins/journald-query/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ Help
identifier. Default: None
--ignore-pattern IGNORE_PATTERN
Any line containing this pattern on the MESSAGE field
will be ignored (repeating).', So, unlike
`journalctl`, you can easily use strings to ignore
certain messages.
will be ignored (repeating). So, unlike `journalctl`,
you can easily use strings to ignore certain messages.
--ignore-regex IGNORE_REGEX
Any line matching this Python regex on the MESSAGE
field will be ignored (must be lowercase; repeating).
So, unlike `journalctl`, you can easily use regular
expressions to ignore certain messages.
field will be ignored (repeating). So, unlike
`journalctl`, you can easily use a regex to ignore
certain messages. Example: '(?i)linuxfabrik' for a
case-insensitive search for "linuxfabrik".
--priority PRIORITY journalctl: Filter output by message priorities or
priority ranges. Default: emerg..err
--severity {warn,crit}
Expand All @@ -81,7 +81,7 @@ Help
--user-unit USER_UNIT
journalctl: Show messages for the specified user
session unit. This parameter can be specified multiple
times.
times. Default: None
Usage Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"4": {
"varname": "journald_query_ignore_pattern",
"caption": "Journald Query: Ignore Pattern",
"description": "Any line containing this pattern on the MESSAGE field will be ignored (repeating).', So, unlike `journalctl`, you can easily use strings to ignore certain messages.",
"description": "Any line containing this pattern on the MESSAGE field will be ignored (repeating). So, unlike `journalctl`, you can easily use strings to ignore certain messages.",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
"format": null,
"settings": {
Expand All @@ -222,7 +222,7 @@
"5": {
"varname": "journald_query_ignore_regex",
"caption": "Journald Query: Ignore Regex",
"description": "Any line matching this Python regex on the MESSAGE field will be ignored (must be lowercase; repeating). So, unlike `journalctl`, you can easily use regular expressions to ignore certain messages.",
"description": "Any line matching this Python regex on the MESSAGE field will be ignored (repeating). So, unlike `journalctl`, you can easily use a regex to ignore certain messages. Example: '(?i)linuxfabrik' for a case-insensitive search for \"linuxfabrik\".",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
"format": null,
"settings": {
Expand All @@ -233,7 +233,7 @@
"6": {
"varname": "journald_query_priority",
"caption": "Journald Query: Priority",
"description": "journalctl: Filter output by message priorities or priority ranges. ",
"description": "journalctl: Filter output by message priorities or priority ranges.",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
"format": null,
"settings": {
Expand All @@ -244,7 +244,7 @@
"7": {
"varname": "journald_query_severity",
"caption": "Journald Query: Severity",
"description": "Severity for alerts if journalctl returns results. One of \"warn\" or \"crit\". ",
"description": "Severity for alerts if journalctl returns results. One of \"warn\" or \"crit\".",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeDatalist",
"format": null,
"settings": {
Expand All @@ -257,7 +257,7 @@
"8": {
"varname": "journald_query_since",
"caption": "Journald Query: Since",
"description": "journalctl: Start showing entries on or newer than the specified date. ",
"description": "journalctl: Start showing entries on or newer than the specified date.",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
"format": null,
"settings": {
Expand Down
82 changes: 46 additions & 36 deletions check-plugins/journald-query/journald-query
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2024030501'
__version__ = '2024033001'

DESCRIPTION = """Query the systemd journal and alert on any events found.
For help on any of the journalctl-specific parameters, see `man journalctl`."""
Expand Down Expand Up @@ -73,86 +73,94 @@ def parse_args():

parser.add_argument(
'--facility',
help='''journalctl: Filter output by syslog facility. Takes a comma-separated list of
numbers or facility names. Default: %(default)s''',
help='journalctl: Filter output by syslog facility. Takes a '
'comma-separated list of numbers or facility names. '
'Default: %(default)s',
dest='FACILITY',
default=DEFAULT_FACILITY,
)

parser.add_argument(
'--identifier',
help='journalctl: Show messages for the specified syslog identifier. Default: %(default)s',
help='journalctl: Show messages for the specified syslog identifier. '
'Default: %(default)s',
dest='IDENTIFIER',
default=DEFAULT_IDENTIFIER,
)

parser.add_argument(
'--ignore-pattern',
help='''Any line containing this pattern on the MESSAGE field will be ignored
(repeating).',
So, unlike `journalctl`, you can easily use strings to ignore certain
messages.''',
help='Any line containing this pattern on the MESSAGE field will be '
'ignored (repeating). So, unlike `journalctl`, you can easily use '
'strings to ignore certain messages.',
action='append',
default=[],
dest='IGNORE_PATTERN',
)

parser.add_argument(
'--ignore-regex',
help='''Any line matching this Python regex on the MESSAGE field will be ignored
(must be lowercase; repeating).
So, unlike `journalctl`, you can easily use regular expressions to ignore certain
messages.''',
help='Any line matching this Python regex on the MESSAGE field will be '
'ignored (repeating). So, unlike `journalctl`, you can easily use '
'a regex to ignore certain messages. '
'Example: \'(?i)linuxfabrik\' for a case-insensitive search for '
'"linuxfabrik".',
action='append',
default=[],
dest='IGNORE_REGEX',
)

parser.add_argument(
'--priority',
help='''journalctl: Filter output by message priorities or priority ranges.
Default: %(default)s''',
help='journalctl: Filter output by message priorities or priority '
'ranges. '
'Default: %(default)s',
dest='PRIORITY',
default=DEFAULT_PRIORITY,
)

parser.add_argument(
'--severity',
help='''Severity for alerts if journalctl returns results. One of "warn" or "crit".
Default: %(default)s''',
help='Severity for alerts if journalctl returns results. One of '
'"warn" or "crit". '
'Default: %(default)s',
dest='SEVERITY',
default=DEFAULT_SERVERITY,
choices=['warn', 'crit'],
)

parser.add_argument(
'--since',
help='''journalctl: Start showing entries on or newer than the specified date.
Default: >= %(default)s''',
help='journalctl: Start showing entries on or newer than the '
'specified date. '
'Default: >= %(default)s',
dest='SINCE',
default=DEFAULT_SINCE,
)

parser.add_argument(
'--test',
help='For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc".',
help='For unit tests. '
'Needs "path-to-stdout-file,path-to-stderr-file,expected-retc".',
dest='TEST',
type=lib.args.csv,
)

parser.add_argument(
'--unit',
help='''journalctl: Show messages for the specified systemd unit UNIT|PATTERN. This
parameter can be specified multiple times. Default: %(default)s''',
help='journalctl: Show messages for the specified systemd unit '
'UNIT|PATTERN. This parameter can be specified multiple times. '
'Default: %(default)s',
dest='UNIT',
default=DEFAULT_UNIT,
action='append',
)

parser.add_argument(
'--user-unit',
help='''journalctl: Show messages for the specified user session unit. This
parameter can be specified multiple times.''',
help='journalctl: Show messages for the specified user session unit. '
'This parameter can be specified multiple times. '
'Default: %(default)s',
dest='USER_UNIT',
default=DEFAULT_USER_UNIT,
action='append',
Expand Down Expand Up @@ -307,19 +315,21 @@ def main():
if shortened:
msg += '\nAttention: Table below is truncated, showing the 5 newest and ' \
'the 5 oldest messages.'
keys = [
'timestamp',
'unit',
'priority',
'MESSAGE',
]
headers = [
'Timestamp',
'Unit',
'Prio',
'Message',
]
msg += '\n\n' + lib.base.get_table(table_data, keys, header=headers)
msg += '\n\n' + lib.base.get_table(
table_data,
[
'timestamp',
'unit',
'priority',
'MESSAGE',
],
header=[
'Timestamp',
'Unit',
'Prio',
'Message',
],
)
if args.UNIT is None:
msg += '\nUse `journalctl --reverse --priority={} --since={}` as a starting point ' \
'for debugging. Be aware of the fact that you may see even more messages ' \
Expand Down

0 comments on commit 8e1f77f

Please sign in to comment.