HttpdConf - files /etc/httpd/conf/httpd.conf
and /etc/httpd/conf.d/*
¶
Parse the keyword-and-value-but-also-vaguely-XML of an Apache configuration file.
Generally, each line is split on the first space into key and value, leading and trailing space being ignored.
Sample (edited) httpd.conf file:
ServerRoot "/etc/httpd"
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
</IfModule>
ErrorLog "|/usr/sbin/httplog -z /var/log/httpd/error_log.%Y-%m-%d"
SSLProtocol -ALL +SSLv3
#SSLProtocol all -SSLv2
NSSProtocol SSLV3 TLSV1.0
#NSSProtocol ALL
# prefork MPM
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 200
</IfModule>
# worker MPM
<IfModule worker.c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
Examples
>>> httpd_conf['ServerRoot'][-1].value
'/etc/httpd'
>>> httpd_conf['LoadModule'][0].value
'auth_basic_module modules/mod_auth_basic.so'
>>> httpd_conf['LoadModule'][-1].value
'auth_digest_module modules/mod_auth_digest.so'
>>> httpd_conf['Directory', '/']['Options'][-1].value
'FollowSymLinks'
>>> type(httpd_conf[('IfModule','prefork.c')]) == type({})
True
>>> httpd_conf[('IfModule','mod_mime_magic.c')]
{'MIMEMagicFile': [ParsedData(value='conf/magic', line='MIMEMagicFile conf/magic', section='IfModule', section_name='mod_mime_magic.c', file_name='path', file_path='/path')]}
>>> httpd_conf[('IfModule','prefork.c')]['StartServers'][0].value
'8'
>>> 'ThreadsPerChild' in httpd_conf[('IfModule','prefork.c')]
False
>>> httpd_conf[('IfModule','worker.c')]['MaxRequestsPerChild'][-1].value
'0'
-
class
insights.parsers.httpd_conf.
HttpdConf
(*args, **kwargs)[source]¶ Bases:
insights.core.LegacyItemAccess
,insights.core.Parser
Note
This parser is deprecated, please use
insights.combiners.httpd_conf.HttpdConfTree
instead.Get the key value pairs separated on the first space, ignoring leading and trailing spaces.
If the file is
httpd.conf
, it also stores first half, beforeIncludeOptional conf.d/*.conf
line, and the rest, to thefirst_half
andsecond_half
attributes respectively.-
data
¶ Dictionary of parsed data with key being the option and value a list of named tuples with the following properties: -
value
- the value of the keyword. -line
- the complete line as found in the config file. The reason why it is a list is to store data for directives which can use selective overriding such asUserDir
.- Type
dict
-
first_half
¶ Parsed data from main config file before inclusion of other files in the same format as
data
.- Type
dict
-
second_half
¶ Parsed data from main config file after inclusion of other files in the same format as
data
.- Type
dict
-
-
class
insights.parsers.httpd_conf.
ParsedData
(value, line, section, section_name, file_name, file_path)¶ Bases:
tuple
namedtuple: Type for storing the parsed httpd configuration’s directive information.
-
property
file_name
¶
-
property
file_path
¶
-
property
line
¶
-
property
section
¶
-
property
section_name
¶
-
property
value
¶
-
property
-
insights.parsers.httpd_conf.
dict_deep_merge
(tgt, src)[source]¶ Utility function to merge the source dictionary src to the target dictionary recursively
Note
The type of the values in the dictionary can only be dict or list
- Parameters
tgt (dict) -- The target dictionary
src (dict) -- The source dictionary