def show_watch(self, context, watch_name): ''' The show_watch method returns the attributes of one watch/alarm arg1 -> RPC context. arg2 -> Name of the watch you want to see, or None to see all ''' if watch_name: try: wr = db_api.watch_rule_get(context, watch_name) except Exception as ex: logger.warn('show_watch (%s) db error %s' % (watch_name, str(ex))) if wr: wrs = [wr] else: raise AttributeError('Unknown watch name %s' % watch_name) else: try: wrs = db_api.watch_rule_get_all(context) except Exception as ex: logger.warn('show_watch (all) db error %s' % str(ex)) return result = [api.format_watch(w) for w in wrs] return result
def get_matching_watches(): if watch_name: yield watchrule.WatchRule.load(cnxt, watch_name) else: for wr in db_api.watch_rule_get_all(cnxt): if watchrule.rule_can_use_sample(wr, stats_data): yield watchrule.WatchRule.load(cnxt, watch=wr)
def _periodic_watcher_task(self, context): try: wrn = [w.name for w in db_api.watch_rule_get_all(context)] except Exception as ex: logger.warn('periodic_task db error (%s) %s' % ('watch rule removed?', str(ex))) return for wr in wrn: rule = watchrule.WatchRule.load(context, wr) rule.evaluate()
def _periodic_watcher_task(self, context): now = timeutils.utcnow() try: wrn = [w.name for w in db_api.watch_rule_get_all(context)] except Exception as ex: logger.warn('periodic_task db error (%s) %s' % ('watch rule removed?', str(ex))) return for wr in wrn: rule = watchrule.WatchRule.load(context, wr) rule.evaluate()
def _periodic_watcher_task(self, context): now = timeutils.utcnow() try: wrs = db_api.watch_rule_get_all(context) except Exception as ex: logger.warn('periodic_task db error (%s) %s' % ('watch rule removed?', str(ex))) return for wr in wrs: # has enough time progressed to run the rule dt_period = datetime.timedelta(seconds=int(wr.rule['Period'])) if now < (wr.last_evaluated + dt_period): continue self.run_rule(context, wr, now)
def show_watch(self, cnxt, watch_name): ''' The show_watch method returns the attributes of one watch/alarm arg1 -> RPC context. arg2 -> Name of the watch you want to see, or None to see all ''' if watch_name: wrn = [watch_name] else: try: wrn = [w.name for w in db_api.watch_rule_get_all(cnxt)] except Exception as ex: logger.warn('show_watch (all) db error %s' % str(ex)) return wrs = [watchrule.WatchRule.load(cnxt, w) for w in wrn] result = [api.format_watch(w) for w in wrs] return result
def show_watch(self, cnxt, watch_name): """ The show_watch method returns the attributes of one watch/alarm :param cnxt: RPC context. :param watch_name: Name of the watch you want to see, or None to see all """ if watch_name: wrn = [watch_name] else: try: wrn = [w.name for w in db_api.watch_rule_get_all(cnxt)] except Exception as ex: LOG.warn(_('show_watch (all) db error %s') % ex) return wrs = [watchrule.WatchRule.load(cnxt, w) for w in wrn] result = [api.format_watch(w) for w in wrs] return result
def get_all(cls, context): return [ cls._from_db_object(context, cls(), db_rule) for db_rule in db_api.watch_rule_get_all(context) ]
def get_all(cls, context): return [cls._from_db_object(context, cls(), db_rule) for db_rule in db_api.watch_rule_get_all(context)]