Trying out a version that uses golog

as well as touching up the Makefiles to set SHELL
This commit is contained in:
Dan Buch 2013-07-07 23:07:38 -04:00
parent 7ef177a38e
commit 38327558d6
4 changed files with 65 additions and 8 deletions

1
logstash/.gitignore vendored
View File

@ -1,2 +1,3 @@
/agent/lib/
/crispy/crispy
/sirgoldenvoncrispywhite/sirgoldenvoncrispywhite

View File

@ -1,7 +1,15 @@
SHELL := /bin/bash
run-crispy: crispy/crispy
$^
run-sirgoldenvoncrispywhite: sirgoldenvoncrispywhite/sirgoldenvoncrispywhite
$^
crispy/crispy: crispy/main.go
pushd crispy && go build -v -x . ; popd
.PHONY: run-crispy
sirgoldenvoncrispywhite/sirgoldenvoncrispywhite: sirgoldenvoncrispywhite/main.go
pushd sirgoldenvoncrispywhite && go build -v -x . ; popd
.PHONY: run-crispy run-sirgoldenvoncrispywhite

View File

@ -1,11 +1,7 @@
SHELL := /bin/bash
LOGSTASH_VERSION ?= 1.1.13
all: lib/logstash.jar
lib/logstash.jar: lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar
pushd lib && ln -sv $(notdir $^) $(notdir $@) ; popd
all: lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar
lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar: lib
pushd lib && \
@ -16,4 +12,4 @@ lib:
mkdir -p $@
run-agent: all
java -jar lib/logstash.jar agent -f agent.conf
java -jar lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar agent -f agent.conf

View File

@ -0,0 +1,52 @@
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/modcloth-labs/golog"
)
func main() {
server, err := newCrispyServer()
if err != nil {
log.Fatal(err)
}
http.Handle("/", server)
log.Printf("Serving on :9764 with %+v\n", server)
log.Fatal(http.ListenAndServe(":9764", nil))
}
type crispyServer struct {
logstasher *golog.Logger
}
func newCrispyServer() (*crispyServer, error) {
logstasher, err := newLogstashLogger()
if err != nil {
return nil, err
}
return &crispyServer{logstasher: logstasher}, nil
}
func (me *crispyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
j, err := json.Marshal(r)
if err == nil {
if me.logstasher != nil {
me.logstasher.Infof("%s", string(j))
}
}
}
func newLogstashLogger() (*golog.Logger, error) {
logger := golog.NewLogger("")
tcpProcessor, err := golog.NewTcpProcessorAt(":55784", golog.LOG_DEBUG)
if err != nil {
return nil, err
}
logger.AddProcessor("tcp", tcpProcessor)
return logger, nil
}