Skip to content

Commit

Permalink
feat: New spec "ls -lZ /var/lib/rsyslog" and the parser (#3618)
Browse files Browse the repository at this point in the history
* feat: New spec "ls -lZ /var/lib/rsyslog" and the parser

Signed-off-by: Huanhuan Li <[email protected]>

* Update to full path import

Signed-off-by: Huanhuan Li <[email protected]>
  • Loading branch information
huali027 authored Dec 7, 2022
1 parent 0e263a5 commit 5438a4d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/ls_var_lib_rsyslog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.ls_var_lib_rsyslog
:members:
:show-inheritance:
29 changes: 29 additions & 0 deletions insights/parsers/ls_var_lib_rsyslog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
LsVarLibRsyslog - command ``ls -lZ /var/lib/rsyslog``
======================================================
"""


from insights.core import CommandParser, FileListing
from insights.core.plugins import parser
from insights.specs import Specs


@parser(Specs.ls_var_lib_rsyslog)
class LsVarLibRsyslog(CommandParser, FileListing):
"""
Parses output of ``ls -lZ /var/lib/rsyslog`` command.
Sample output::
total 4
-rw-------. 1 root root system_u:object_r:syslogd_var_lib_t:s0 127 Nov 30 03:40 imjournal.state
Examples:
>>> rsyslog_obj.dir_contains('/var/lib/rsyslog', 'imjournal.state')
True
>>> imjournal_entry = rsyslog_obj.dir_entry('/var/lib/rsyslog', 'imjournal.state')
>>> imjournal_entry['se_type']
'syslogd_var_lib_t'
"""
pass
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class Specs(SpecSet):
ls_var_lib_mongodb = RegistryPoint()
ls_var_lib_nova_instances = RegistryPoint()
ls_var_lib_pcp = RegistryPoint()
ls_var_lib_rsyslog = RegistryPoint()
ls_var_log = RegistryPoint()
ls_var_opt_mssql = RegistryPoint()
ls_var_opt_mssql_log = RegistryPoint()
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ class DefaultSpecs(Specs):
ls_var_lib_mongodb = simple_command("/bin/ls -la /var/lib/mongodb")
ls_var_lib_nova_instances = simple_command("/bin/ls -laRZ /var/lib/nova/instances")
ls_var_lib_pcp = simple_command("/bin/ls -la /var/lib/pcp")
ls_var_lib_rsyslog = simple_command("/bin/ls -lZ /var/lib/rsyslog")
ls_var_log = simple_command("/bin/ls -la /var/log /var/log/audit")
ls_var_opt_mssql = simple_command("/bin/ls -ld /var/opt/mssql")
ls_var_opt_mssql_log = simple_command("/bin/ls -la /var/opt/mssql/log")
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 @@ -136,6 +136,7 @@ class InsightsArchiveSpecs(Specs):
ls_var_lib_mongodb = simple_file("insights_commands/ls_-la_.var.lib.mongodb")
ls_var_lib_nova_instances = simple_file("insights_commands/ls_-laRZ_.var.lib.nova.instances")
ls_var_lib_pcp = simple_file("insights_commands/ls_-la_.var.lib.pcp")
ls_var_lib_rsyslog = simple_file("insights_commands/ls_-lZ_.var.lib.rsyslog")
ls_var_log = simple_file("insights_commands/ls_-la_.var.log_.var.log.audit")
ls_var_opt_mssql = simple_file("insights_commands/ls_-ld_.var.opt.mssql")
ls_var_opt_mssql_log = simple_file("insights_commands/ls_-la_.var.opt.mssql.log")
Expand Down
32 changes: 32 additions & 0 deletions insights/tests/parsers/test_ls_var_lib_rsyslog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import doctest

from insights.parsers import ls_var_lib_rsyslog
from insights.tests import context_wrap


LS_VAR_LIB_RSYSLOG_1 = """
total 4
-rw-------. 1 root root system_u:object_r:syslogd_var_lib_t:s0 127 Nov 30 03:40 imjournal.state
"""

LS_VAR_LIB_RSYSLOG_2 = """
total 4
-rw-------. root root system_u:object_r:syslogd_var_lib_t:s0 imjournal.state
"""


def test_ls_var_lib_rsyslog():
rsyslog_obj = ls_var_lib_rsyslog.LsVarLibRsyslog(context_wrap(LS_VAR_LIB_RSYSLOG_2, path="insights_commands/ls_-lZ_.var.lib.rsyslog"))
assert rsyslog_obj.files_of('/var/lib/rsyslog') == ['imjournal.state']
journal_obj = rsyslog_obj.dir_entry('/var/lib/rsyslog', 'imjournal.state')
assert journal_obj is not None
assert journal_obj['se_type'] == 'syslogd_var_lib_t'
assert journal_obj['owner'] == 'root'


def test_ls_var_lib_pcp_doc_examples():
env = {
'rsyslog_obj': ls_var_lib_rsyslog.LsVarLibRsyslog(context_wrap(LS_VAR_LIB_RSYSLOG_1, path="insights_commands/ls_-lZ_.var.lib.rsyslog")),
}
failed, total = doctest.testmod(ls_var_lib_rsyslog, globs=env)
assert failed == 0

0 comments on commit 5438a4d

Please sign in to comment.