def get_client(self, reset=False): if self.client and reset is False: return self.client # Use cached client if self.settings.get('port') is not -1: try_ports = [self.settings.get('port')] else: try_ports = DEFAULT_ETCD_PORTS for port in try_ports: try: self.client = etcd_client( host=self.settings.get('host'), port=port, username=self.settings.get('username'), password=self.settings.get('password'), allow_reconnect=self.settings.get('allow_reconnect'), protocol=self.settings.get('protocol'), ) return self.client except EtcdConnectionFailed as e: log.debug("Can't connect to etcd on %s://%s:%d: %s" % (self.settings.get('protocol'), self.settings.get('host'), port, str(e))) # No port succeeded, raise an exception if self.settings.get('port') is not -1: raise ValueError( "Can't connect to etcd on %s://%s:%d" % (self.settings.get('protocol'), self.settings.get('host'), self.settings.get('port'))) else: raise ValueError( "Can't connect to etcd host on %s://%s on default ports 4001 and 2379" % (self.settings.get('protocol'), self.settings.get('host')))
def get_client(self, reset=False): if self.client is None or reset is True: self.client = etcd_client( host=self.settings.get('host'), port=self.settings.get('port'), allow_reconnect=self.settings.get('allow_reconnect'), protocol=self.settings.get('protocol'), ) return self.client
def main(): conf_name = argv[1] data = json.loads(argv[2]) ConfigManager(conf_name, data).generate_config_file() config = load_config( 'node-monitoring', '/etc/tendrl/node-monitoring/node-monitoring.conf.yaml') central_store = etcd_client(host=config['etcd_connection'], port=config['etcd_port']) with open('/etc/machine-id') as f: machine_id = f.read().strip('\n') node_id = central_store.read('/indexes/machine_id/%s' % machine_id).value return Service('collectd', publisher_id='node_monitoring', node_id=node_id, socket_path=config['logging_socket_path'], enabled=True).restart()
from tendrl.commons.config import load_config from tendrl.commons.event import Event from tendrl.commons.message import Message from tendrl.commons.utils.time_utils import now as tendrl_now tendrl_collectd_severity_map = { 'FAILURE': 'CRITICAL', 'WARNING': 'WARNING', 'OK': 'INFO', 'OKAY': 'INFO' } config = load_config('node-monitoring', '/etc/tendrl/node-monitoring/node-monitoring.conf.yaml') central_store = etcd_client(host=config['etcd_connection'], port=config['etcd_port']) timestamp = tendrl_now().isoformat() if is_collectd_imported: sys.path.append('/usr/lib64/collectd') '''Collectd forks an instance of this plugin per threshold breach detected Read collectd detected threshold breach details from standard input of current fork.''' def get_notification(): collectd_alert = {} is_end_of_dictionary = False for line in sys.stdin: if not line.strip():