-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.go
More file actions
236 lines (206 loc) · 7.9 KB
/
main.go
File metadata and controls
236 lines (206 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Copyright (C) INFINI Labs & INFINI LIMITED.
//
// The INFINI Console is offered under the GNU Affero General Public License v3.0
// and as commercial software.
//
// For commercial licensing, contact us at:
// - Website: infinilabs.com
// - Email: hello@infini.ltd
//
// Open Source licensed under AGPL V3:
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"context"
"errors"
_ "expvar"
"fmt"
api3 "infini.sh/console/modules/agent/api"
"infini.sh/console/plugin/api/email"
"infini.sh/console/plugin/audit_log"
"infini.sh/framework/core/api"
"infini.sh/framework/core/host"
model2 "infini.sh/framework/core/model"
"infini.sh/framework/core/util"
elastic2 "infini.sh/framework/modules/elastic"
_ "time/tzdata"
log "github.com/cihub/seelog"
"infini.sh/console/config"
"infini.sh/console/model"
"infini.sh/console/model/alerting"
"infini.sh/console/model/insight"
"infini.sh/console/modules/security"
_ "infini.sh/console/plugin"
_ "infini.sh/console/plugin/managed"
setup1 "infini.sh/console/plugin/setup"
alerting2 "infini.sh/console/service/alerting"
"infini.sh/framework"
"infini.sh/framework/core/elastic"
"infini.sh/framework/core/env"
"infini.sh/framework/core/global"
"infini.sh/framework/core/module"
"infini.sh/framework/core/orm"
task1 "infini.sh/framework/core/task"
_ "infini.sh/framework/modules/api"
"infini.sh/framework/modules/metrics"
"infini.sh/framework/modules/pipeline"
queue2 "infini.sh/framework/modules/queue/disk_queue"
"infini.sh/framework/modules/redis"
"infini.sh/framework/modules/stats"
"infini.sh/framework/modules/task"
"infini.sh/framework/modules/web"
_ "infini.sh/framework/plugins"
)
var appConfig *config.AppConfig
var appUI *UI
func main() {
terminalHeader := ("\n")
terminalHeader += (" ___ ___ __ __ ___ __ __ \n")
terminalHeader += (" / __\\/___\\/\\ \\ \\/ _\\ /___\\/ / /__\\\n")
terminalHeader += (" / / // // \\/ /\\ \\ // // / /_\\ \n")
terminalHeader += ("/ /__/ \\_// /\\ / _\\ \\/ \\_// /__//__ \n")
terminalHeader += ("\\____|___/\\_\\ \\/ \\__/\\___/\\____|__/ \n\n")
terminalHeader += ("HOME: https://github.com/infinilabs/console/\n\n")
terminalFooter := ""
app := framework.NewApp("console", "The easiest way to operate your own search platform, open-sourced under the GNU AGPLv3.",
config.Version, config.BuildNumber, config.LastCommitLog, config.BuildDate, config.EOLDate, terminalHeader, terminalFooter)
app.Init(nil)
defer app.Shutdown()
modules := []module.ModuleItem{}
modules = append(modules, module.ModuleItem{Value: &stats.SimpleStatsModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &elastic2.ElasticModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &queue2.DiskQueue{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &redis.RedisModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &pipeline.PipeModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &task.TaskModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &metrics.MetricsModule{}, Priority: 1})
modules = append(modules, module.ModuleItem{Value: &security.Module{}, Priority: 1})
uiModule := &web.WebModule{}
global.Env().EnableSetup(true)
if app.Setup(func() {
//load core modules first
module.RegisterSystemModule(&setup1.Module{})
module.RegisterSystemModule(uiModule)
if !global.Env().SetupRequired() {
for _, v := range modules {
module.RegisterModuleWithPriority(v.Value, v.Priority)
}
} else {
for _, v := range modules {
v.Value.Setup()
}
}
api3.Init()
appConfig = &config.AppConfig{
UI: config.UIConfig{
LocalPath: ".public",
VFSEnabled: true,
LocalEnabled: true,
},
}
ok, err := env.ParseConfig("web", appConfig)
if err != nil && global.Env().SystemConfig.Configs.PanicOnConfigError {
panic(err)
}
if !ok {
panic(errors.New("config not exists"))
}
//load web UI files
appUI = &UI{Config: appConfig}
appUI.InitUI()
api.AddGlobalInterceptors(new(audit_log.MonitoringInterceptor))
}, func() {
//orm.RegisterSchema(model.Dict{}, "dict")
orm.RegisterSchemaWithIndexName(elastic.View{}, "view")
orm.RegisterSchemaWithIndexName(elastic.CommonCommand{}, "commands")
//orm.RegisterSchema(elastic.TraceTemplate{}, "trace-template")
orm.RegisterSchemaWithIndexName(alerting.Rule{}, "alert-rule")
orm.RegisterSchemaWithIndexName(alerting.Alert{}, "alert-history")
orm.RegisterSchemaWithIndexName(alerting.AlertMessage{}, "alert-message")
orm.RegisterSchemaWithIndexName(alerting.Channel{}, "channel")
orm.RegisterSchemaWithIndexName(insight.Visualization{}, "visualization")
orm.RegisterSchemaWithIndexName(insight.Dashboard{}, "dashboard")
orm.RegisterSchemaWithIndexName(insight.Widget{}, "widget")
orm.RegisterSchemaWithIndexName(task1.Task{}, "task")
orm.RegisterSchemaWithIndexName(model.Layout{}, "layout")
orm.RegisterSchemaWithIndexName(model.Notification{}, "notification")
orm.RegisterSchemaWithIndexName(model.EmailServer{}, "email-server")
orm.RegisterSchemaWithIndexName(model2.Instance{}, "instance")
orm.RegisterSchemaWithIndexName(api3.RemoteConfig{}, "configs")
orm.RegisterSchemaWithIndexName(model.AuditLog{}, "audit-logs")
orm.RegisterSchemaWithIndexName(host.HostInfo{}, "host")
module.Start()
var initFunc = func() {
// check cluster health before initialization, refuse to start if status is red
sysClusterID := global.MustLookupString(elastic.GlobalSystemElasticsearchID)
client := elastic.GetClient(sysClusterID)
health, err := client.ClusterHealth(context.Background())
if err != nil {
panic(fmt.Errorf("failed to get system cluster health: %v", err))
}
if health != nil && health.Status == "red" {
panic(fmt.Errorf("system cluster health status is [red], please fix the cluster before starting"))
}
elastic2.InitTemplate(false)
if global.Env().SetupRequired() {
for _, v := range modules {
v.Value.Start()
}
}
task1.RunWithinGroup("initialize_alerting", func(ctx context.Context) error {
err := alerting2.InitTasks()
if err != nil {
log.Errorf("init alerting task error: %v", err)
}
return err
})
task1.RunWithinGroup("initialize_email_server", func(ctx context.Context) error {
err := email.InitEmailServer()
if err != nil {
log.Errorf("init email server error: %v", err)
}
return err
})
api.RegisterAppSetting("system_cluster", func() interface{} {
client := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
settings, err := client.GetClusterSettings(nil)
if err != nil {
log.Errorf("failed to get cluster settings with system cluster: %v", err)
return nil
}
rollupEnabled, _ := util.GetMapValueByKeys([]string{"persistent", "rollup", "search", "enabled"}, settings)
rollupEnabledValue := false
if v, ok := rollupEnabled.(string); ok && v == "true" {
rollupEnabledValue = true
}
return map[string]interface{}{
"rollup_enabled": rollupEnabledValue,
}
})
}
if !global.Env().SetupRequired() {
initFunc()
} else {
setup1.RegisterSetupCallback(initFunc)
}
if !global.Env().SetupRequired() {
err := bootstrapRequirementCheck()
if err != nil {
panic(err)
}
}
}, nil) {
app.Run()
}
}