From 6e3d50ad2de0db18e8e8b1246c8af217a7fe605f Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 2 Apr 2021 21:23:38 -0400 Subject: [PATCH] initial commit Signed-off-by: Christine Dodrill --- .envrc | 1 + LICENSE | 12 +++++++++++ README.md | 4 ++++ aegis.txt | 26 +++++++++++++++++++++++ go.mod | 3 +++ main.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 10 +++++++++ 7 files changed, 118 insertions(+) create mode 100644 .envrc create mode 100644 LICENSE create mode 100644 README.md create mode 100644 aegis.txt create mode 100644 go.mod create mode 100644 main.go create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..051d09d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +eval "$(lorri direnv)" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4cb9bcc --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ + YOLO LICENSE + Version 1, July 10 2015 + +THIS SOFTWARE LICENSE IS PROVIDED "ALL CAPS" SO THAT YOU KNOW IT IS SUPER +SERIOUS AND YOU DON'T MESS AROUND WITH COPYRIGHT LAW BECAUSE YOU WILL GET IN +TROUBLE HERE ARE SOME OTHER BUZZWORDS COMMONLY IN THESE THINGS WARRANTIES +LIABILITY CONTRACT TORT LIABLE CLAIMS RESTRICTION MERCHANTABILITY SUBJECT TO +THE FOLLOWING CONDITIONS: + +1. #yolo +2. #swag +3. #blazeit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c0cf1d --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Aegis + +Relays information from services running over Unix sockets to Prometheus. Aegis +contacts services (blades) over their Unix sockets when Prometheus asks for them. diff --git a/aegis.txt b/aegis.txt new file mode 100644 index 0000000..3e09a67 --- /dev/null +++ b/aegis.txt @@ -0,0 +1,26 @@ + =:::::::::~~= + :,:::::::,,:= + = +++++ + += + :~+~~~~~~~=== + :=+=~~~~~~=~= + =~:===~~~~~=~~= + =::~====~~~~=::::= + =: ++====~~~~==::= + =: -=+====~~~~~=~= + =~= ~++===~~~~=,~= + =~ +++==~~=:=~+= + ,= +++==~~=~++ + := +++=+=~=~++ + ,= ++++==~==++ + ,~ ++++==~=+++ + ,~ +++===~~==+ + ,= ++====~~=++ + ,= +==~===~==+ + ,=+======~~==+ + :=+=~~~~~~~=++ + :===~~~~~~~+== + :~===~~~~~~=+= + ,~=~~~~~~~~=== + ,~=~~~~~~~~+=~ + ::+========+~= + +=~~~~~~~~~~~= diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5bc9612 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module tulpa.dev/cadey/aegis + +go 1.16 diff --git a/main.go b/main.go new file mode 100644 index 0000000..1950b7b --- /dev/null +++ b/main.go @@ -0,0 +1,62 @@ +package main + +import ( + _ "embed" + "flag" + "fmt" + "log" + "net" + "net/http" + "net/http/httputil" + "os" + "path" + "path/filepath" +) + +var ( + hostport = flag.String("hostport", "[::]:31337", "TCP host:port to listen on") + sockdir = flag.String("sockdir", "./run", "directory full of unix sockets to monitor") +) + +//go:embed "aegis.txt" +var core string + +func main() { + flag.Parse() + + fmt.Print(core) + log.SetFlags(0) + log.Printf("%s -> %s", *hostport, *sockdir) + + http.DefaultServeMux.HandleFunc("/", proxyToUnixSocket) + + log.Fatal(http.ListenAndServe(*hostport, nil)) +} + +func proxyToUnixSocket(w http.ResponseWriter, r *http.Request) { + name := path.Base(r.URL.Path) + + fname := filepath.Join(*sockdir, name+".sock") + _, err := os.Stat(fname) + if os.IsNotExist(err) { + http.NotFound(w, r) + return + } + + ts := &http.Transport{ + Dial: func(_, _ string) (net.Conn, error) { + return net.Dial("unix", fname) + }, + } + + rp := httputil.ReverseProxy{ + Director: func(req *http.Request) { + req.URL.Scheme = "http" + req.URL.Host = "aegis" + req.URL.Path = "/metrics" + req.URL.RawPath = "/metrics" + }, + Transport: ts, + } + rp.ServeHTTP(w, r) +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..67222cb --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + buildInputs = with pkgs; [ + go gopls goimports + + # keep this line if you use bash + pkgs.bashInteractive + ]; +}