Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to improve Syslog daemon detection. #26

Merged
merged 4 commits into from Aug 31, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -33,3 +33,6 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

loggly_setup.log
env_details.txt
@@ -14,7 +14,7 @@
# (c) Copyright Loggly 2013.
######################################################################

import os
import os, os.path
import platform
import re
import sys
@@ -317,9 +317,9 @@ def printEnvironment(current_environment):

Logger.printLog("Syslog versions:", print_comp = True)
if current_environment['syslog_versions']:
for i, version in enumerate(current_environment['syslog_versions']):
line = "\t%d. %s(%s)" % (i + 1, version[0], version[1])
Logger.printLog(line, print_comp = True)
for i, version in enumerate(current_environment['syslog_versions'], 1):

This comment has been minimized.

@MichaelBlume

MichaelBlume Aug 31, 2013
Contributor

nice

line = "\t%d. %s(%s)" % (i, version[0], version[1])
LOGGER.info(line)
else:
Logger.printLog("\tNo Syslog Version Found......", prio = 'crit',
print_comp = True)
@@ -397,30 +397,43 @@ def get_syslog_process_name(product_name):
'rsyslog': RSYSLOG_PROCESS,
}.get(product_name.lower(), PROD_UNSUPPORTED)

def get_syslog_version(distro_id):
def get_syslog_version(verify_config_paths=False):
"""
Determine which syslog version is installed
Guess the syslog daemon and version number,
returns a singleton list containing a tuple: [(daemon, version_string)]
if verify_config_paths is set, this will also verify the configuration file
and/or paths are present on this system
"""
Logger.printLog("Reading installed Syslog versions....", prio = 'debug')
if distro_id == OS_UBUNTU:
command = r"dpkg -l \*sys\*log\* | grep ^ii"
pattern = r'ii\s+(rsyslog|syslog-ng)\s+(\d+\.\d+)'
elif distro_id == OS_FEDORA:
command = "rpm -qa | grep -i 'sys' | grep -i 'log'"
pattern = r'(rsyslog|syslog-ng)-(\d+\.\d+)'
elif distro_id == OS_RHEL:
command = "rpm -qa | grep -i 'sys' | grep -i 'log'"
pattern = r'(rsyslog|syslog-ng)-(\d+\.\d+)'
elif distro_id == OS_CENTOS:
command = "rpm -qa | grep -i 'sys' | grep -i 'log'"
pattern = r'(rsyslog|syslog-ng)-(\d+\.\d+)'
else:
return []

output = os.popen(command).read()
compiled_regex = re.compile(pattern, re.MULTILINE | re.IGNORECASE)
SYSLOG_PATHS = [
# (syslog type, command, conf path, conf.d path)
("rsyslog", "rsyslogd -v", "/etc/rsyslog.conf", "/etc/rsyslog.d/"),
("syslog-ng", "syslog-ng --version", "/etc/syslog-ng/syslog-ng.conf", "/etc/syslog-ng/")
]

for s in SYSLOG_PATHS:

p = subprocess.Popen(s[1], shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
p.wait()
if p.returncode != 0:
continue

version_line = p.stdout.readlines()[0]

if verify_config_paths:
if not os.path.isfile(s[2]) or not os.path.isdir(s[3]):
continue

# extract the version number from the daemon's version report,
# only cares about the major and minor version numbers and ignores
# the point number.
version_pattern = r'%s (\d+\.+\d)' % s[0]
version_string = re.search(version_pattern, version_line).group(1)

return [(s[0], version_string)]

return compiled_regex.findall(output)
return []

def get_user_type():
"""
@@ -457,7 +470,7 @@ def get_environment_details():
'distro_id': distro_id,
'version': version,
'id': version_id,
'syslog_versions': get_syslog_version(distro_id),
'syslog_versions': get_syslog_version(),
'supported_syslog_versions': {},
'operating_system': "%s-%s(%s)" % distribution
}
@@ -897,8 +910,7 @@ def syslog_config_file_content(syslog_id, source, authorization_details):
configured_source = source
source_created = ''
if len(configured_source) <= 0:
syslog_version = get_selected_syslog_version(syslog_id,
get_syslog_version(get_os_id(platform.linux_distribution()[0])))
syslog_version = get_selected_syslog_version(syslog_id, get_syslog_version())

if syslog_version > float(3.2):
source_created = (SYSLOG_NG_SOURCE_TEXT_ABOVE_3_2
@@ -1164,9 +1176,9 @@ def write_env_details(current_environment):
(current_environment['operating_system']))
env_file.write("\nSyslog versions:\n")
if len(current_environment['syslog_versions']) > 0:
for i, version in enumerate(current_environment['syslog_versions']):
for i, version in enumerate(current_environment['syslog_versions'], 1):
env_file.write("\t%d. %s(%s)" %
(i + 1, version[0], version[1]))
(i, version[0], version[1]))

else:
env_file.write("\tNo Syslog version Found......")
@@ -0,0 +1,38 @@
import unittest, platform

confsys = __import__("configure-syslog")

# "mock" out the LOGGER object
class Amorphous(object):
def __getattr__(self, name):
return lambda x: x

confsys.LOGGER = Amorphous()

class TestConfigureSyslog(unittest.TestCase):

def test_get_syslog_version(self):

r = confsys.get_syslog_version()
t = r[0]

self.assertTrue(len(r) > 0)
self.assertTrue(isinstance(t, tuple) )

self.assertTrue(t[0] in ['rsyslog', 'syslog-ng'] )

# versions should only be of xx.yy form; no more, no less
self.assertEquals(2, len(t[1].split('.')) )

def skip_test_new_old_equality(self):

new_get = confsys.new_get_syslog_version()

distro_name, version, version_id = platform.linux_distribution()
distro_id = confsys.get_os_id(distro_name)
old_get = confsys.get_syslog_version(distro_id)

self.assertEquals( new_get, old_get)

if __name__ == "__main__":
unittest.main()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.