Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: New journal_header #3498

Merged
merged 14 commits into from
Aug 25, 2022
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/journalctl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.journalctl
:members:
:show-inheritance:
17 changes: 17 additions & 0 deletions insights/parsers/journal_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@

from .. import Syslog, parser
from insights.specs import Specs
from insights.util import deprecated


@parser(Specs.journal_all)
class JournalAll(Syslog):
"""

.. warning::

This parser is deprecated, please use
psachin marked this conversation as resolved.
Show resolved Hide resolved
:py:class:`insights.parsers.journalctl.JournalAll` instead.


Read the ``/sos_commands/logs/journalctl_--no-pager`` file. Uses the
``Syslog`` class parser functionality - see the base class for more details.

Expand Down Expand Up @@ -41,4 +49,13 @@ class JournalAll(Syslog):
>>> msgs.daemon_start # Token set if matching lines present in logs
True
"""

def __init__(self, context):
deprecated(
JournalAll,
"Please use the :class:`insights.parsers.journalctl.JournalAll` instead.",
"3.1.25"
)
super(JournalAll, self).__init__(context)

pass
17 changes: 17 additions & 0 deletions insights/parsers/journal_since_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@

from .. import Syslog, parser
from insights.specs import Specs
from insights.util import deprecated


@parser(Specs.journal_since_boot)
class JournalSinceBoot(Syslog):
"""

.. warning::

psachin marked this conversation as resolved.
Show resolved Hide resolved
This parser is deprecated, please use
:py:class:`insights.parsers.journalctl.JournalSinceBoot` instead.


Read the ``/sos_commands/logs/journalctl_--no-pager_--boot`` file. Uses
the ``Syslog`` class parser functionality - see the base class for more
details.
Expand Down Expand Up @@ -42,4 +50,13 @@ class JournalSinceBoot(Syslog):
>>> msgs.daemon_start # Token set if matching lines present in logs
True
"""

def __init__(self, context):
deprecated(
JournalSinceBoot,
"Please use the :class:`insights.parsers.journalctl.JournalSinceBoot` instead.",
"3.1.25"
)
super(JournalSinceBoot, self).__init__(context)

pass
134 changes: 134 additions & 0 deletions insights/parsers/journalctl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""
JournalCtl - command ``journalctl xxx``
=======================================

This module contains the following parsers:

JournalAll - command ``journalctl --no-pager``
----------------------------------------------
JournalHeader - command ``journalctl --no-pager --header``
----------------------------------------------------------
JournalSinceBoot - command ``journalctl --no-pager --boot``
-----------------------------------------------------------

"""


from insights.core.plugins import parser
from insights.specs import Specs
from insights.core import Syslog


@parser(Specs.journal_all)
class JournalAll(Syslog):
"""
Handle the output of ``journalctl --no-pager`` command. Uses the ``Syslog`` class
parser functionality - see the base class for more details.

Sample log lines::

-- Logs begin at Wed 2017-02-08 15:18:00 CET, end at Tue 2017-09-19 09:25:27 CEST. --
May 18 15:13:34 lxc-rhel68-sat56 jabberd/sm[11057]: session started: [email protected]/superclient
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: --> Wrapper Started as Daemon
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: Launching a JVM...
May 18 15:24:28 lxc-rhel68-sat56 yum[11597]: Installed: lynx-2.8.6-27.el6.x86_64
May 18 15:36:19 lxc-rhel68-sat56 yum[11954]: Updated: sos-3.2-40.el6.noarch

.. note::
Because journal timestamps by default have no year,
the year of the logs will be inferred from the year in your timestamp.
This will also work around December/January crossovers.

Examples:
>>> type(JournalAll)
<class 'insights.parsers.journalctl.JournalAll'>
>>> len(JournalAll.lines)
10
>>> bona_list = JournalAll.get('(root) LIST (root)')
>>> bona_list[0].get('message')
'(root) LIST (root)'
"""
pass


@parser(Specs.journal_header)
class JournalHeader(Syslog):
"""
Parses the output of command "journalctl --no-pager --header", this command shows
internal header information of the journal fields accessed. Although its output is
not kind of Logs, we used the `Syslog` as the base class to parser it.

Sample Output::

File Path: /run/log/journal/6bdaf92aa0754b53acbb1dbff7127e2b/system.journal
File ID: b1390ea69aa747e9ac5c597835c3c562
Machine ID: 6bdaf92aa0754b53acbb1dbff7127e2b
Boot ID: 082ada53f8184c4896c73101ad793eb5
Sequential Number ID: 435b0e30f47a46d8a2a2f9a42eae0aaf
State: ONLINE
Compatible Flags:
Incompatible Flags: COMPRESSED-LZ4
Header size: 240
Arena size: 8388368
Data Hash Table Size: 19904
Field Hash Table Size: 333
Rotate Suggested: no
Head Sequential Number: 74388 (12294)
Tail Sequential Number: 81647 (13eef)
Head Realtime Timestamp: Mon 2022-08-15 12:01:10 CST (5e63fae9e6e58)
Tail Realtime Timestamp: Wed 2022-08-17 18:38:48 CST (5e66d7852bb3e)
Tail Monotonic Timestamp: 1month 2w 3d 14h 19min 3.733s (3c647d7ce0f)
Objects: 19073
Entry Objects: 7260
Data Objects: 9297
Data Hash Table Fill: 46.7%
Field Objects: 52
Field Hash Table Fill: 15.6%
Tag Objects: 0
Entry Array Objects: 2462
Disk usage: 8.0M

Examples:
>>> type(journal_header)
<class 'insights.parsers.journalctl.JournalHeader'>
>>> result_list = journal_header.get('File Path')
>>> len(result_list)
1
>>> result_list[0].get('raw_message')
'File Path: /run/log/journal/6bdaf92aa0754b53acbb1dbff7127e2b/system.journal'
"""

psachin marked this conversation as resolved.
Show resolved Hide resolved
pass


@parser(Specs.journal_since_boot)
class JournalSinceBoot(Syslog):
"""
Handle the output of ``journalctl --no-pager --boot`` command. Uses
the ``Syslog`` class parser functionality - see the base class for more
details.

Sample log lines::

-- Logs begin at Wed 2017-02-08 15:18:00 CET, end at Tue 2017-09-19 09:25:27 CEST. --
May 18 15:13:34 lxc-rhel68-sat56 jabberd/sm[11057]: session started: [email protected]/superclient
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: --> Wrapper Started as Daemon
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: Launching a JVM...
May 18 15:24:28 lxc-rhel68-sat56 yum[11597]: Installed: lynx-2.8.6-27.el6.x86_64
May 18 15:36:19 lxc-rhel68-sat56 yum[11954]: Updated: sos-3.2-40.el6.noarch

Note:
Because journal timestamps by default have no year,
the year of the logs will be inferred from the year in your timestamp.
This will also work around December/January crossovers.

Examples:
>>> type(JournalSinceBoot)
<class 'insights.parsers.journalctl.JournalSinceBoot'>
>>> len(JournalSinceBoot.lines)
10
>>> bona_list = JournalSinceBoot.get('(root) LIST (root)')
>>> bona_list[0].get('message')
'(root) LIST (root)'
"""
pass
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class Specs(SpecSet):
jboss_version = RegistryPoint(multi_output=True)
journal_all = RegistryPoint(filterable=True)
journal_since_boot = RegistryPoint(filterable=True)
journal_header = RegistryPoint(filterable=True)
katello_service_status = RegistryPoint(filterable=True)
kdump_conf = RegistryPoint()
kerberos_kdc_log = RegistryPoint(filterable=True)
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class DefaultSpecs(Specs):
ipv6_neigh = simple_command("/sbin/ip -6 neighbor show nud all")
ironic_inspector_log = first_file(["/var/log/containers/ironic-inspector/ironic-inspector.log", "/var/log/ironic-inspector/ironic-inspector.log"])
iscsiadm_m_session = simple_command("/usr/sbin/iscsiadm -m session")
journal_header = simple_command("/usr/bin/journalctl --no-pager --header")
kdump_conf = simple_file("/etc/kdump.conf")
kernel_config = glob_file("/boot/config-*")
kernel_crash_kexec_post_notifiers = simple_file("/sys/module/kernel/parameters/crash_kexec_post_notifiers")
Expand Down
1 change: 1 addition & 0 deletions insights/specs/insights_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class InsightsArchiveSpecs(Specs):
ipv4_neigh = simple_file("insights_commands/ip_-4_neighbor_show_nud_all")
ipv6_neigh = simple_file("insights_commands/ip_-6_neighbor_show_nud_all")
iscsiadm_m_session = simple_file("insights_commands/iscsiadm_-m_session")
journal_header = simple_file("insights_commands/journalctl_--no-pager_--header")
keystone_crontab = first_file(["insights_commands/crontab_-l_-u_keystone", "var/spool/cron/keystone"])
kpatch_list = simple_file("insights_commands/kpatch_list")
localtime = simple_file("insights_commands/file_-L_.etc.localtime")
Expand Down
Loading