Skip to content

Commit

Permalink
Merge pull request #526 from sipcapture/add-loki-template
Browse files Browse the repository at this point in the history
Add loki template
  • Loading branch information
adubovikov authored Jul 5, 2023
2 parents 2b7959d + 49d362b commit f9f1f70
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 18 deletions.
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
78 changes: 66 additions & 12 deletions controller/v1/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()))

}
9 changes: 6 additions & 3 deletions etc/webapp_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion router/v1/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit f9f1f70

Please sign in to comment.