Skip to content

Commit

Permalink
CP-44440: Collect config files in Server Status Report
Browse files Browse the repository at this point in the history
  • Loading branch information
BengangY committed Nov 23, 2023
1 parent ee16423 commit 3e54079
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ NRPE_DIR = '/etc/nrpe.d'
XEN_BUGTOOL_LOG = 'xen-bugtool.log'
CRON_DIRS = '/etc/cron*'
CRON_SPOOL = '/var/spool/cron'
SNMP_XS_CONF = '/etc/snmp/snmp.xs.conf'
SNMPD_XS_CONF = '/etc/snmp/snmpd.xs.conf'
SNMPD_CONF = '/var/lib/net-snmp/snmpd.conf'
SYSCONFIG_SNMPD = '/etc/sysconfig/snmpd'

#
# External programs
Expand Down Expand Up @@ -1067,6 +1071,10 @@ exclude those logs from the archive.
'vgscan-log']])
tree_output(CAP_XENSERVER_INSTALL, INSTALLED_REPOS_DIR)
tree_output(CAP_XENSERVER_INSTALL, UPDATE_APPLIED_DIR)
func_output(CAP_XENSERVER_CONFIG, 'snmp_xs_conf', filter_snmp_xs_conf)
func_output(CAP_XENSERVER_CONFIG, 'snmpd_xs_conf', filter_snmpd_xs_conf)
func_output(CAP_XENSERVER_CONFIG, 'snmpd_conf', filter_snmpd_conf)
file_output(CAP_XENSERVER_CONFIG, [SYSCONFIG_SNMPD])

try:
load_plugins()
Expand Down Expand Up @@ -1516,6 +1524,26 @@ def multipathd_topology(cap):

return stdout

def filter_snmp_xs_conf(_):
"""Filter /etc/snmp/snmp.xs.conf with keys and community removed"""
return snmp_regex_filter(SNMP_XS_CONF, r"((community|\w_key)\s*=\s*)\S+", r"\1REMOVED")

def filter_snmpd_xs_conf(_):
"""Filter /etc/snmp/snmpd.xs.conf with the com2sec community removed"""
return snmp_regex_filter(SNMPD_XS_CONF, r"(com2sec(\s+\S+){2}\s+)\S+", r"\1REMOVED")

def filter_snmpd_conf(_):
"""Filter /var/lib/net-snmp/snmpd.conf with the usmUser fields authKey and privKey removed"""
return snmp_regex_filter(SNMPD_CONF, r"(usmUser(\s+\S+){7}\s+)\S+(\s+\S+\s+)\S+(\s+\S+)", r"\1REMOVED\3REMOVED\4")

def snmp_regex_filter(replace_file, regex_str, replace_str):
try:
with open(replace_file, "r") as file:
return re.sub(regex_str, replace_str, file.read())
except Exception as e:
return "Failed to filter %s %s" % (replace_file, str(e))


def dp_list():
output = StringIO.StringIO()
procs = [ProcOutput([OVS_DPCTL, 'dump-dps'], caps[CAP_NETWORK_STATUS][MAX_TIME], output)]
Expand Down

0 comments on commit 3e54079

Please sign in to comment.