def validate_options(self): if not self.options['proxy_address']: message.print_warn("Missing required option: proxy_address") return False if not self.options['proxy_port']: # default to 2878 self.options['proxy_port'] = 2878 return True
def __init__(self, name, options): self.name = name self.options = options cmd = "mkdir -p /etc/telegraf/telegraf.d" ret_code = subprocess.call(cmd, shell=True) if ret_code > 0: message.print_warn("Unable to create integrations config directory at /etc/telegraf/telegraf.d")
def remove(self): try: os.remove(self.conf_path) message.print_success("Removed StatsD configuration file " + self.conf_path) except: message.print_warn("Unable to remove conf file at: " + self.conf_path) message.print_warn("Was StatsD integration already removed?") return False return True
def install(self): self.validate_options() statsd_port = self.options["statsd_port"] out = self.conf % (statsd_port) if system.write_file(self.conf_path, out): message.print_success( "Wrote StatsD service plugin configuration to %s" % (self.conf_path)) else: message.print_warn( "Failed writing config file to %s - do you have write permission on this location?" % (self.conf_path)) return False return True
def install(self): if not self.validate_options(): return False proxy_address = self.options["proxy_address"] proxy_port = self.options["proxy_port"] out = self.conf % (proxy_address, proxy_port) if system.write_file(self.conf_path, out): message.print_success("Wrote Wavefront configuration to " + self.conf_path) else: message.print_warn( "Failed writing config file to %s - do you have write permission on this location?" % (self.conf_path)) return False return True
def run(self): message.print_welcome() int_name = self.options['<name>'] int_options = self.options['<option>'] int_options = util.option_to_dict(int_options) message.print_bold(int_name + " Integration with Options:") for k,v in int_options.iteritems(): print(k,": ",v) integration_class = None try: integration_class = getattr(importlib.import_module("wavefront_cli.integrations"), int_name) instance = integration_class(int_name, int_options) except: message.print_warn("Error: Unrecognized Integration: " + int_name) sys.exit(1) if self.options['install']: print("Action: install") if not instance.install(): instance.print_failure() sys.exit(1) else: instance.print_success() elif self.options['remove']: print("Action: remove") if not instance.remove(): instance.print_failure() sys.exit(1) else: instance.print_success() system.restart_service("telegraf") sys.exit(0)
def print_failure(self): message.print_warn("Failed to install %s integration!" % (self.name))