Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cachet-monitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
cachet-monitor
Commits
d88b7aa2
Verified
Commit
d88b7aa2
authored
6 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Expand API implementation
parent
23260b5c
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
api_component.go
+5
-6
5 additions, 6 deletions
api_component.go
api_group.go
+68
-0
68 additions, 0 deletions
api_group.go
api_incident.go
+84
-0
84 additions, 0 deletions
api_incident.go
api_metric.go
+64
-0
64 additions, 0 deletions
api_metric.go
api_metric_points.go
+59
-0
59 additions, 0 deletions
api_metric_points.go
with
280 additions
and
6 deletions
api_component
s
.go
→
api_component.go
+
5
−
6
View file @
d88b7aa2
...
@@ -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
),
...
...
This diff is collapsed.
Click to expand it.
api_group
s
.go
→
api_group.go
+
68
−
0
View file @
d88b7aa2
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
}
This diff is collapsed.
Click to expand it.
api_incident.go
0 → 100644
+
84
−
0
View file @
d88b7aa2
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
}
This diff is collapsed.
Click to expand it.
api_metric.go
0 → 100644
+
64
−
0
View file @
d88b7aa2
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
}
This diff is collapsed.
Click to expand it.
api_metric_points.go
0 → 100644
+
59
−
0
View file @
d88b7aa2
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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment