def configure_proxy(url, token): message.print_bold("Starting Wavefront Proxy Configuration!") url = api.clean_url(url) + "/api/" print url print token # replace token cmd = "sed -i -e '/token=/c\ttoken=%s' /etc/wavefront/wavefront-proxy/wavefront.conf" % ( token) ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn("Error Configuring Wavefront Proxy") # replace server url cmd = "sed -i -e '/server=/c\tserver=%s' /etc/wavefront/wavefront-proxy/wavefront.conf" % ( url) ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn("Error Configuring Wavefront Proxy") # restart proxy ret_code = system.restart_service("wavefront-proxy") if ret_code > 0: message.print_warn("Error restarting proxy service") return False message.print_success("Finished Wavefront Proxy Configuration!") message.print_success( "The Proxy's configuration file can be found at /etc/wavefront/wavefront-proxy/wavefront.conf" ) return True
def tag_telegraf_config(comment, tags): message.print_bold("Adding custom tags to Telegraf configuration") tags_pre = "- %s -" % (comment) tags_post = "- end %s tags - " % (comment) tagStr = " # %s\n" % (tags_pre) for k, v in tags.iteritems(): tagStr += ' %s = "%s"\n' % (k.lower(), v) tagStr += " # %s\n" % (tags_post) try: tagTxt = open("tags.txt", "w") tagTxt.write(tagStr) tagTxt.close() except: message.print_warn("Error writing tags.txt: " + sys.exc_info()) return False # remove existing ec2 tags conf = conf_path cmd = "sed -i '/%s/,/%s/d' %s" % (tags_pre, tags_post, conf) ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn("Error adding tags to Telegraf configuration") return False cmd = "sed -i '/\[global_tags\]/r tags.txt' %s" % (conf) ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn( "Error overwriting telegraf.conf. Is the file located at " + conf + "? ") message.print_success("Finished adding tags to Telegraf configuration.") return True
def install_agent(): message.print_bold("Starting Telegraf Installation!") print "Downloading configuration to ", conf_path cmd = "mkdir -p /etc/telegraf && sudo curl -o %s %s" % (conf_path, telegraf_conf) ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn("Error downloading Telegraf config file.") return False cmd = get_install_agent_cmd() print "Running ", cmd ret_code = system.run_command(cmd) if ret_code > 0: message.print_warn("Error installing Telegraf") return False message.print_success("Finished Installing Telegraf!") message.print_success( "The Telegraf configuration file can be found at /etc/telegraf/telegraf.conf" ) return True