forked from documize/community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
84 lines (74 loc) · 2.25 KB
/
model.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
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package papertrail
import "strings"
// the HTML that is rendered by this section.
const renderTemplate = `
{{if .HasData}}
<p class="margin-left-20">The <a href="https://papertrailapp.com">Papertrail log</a> for query <em>{{.Config.Query}}</em> contains {{.Count}} entries.</p>
<table class="basic-table section-papertrail-table">
<thead>
<tr>
<th class="bordered no-width">Date</th>
<th class="bordered no-width">Severity</th>
<th class="bordered">Message</th>
</tr>
</thead>
<tbody>
{{range $item := .Events}}
<tr>
<td class="bordered no-width color-gray">{{ $item.Dated }}</td>
<td class="bordered no-width">{{ $item.Severity }}</td>
<td class="bordered width-90">{{ $item.Message }}</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<p>There are no Papertrail log entries to see.</p>
{{end}}
`
// Papertrail helpers
type papertrailRender struct {
Config papertrailConfig
Events []papertrailEvent
Count int
Authenticated bool
HasData bool
}
type papertrailSearch struct {
Events []papertrailEvent `json:"events"`
}
type papertrailEvent struct {
ID string `json:"id"`
Dated string `json:"display_received_at"`
Message string `json:"message"`
Severity string `json:"severity"`
}
type papertrailConfig struct {
APIToken string `json:"APIToken"` // only contains the correct token just after it is typed in
Query string `json:"query"`
Max int `json:"max"`
Group papertrailOption `json:"group"`
System papertrailOption `json:"system"`
}
func (c *papertrailConfig) Clean() {
c.APIToken = strings.TrimSpace(c.APIToken)
c.Query = strings.TrimSpace(c.Query)
}
type papertrailOption struct {
ID int `json:"id"`
Name string `json:"name"`
}
type papertrailOptions struct {
Groups []papertrailOption `json:"groups"`
Systems []papertrailOption `json:"systems"`
}