mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
Add hostname to /api
This commit is contained in:
committed by
David Kaltschmidt
parent
2b4596ca67
commit
f1d225c836
@@ -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(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user