Haproxy configuration files

Parsers provided by this module are:

HaproxyCfg - file /var/lib/config-data/puppet-generated/haproxy/etc/haproxy/haproxy.cfg or /etc/haproxy/haproxy.cfg

HaproxyCfgScl - file /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg

class insights.parsers.haproxy_cfg.HaproxyCfg(context)[source]

Bases: HaproxyFile

Class to parse file /var/lib/config-data/puppet-generated/haproxy/etc/haproxy/haproxy.cfg or haproxy.cfg.

class insights.parsers.haproxy_cfg.HaproxyCfgScl(context)[source]

Bases: HaproxyFile

Class to parse file /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg.

class insights.parsers.haproxy_cfg.HaproxyFile(context)[source]

Bases: Parser

Base class for HaproxyCfg and HaproxyCfgScl classes.

data

Dictionary of all parsed sections.

Type:

dict

lines

List of all non-commented lines.

Type:

list

Content of the haproxy.cfg file looks like:

global
    daemon
    group       haproxy
    log         /dev/log local0
    user        haproxy
    maxconn     20480
    pidfile     /var/run/haproxy.pid

defaults
    retries     3
    maxconn     4096
    log         global
    timeout     http-request 10s
    timeout     queue 1m
    timeout     connect 10s

Examples

>>> type(haproxy)
<class 'insights.parsers.haproxy_cfg.HaproxyFile'>
>>> haproxy.data['global']
{'daemon': '', 'group': 'haproxy', 'log': '/dev/log local0', 'user': 'haproxy', 'maxconn': '20480', 'pidfile': '/var/run/haproxy.pid'}
>>> haproxy.data['global']['group']
'haproxy'
>>> 'global' in haproxy.data
True
>>> 'user' in haproxy.data.get('global')
True
>>> haproxy.data['defaults']
{'retries': '3', 'maxconn': '4096', 'log': 'global', 'timeout': ['http-request 10s', 'queue 1m', 'connect 10s']}
parse_content(content)[source]

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