def configure(app, count): """Create, get or modify an app monitor configuration""" zkclient = context.GLOBAL.zk.conn if count is not None: data = masterapi.update_appmonitor(zkclient, app, count) else: data = masterapi.get_appmonitor(zkclient, app) cli.out(formatter(data))
def _list(): """List all configured monitors""" zkclient = context.GLOBAL.zk.conn suspended_monitors = masterapi.get_suspended_appmonitors(zkclient) monitors = [ masterapi.get_appmonitor( zkclient, app, suspended_monitors=suspended_monitors, ) for app in masterapi.appmonitors(zkclient) ] cli.out(formatter(monitors))
def _list(match=None): """List configured monitors.""" if match is None: match = '*' zkclient = context.GLOBAL.zk.conn monitors = [ masterapi.get_appmonitor(zkclient, app) for app in masterapi.appmonitors(zkclient) ] filtered = [ monitor for monitor in monitors if (monitor is not None and fnmatch.fnmatch(monitor['_id'], match)) ] return sorted(filtered, key=lambda item: item['_id'])
def configure(app, count, policy): """Create, get or modify an app monitor configuration""" zkclient = context.GLOBAL.zk.conn options = {} if count is not None: options['count'] = count if policy is not None: options['policy'] = policy existing = masterapi.get_appmonitor(zkclient, app) # reconfigure if any of the parameters is specified if options: if count is None and existing is not None: count = existing.get('count') if policy is None and existing is not None: policy = existing.get('policy') data = masterapi.update_appmonitor(zkclient, app, count, policy) else: data = existing cli.out(formatter(data))
def get(rsrc_id): """Get application monitor configuration.""" zkclient = context.GLOBAL.zk.conn return masterapi.get_appmonitor(zkclient, rsrc_id, raise_notfound=True)
def update(rsrc_id, rsrc): """Update application configuration.""" zkclient = context.GLOBAL.zk.conn masterapi.update_appmonitor(zkclient, rsrc_id, rsrc['count']) return masterapi.get_appmonitor(zkclient, rsrc_id)
def create(rsrc_id, rsrc): """Create (configure) application monitor.""" zkclient = context.GLOBAL.zk.conn masterapi.update_appmonitor(zkclient, rsrc_id, rsrc['count']) return masterapi.get_appmonitor(zkclient, rsrc_id)