-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
126 lines (100 loc) · 3.48 KB
/
status.go
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
package main
import (
"bytes"
"database/sql"
"fmt"
"net/http"
"time"
"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/engine/api/context"
"github.com/ovh/cds/engine/api/database"
"github.com/ovh/cds/engine/api/event"
"github.com/ovh/cds/engine/api/internal"
"github.com/ovh/cds/engine/api/mail"
"github.com/ovh/cds/engine/api/objectstore"
"github.com/ovh/cds/engine/api/repositoriesmanager/polling"
"github.com/ovh/cds/engine/api/scheduler"
"github.com/ovh/cds/engine/api/sessionstore"
"github.com/ovh/cds/engine/log"
"github.com/ovh/cds/engine/api/secret"
"github.com/ovh/cds/sdk"
)
func getError(w http.ResponseWriter, r *http.Request, db *sql.DB, c *context.Context) {
WriteError(w, r, sdk.ErrInvalidProjectKey)
}
func getVersionHandler(w http.ResponseWriter, r *http.Request, db *sql.DB, c *context.Context) {
s := struct {
Version string `json:"version"`
}{
Version: internal.VERSION,
}
WriteJSON(w, r, s, http.StatusOK)
}
func statusHandler(w http.ResponseWriter, r *http.Request, db *sql.DB, c *context.Context) {
var output []string
// Version
output = append(output, fmt.Sprintf("Version: %s", internal.VERSION))
log.Info("Status> Version: %s", internal.VERSION)
// Uptime
output = append(output, fmt.Sprintf("Uptime: %s", time.Since(startupTime)))
log.Info("Status> Uptime: %s", time.Since(startupTime))
//Nb Panics
output = append(output, fmt.Sprintf("Nb of Panics: %d", nbPanic))
log.Info("Status> Nb of Panics: %d", nbPanic)
// Check vault
output = append(output, fmt.Sprintf("Secret Backend: %s", secret.Status()))
log.Info("Status> Secret Backend: %s", secret.Status())
// Check Scheduler
output = append(output, fmt.Sprintf("Scheduler: %s", scheduler.Status()))
log.Info("Status> Scheduler: %s", scheduler.Status())
// Check Event
output = append(output, fmt.Sprintf("Event: %s", event.Status()))
log.Info("Status> Event: %s", event.Status())
// Check redis
output = append(output, fmt.Sprintf("Cache: %s", cache.Status))
log.Info("Status> Cache: %s", cache.Status)
// Check session-store
output = append(output, fmt.Sprintf("Session-Store: %s", sessionstore.Status))
log.Info("Status> Session-Store: %s", sessionstore.Status)
// Check object-store
output = append(output, fmt.Sprintf("Object-Store: %s", objectstore.Status()))
log.Info("Status> Object-Store: %s", objectstore.Status())
//Check smtp
mailStatus := mail.Status()
output = append(output, fmt.Sprintf("SMTP: %s", mailStatus))
log.Info("Status> SMTP: %s", mailStatus)
// Check database
output = append(output, database.Status())
log.Info("Status> %s", database.Status())
var status = http.StatusOK
if panicked {
status = http.StatusServiceUnavailable
}
WriteJSON(w, r, output, status)
}
func pollinStatusHandler(w http.ResponseWriter, r *http.Request, db *sql.DB, c *context.Context) {
project := r.FormValue("project")
application := r.FormValue("application")
pipeline := r.FormValue("pipeline")
exec, err := polling.LoadExecutions(db, project, application, pipeline)
if err != nil {
log.Warning("Error %s\n", err)
WriteError(w, r, err)
return
}
WriteJSON(w, r, exec, 200)
return
}
func smtpPingHandler(w http.ResponseWriter, r *http.Request, db *sql.DB, c *context.Context) {
if c.User == nil {
WriteError(w, r, sdk.ErrForbidden)
return
}
message := "mail sent"
if err := mail.SendEmail("Ping", bytes.NewBufferString("Pong"), c.User.Email); err != nil {
message = err.Error()
}
WriteJSON(w, r, map[string]string{
"message": message,
}, http.StatusOK)
}