def UpdateOMSAgentConf(WorkspaceID, HeartbeatIntervalSeconds, PerfCounterObject):
    if os.path.exists(conf_path):
        txt = codecs.open(conf_path, 'r', 'utf8').read().encode('ascii', 'ignore')
        LG().Log('INFO', (('Read omsagent configuration ' + conf_path) + '.'))
    else:
        LG().Log('INFO', (('No omsagent configuration file present.  Will create new  configuration file at ' + conf_path) + '.'))
        txt = ''
    heartbeat_srch_str = '<source>.*?tag heartbeat.*?</source>\\n'
    heartbeat_srch = re.compile(heartbeat_srch_str, (re.M | re.S))
    heartbeat_cmd = non_mh_heartbeat_cmd
    if multi_homed:
        heartbeat_cmd = 'echo'
    heartbeat_src = (((('<source>\n  type exec\n  tag heartbeat.output\n  command ' + heartbeat_cmd) + ' > /dev/null\n  format tsv\n  keys severity,message\n  run_interval ') + str(HeartbeatIntervalSeconds)) + 's\n</source>\n')
    txt = heartbeat_srch.sub(heartbeat_src, txt)
    d = {}
    perf_src_srch_str = '\\n<source>\\n  type oms_omi.*?</source>\\n'
    perf_src_srch = re.compile(perf_src_srch_str, (re.M | re.S))
    for source in perf_src_srch.findall(txt):
        txt = txt.replace(source, '')
    new_source = ''
    for perf in PerfCounterObject:
        d = TranslatePerfs(perf['ObjectName'], perf['PerformanceCounter'])
        for k in d.keys():
            names = (('(' + reduce((lambda x, y: ((x + '|') + y)), d[k])) + ')')
            instances = re.sub('([><]|&gt|&lt)', '', perf['InstanceName'])
            instances = re.sub('([*])', '.*', instances)
            new_source += (((((((('\n<source>\n  type oms_omi\n  object_name "' + k) + '"\n  instance_regex "') + instances) + '"\n  counter_name_regex "') + names) + '"\n  interval ') + str(perf['IntervalSeconds'])) + 's\n</source>\n')
    m = heartbeat_srch.search(txt)
    if (m is not None):
        i = (m.end(0) + 1)
        txt = ((txt[:i] + new_source) + txt[i:])
    else:
        txt = new_source
    try:
        codecs.open(conf_path, 'w', 'utf8').write(txt)
        LG().Log('INFO', (('Created omsagent configuration at ' + conf_path) + '.'))
    except:
        LG().Log('ERROR', (('Unable to create omsagent configuration at ' + conf_path) + '.'))
        return False
    global oms_restart_cmd
    process_to_restart = 'omsagent'
    if multi_homed:
        restart_cmd += (' ' + WorkspaceID)
        process_to_restart += ('-' + WorkspaceID)
    if (os.system(restart_cmd) == 0):
        LG().Log('INFO', (('Successfully restarted ' + process_to_restart) + '.'))
    else:
        LG().Log('ERROR', (('Error restarting ' + process_to_restart) + '.'))
        return False
    return True
def UpdateOMSAgentConf(WorkspaceID, HeartbeatIntervalSeconds, PerfCounterObject):
    if os.path.exists(conf_path):
        txt = codecs.open(conf_path, 'r', 'utf8').read().encode('ascii', 'ignore')
        LG().Log('INFO', (('Read omsagent configuration ' + conf_path) + '.'))
    else:
        LG().Log('INFO', (('No omsagent configuration file present.  Will create new  configuration file at ' + conf_path) + '.'))
        txt = 
    heartbeat_srch_str = '<source>.*?tag heartbeat.*?</source>\\n'
    heartbeat_srch = re.compile(heartbeat_srch_str, (re.M | re.S))
    heartbeat_cmd = non_mh_heartbeat_cmd
    if multi_homed:
        heartbeat_cmd = 'echo'
    heartbeat_src = (((('<source>\n  type exec\n  tag heartbeat.output\n  command ' + heartbeat_cmd) + ' > /dev/null\n  format tsv\n  keys severity,message\n  run_interval ') + str(HeartbeatIntervalSeconds)) + 's\n</source>\n')
    txt = heartbeat_srch.sub(heartbeat_src, txt)
    d = {}
    perf_src_srch_str = '\\n<source>\\n  type oms_omi.*?</source>\\n'
    perf_src_srch = re.compile(perf_src_srch_str, (re.M | re.S))
    for source in perf_src_srch.findall(txt):
        txt = txt.replace(source, )
    new_source = 
    for perf in PerfCounterObject:
        d = TranslatePerfs(perf['ObjectName'], perf['PerformanceCounter'])
        for k in d.keys():
            names = (('(' + reduce((lambda x, y: ((x + '|') + y)), d[k])) + ')')
            instances = re.sub('([><]|&gt|&lt)', , perf['InstanceName'])
            instances = re.sub('([*])', '.*', instances)
            new_source += (((((((('\n<source>\n  type oms_omi\n  object_name "' + k) + '"\n  instance_regex "') + instances) + '"\n  counter_name_regex "') + names) + '"\n  interval ') + str(perf['IntervalSeconds'])) + 's\n</source>\n')
    m = heartbeat_srch.search(txt)
    if (m is not None):
        i = (m.end(0) + 1)
        txt = ((txt[:i] + new_source) + txt[i:])
    else:
        txt = new_source
    try:
        codecs.open(conf_path, 'w', 'utf8').write(txt)
        LG().Log('INFO', (('Created omsagent configuration at ' + conf_path) + '.'))
    except:
        LG().Log('ERROR', (('Unable to create omsagent configuration at ' + conf_path) + '.'))
        return False
    global oms_restart_cmd
    process_to_restart = 'omsagent'
    if multi_homed:
        restart_cmd += (' ' + WorkspaceID)
        process_to_restart += ('-' + WorkspaceID)
    if (os.system(restart_cmd) == 0):
        LG().Log('INFO', (('Successfully restarted ' + process_to_restart) + '.'))
    else:
        LG().Log('ERROR', (('Error restarting ' + process_to_restart) + '.'))
        return False
    return True