def get_alert(self, current=0, minimum=0, maximum=100, header="", log=False): """Return the alert status relative to a current value. Use this function for minor stats. If current < CAREFUL of max then alert = OK If current > CAREFUL of max then alert = CAREFUL If current > WARNING of max then alert = WARNING If current > CRITICAL of max then alert = CRITICAL If defined 'header' is added between the plugin name and the status. Only useful for stats with several alert status. If log=True than add log if necessary elif log=False than do not log elig log=None than apply the config given in the conf file """ # Compute the % try: value = (current * 100) / maximum except ZeroDivisionError: return 'DEFAULT' except TypeError: return 'DEFAULT' # Build the stat_name = plugin_name + header if header == "": stat_name = self.plugin_name else: stat_name = self.plugin_name + '_' + header # Manage limits ret = 'OK' try: if value > self.__get_limit('critical', stat_name=stat_name): ret = 'CRITICAL' elif value > self.__get_limit('warning', stat_name=stat_name): ret = 'WARNING' elif value > self.__get_limit('careful', stat_name=stat_name): ret = 'CAREFUL' elif current < minimum: ret = 'CAREFUL' except KeyError: return 'DEFAULT' # Manage log log_str = "" if self.__get_limit_log(stat_name=stat_name, default_action=log): # Add _LOG to the return string # So stats will be highlited with a specific color log_str = "_LOG" # Add the log to the list glances_logs.add(ret, stat_name.upper(), value, []) # Manage action # Here is a command line for the current trigger ? try: command = self.__get_limit_action(ret.lower(), stat_name=stat_name) except KeyError: # Reset the trigger self.actions.set(stat_name, ret.lower()) else: # A command line is available for the current alert, run it # Build the {{mustache}} dictionnary if isinstance(self.stats, list): # If the stats are stored in a list of dict (fs plugin for exemple) # Return the dict for the current header mustache_dict = {} for item in self.stats: if item[self.get_key()] == header: mustache_dict = item break else: # Use the stats dict mustache_dict = self.stats # Run the action self.actions.run( stat_name, ret.lower(), command, mustache_dict=mustache_dict) # Default is ok return ret + log_str
def get_alert(self, current=0, minimum=0, maximum=100, highlight_zero=True, is_max=False, header="", action_key=None, log=False): """Return the alert status relative to a current value. Use this function for minor stats. If current < CAREFUL of max then alert = OK If current > CAREFUL of max then alert = CAREFUL If current > WARNING of max then alert = WARNING If current > CRITICAL of max then alert = CRITICAL If highlight=True than 0.0 is highlighted If defined 'header' is added between the plugin name and the status. Only useful for stats with several alert status. If defined, 'action_key' define the key for the actions. By default, the action_key is equal to the header. If log=True than add log if necessary elif log=False than do not log elif log=None than apply the config given in the conf file """ # Manage 0 (0.0) value if highlight_zero is not True if not highlight_zero and current == 0: return 'DEFAULT' # Compute the % try: value = (current * 100) / maximum except ZeroDivisionError: return 'DEFAULT' except TypeError: return 'DEFAULT' # Build the stat_name = plugin_name + header if header == "": stat_name = self.plugin_name else: stat_name = self.plugin_name + '_' + header # Manage limits # If is_max is set then display the value in MAX ret = 'MAX' if is_max else 'OK' try: if value >= self.get_limit('critical', stat_name=stat_name): ret = 'CRITICAL' elif value >= self.get_limit('warning', stat_name=stat_name): ret = 'WARNING' elif value >= self.get_limit('careful', stat_name=stat_name): ret = 'CAREFUL' elif current < minimum: ret = 'CAREFUL' except KeyError: return 'DEFAULT' # Manage log log_str = "" if self.get_limit_log(stat_name=stat_name, default_action=log): # Add _LOG to the return string # So stats will be highlited with a specific color log_str = "_LOG" # Add the log to the list glances_logs.add(ret, stat_name.upper(), value) # Manage threshold self.manage_threshold(stat_name, ret) # Manage action self.manage_action(stat_name, ret.lower(), header, action_key) # Default is 'OK' return ret + log_str
def get_alert(self, current=0, minimum=0, maximum=100, header="", log=False): """Return the alert status relative to a current value. Use this function for minor stats. If current < CAREFUL of max then alert = OK If current > CAREFUL of max then alert = CAREFUL If current > WARNING of max then alert = WARNING If current > CRITICAL of max then alert = CRITICAL If defined 'header' is added between the plugin name and the status. Only useful for stats with several alert status. If log=True than add log if necessary elif log=False than do not log elig log=None than apply the config given in the conf file """ # Compute the % try: value = (current * 100) / maximum except ZeroDivisionError: return 'DEFAULT' except TypeError: return 'DEFAULT' # Build the stat_name = plugin_name + header if header == "": stat_name = self.plugin_name else: stat_name = self.plugin_name + '_' + header # Manage limits ret = 'OK' try: if value > self.__get_limit('critical', stat_name=stat_name): ret = 'CRITICAL' elif value > self.__get_limit('warning', stat_name=stat_name): ret = 'WARNING' elif value > self.__get_limit('careful', stat_name=stat_name): ret = 'CAREFUL' elif current < minimum: ret = 'CAREFUL' except KeyError: return 'DEFAULT' # Manage log log_str = "" if self.__get_limit_log(stat_name=stat_name, default_action=log): # Add _LOG to the return string # So stats will be highlited with a specific color log_str = "_LOG" # Add the log to the list glances_logs.add(ret, stat_name.upper(), value) # Manage action # Here is a command line for the current trigger ? try: command = self.__get_limit_action(ret.lower(), stat_name=stat_name) except KeyError: # Reset the trigger self.actions.set(stat_name, ret.lower()) else: # A command line is available for the current alert, run it # Build the {{mustache}} dictionnary if isinstance(self.stats, list): # If the stats are stored in a list of dict (fs plugin for exemple) # Return the dict for the current header mustache_dict = {} for item in self.stats: if item[self.get_key()] == header: mustache_dict = item break else: # Use the stats dict mustache_dict = self.stats # Run the action self.actions.run(stat_name, ret.lower(), command, mustache_dict=mustache_dict) # Default is ok return ret + log_str