83 lines
1.8 KiB
Go
Executable File
83 lines
1.8 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
p := os.Getenv("PORT")
|
|
flag.StringVar(&p, "p", "8500", "port to listen on")
|
|
flag.Parse()
|
|
http.Handle("/v1/catalog/service/alert-on-metrics", http.HandlerFunc(catalogService))
|
|
http.Handle("/v1/health/node/127.0.0.1", http.HandlerFunc(healthNode))
|
|
log.Println("Listening on", p)
|
|
if err := http.ListenAndServe(":"+strings.TrimPrefix(p, ":"), nil); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func healthNode(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintln(w, `
|
|
[
|
|
{
|
|
"CheckID": "check_healthcheck_alert-on-metrics_alert-on-metrics",
|
|
"CreateIndex": 727094265,
|
|
"Definition": {},
|
|
"ModifyIndex": 727094265,
|
|
"Name": "Serf Health Status",
|
|
"Node": "gobs2-nomad.b1-prv.qops.net",
|
|
"Notes": "",
|
|
"Output": "Agent alive and reachable",
|
|
"ServiceID": "",
|
|
"ServiceName": "",
|
|
"ServiceTags": [],
|
|
"Status": "passing"
|
|
}
|
|
]
|
|
`)
|
|
}
|
|
|
|
func catalogService(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintln(w, `
|
|
[
|
|
{
|
|
"Address": "127.0.0.1",
|
|
"CreateIndex": 231035602,
|
|
"Datacenter": "eng",
|
|
"ID": "95dace59-f06b-d483-a06e-38288dc2019a",
|
|
"ModifyIndex": 231035602,
|
|
"Node": "127.0.0.1",
|
|
"NodeMeta": {
|
|
"consul-network-segment": ""
|
|
},
|
|
"ServiceAddress": "",
|
|
"ServiceConnect": {},
|
|
"ServiceEnableTagOverride": false,
|
|
"ServiceID": "alert-on-metrics",
|
|
"ServiceKind": "",
|
|
"ServiceMeta": {},
|
|
"ServiceName": "alert-on-metrics",
|
|
"ServicePort": 8080,
|
|
"ServiceProxy": {},
|
|
"ServiceProxyDestination": "",
|
|
"ServiceTags": [
|
|
""
|
|
],
|
|
"ServiceWeights": {
|
|
"Passing": 1,
|
|
"Warning": 1
|
|
},
|
|
"TaggedAddresses": {
|
|
"lan": "127.0.0.1",
|
|
"wan": "127.0.0.1"
|
|
}
|
|
}
|
|
]
|
|
`)
|
|
}
|