From 15396e35ec7263366d57351b9a1785189d26efc4 Mon Sep 17 00:00:00 2001 From: Alexey Oplachko Date: Wed, 5 Jul 2023 11:10:44 +0300 Subject: [PATCH 1/2] Added /modules and loki template to it. --- config/config.go | 13 +++++++ controller/v1/profile.go | 78 +++++++++++++++++++++++++++++++++------- etc/webapp_config.json | 9 +++-- main.go | 4 ++- router/v1/profile.go | 3 +- 5 files changed, 90 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 07d69f76..8aa2a3b4 100644 --- a/config/config.go +++ b/config/config.go @@ -112,4 +112,17 @@ type HomerSettingServer struct { ImportNode string `default:""` Enable bool `default:"false"` } + //Loki + LOKI_CONFIG struct { + User string `json:"user" mapstructure:"user" default:"admin"` + Pass string `json:"pass" mapstructure:"pass" default:""` + OldStylePass string `json:"password" mapstructure:"password" default:""` + ParamQuery string `json:"param_query" mapstructure:"param_query" default:"query_range"` + Regexp bool `json:"regexp" mapstructure:"regexp" default:"false"` + Host string `json:"host" mapstructure:"host" default:"http:/127.0.0.1:3100"` + Template string `json:"template" mapstructure:"template" default:"{job=\"heplify-server\"}"` + ExternalUrl string `json:"external_url" mapstructure:"external_url" default:""` + Api string `json:"api" mapstructure:"api" default:"api/v1"` + Enable bool `json:"enable" mapstructure:"enable" default:"false"` + } `json:"loki_config" mapstructure:"loki_config"` } diff --git a/controller/v1/profile.go b/controller/v1/profile.go index 25164aef..0f046b21 100644 --- a/controller/v1/profile.go +++ b/controller/v1/profile.go @@ -3,7 +3,9 @@ package controllerv1 import ( "net/http" + "github.com/Jeffail/gabs/v2" "github.com/labstack/echo/v4" + "github.com/sipcapture/homer-app/config" "github.com/sipcapture/homer-app/data/service" httpresponse "github.com/sipcapture/homer-app/network/response" "github.com/sipcapture/homer-app/system/webmessages" @@ -33,17 +35,19 @@ func (pc *ProfileController) GetHepsub(c echo.Context) error { // produces: // - application/json // securityDefinitions: -// bearer: -// type: apiKey -// in: header -// name: Authorization +// +// bearer: +// type: apiKey +// in: header +// name: Authorization +// // security: // - bearer: [] // -// // responses: -// 201: body:HepsubSchema -// 400: body:FailureResponse +// +// 201: body:HepsubSchema +// 400: body:FailureResponse func (pc *ProfileController) GetDashboardList(c echo.Context) error { reply, err := pc.ProfileService.GetProfile() @@ -67,12 +71,15 @@ func (pc *ProfileController) GetDashboardList(c echo.Context) error { // // SecurityDefinitions: // bearer: -// type: apiKey -// name: Authorization -// in: header +// +// type: apiKey +// name: Authorization +// in: header +// // responses: -// 201: body:NodeList -// 400: body:FailureResponse +// +// 201: body:NodeList +// 400: body:FailureResponse func (pc *ProfileController) GetDBNodeList(c echo.Context) error { reply, err := pc.ProfileService.GetDBNodeList() @@ -83,3 +90,50 @@ func (pc *ProfileController) GetDBNodeList(c echo.Context) error { return httpresponse.CreateSuccessResponseWithJson(&c, http.StatusOK, []byte(reply)) } + +// swagger:route GET /modules/status Status ListMapping +// +// Returns data from server +// --- +// consumes: +// - application/json +// produces: +// - application/json +// Security: +// - JWT +// - ApiKeyAuth +// +// SecurityDefinitions: +// JWT: +// +// type: apiKey +// name: Authorization +// in: header +// +// ApiKeyAuth: +// +// type: apiKey +// in: header +// name: Auth-Token +// +// Responses: +// +// 201: body:SuccessResponse +// 400: body:FailureResponse +func (pc *ProfileController) GetModulesStatus(c echo.Context) error { + + moduleLoki := gabs.New() + moduleLoki.Set(config.Setting.LOKI_CONFIG.Enable, "enable") + moduleLoki.Set(config.Setting.LOKI_CONFIG.Template, "template") + moduleLoki.Set(config.Setting.LOKI_CONFIG.ExternalUrl, "external_url") + + modulesResponse := gabs.New() + modulesResponse.Set(moduleLoki.Data(), "loki") + + reply := gabs.New() + reply.Set("Modules status", "message") + reply.Set(modulesResponse.Data(), "data") + + return httpresponse.CreateSuccessResponseWithJson(&c, http.StatusOK, []byte(reply.String())) + +} diff --git a/etc/webapp_config.json b/etc/webapp_config.json index b1649971..cc406139 100644 --- a/etc/webapp_config.json +++ b/etc/webapp_config.json @@ -48,13 +48,16 @@ "api_host": "127.0.0.1:9080" }, "loki_config": { - "enable": true, "help": "Settings for LOKI Database (optional)", "user": "admin", - "pass": "admin", + "password": "admin", + "param_query": "query_range", + "regexp": false, "host": "http://127.0.0.1:3100", + "template": "{job=\"heplify-server\"}", + "external_url": "", "api": "loki/api/v1", - "param_query": "query_range" + "enable": true }, "grafana_config": { "help": "Settings for Grafana", diff --git a/main.go b/main.go index a32c9a56..159376b8 100644 --- a/main.go +++ b/main.go @@ -692,7 +692,9 @@ func configureAsHTTPServer() { if viper.IsSet("grafana_config.token") { config.Setting.GRAFANA_SETTINGS.AuthKey = viper.GetString("grafana_config.token") } - + if viper.IsSet("loki_config.template") { + config.Setting.LOKI_CONFIG.Template = viper.GetString("loki_config.template") + } if viper.IsSet("grafana_config.proxy_control") { config.Setting.GRAFANA_SETTINGS.ProxyControl = viper.GetBool("grafana_config.proxy_control") } diff --git a/router/v1/profile.go b/router/v1/profile.go index 9eec422f..9a3522c8 100644 --- a/router/v1/profile.go +++ b/router/v1/profile.go @@ -8,7 +8,7 @@ import ( "github.com/sipcapture/homer-app/model" ) -//comments +// comments func RouteProfileApis(acc *echo.Group, session *gorm.DB, databaseNodeMap []model.DatabasesMap) { // initialize service of user ProfileService := service.ProfileService{ServiceConfig: service.ServiceConfig{Session: session}, DatabaseNodeMap: &databaseNodeMap} @@ -19,6 +19,7 @@ func RouteProfileApis(acc *echo.Group, session *gorm.DB, databaseNodeMap []model // get all dashboards acc.GET("/admin/profiles", hs.GetDashboardList) acc.GET("/database/node/list", hs.GetDBNodeList) + acc.GET("/modules/status", hs.GetModulesStatus) //acc.GET("/hepsub/protocol", hs.GetHepsub) } From 49d362b0c344e17382d7be7929f53fa86c177f50 Mon Sep 17 00:00:00 2001 From: Alexey Oplachko Date: Wed, 5 Jul 2023 11:11:16 +0300 Subject: [PATCH 2/2] updated version --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 9bf0d2fc..89efffce 100644 --- a/version.go +++ b/version.go @@ -1,7 +1,7 @@ package main // VERSION -var VERSION_APPLICATION = "1.4.56" +var VERSION_APPLICATION = "1.4.57" // NAME var NAME_APPLICATION = "homer-app"