LogrotateConf - files /etc/logrotate.conf and others

Class to parse logrotate confuration files: - /etc/logrotate.conf - /etc/logrotate.d/*

See: http://www.linuxmanpages.org/8/logrotate

class insights.parsers.logrotate_conf.LogRotateConfPEG(context)[source]

Bases: ConfigParser

Class for parsing /etc/logrotate.conf and /etc/logrotate.d/* configuration files.

Note: It cannot handle the case without the target log file before the braces for now.

Sample logrotate configuration file:

# sample file
compress

/var/log/messages {
    rotate 5
    weekly
    postrotate
                /sbin/killall -HUP syslogd
    endscript
}

"/var/log/httpd/access.log" /var/log/httpd/error.log {
    rotate 5
    mail www@my.org
    size=100k
    sharedscripts
    postrotate
                /sbin/killall -HUP httpd
    endscript
}

/var/log/news/news.crit
/var/log/news/olds.crit  {
    monthly
    rotate 2
    olddir /var/log/news/old
    missingok
    postrotate
                kill -HUP `cat /var/run/inn.pid`
    endscript
    nocompress
}

Examples

>>> type(log_rt_peg)
<class 'insights.parsers.logrotate_conf.LogRotateConfPEG'>
>>> 'compress' in log_rt_peg
True
>>> 'weekly' in log_rt['/var/log/messages']
True
>>> log_rt_peg['/var/log/messages']['postrotate'][-1].value
'/sbin/killall -HUP syslogd'
parse_doc(content)[source]

configuration format pre-check for logrotate configuration file

class insights.parsers.logrotate_conf.LogrotateConf(context)[source]

Bases: Parser, LegacyItemAccess

Class for parsing /etc/logrotate.conf and /etc/logrotate.d/* configuration files.

Sample logrotate configuration file:

# sample file
compress

/var/log/messages {
    rotate 5
    weekly
    postrotate
                /sbin/killall -HUP syslogd
    endscript
}

"/var/log/httpd/access.log" /var/log/httpd/error.log {
    rotate 5
    mail www@my.org
    size=100k
    sharedscripts
    postrotate
                /sbin/killall -HUP httpd
    endscript
}

/var/log/news/news.crit
/var/log/news/olds.crit  {
    monthly
    rotate 2
    olddir /var/log/news/old
    missingok
    postrotate
                kill -HUP `cat /var/run/inn.pid`
    endscript
    nocompress
}

Examples

>>> type(log_rt)
<class 'insights.parsers.logrotate_conf.LogrotateConf'>
>>> log_rt.options
['compress']
>>> log_rt.log_files
['/var/log/messages', '/var/log/httpd/access.log', '/var/log/httpd/error.log', '/var/log/news/news.crit', '/var/log/news/olds.crit']
>>> log_rt['compress']
True
>>> 'weekly' in log_rt['/var/log/messages']
True
>>> log_rt['/var/log/messages']['postrotate']
['/sbin/killall -HUP syslogd']
data

All parsed options and log files are stored in this dictionary

Type:

dict

options

List of global options in the configuration file

Type:

list

log_files

List of log files in the configuration file

Type:

list

parse_content(content)[source]

This method must be implemented by classes based on this class.

insights.parsers.logrotate_conf.parse_doc(content, ctx=None)[source]

Parse a configuration document into a tree that can be queried.