Skip to content

Commit

Permalink
the horror grows
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Mar 6, 2024
1 parent d87e734 commit fecc2f2
Show file tree
Hide file tree
Showing 8 changed files with 761 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fmt:
go fmt

serve:
find . -name '*.go' | entr -r go run main.go
find . -name '*.go' | entr -r bash -c "go build && ./sentry-journald --port 8000"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ go 1.20
require github.com/ssgreg/journald v1.0.0

require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-chi/cors v1.2.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/mileusna/useragent v1.3.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mileusna/useragent v1.3.4 h1:MiuRRuvGjEie1+yZHO88UBYg8YBC/ddF6T7F56i3PCk=
github.com/mileusna/useragent v1.3.4/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
90 changes: 90 additions & 0 deletions list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sentry Journald</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/normalize.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/concrete.css">
<link rel="stylesheet" href="https://unpkg.com/charts.css/dist/charts.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
main, header {
margin: auto;
max-width: 80%;
padding: 0 1rem;
width: 100%;
}
header {
padding: 3rem 0;
}
pre {
white-space: pre-wrap;
}
#meta {
--labels-size: 22rem;
--aspect-ratio: 3/1;
}
.spark {
border-bottom: 1px solid black
}
.spark {
--color: #ccf;
}

.level-Emergency::before {content: "🔥"}
.level-Alert::before {content: "🔥"}
.level-Critical::before {content: "❌"}
.level-Error::before {content: "❌"}
.level-Warning::before {content: "⚠️"}
.level-Notice::before {content: "ℹ️"}
.level-Informational::before {content: "💬"}
.level-Debug::before {content: "💬"}

</style>
</head>
<body>
<header>
<a href="/">Sentry-Journald</a>
</header>
<main>
<hgroup>
<h1>Reports</h1>
</hgroup>

<table>
<tr>
<th>Level</th>
<th>Title</th>
<th>Age</th>
<th>Incidents</th>
</tr>
{{ range $k, $v := .Entries }}
<tr>
<td class="level-{{ $v.GetLogLevel }}">
{{ $v.GetLogLevel }}
</td>
<td><a href="/issues/{{ $v.GetId }}">{{ $v.GetMessage }}</a></td>
<td class="tt">{{ $v.GetTime }}</td>
<td>
<table class="spark charts-css column hide-data">
<tbody>
{{ range $q := $v.GetHistogram12h }}
<tr><td style="--size:{{ $q }};"><span class="data"> {{ $q }} </span></td></tr>
{{ end }}
</tbody>
</table>
</td>
</tr>
{{ end }}
</table>
<script>
document.querySelectorAll('.tt').forEach(el => {
el.textContent = moment(el.textContent).fromNow();
});
</script>

</main>

</body>
</html>

120 changes: 45 additions & 75 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package main
import (
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"text/template"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
Expand All @@ -18,90 +20,58 @@ import (
"github.com/urfave/cli/v2"
)

type SentryHeaderSdk struct {
Name string `json:"name"`
Version string `json:"version"`
}
func indexPage(w http.ResponseWriter, r *http.Request) {
list_tpl_text, err := os.ReadFile("list.html")

type SentryHeaderTrace struct {
Environment string `json:"environment"`
Release string `json:"release"`
Public_key string `json:"public_key"`
Trace_id string `json:"trace_id"`
}
type SentryHeader struct {
Event_id string `json:"event_id"`
Sent_at string `json:"sent_at"`
Sdk SentryHeaderSdk `json:"sdk"`
Trace SentryHeaderTrace `json:"trace"`
}
entries := GroupMain()

type SentryEnvelope struct {
Type string `json:"type"`
}
type Zzz struct {
Entries []LogEntry
}

type SentryBreadcrumb struct {
Category string `json:"category"`
Level string `json:"level"`
Message string `json:"message"`
Type string `json:"type"`
Timestamp string `json:"timestamp"`
}
zzz := Zzz{Entries: entries}

type SentryBreadcrumbContainer struct {
Values []SentryBreadcrumb `json:"values"`
}
if err != nil {
fmt.Println(err)
}
list_tpl, err := template.New("list").Parse(string(list_tpl_text))
if err != nil {
fmt.Println(err)
}

type SentryRequest struct {
Url string `json:"url"`
Headers map[string]string `json:"headers"`
err = list_tpl.Execute(w, zzz)
if err != nil {
fmt.Println(err)
}
}

type SentryStackTraceFrame struct {
Filename string `json:"filename"`
Function string `json:"function"`
InApp bool `json:"in_app"`
Lineno int `json:"lineno"`
Colno int `json:"colno"`
}
func issuePage(w http.ResponseWriter, r *http.Request) {
msg := chi.URLParam(r, "msg")
// base64 decode
msg_bytes, err := base64.StdEncoding.DecodeString(msg)

type SentryStackTrace struct {
Frames []SentryStackTraceFrame `json:"frames"`
}
list_tpl_text, err := os.ReadFile("show.html")
entries := aggregateIdenticalMessages(string(msg_bytes), 24)

type SentryExceptionItem struct {
Type string `json:"type"`
Value string `json:"value"`
Stacktrace SentryStackTrace `json:"stacktrace"`
}
type Zzy struct {
Entry LogEntry
Message string
}

type SentryException struct {
Values []SentryExceptionItem `json:"values"`
}
zzz := Zzy{Entry: entries, Message: string(msg_bytes)}

type SentryLogEntry struct {
Message string `json:"message"`
Params []string `json:"params"`
}
if err != nil {
fmt.Println(err)
}
list_tpl, err := template.New("show").Parse(string(list_tpl_text))
if err != nil {
fmt.Println(err)
}

type SentryEvent struct {
Message string `json:"message"`
Level string `json:"level"`
Logger string `json:"logger"`
LogEntry SentryLogEntry `json:"logentry"`
Event_id string `json:"event_id"`
Timestamp interface{} `json:"timestamp"`
Contexts map[string]interface{} `json:"contexts"`
Extra map[string]interface{} `json:"extra"`
Exception SentryException `json:"exception"`
Stacktrace SentryStackTrace `json:"stacktrace"`
// Breadcrumbs []SentryBreadcrumb `json:"breadcrumbs"`
Modules map[string]string `json:"modules"`
Release string `json:"release"`
Environment string `json:"environment"`
Server_name string `json:"server_name"`
Platform string `json:"platform"`
Request SentryRequest `json:"request"`
err = list_tpl.Execute(w, zzz)
if err != nil {
fmt.Println(err)
}
}

func processSentryRequest(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -274,9 +244,9 @@ func main() {
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("welcome"))
})
r.Get("/", indexPage)

r.Get("/issues/{msg}", issuePage)

r.Post("/api/{projectID}/envelope/", func(w http.ResponseWriter, r *http.Request) {
processSentryRequest(w, r)
Expand Down
Loading

0 comments on commit fecc2f2

Please sign in to comment.