-
Notifications
You must be signed in to change notification settings - Fork 29
/
httptest.go
53 lines (45 loc) · 1.12 KB
/
httptest.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
package main
import (
"fmt"
"strconv"
"time"
)
// HTTPTestStep represents single step in the web scenario.
type HTTPTestStep struct {
ID string `json:"httpstepid"`
TestID string `json:"httptestid"`
URL string `json:"url"`
}
// HTTPTest represents web scenario, which often used for simple step-by-step
// external monitoring of websites via HTTP.
type HTTPTest struct {
ID string `json:"httptestid"`
HostID string `json:"hostid"`
Name string `json:"name"`
Delay string `json:"delay"`
NextCheck string `json:"nextcheck"`
TemplateID string `json:"templateid"`
Steps []HTTPTestStep `json:"steps"`
}
func (check *HTTPTest) DateTime() string {
if check.NextCheck == "0" {
return "-"
}
return check.date().Format("2006-01-02 15:04:05")
}
func (check *HTTPTest) date() time.Time {
date, err := strconv.ParseInt(check.NextCheck, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0)
}
func (check *HTTPTest) Format() string {
return fmt.Sprintf(
"%s (%d steps every %s seconds)\t%s (next)\t",
check.Name,
len(check.Steps),
check.Delay,
check.DateTime(),
)
}