From 51bdcf24bf56987fd75e5953b73bf4c182dddbd0 Mon Sep 17 00:00:00 2001 From: rhigdon Date: Fri, 30 Aug 2013 19:24:54 +0000 Subject: [PATCH 1/4] added new dry-run flow --- configure-syslog.py | 67 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/configure-syslog.py b/configure-syslog.py index fa02210..4764b30 100755 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -86,10 +86,10 @@ "to manually re-configure syslog for Loggly.") STR_SYSLOG_DAEMON_MESSAGE = ("\nSyslog daemon (%s) is not running. " "Please start %s daemon and try again.\n") -REST_URL_GET_AUTH_TOKEN = ("http://%s.loggly.com/apiv2/customer") -REST_URL_GET_SEARCH_ID = ("http://%s.loggly.com" +REST_URL_GET_AUTH_TOKEN = ("http://%s.frontend.chipper01.loggly.net/apiv2/customer") +REST_URL_GET_SEARCH_ID = ("http://%s.frontend.chipper01.loggly.net" "/apiv2/search?q=%s&from=-2h&until=now&size=10") -REST_URL_GET_SEARCH_RESULT = ("http://%s.loggly.com/apiv2/events?rsid=%s") +REST_URL_GET_SEARCH_RESULT = ("http://%s.frontend.chipper01.loggly.net/apiv2/events?rsid=%s") USER_NAME_TEXT = ("Enter the username that you use to log into your Loggly account.") ACCOUNT_NAME_TEXT = ("Enter your Loggly account name. This is your subdomain. " "For example if you login at mycompany.loggly.com," @@ -1207,16 +1207,59 @@ def uninstall(current_environment): send_sighup_to_syslog(syslog_name_for_configuration) LOGGER.debug("Uninstall completed") +def rsyslog_dryrun(): + errors = [] + process = subprocess.Popen('rsyslogd -N1', shell=True, + stdout=subprocess.PIPE, + stdin=open(os.devnull), + stderr=subprocess.PIPE) + results = process.stderr.readlines() + process.stderr.close() + + for line in results: + if 'UDP' in line: + if 'enabled' in line: + print 'UDP Reception: Enabled' + else: + print 'UDP Reception: Disabled' + if 'error' in line.lower(): + errors.append(line) + + return errors + +def syslogng_dryrun(): + for line in results: + pass + def dryrun(current_environment): - LOGGER.debug("Dryrun started") - user_type = get_user_type() - if user_type == NON_ROOT_USER: - LOGGER.warning("Current user is not root user") - sys.exit() - syslog_name_for_configuration = install(current_environment) - remove_configuration(syslog_name_for_configuration) - send_sighup_to_syslog(syslog_name_for_configuration) - LOGGER.debug("Dryrun completed") + syslogd = perform_sanity_check_and_get_product_for_configuration(current_environment) + LOGGER.debug("Dryrun started for syslog version %s" % syslogd) + + config_file = write_configuration(syslogd, {'token': 'foofey', 'id': DISTRIBUTION_ID }, 1) + errors = [] + + if syslogd == 'rsyslog': + errors = rsyslog_dryrun() + elif syslogd == 'syslog-ng': + errors = syslogng_dryrun() + + remove_configuration(syslogd) + + if len(errors) > 0: + LOGGER.error('\n!Dry Run FAIL: errors in config script!\n') + for error in errors: + LOGGER.error(' %s' % error) + else: + LOGGER.info("Dryrun completed successfully!!!") + +# user_type = get_user_type() +# if user_type == NON_ROOT_USER: +# LOGGER.warning("Current user is not root user") +# sys.exit() +# syslog_name_for_configuration = install(current_environment) +# remove_configuration(syslog_name_for_configuration) +# send_sighup_to_syslog(syslog_name_for_configuration) +# LOGGER.debug("Dryrun completed") module_dict = { 'sysinfo' : write_env_details, From 043f28ca1771e80fbc38f1ce9cefd96c7afba016 Mon Sep 17 00:00:00 2001 From: rhigdon Date: Fri, 30 Aug 2013 19:39:41 +0000 Subject: [PATCH 2/4] updates for syslog-ng dryrun --- configure-syslog.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/configure-syslog.py b/configure-syslog.py index 4764b30..431aa72 100755 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -1208,14 +1208,8 @@ def uninstall(current_environment): LOGGER.debug("Uninstall completed") def rsyslog_dryrun(): + results = get_stderr_from_process('rsyslogd -N1') errors = [] - process = subprocess.Popen('rsyslogd -N1', shell=True, - stdout=subprocess.PIPE, - stdin=open(os.devnull), - stderr=subprocess.PIPE) - results = process.stderr.readlines() - process.stderr.close() - for line in results: if 'UDP' in line: if 'enabled' in line: @@ -1227,11 +1221,31 @@ def rsyslog_dryrun(): return errors -def syslogng_dryrun(): +def get_stderr_from_process(command): + process = subprocess.Popen('rsyslogd -N1', shell=True, + stdout=subprocess.PIPE, + stdin=open(os.devnull), + stderr=subprocess.PIPE) + results = process.stderr.readlines() + process.stderr.close() + return results + +def syslog_ng_dryrun(): + results = get_stderr_from_process('syslog-ng -s') + errors = [] for line in results: - pass + if 'error' in line.lower(): + errors.append(line) + return errors + +def ensure_root(): + user_type = get_user_type() + if user_type == NON_ROOT_USER: + LOGGER.warning("Current user is not root user") + sys.exit() def dryrun(current_environment): + ensure_root() syslogd = perform_sanity_check_and_get_product_for_configuration(current_environment) LOGGER.debug("Dryrun started for syslog version %s" % syslogd) @@ -1241,7 +1255,7 @@ def dryrun(current_environment): if syslogd == 'rsyslog': errors = rsyslog_dryrun() elif syslogd == 'syslog-ng': - errors = syslogng_dryrun() + errors = syslog_ng_dryrun() remove_configuration(syslogd) @@ -1251,15 +1265,6 @@ def dryrun(current_environment): LOGGER.error(' %s' % error) else: LOGGER.info("Dryrun completed successfully!!!") - -# user_type = get_user_type() -# if user_type == NON_ROOT_USER: -# LOGGER.warning("Current user is not root user") -# sys.exit() -# syslog_name_for_configuration = install(current_environment) -# remove_configuration(syslog_name_for_configuration) -# send_sighup_to_syslog(syslog_name_for_configuration) -# LOGGER.debug("Dryrun completed") module_dict = { 'sysinfo' : write_env_details, From 369b9f515bf38cf9614d25993e57515fe1968ece Mon Sep 17 00:00:00 2001 From: rhigdon Date: Fri, 30 Aug 2013 20:02:22 +0000 Subject: [PATCH 3/4] fix for static param -- should be dynamic --- configure-syslog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure-syslog.py b/configure-syslog.py index 431aa72..8eef70c 100755 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -1222,7 +1222,7 @@ def rsyslog_dryrun(): return errors def get_stderr_from_process(command): - process = subprocess.Popen('rsyslogd -N1', shell=True, + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.PIPE) From db333ef8dff4e13b4fea16c7aa9110659f082ee4 Mon Sep 17 00:00:00 2001 From: rhigdon Date: Fri, 30 Aug 2013 20:04:26 +0000 Subject: [PATCH 4/4] undo changes to point at chipper --- configure-syslog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure-syslog.py b/configure-syslog.py index 8eef70c..d09762b 100755 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -86,10 +86,10 @@ "to manually re-configure syslog for Loggly.") STR_SYSLOG_DAEMON_MESSAGE = ("\nSyslog daemon (%s) is not running. " "Please start %s daemon and try again.\n") -REST_URL_GET_AUTH_TOKEN = ("http://%s.frontend.chipper01.loggly.net/apiv2/customer") -REST_URL_GET_SEARCH_ID = ("http://%s.frontend.chipper01.loggly.net" +REST_URL_GET_AUTH_TOKEN = ("http://%s.loggly.com/apiv2/customer") +REST_URL_GET_SEARCH_ID = ("http://%s.loggly.com" "/apiv2/search?q=%s&from=-2h&until=now&size=10") -REST_URL_GET_SEARCH_RESULT = ("http://%s.frontend.chipper01.loggly.net/apiv2/events?rsid=%s") +REST_URL_GET_SEARCH_RESULT = ("http://%s.loggly.com/apiv2/events?rsid=%s") USER_NAME_TEXT = ("Enter the username that you use to log into your Loggly account.") ACCOUNT_NAME_TEXT = ("Enter your Loggly account name. This is your subdomain. " "For example if you login at mycompany.loggly.com,"