diff --git a/ingest/management/__init__.py b/ingest/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ingest/management/commands/__init__.py b/ingest/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ingest/management/commands/send_json.py b/ingest/management/commands/send_json.py new file mode 100644 index 0000000..395c6af --- /dev/null +++ b/ingest/management/commands/send_json.py @@ -0,0 +1,35 @@ +import json +import requests + +from django.core.management.base import BaseCommand + +from compat.dsn import get_store_url, get_header_value + + +class Command(BaseCommand): + help = "..." + + def add_arguments(self, parser): + parser.add_argument("--dsn") + parser.add_argument("json_files", nargs="+") + + def handle(self, *args, **options): + dsn = options['dsn'] + + for json_filename in options["json_files"]: + with open(json_filename) as f: + print("HIER", json_filename) + try: + data = json.loads(f.read()) + except Exception as e: + self.stderr.write("%s %s %s" % ("Not JSON", json_filename, str(e))) + + try: + response = requests.post( + get_store_url(dsn), + headers={"X-Sentry-Auth": get_header_value(dsn)}, + json=data, + ) + response.raise_for_status() + except Exception as e: + self.stderr.write("%s %s" % ("foo", e)) diff --git a/ingest/views.py b/ingest/views.py index 265afab..567d6f0 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -60,6 +60,7 @@ class BaseIngestAPIView(APIView): hash_ = get_hash_for_data(event_data) issue, _ = Issue.objects.get_or_create( + project=project, hash=hash_, ) issue.events.add(event) diff --git a/issues/admin.py b/issues/admin.py index 454cb4e..367adc4 100644 --- a/issues/admin.py +++ b/issues/admin.py @@ -6,9 +6,15 @@ from .models import Issue @admin.register(Issue) class IssueAdmin(admin.ModelAdmin): list_display = [ + "title", "hash", + "project", "event_count", # expensive operation as written now (query in loop) ] + list_filter = [ + "project", + ] + exclude = ["events"] readonly_fields = [ diff --git a/issues/models.py b/issues/models.py index 65a2529..12614a6 100644 --- a/issues/models.py +++ b/issues/models.py @@ -22,5 +22,15 @@ class Issue(models.Model): def title(self): # TODO: refactor to a (filled-on-create) field parsed_data = json.loads(self.events.first().data) - foo = parsed_data["exception"]["values"][0] - return foo["type"] + ": " + foo["value"] + exc = parsed_data.get("exception", {}) + if "values" in exc: + values = exc["values"] + else: + values = exc + + if isinstance(values, list): + first_value = values[0] if values else {} + else: + first_value = values + + return first_value.get("type", "none") + ": " + first_value.get("value", "none") diff --git a/projects/models.py b/projects/models.py index 1fdf23f..02b6f7e 100644 --- a/projects/models.py +++ b/projects/models.py @@ -30,3 +30,7 @@ class Project(models.Model): def __str__(self): return self.name + + def get_dsn(self): + # TODO, because the server needs to know its own address + return get_dsn()