diff --git a/api_components.go b/api_component.go similarity index 92% rename from api_components.go rename to api_component.go index 2ba41ccd074d352cff39be54cbf9f0efb8514af3..1188d269358256997c7cff1d984cb8c8529d21ad 100644 --- a/api_components.go +++ b/api_component.go @@ -5,7 +5,6 @@ import "fmt" import "encoding/json" const ( - ComponentStatusUnknown = 0 ComponentStatusOperational = 1 ComponentStatusPerformanceIssues = 2 ComponentStatusPartialOutage = 3 @@ -39,7 +38,7 @@ type ApiComponentBody struct { } type ApiComponentRepo struct { - parent ConfigApi + ConfigApi } func (api ConfigApi) Components() ApiComponentRepo { @@ -49,7 +48,7 @@ func (api ConfigApi) Components() ApiComponentRepo { } func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) { - _, err = repo.parent.Request( + _, err = repo.Request( &component, "GET", fmt.Sprintf("/components/%d", id), @@ -59,7 +58,7 @@ func (repo ApiComponentRepo) Get(id int) (component ApiComponent, err error) { } func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiComponent, err error) { - _, err = repo.parent.Request( + _, err = repo.Request( &component, "POST", "/components", @@ -69,7 +68,7 @@ func (repo ApiComponentRepo) Create(body ApiComponentBody) (component ApiCompone } func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiComponent, err error) { - _, err = repo.parent.Request( + _, err = repo.Request( &component, "PUT", fmt.Sprintf("/components/%d", id), @@ -79,7 +78,7 @@ func (repo ApiComponentRepo) Save(id int, body ApiComponentBody) (component ApiC } func (repo ApiComponentRepo) Delete(id int) (err error) { - _, err = repo.parent.Request( + _, err = repo.Request( nil, "DELETE", fmt.Sprintf("/components/%d", id), diff --git a/api_group.go b/api_group.go new file mode 100644 index 0000000000000000000000000000000000000000..b6a2da38fba4ab53faddeb11e7dd3f36d33def49 --- /dev/null +++ b/api_group.go @@ -0,0 +1,68 @@ +package main + +import "fmt" + +type ApiGroup struct { + Id int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + Order int `json:"order,omitempty"` + Collapsed int `json:"collapsed,omitempty"` +} + +type ApiGroupBody struct { + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + Collapsed int `json:"collapsed,omitempty"` +} + +type ApiGroupRepo struct { + ConfigApi +} + +func (api ConfigApi) Groups() ApiGroupRepo { + return ApiGroupRepo{ + 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 +} diff --git a/api_groups.go b/api_groups.go deleted file mode 100644 index d0a53ee2c7bd014622579ddc26c57ec9f70aadf4..0000000000000000000000000000000000000000 --- a/api_groups.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -type ApiGroup struct { - Id int `json:"id,omitempty"` - Name string `json:"name,omitempty"` - CreatedAt string `json:"created_at,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` - Order int `json:"order,omitempty"` - Collapsed int `json:"collapsed,omitempty"` -} - -type ApiGroupBody struct { - Name string `json:"name,omitempty"` - Order int `json:"order,omitempty"` - Collapsed int `json:"collapsed,omitempty"` -} - -type ApiGroupRepo struct { - parent ConfigApi -} - -func (api ConfigApi) Groups() ApiGroupRepo { - return ApiGroupRepo{ - api, - } -} diff --git a/api_incident.go b/api_incident.go new file mode 100644 index 0000000000000000000000000000000000000000..d371299c260fe20c3c547493c28d2c99477c1ccc --- /dev/null +++ b/api_incident.go @@ -0,0 +1,84 @@ +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 +} diff --git a/api_metric.go b/api_metric.go new file mode 100644 index 0000000000000000000000000000000000000000..3f2f2f6a1e0bff95f7657d26a25898ddedc78cd2 --- /dev/null +++ b/api_metric.go @@ -0,0 +1,64 @@ +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 +} diff --git a/api_metric_points.go b/api_metric_points.go new file mode 100644 index 0000000000000000000000000000000000000000..b25b85e97eeafd34fc699fe0aacd94aa4d192664 --- /dev/null +++ b/api_metric_points.go @@ -0,0 +1,59 @@ +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 +}