Skip to content
Snippets Groups Projects
Verified Commit d88b7aa2 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Expand API implementation

parent 23260b5c
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ import "fmt" ...@@ -5,7 +5,6 @@ import "fmt"
import "encoding/json" import "encoding/json"
const ( const (
ComponentStatusUnknown = 0
ComponentStatusOperational = 1 ComponentStatusOperational = 1
ComponentStatusPerformanceIssues = 2 ComponentStatusPerformanceIssues = 2
ComponentStatusPartialOutage = 3 ComponentStatusPartialOutage = 3
...@@ -39,7 +38,7 @@ type ApiComponentBody struct { ...@@ -39,7 +38,7 @@ type ApiComponentBody struct {
} }
type ApiComponentRepo struct { type ApiComponentRepo struct {
parent ConfigApi ConfigApi
} }
func (api ConfigApi) Components() ApiComponentRepo { func (api ConfigApi) Components() ApiComponentRepo {
...@@ -49,7 +48,7 @@ func (api ConfigApi) Components() ApiComponentRepo { ...@@ -49,7 +48,7 @@ func (api ConfigApi) Components() ApiComponentRepo {
} }
func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) { func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) {
_, err = repo.parent.Request( _, err = repo.Request(
&component, &component,
"GET", "GET",
fmt.Sprintf("/components/%d", id), fmt.Sprintf("/components/%d", id),
...@@ -59,7 +58,7 @@ func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) { ...@@ -59,7 +58,7 @@ func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) {
} }
func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiComponent, err error) { func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiComponent, err error) {
_, err = repo.parent.Request( _, err = repo.Request(
&component, &component,
"POST", "POST",
"/components", "/components",
...@@ -69,7 +68,7 @@ func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiCompone ...@@ -69,7 +68,7 @@ func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiCompone
} }
func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiComponent, err error) { func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiComponent, err error) {
_, err = repo.parent.Request( _, err = repo.Request(
&component, &component,
"PUT", "PUT",
fmt.Sprintf("/components/%d", id), fmt.Sprintf("/components/%d", id),
...@@ -79,7 +78,7 @@ func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiC ...@@ -79,7 +78,7 @@ func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiC
} }
func (repo ApiComponentRepo) Delete(id int) (err error) { func (repo ApiComponentRepo) Delete(id int) (err error) {
_, err = repo.parent.Request( _, err = repo.Request(
nil, nil,
"DELETE", "DELETE",
fmt.Sprintf("/components/%d", id), fmt.Sprintf("/components/%d", id),
......
package main package main
import "fmt"
type ApiGroup struct { type ApiGroup struct {
Id int `json:"id,omitempty"` Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
...@@ -16,7 +18,7 @@ type ApiGroupBody struct { ...@@ -16,7 +18,7 @@ type ApiGroupBody struct {
} }
type ApiGroupRepo struct { type ApiGroupRepo struct {
parent ConfigApi ConfigApi
} }
func (api ConfigApi) Groups() ApiGroupRepo { func (api ConfigApi) Groups() ApiGroupRepo {
...@@ -24,3 +26,43 @@ func (api ConfigApi) Groups() ApiGroupRepo { ...@@ -24,3 +26,43 @@ func (api ConfigApi) Groups() ApiGroupRepo {
api, api,
} }
} }
func (repo ApiGroupRepo) Get(id int) (group ApiGroup, err error) {
_, err = repo.Request(
&group,
"GET",
fmt.Sprintf("/components/groups/%d", id),
nil,
)
return
}
func (repo ApiGroupRepo) Create(body ApiGroupBody) (group ApiGroup, err error) {
_, err = repo.Request(
&group,
"POST",
"/components/groups",
body,
)
return
}
func (repo ApiGroupRepo) Save(id int, body ApiGroupBody) (group ApiGroup, err error) {
_, err = repo.Request(
&group,
"PUT",
fmt.Sprintf("/components/groups/%d", id),
body,
)
return
}
func (repo ApiGroupRepo) Delete(id int) (err error) {
_, err = repo.Request(
nil,
"DELETE",
fmt.Sprintf("/components/groups/%d", id),
nil,
)
return
}
package main
import "fmt"
type ApiIncident struct {
Id int `json:"id,omitempty"`
ComponentId int `json:"component_id,omitempty"`
Name string `json:"name,omitempty"`
Status int `json:"status,omitempty"`
Visible int `json:"visible,omitempty"`
Message string `json:"message,omitempty"`
ScheduledAt string `json:"scheduled_at,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DeletedAt string `json:"deleted_at,omitempty"`
HumanStatus string `json:"human_status,omitempty"`
}
type ApiIncidentBody struct {
Name string `json:"name,omitempty"`
Message string `json:"message,omitempty"`
Status int `json:"status,omitempty"`
Visible int `json:"visible,omitempty"`
ComponentId int `json:"component_id,omitempty"`
ComponentStatus int `json:"component_status,omitempty"`
Notify bool `json:"notify,omitempty"`
ApiIncidentCreate
}
type ApiIncidentCreate struct {
CreatedAt string `json:"created_at,omitempty"`
Template string `json:"template,omitempty"`
Vars []string `json:"vars,omitempty"`
}
type ApiIncidentRepo struct {
ConfigApi
}
func (api ConfigApi) Incidents() ApiIncidentRepo {
return ApiIncidentRepo{
api,
}
}
func (repo ApiIncidentRepo) Get(id int) (incident ApiIncident, err error) {
_, err = repo.Request(
&incident,
"GET",
fmt.Sprintf("/incidents/%d", id),
nil,
)
return
}
func (repo ApiIncidentRepo) Create(body ApiIncidentBody) (incident ApiIncident, err error) {
_, err = repo.Request(
&incident,
"POST",
"/incidents",
body,
)
return
}
func (repo ApiIncidentRepo) Save(id int, body ApiIncidentBody) (incident ApiIncident, err error) {
_, err = repo.Request(
&incident,
"PUT",
fmt.Sprintf("/incidents/%d", id),
body,
)
return
}
func (repo ApiIncidentRepo) Delete(id int) (err error) {
_, err = repo.Request(
nil,
"DELETE",
fmt.Sprintf("/incidents/%d", id),
nil,
)
return
}
package main
import "fmt"
type ApiMetric struct {
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Suffix string `json:"suffix,omitempty"`
Description string `json:"description,omitempty"`
DefaultValue string `json:"default_value,omitempty"`
DisplayChart int `json:"display_chart,omitempty"`
CalcType int `json:"calc_type,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DefaultViewName string `json:"default_view_name,omitempty"`
}
type ApiMetricBody struct {
Name string `json:"name,omitempty"`
Suffix string `json:"suffix,omitempty"`
Description string `json:"description,omitempty"`
DefaultValue string `json:"default_value,omitempty"`
DisplayChart int `json:"display_chart,omitempty"`
}
type ApiMetricRepo struct {
ConfigApi
}
func (api ConfigApi) Metrics() ApiMetricRepo {
return ApiMetricRepo{
api,
}
}
func (repo ApiMetricRepo) Get(id int) (metric ApiMetric, err error) {
_, err = repo.Request(
&metric,
"GET",
fmt.Sprintf("/metrics/%d", id),
nil,
)
return
}
func (repo ApiMetricRepo) Create(body ApiMetricBody) (metric ApiMetric, err error) {
_, err = repo.Request(
&metric,
"POST",
"/metrics",
body,
)
return
}
func (repo ApiMetricRepo) Delete(id int) (err error) {
_, err = repo.Request(
nil,
"DELETE",
fmt.Sprintf("/metrics/%d", id),
nil,
)
return
}
package main
import "fmt"
type ApiMetricPoint struct {
Id int `json:"id,omitempty"`
MetricId int `json:"metric_id,omitempty"`
Value int `json:"value,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
type ApiMetricPointBody struct {
Metric int `json:"metric,omitempty"`
Value int `json:"value,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
}
type ApiMetricPointRepo struct {
ConfigApi
MetricId int
}
func (api ConfigApi) MetricPoints(metricId int) ApiMetricPointRepo {
return ApiMetricPointRepo{
api,
metricId,
}
}
func (repo ApiMetricPointRepo) List(id int) (points []ApiMetricPoint, err error) {
_, err = repo.Request(
&points,
"GET",
fmt.Sprintf("/metrics/%d/points/%d", repo.MetricId, id),
nil,
)
return
}
func (repo ApiMetricPointRepo) Create(body ApiMetricPointBody) (point ApiMetricPoint, err error) {
_, err = repo.Request(
&point,
"POST",
fmt.Sprintf("/metrics/%d/points", repo.MetricId),
body,
)
return
}
func (repo ApiMetricPointRepo) Delete(id int) (err error) {
_, err = repo.Request(
nil,
"DELETE",
fmt.Sprintf("/metrics/%d/points/%d", repo.MetricId, id),
nil,
)
return
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment