(cid)
return results
Lookup a monitor via either rethinkdb or redis
Lookup a monitor via either rethinkdb or redis
Lookup a monitor via either rethinkdb or redis
def getMonitor(cid):
    ''' Lookup a monitor via either rethinkdb or redis '''
    # Pull from redis first
    cache = lookupRedis("monitor", cid)

    # Pull from RethinkDB second
    try:
        results = r.table('monitors').get(cid).run(rdb_server)
        results['cacheonly'] = False
        if int(cache['failcount']) > results['failcount']:
            results['failcount'] = int(cache['failcount'])
        if "encrypted" in results:
            if results['encrypted'] is True:
                crypto = Fernet(config['crypto_key'])
                results['data'] = json.loads(crypto.decrypt(bytes(results['data'])))
    except (RqlDriverError, RqlRuntimeError, socket.error) as e:
        results = cache
        results['cacheonly'] = True
        logger.critical("RethinkDB is unaccessible, monitor %s was pulled from cache" % cid)
        logger.critical("RethinkDB Error: %s" % e.message)
    return results
def getMonitor ( cid ) : # Pull from redis first cache = lookupRedis ( "monitor" , cid ) # Pull from RethinkDB second try : results = r . table ( 'monitors' ) . get ( cid ) . run ( rdb_server ) results [ 'cacheonly' ] = False if int ( cache [ 'failcount' ] ) > results [ 'failcount' ] : results [ 'failcount' ] = int ( cache [ 'failcount' ] ) if "encrypted" in results : if results [ 'encrypted' ] is True : crypto = Fernet ( config [ 'crypto_key' ] ) results [ 'data' ] = json . loads ( crypto . decrypt ( bytes ( results [ 'data' ] ) ) ) except ( RqlDriverError , RqlRuntimeError , socket . error ) as e : results = cache results [ 'cacheonly' ] = True logger . critical ( "RethinkDB is unaccessible, monitor %s was pulled from cache" % cid ) logger . critical ( "RethinkDB Error: %s" % e . message ) return results