initial commit

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-04-02 21:23:38 -04:00
commit 6e3d50ad2d
7 changed files with 118 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
eval "$(lorri direnv)"

12
LICENSE Normal file
View File

@ -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

4
README.md Normal file
View File

@ -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.

26
aegis.txt Normal file
View File

@ -0,0 +1,26 @@
=:::::::::~~=
:,:::::::,,:=
= +++++ + +=
:~+~~~~~~~===
:=+=~~~~~~=~=
=~:===~~~~~=~~=
=::~====~~~~=::::=
=: ++====~~~~==::=
=: -=+====~~~~~=~=
=~= ~++===~~~~=,~=
=~ +++==~~=:=~+=
,= +++==~~=~++
:= +++=+=~=~++
,= ++++==~==++
,~ ++++==~=+++
,~ +++===~~==+
,= ++====~~=++
,= +==~===~==+
,=+======~~==+
:=+=~~~~~~~=++
:===~~~~~~~+==
:~===~~~~~~=+=
,~=~~~~~~~~===
,~=~~~~~~~~+=~
::+========+~=
+=~~~~~~~~~~~=

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module tulpa.dev/cadey/aegis
go 1.16

62
main.go Normal file
View File

@ -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)
}

10
shell.nix Normal file
View File

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
go gopls goimports
# keep this line if you use bash
pkgs.bashInteractive
];
}