|
@@ -1,36 +1,15 @@
|
|
package functions
|
|
package functions
|
|
|
|
|
|
import (
|
|
import (
|
|
- "io"
|
|
|
|
- "log"
|
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
|
- "github.com/gravitl/netmaker/cli/config"
|
|
|
|
cfg "github.com/gravitl/netmaker/config"
|
|
cfg "github.com/gravitl/netmaker/config"
|
|
"github.com/gravitl/netmaker/models"
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
)
|
|
|
|
|
|
// GetLogs - fetch Netmaker server logs
|
|
// GetLogs - fetch Netmaker server logs
|
|
func GetLogs() string {
|
|
func GetLogs() string {
|
|
- _, ctx := config.GetCurrentContext()
|
|
|
|
- req, err := http.NewRequest(http.MethodGet, ctx.Endpoint+"/api/logs", nil)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if ctx.MasterKey != "" {
|
|
|
|
- req.Header.Set("Authorization", "Bearer "+ctx.MasterKey)
|
|
|
|
- } else {
|
|
|
|
- req.Header.Set("Authorization", "Bearer "+getAuthToken(ctx, true))
|
|
|
|
- }
|
|
|
|
- res, err := http.DefaultClient.Do(req)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- bodyBytes, err := io.ReadAll(res.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- return string(bodyBytes)
|
|
|
|
|
|
+ return get("/api/logs")
|
|
}
|
|
}
|
|
|
|
|
|
// GetServerInfo - fetch minimal server info
|
|
// GetServerInfo - fetch minimal server info
|
|
@@ -45,23 +24,5 @@ func GetServerConfig() *cfg.ServerConfig {
|
|
|
|
|
|
// GetServerHealth - fetch server current health status
|
|
// GetServerHealth - fetch server current health status
|
|
func GetServerHealth() string {
|
|
func GetServerHealth() string {
|
|
- _, ctx := config.GetCurrentContext()
|
|
|
|
- req, err := http.NewRequest(http.MethodGet, ctx.Endpoint+"/api/server/health", nil)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if ctx.MasterKey != "" {
|
|
|
|
- req.Header.Set("Authorization", "Bearer "+ctx.MasterKey)
|
|
|
|
- } else {
|
|
|
|
- req.Header.Set("Authorization", "Bearer "+getAuthToken(ctx, true))
|
|
|
|
- }
|
|
|
|
- res, err := http.DefaultClient.Do(req)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- bodyBytes, err := io.ReadAll(res.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- }
|
|
|
|
- return string(bodyBytes)
|
|
|
|
|
|
+ return get("/api/server/health")
|
|
}
|
|
}
|