Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6beb9be4
Commit
6beb9be4
authored
Oct 26, 2015
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add CloudWatch Alarm API support
parent
38f4cfb7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
7 deletions
+73
-7
pkg/api/cloudwatch/cloudwatch.go
+73
-7
No files found.
pkg/api/cloudwatch/cloudwatch.go
View file @
6beb9be4
...
...
@@ -31,13 +31,15 @@ type cwRequest struct {
func
init
()
{
actionHandlers
=
map
[
string
]
actionHandler
{
"GetMetricStatistics"
:
handleGetMetricStatistics
,
"ListMetrics"
:
handleListMetrics
,
"DescribeInstances"
:
handleDescribeInstances
,
"__GetRegions"
:
handleGetRegions
,
"__GetNamespaces"
:
handleGetNamespaces
,
"__GetMetrics"
:
handleGetMetrics
,
"__GetDimensions"
:
handleGetDimensions
,
"GetMetricStatistics"
:
handleGetMetricStatistics
,
"ListMetrics"
:
handleListMetrics
,
"DescribeAlarmsForMetric"
:
handleDescribeAlarmsForMetric
,
"DescribeAlarmHistory"
:
handleDescribeAlarmHistory
,
"DescribeInstances"
:
handleDescribeInstances
,
"__GetRegions"
:
handleGetRegions
,
"__GetNamespaces"
:
handleGetNamespaces
,
"__GetMetrics"
:
handleGetMetrics
,
"__GetDimensions"
:
handleGetDimensions
,
}
}
...
...
@@ -137,6 +139,70 @@ func handleListMetrics(req *cwRequest, c *middleware.Context) {
c
.
JSON
(
200
,
resp
)
}
func
handleDescribeAlarmsForMetric
(
req
*
cwRequest
,
c
*
middleware
.
Context
)
{
svc
:=
cloudwatch
.
New
(
&
aws
.
Config
{
Region
:
aws
.
String
(
req
.
Region
)})
reqParam
:=
&
struct
{
Parameters
struct
{
Namespace
string
`json:"namespace"`
MetricName
string
`json:"metricName"`
Dimensions
[]
*
cloudwatch
.
Dimension
`json:"dimensions"`
Statistic
string
`json:"statistic"`
Period
int64
`json:"period"`
}
`json:"parameters"`
}{}
json
.
Unmarshal
(
req
.
Body
,
reqParam
)
params
:=
&
cloudwatch
.
DescribeAlarmsForMetricInput
{
Namespace
:
aws
.
String
(
reqParam
.
Parameters
.
Namespace
),
MetricName
:
aws
.
String
(
reqParam
.
Parameters
.
MetricName
),
Period
:
aws
.
Int64
(
reqParam
.
Parameters
.
Period
),
}
if
len
(
reqParam
.
Parameters
.
Dimensions
)
!=
0
{
params
.
Dimensions
=
reqParam
.
Parameters
.
Dimensions
}
if
reqParam
.
Parameters
.
Statistic
!=
""
{
params
.
Statistic
=
aws
.
String
(
reqParam
.
Parameters
.
Statistic
)
}
resp
,
err
:=
svc
.
DescribeAlarmsForMetric
(
params
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to call AWS API"
,
err
)
return
}
c
.
JSON
(
200
,
resp
)
}
func
handleDescribeAlarmHistory
(
req
*
cwRequest
,
c
*
middleware
.
Context
)
{
svc
:=
cloudwatch
.
New
(
&
aws
.
Config
{
Region
:
aws
.
String
(
req
.
Region
)})
reqParam
:=
&
struct
{
Parameters
struct
{
AlarmName
string
`json:"alarmName"`
HistoryItemType
string
`json:"historyItemType"`
StartDate
int64
`json:"startDate"`
EndDate
int64
`json:"endDate"`
}
`json:"parameters"`
}{}
json
.
Unmarshal
(
req
.
Body
,
reqParam
)
params
:=
&
cloudwatch
.
DescribeAlarmHistoryInput
{
AlarmName
:
aws
.
String
(
reqParam
.
Parameters
.
AlarmName
),
StartDate
:
aws
.
Time
(
time
.
Unix
(
reqParam
.
Parameters
.
StartDate
,
0
)),
EndDate
:
aws
.
Time
(
time
.
Unix
(
reqParam
.
Parameters
.
EndDate
,
0
)),
}
if
reqParam
.
Parameters
.
HistoryItemType
!=
""
{
params
.
HistoryItemType
=
aws
.
String
(
reqParam
.
Parameters
.
HistoryItemType
)
}
resp
,
err
:=
svc
.
DescribeAlarmHistory
(
params
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to call AWS API"
,
err
)
return
}
c
.
JSON
(
200
,
resp
)
}
func
handleDescribeInstances
(
req
*
cwRequest
,
c
*
middleware
.
Context
)
{
sess
:=
session
.
New
()
creds
:=
credentials
.
NewChainCredentials
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment