Added timefilter to problems
This commit is contained in:
parent
9700bc9d3c
commit
f7dcb4a079
4 changed files with 62 additions and 62 deletions
37
problem.go
37
problem.go
|
|
@ -16,7 +16,7 @@ import (
|
|||
type Problem struct { // {{{
|
||||
ID int
|
||||
Start time.Time
|
||||
End sql.NullTime
|
||||
End time.Time
|
||||
Acknowledged bool
|
||||
Datapoints map[string]any
|
||||
DatapointValues map[string]any `json:"datapoints"`
|
||||
|
|
@ -26,7 +26,7 @@ type Problem struct { // {{{
|
|||
SectionName string `json:"section_name"`
|
||||
} // }}}
|
||||
|
||||
func ProblemsRetrieve() (problems []Problem, err error) { // {{{
|
||||
func ProblemsRetrieve(archived bool, from, to time.Time) (problems []Problem, err error) { // {{{
|
||||
problems = []Problem{}
|
||||
row := service.Db.Conn.QueryRow(`
|
||||
SELECT
|
||||
|
|
@ -35,7 +35,7 @@ func ProblemsRetrieve() (problems []Problem, err error) { // {{{
|
|||
(SELECT
|
||||
p.id,
|
||||
p.start,
|
||||
p.end,
|
||||
TO_CHAR(p.end, 'YYYY-MM-DD"T"HH24:MI:SSTZH:TZM') AS end,
|
||||
p.acknowledged,
|
||||
p.datapoints,
|
||||
t.id AS trigger_id,
|
||||
|
|
@ -47,12 +47,18 @@ func ProblemsRetrieve() (problems []Problem, err error) { // {{{
|
|||
INNER JOIN section s ON t.section_id = s.id
|
||||
INNER JOIN area a ON s.area_id = a.id
|
||||
WHERE
|
||||
p.end IS NULL
|
||||
CASE
|
||||
WHEN $1 THEN true
|
||||
WHEN NOT $1 THEN p.end IS NULL
|
||||
END AND
|
||||
p.start >= $2 AND
|
||||
p.end <= $3
|
||||
|
||||
ORDER BY
|
||||
p.start DESC)
|
||||
|
||||
UNION ALL
|
||||
|
||||
|
||||
(SELECT
|
||||
-1 AS id,
|
||||
null,
|
||||
|
|
@ -71,8 +77,11 @@ func ProblemsRetrieve() (problems []Problem, err error) { // {{{
|
|||
dp.nodata_is_problem
|
||||
ORDER BY
|
||||
dp.name ASC)
|
||||
) AS problems
|
||||
`)
|
||||
) AS problems`,
|
||||
archived,
|
||||
from,
|
||||
to,
|
||||
)
|
||||
|
||||
var jsonBody []byte
|
||||
err = row.Scan(&jsonBody)
|
||||
|
|
@ -112,7 +121,12 @@ func ProblemStart(trigger Trigger) (problemID int, err error) { // {{{
|
|||
// Open up a new problem if no open exists.
|
||||
if openProblems == 0 {
|
||||
datapointValuesJson, _ := json.Marshal(trigger.DatapointValues)
|
||||
row = service.Db.Conn.QueryRow(`INSERT INTO problem(trigger_id, datapoints) VALUES($1, $2) RETURNING id`, trigger.ID, datapointValuesJson)
|
||||
row = service.Db.Conn.QueryRow(
|
||||
`INSERT INTO problem(trigger_id, datapoints, trigger_expression) VALUES($1, $2, $3) RETURNING id`,
|
||||
trigger.ID,
|
||||
datapointValuesJson,
|
||||
trigger.Expression,
|
||||
)
|
||||
err = row.Scan(&problemID)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err).WithData(trigger)
|
||||
|
|
@ -144,7 +158,7 @@ func ProblemAcknowledge(id int, state bool) (err error) { // {{{
|
|||
return
|
||||
} // }}}
|
||||
|
||||
func (p Problem) FormattedValues() string {// {{{
|
||||
func (p Problem) FormattedValues() string { // {{{
|
||||
out := []string{}
|
||||
for key, val := range p.DatapointValues {
|
||||
var keyval string
|
||||
|
|
@ -174,4 +188,7 @@ func (p Problem) FormattedValues() string {// {{{
|
|||
sort.Strings(out)
|
||||
|
||||
return strings.Join(out, "\n")
|
||||
}// }}}
|
||||
} // }}}
|
||||
func (p Problem) IsArchived() bool { // {{{
|
||||
return !p.End.IsZero()
|
||||
} // }}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue