/
health.go
55 lines (47 loc) · 1.5 KB
/
health.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
package oc
import (
"context"
"net/url"
"strconv"
"time"
)
// HealthRequest is a request to the health check endpoint.
type HealthRequest struct {
// SkipIndexer tells OC to omit the indexer health check.
SkipIndexer bool
// SkipSolr tells OC to omit the Solr health check.
SkipSolr bool
// SkipStorage tells OC to omit the storage health check.
SkipStorage bool
}
// Health is a OpenContent health check response.
type Health struct {
Indexer bool `json:"indexer"`
Solr bool `json:"index"`
Database bool `json:"database"`
Storage bool `json:"filesystem"`
FreeSystemDiskSpace int64 `json:"freeSystemDiskSpace"`
MaximumMemory int `json:"maximumMemory"`
CurrentMemory int `json:"currentMemory"`
ActiveConfiguration struct {
Checksum string `json:"checksum"`
LastModified time.Time `json:"lastModified"`
} `json:"activeConfiguration"`
TempConfiguration struct {
Checksum string `json:"checksum"`
LastModified time.Time `json:"lastModified"`
} `json:"tempConfiguration"`
}
// Health performs a health check request against OC.
func (c *Client) Health(ctx context.Context, req HealthRequest) (Health, error) {
q := url.Values{}
q.Set("indexer", strconv.FormatBool(!req.SkipIndexer))
q.Set("solr", strconv.FormatBool(!req.SkipSolr))
q.Set("storage", strconv.FormatBool(!req.SkipStorage))
var health Health
_, err := c.getJSON(ctx, "health", q, &health)
if err != nil {
return health, err
}
return health, nil
}