Ejemplo n.º 1
0
 def get_user_by_name(cls, name):
     with ErrorReport():
         user = User.objects.filter(username=name)[:1]
         if user:
             return user[0]
         else:
             metrics["error", ("type", "user_not_found")] += 1
             return None
Ejemplo n.º 2
0
Archivo: base.py Proyecto: nbashev/noc
 def call_raw_handler(message):
     metrics[metric_in] += 1
     with ErrorReport():
         r = handler(message, message.body)
     if r:
         metrics[metric_processed] += 1
     elif message.is_async():
         message.on("finish", on_finish)
     else:
         metrics[metric_deferred] += 1
     return r
Ejemplo n.º 3
0
Archivo: base.py Proyecto: nbashev/noc
 def call_json_handler(message):
     metrics[metric_in] += 1
     try:
         data = orjson.loads(message.body)
     except ValueError as e:
         metrics[metric_decode_fail] += 1
         self.logger.debug("Cannot decode JSON message: %s", e)
         return True  # Broken message
     if isinstance(data, dict):
         with ErrorReport():
             r = handler(message, **data)
     else:
         with ErrorReport():
             r = handler(message, data)
     if r:
         metrics[metric_processed] += 1
     elif message.is_async():
         message.on("finish", on_finish)
     else:
         metrics[metric_deferred] += 1
     return r
Ejemplo n.º 4
0
def test_error_report():
    stream = StringIO()
    logger = logging.Logger(__name__ + "::test_error_report")
    logger.setLevel(logging.DEBUG)
    logger.addHandler(logging.StreamHandler(stream))
    with pytest.raises(ValueError):
        with ErrorReport(logger=logger):
            raise ValueError("Ошибка--@!@--")
    report = stream.getvalue()
    assert "@!@" in report
    assert "ValueError" in report
    assert "stream" in report
Ejemplo n.º 5
0
Archivo: card.py Proyecto: nbashev/noc
 def get_current_user(self):
     user = None
     with ErrorReport():
         user = self.get_user_by_name(
             self.request.headers.get("Remote-User"))
     return user