Beispiel #1
0
def test_conf_7_include_dir():
    rsyslog1 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_7, path="/etc/rsyslog.conf"))
    rsyslog2 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_CONF_DIR_7,
                     path="/etc/rsyslog.d/test.conf"))
    result = RsyslogAllConf([rsyslog1, rsyslog2])
    assert len(result) == 2
    assert result['/etc/rsyslog.conf'][0] == '$ModLoad imuxsock'
Beispiel #2
0
def test_conf_8_no_include_dir():
    rsyslog1 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_NO_INCLUDE_8, path="/etc/rsyslog.conf"))
    rsyslog2 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_CONF_DIR_8,
                     path="/etc/rsyslog.d/test.conf"))
    result = RsyslogAllConf([rsyslog1, rsyslog2])
    assert len(result) == 1
    assert result['/etc/rsyslog.conf'][
        2] == 'global(workDirectory="/var/lib/rsyslog")'
Beispiel #3
0
def test_conf_8_include_dir():
    rsyslog1 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_8, path="/etc/rsyslog.conf"))
    rsyslog2 = RsyslogConf(
        context_wrap(RSYSLOG_CONF_MAIN_CONF_DIR_8,
                     path="/etc/rsyslog.d/test.conf"))
    result = RsyslogAllConf([rsyslog1, rsyslog2])
    assert len(result) == 2
    assert result['/etc/rsyslog.d/test.conf'] == [
        '*.info { action( type="omfile" name="hehe" file="/tmp/test") }'
    ]
Beispiel #4
0
def test_rsyslog_confs_doc_examples():
    env = {
        'confs':
        RsyslogAllConf([
            RsyslogConf(
                context_wrap(RSYSLOG_CONF_MAIN_7, path='/etc/rsyslog.conf')),
            RsyslogConf(
                context_wrap(RSYSLOG_CONF_MAIN_CONF_DIR_7,
                             path='/etc/rsyslog.d/test.conf'))
        ])
    }
    failed, total = doctest.testmod(rsyslog_confs, globs=env)
    assert failed == 0
def test_rsyslog_conf_1():
    rsyslogconf = RsyslogConf(context_wrap(RSYSLOG_CONF))
    assert len(rsyslogconf) == 13
    assert rsyslogconf[
        2] == "authpriv.*                                              /var/log/secure"
    assert rsyslogconf[
        9] == """*.info { action( type="omfile" name="hehe" file="/tmp/testnimei") }"""
def test_rsyslog_conf_1():
    ctx = context_wrap(RSYSLOG_CONF_1)
    m = RsyslogConf(ctx)
    d = list(m)
    assert len(m) == 1
    assert len(d) == 1
    # Test that commented-out config items are not detected
    assert 'ModLoad' not in m.config_items
    assert 'InputTCPServerRun' not in m.config_items
def test_rsyslog_conf_0():
    ctx = context_wrap(RSYSLOG_CONF_0)
    m = RsyslogConf(ctx)
    d = list(m)
    assert len(m) == 5
    assert len(d) == 5
    # Test configuration item detection in dictionary
    assert hasattr(m, 'config_items')
    assert isinstance(m.config_items, dict)
    assert 'ModLoad' in m.config_items
    assert m.config_items['ModLoad'] == 'imtcp'
    assert m.config_items['InputTCPServerRun'] == '10514'
    assert m.config_items[
        'template'] == 'SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\\n"'
    assert 'ForwardSyslogHost' not in m.config_items
    # configuration items should not include the comment.
    assert 'WorkDirectory' in m.config_items
    assert m.config_items['WorkDirectory'] == '/var/opt/rsyslog'
    # Test configuration item accessor
    assert hasattr(m, 'config_val')
    assert m.config_val('ModLoad') == 'imtcp'
    assert m.config_val('ForwardSyslogHost',
                        'syslog.example.com') == 'syslog.example.com'
def test_rsyslog_doc_examples():
    env = {
        'rsysconf': RsyslogConf(context_wrap(RSYSLOG_CONF)),
    }
    failed, total = doctest.testmod(rsyslog_conf, globs=env)
    assert failed == 0