Add hostname to /api

This commit is contained in:
Tom Wilkie
2015-11-30 14:15:07 +00:00
committed by David Kaltschmidt
parent 2b4596ca67
commit f1d225c836
4 changed files with 13 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/PuerkitoBio/ghost/handlers"
"github.com/gorilla/mux"
"github.com/weaveworks/scope/common/hostname"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/xfer"
)
@@ -105,5 +106,9 @@ func makeReportPostHandler(a Adder) http.HandlerFunc {
}
func apiHandler(w http.ResponseWriter, r *http.Request) {
respondWith(w, http.StatusOK, xfer.Details{ID: uniqueID, Version: version})
respondWith(w, http.StatusOK, xfer.Details{
ID: uniqueID,
Version: version,
Hostname: hostname.Get(),
})
}

View File

@@ -1,9 +1,9 @@
package probe
package hostname
import "os"
// Hostname returns the hostname of this host.
func Hostname() string {
func Get() string {
if hostname := os.Getenv("SCOPE_HOSTNAME"); hostname != "" {
return hostname
}

View File

@@ -16,6 +16,7 @@ import (
"github.com/armon/go-metrics"
"github.com/weaveworks/weave/common"
"github.com/weaveworks/scope/common/hostname"
"github.com/weaveworks/scope/probe"
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/probe/docker"
@@ -78,7 +79,7 @@ func main() {
rand.Seed(time.Now().UnixNano())
probeID := strconv.FormatInt(rand.Int63(), 16)
var (
hostName = probe.Hostname()
hostName = hostname.Get()
hostID = hostName // TODO(pb): we should sanitize the hostname
)
log.Printf("probe starting, version %s, ID %s", version, probeID)

View File

@@ -15,8 +15,9 @@ import (
// Details are some generic details that can be fetched from /api
type Details struct {
ID string `json:"id"`
Version string `json:"version"`
ID string `json:"id"`
Version string `json:"version"`
Hostname string `json:"hostname"`
}
// AppClient is a client to an app for dealing with controls.