def _get_data(data, elc, opt, **kwargs): """Function: _get_data Description: Private function for get_status function. Get data from Elasticsearch database. Arguments: (input) data -> Data results. (input) elc -> Elasticsearch status class instance. (input) opt -> Method to run in class instance. (input) **kwargs: status_call -> Contains class method names for the '-D' option. (output) data -> Modified data results. """ func_call = dict(kwargs.get("status_call")) data = dict(data) if opt in func_call: data, _, _ = gen_libs.merge_two_dicts(data, getattr(elc, func_call[opt])()) else: print("Warning: Option '{%s}' is not supported" % (opt)) return data
def get_status(els, **kwargs): """Function: get_status Description: Display status on a number of different options in an Elasticsearch database cluster. Arguments: (input) els -> Elasticsearch class instance. (input) **kwargs: args_array -> Dict of command line options and values. status_call -> Contains class method names for the '-D' option. """ elc = elastic_class.ElasticSearchStatus(els.hosts, els.port, **kwargs) args_array = dict(kwargs.get("args_array")) display_list = list(args_array.get("-D", [])) if not display_list or "all" in display_list: print(elc.get_all()) else: data, _, _ = gen_libs.merge_two_dicts(elc.get_cluster(), elc.get_nodes()) for opt in display_list: data = _get_data(data, elc, opt, **kwargs) print(data)
def _process_data(check_list, err_flag, err_msg, esc, **kwargs): """Function: _process_data Description: Private function for check_status function. Process data from Elasticsearch database. Arguments: (input) check_list -> Contains class method names for the '-C' option. (input) err_flag -> True|False - Status of results. (input) err_msg -> Error message(s). (input) esc -> Elasticsearch status class instance. (input) **kwargs: check_call -> Contains class method names for the '-C' option. cutoff_cpu -> Cutoff value for CPU usage. cutoff_mem -> Cutoff value for Memory usage. cutoff_disk -> Cutoff value for Disk usage. (output) err_flag -> True|False - Status of results. (output) err_msg -> Error message(s). """ check_list = list(check_list) func_call = dict(kwargs.get("check_call")) cutoff_cpu = kwargs.get("cutoff_cpu") cutoff_mem = kwargs.get("cutoff_mem") cutoff_disk = kwargs.get("cutoff_disk") if err_msg: err_msg = dict(err_msg) for opt in check_list: if opt in func_call: results = getattr(esc, func_call[opt])(cutoff_cpu=cutoff_cpu, cutoff_mem=cutoff_mem, cutoff_disk=cutoff_disk) if results: err_flag = True err_msg, _, _ = gen_libs.merge_two_dicts(err_msg, results) else: print("Warning: Option '{%s}' is not supported" % (opt)) return err_flag, err_msg
def get_all(self, **kwargs): """Method: get_all Description: Return dictionary format of status of all elements. Arguments: (output) data -> Dictionary format of status of all elements. """ # List of checks to be called func_list = [ self.get_nodes, self.get_node_status, self.get_svr_status, self.get_mem_status, self.get_shrd_status, self.get_gen_status, self.get_disk_status ] data = self.get_cluster() for func in func_list: results = func() data, _, _ = gen_libs.merge_two_dicts(data, results) return data
def chk_all(self, cutoff_cpu=None, cutoff_mem=None, cutoff_disk=None, **kwargs): """Method: chk_all Description: Check status of all elements. Arguments: (input) cutoff_cpu -> Percentage threshold on cpu usage. (input) cutoff_mem -> Percentage threshold on memory used. (input) cutoff_disk -> Percentage threshold on disk usage. (output) Return any messages from all element check. """ # List of checks to be called func_list = [ self.chk_mem, self.chk_nodes, self.chk_shards, self.chk_server, self.chk_status, self.chk_disk ] err_flag = False data = self.get_cluster() for func in func_list: results = func(cutoff_cpu=cutoff_cpu, cutoff_mem=cutoff_mem, cutoff_disk=cutoff_disk) if results: err_flag = True data, _, _ = gen_libs.merge_two_dicts(data, results) return data if err_flag else {}