Add prometheus api AddGrafana and AddIntegration.

This commit is contained in:
sdk-team
2020-04-09 21:22:01 +08:00
parent abfdc41f3b
commit 485d712ddd
15 changed files with 604 additions and 69 deletions

View File

@@ -51,6 +51,78 @@ ARMSClient::ARMSClient(const std::string & accessKeyId, const std::string & acce
ARMSClient::~ARMSClient()
{}
ARMSClient::AddGrafanaOutcome ARMSClient::addGrafana(const AddGrafanaRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return AddGrafanaOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return AddGrafanaOutcome(AddGrafanaResult(outcome.result()));
else
return AddGrafanaOutcome(outcome.error());
}
void ARMSClient::addGrafanaAsync(const AddGrafanaRequest& request, const AddGrafanaAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, addGrafana(request), context);
};
asyncExecute(new Runnable(fn));
}
ARMSClient::AddGrafanaOutcomeCallable ARMSClient::addGrafanaCallable(const AddGrafanaRequest &request) const
{
auto task = std::make_shared<std::packaged_task<AddGrafanaOutcome()>>(
[this, request]()
{
return this->addGrafana(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
ARMSClient::AddIntegrationOutcome ARMSClient::addIntegration(const AddIntegrationRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return AddIntegrationOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return AddIntegrationOutcome(AddIntegrationResult(outcome.result()));
else
return AddIntegrationOutcome(outcome.error());
}
void ARMSClient::addIntegrationAsync(const AddIntegrationRequest& request, const AddIntegrationAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, addIntegration(request), context);
};
asyncExecute(new Runnable(fn));
}
ARMSClient::AddIntegrationOutcomeCallable ARMSClient::addIntegrationCallable(const AddIntegrationRequest &request) const
{
auto task = std::make_shared<std::packaged_task<AddIntegrationOutcome()>>(
[this, request]()
{
return this->addIntegration(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
ARMSClient::CreateAlertContactOutcome ARMSClient::createAlertContact(const CreateAlertContactRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/arms/model/AddGrafanaRequest.h>
using AlibabaCloud::ARMS::Model::AddGrafanaRequest;
AddGrafanaRequest::AddGrafanaRequest() :
RpcServiceRequest("arms", "2019-08-08", "AddGrafana")
{
setMethod(HttpRequest::Method::Post);
}
AddGrafanaRequest::~AddGrafanaRequest()
{}
std::string AddGrafanaRequest::getRegionId()const
{
return regionId_;
}
void AddGrafanaRequest::setRegionId(const std::string& regionId)
{
regionId_ = regionId;
setParameter("RegionId", regionId);
}
std::string AddGrafanaRequest::getIntegration()const
{
return integration_;
}
void AddGrafanaRequest::setIntegration(const std::string& integration)
{
integration_ = integration;
setParameter("Integration", integration);
}
std::string AddGrafanaRequest::getClusterId()const
{
return clusterId_;
}
void AddGrafanaRequest::setClusterId(const std::string& clusterId)
{
clusterId_ = clusterId;
setParameter("ClusterId", clusterId);
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/arms/model/AddGrafanaResult.h>
#include <json/json.h>
using namespace AlibabaCloud::ARMS;
using namespace AlibabaCloud::ARMS::Model;
AddGrafanaResult::AddGrafanaResult() :
ServiceResult()
{}
AddGrafanaResult::AddGrafanaResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
AddGrafanaResult::~AddGrafanaResult()
{}
void AddGrafanaResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
if(!value["Data"].isNull())
data_ = value["Data"].asString();
}
std::string AddGrafanaResult::getData()const
{
return data_;
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/arms/model/AddIntegrationRequest.h>
using AlibabaCloud::ARMS::Model::AddIntegrationRequest;
AddIntegrationRequest::AddIntegrationRequest() :
RpcServiceRequest("arms", "2019-08-08", "AddIntegration")
{
setMethod(HttpRequest::Method::Post);
}
AddIntegrationRequest::~AddIntegrationRequest()
{}
std::string AddIntegrationRequest::getRegionId()const
{
return regionId_;
}
void AddIntegrationRequest::setRegionId(const std::string& regionId)
{
regionId_ = regionId;
setParameter("RegionId", regionId);
}
std::string AddIntegrationRequest::getIntegration()const
{
return integration_;
}
void AddIntegrationRequest::setIntegration(const std::string& integration)
{
integration_ = integration;
setParameter("Integration", integration);
}
std::string AddIntegrationRequest::getClusterId()const
{
return clusterId_;
}
void AddIntegrationRequest::setClusterId(const std::string& clusterId)
{
clusterId_ = clusterId;
setParameter("ClusterId", clusterId);
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/arms/model/AddIntegrationResult.h>
#include <json/json.h>
using namespace AlibabaCloud::ARMS;
using namespace AlibabaCloud::ARMS::Model;
AddIntegrationResult::AddIntegrationResult() :
ServiceResult()
{}
AddIntegrationResult::AddIntegrationResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
AddIntegrationResult::~AddIntegrationResult()
{}
void AddIntegrationResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
if(!value["Data"].isNull())
data_ = value["Data"].asString();
}
std::string AddIntegrationResult::getData()const
{
return data_;
}

View File

@@ -46,98 +46,98 @@ void SearchAlertRulesResult::parse(const std::string &payload)
pageBean_.pageNumber = std::stoi(pageBeanNode["PageNumber"].asString());
if(!pageBeanNode["PageSize"].isNull())
pageBean_.pageSize = std::stoi(pageBeanNode["PageSize"].asString());
auto allAlertRulesNode = pageBeanNode["AlertRules"]["AlertRule"];
for (auto pageBeanNodeAlertRulesAlertRule : allAlertRulesNode)
auto allAlertRulesNode = pageBeanNode["AlertRules"]["AlertRuleEntity"];
for (auto pageBeanNodeAlertRulesAlertRuleEntity : allAlertRulesNode)
{
PageBean::AlertRule alertRuleObject;
if(!pageBeanNodeAlertRulesAlertRule["AlertTitle"].isNull())
alertRuleObject.alertTitle = pageBeanNodeAlertRulesAlertRule["AlertTitle"].asString();
if(!pageBeanNodeAlertRulesAlertRule["AlertLevel"].isNull())
alertRuleObject.alertLevel = pageBeanNodeAlertRulesAlertRule["AlertLevel"].asString();
if(!pageBeanNodeAlertRulesAlertRule["AlertType"].isNull())
alertRuleObject.alertType = std::stoi(pageBeanNodeAlertRulesAlertRule["AlertType"].asString());
if(!pageBeanNodeAlertRulesAlertRule["AlertVersion"].isNull())
alertRuleObject.alertVersion = std::stoi(pageBeanNodeAlertRulesAlertRule["AlertVersion"].asString());
if(!pageBeanNodeAlertRulesAlertRule["Config"].isNull())
alertRuleObject.config = pageBeanNodeAlertRulesAlertRule["Config"].asString();
if(!pageBeanNodeAlertRulesAlertRule["ContactGroupIdList"].isNull())
alertRuleObject.contactGroupIdList = pageBeanNodeAlertRulesAlertRule["ContactGroupIdList"].asString();
if(!pageBeanNodeAlertRulesAlertRule["CreateTime"].isNull())
alertRuleObject.createTime = std::stol(pageBeanNodeAlertRulesAlertRule["CreateTime"].asString());
if(!pageBeanNodeAlertRulesAlertRule["Id"].isNull())
alertRuleObject.id = std::stol(pageBeanNodeAlertRulesAlertRule["Id"].asString());
if(!pageBeanNodeAlertRulesAlertRule["RegionId"].isNull())
alertRuleObject.regionId = pageBeanNodeAlertRulesAlertRule["RegionId"].asString();
if(!pageBeanNodeAlertRulesAlertRule["Status"].isNull())
alertRuleObject.status = pageBeanNodeAlertRulesAlertRule["Status"].asString();
if(!pageBeanNodeAlertRulesAlertRule["TaskId"].isNull())
alertRuleObject.taskId = std::stol(pageBeanNodeAlertRulesAlertRule["TaskId"].asString());
if(!pageBeanNodeAlertRulesAlertRule["TaskStatus"].isNull())
alertRuleObject.taskStatus = pageBeanNodeAlertRulesAlertRule["TaskStatus"].asString();
if(!pageBeanNodeAlertRulesAlertRule["UpdateTime"].isNull())
alertRuleObject.updateTime = std::stol(pageBeanNodeAlertRulesAlertRule["UpdateTime"].asString());
if(!pageBeanNodeAlertRulesAlertRule["UserId"].isNull())
alertRuleObject.userId = pageBeanNodeAlertRulesAlertRule["UserId"].asString();
PageBean::AlertRuleEntity alertRuleEntityObject;
if(!pageBeanNodeAlertRulesAlertRuleEntity["AlertTitle"].isNull())
alertRuleEntityObject.alertTitle = pageBeanNodeAlertRulesAlertRuleEntity["AlertTitle"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["AlertLevel"].isNull())
alertRuleEntityObject.alertLevel = pageBeanNodeAlertRulesAlertRuleEntity["AlertLevel"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["AlertType"].isNull())
alertRuleEntityObject.alertType = std::stoi(pageBeanNodeAlertRulesAlertRuleEntity["AlertType"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["AlertVersion"].isNull())
alertRuleEntityObject.alertVersion = std::stoi(pageBeanNodeAlertRulesAlertRuleEntity["AlertVersion"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["Config"].isNull())
alertRuleEntityObject.config = pageBeanNodeAlertRulesAlertRuleEntity["Config"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["ContactGroupIdList"].isNull())
alertRuleEntityObject.contactGroupIdList = pageBeanNodeAlertRulesAlertRuleEntity["ContactGroupIdList"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["CreateTime"].isNull())
alertRuleEntityObject.createTime = std::stol(pageBeanNodeAlertRulesAlertRuleEntity["CreateTime"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["Id"].isNull())
alertRuleEntityObject.id = std::stol(pageBeanNodeAlertRulesAlertRuleEntity["Id"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["RegionId"].isNull())
alertRuleEntityObject.regionId = pageBeanNodeAlertRulesAlertRuleEntity["RegionId"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["Status"].isNull())
alertRuleEntityObject.status = pageBeanNodeAlertRulesAlertRuleEntity["Status"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["TaskId"].isNull())
alertRuleEntityObject.taskId = std::stol(pageBeanNodeAlertRulesAlertRuleEntity["TaskId"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["TaskStatus"].isNull())
alertRuleEntityObject.taskStatus = pageBeanNodeAlertRulesAlertRuleEntity["TaskStatus"].asString();
if(!pageBeanNodeAlertRulesAlertRuleEntity["UpdateTime"].isNull())
alertRuleEntityObject.updateTime = std::stol(pageBeanNodeAlertRulesAlertRuleEntity["UpdateTime"].asString());
if(!pageBeanNodeAlertRulesAlertRuleEntity["UserId"].isNull())
alertRuleEntityObject.userId = pageBeanNodeAlertRulesAlertRuleEntity["UserId"].asString();
auto alarmContextNode = value["AlarmContext"];
if(!alarmContextNode["AlarmContentTemplate"].isNull())
alertRuleObject.alarmContext.alarmContentTemplate = alarmContextNode["AlarmContentTemplate"].asString();
alertRuleEntityObject.alarmContext.alarmContentTemplate = alarmContextNode["AlarmContentTemplate"].asString();
if(!alarmContextNode["AlarmContentSubTitle"].isNull())
alertRuleObject.alarmContext.alarmContentSubTitle = alarmContextNode["AlarmContentSubTitle"].asString();
auto alertRule1Node = value["AlertRule"];
if(!alertRule1Node["Operator"].isNull())
alertRuleObject.alertRule1._operator = alertRule1Node["Operator"].asString();
auto allRulesNode = alertRule1Node["Rules"]["Rule"];
for (auto alertRule1NodeRulesRule : allRulesNode)
alertRuleEntityObject.alarmContext.alarmContentSubTitle = alarmContextNode["AlarmContentSubTitle"].asString();
auto alertRuleNode = value["AlertRule"];
if(!alertRuleNode["Operator"].isNull())
alertRuleEntityObject.alertRule._operator = alertRuleNode["Operator"].asString();
auto allRulesNode = alertRuleNode["Rules"]["Rule"];
for (auto alertRuleNodeRulesRule : allRulesNode)
{
PageBean::AlertRule::AlertRule1::Rule ruleObject;
if(!alertRule1NodeRulesRule["Aggregates"].isNull())
ruleObject.aggregates = alertRule1NodeRulesRule["Aggregates"].asString();
if(!alertRule1NodeRulesRule["Alias"].isNull())
ruleObject.alias = alertRule1NodeRulesRule["Alias"].asString();
if(!alertRule1NodeRulesRule["Measure"].isNull())
ruleObject.measure = alertRule1NodeRulesRule["Measure"].asString();
if(!alertRule1NodeRulesRule["NValue"].isNull())
ruleObject.nValue = std::stoi(alertRule1NodeRulesRule["NValue"].asString());
if(!alertRule1NodeRulesRule["Operator"].isNull())
ruleObject._operator = alertRule1NodeRulesRule["Operator"].asString();
if(!alertRule1NodeRulesRule["Value"].isNull())
ruleObject.value = std::stof(alertRule1NodeRulesRule["Value"].asString());
alertRuleObject.alertRule1.rules.push_back(ruleObject);
PageBean::AlertRuleEntity::AlertRule::Rule ruleObject;
if(!alertRuleNodeRulesRule["Aggregates"].isNull())
ruleObject.aggregates = alertRuleNodeRulesRule["Aggregates"].asString();
if(!alertRuleNodeRulesRule["Alias"].isNull())
ruleObject.alias = alertRuleNodeRulesRule["Alias"].asString();
if(!alertRuleNodeRulesRule["Measure"].isNull())
ruleObject.measure = alertRuleNodeRulesRule["Measure"].asString();
if(!alertRuleNodeRulesRule["NValue"].isNull())
ruleObject.nValue = std::stoi(alertRuleNodeRulesRule["NValue"].asString());
if(!alertRuleNodeRulesRule["Operator"].isNull())
ruleObject._operator = alertRuleNodeRulesRule["Operator"].asString();
if(!alertRuleNodeRulesRule["Value"].isNull())
ruleObject.value = std::stof(alertRuleNodeRulesRule["Value"].asString());
alertRuleEntityObject.alertRule.rules.push_back(ruleObject);
}
auto metricParamNode = value["MetricParam"];
if(!metricParamNode["AppGroupId"].isNull())
alertRuleObject.metricParam.appGroupId = metricParamNode["AppGroupId"].asString();
alertRuleEntityObject.metricParam.appGroupId = metricParamNode["AppGroupId"].asString();
if(!metricParamNode["AppId"].isNull())
alertRuleObject.metricParam.appId = metricParamNode["AppId"].asString();
alertRuleEntityObject.metricParam.appId = metricParamNode["AppId"].asString();
if(!metricParamNode["Pid"].isNull())
alertRuleObject.metricParam.pid = metricParamNode["Pid"].asString();
alertRuleEntityObject.metricParam.pid = metricParamNode["Pid"].asString();
if(!metricParamNode["Type"].isNull())
alertRuleObject.metricParam.type = metricParamNode["Type"].asString();
alertRuleEntityObject.metricParam.type = metricParamNode["Type"].asString();
auto allDimensionsNode = metricParamNode["Dimensions"]["Dimension"];
for (auto metricParamNodeDimensionsDimension : allDimensionsNode)
{
PageBean::AlertRule::MetricParam::Dimension dimensionObject;
PageBean::AlertRuleEntity::MetricParam::Dimension dimensionObject;
if(!metricParamNodeDimensionsDimension["Key"].isNull())
dimensionObject.key = metricParamNodeDimensionsDimension["Key"].asString();
if(!metricParamNodeDimensionsDimension["Type"].isNull())
dimensionObject.type = metricParamNodeDimensionsDimension["Type"].asString();
if(!metricParamNodeDimensionsDimension["Value"].isNull())
dimensionObject.value = metricParamNodeDimensionsDimension["Value"].asString();
alertRuleObject.metricParam.dimensions.push_back(dimensionObject);
alertRuleEntityObject.metricParam.dimensions.push_back(dimensionObject);
}
auto noticeNode = value["Notice"];
if(!noticeNode["EndTime"].isNull())
alertRuleObject.notice.endTime = std::stol(noticeNode["EndTime"].asString());
alertRuleEntityObject.notice.endTime = std::stol(noticeNode["EndTime"].asString());
if(!noticeNode["NoticeEndTime"].isNull())
alertRuleObject.notice.noticeEndTime = std::stol(noticeNode["NoticeEndTime"].asString());
alertRuleEntityObject.notice.noticeEndTime = std::stol(noticeNode["NoticeEndTime"].asString());
if(!noticeNode["NoticeStartTime"].isNull())
alertRuleObject.notice.noticeStartTime = std::stol(noticeNode["NoticeStartTime"].asString());
alertRuleEntityObject.notice.noticeStartTime = std::stol(noticeNode["NoticeStartTime"].asString());
if(!noticeNode["StartTime"].isNull())
alertRuleObject.notice.startTime = std::stol(noticeNode["StartTime"].asString());
alertRuleEntityObject.notice.startTime = std::stol(noticeNode["StartTime"].asString());
auto allAlertWays = value["AlertWays"]["AlertWay"];
for (auto value : allAlertWays)
alertRuleObject.alertWays.push_back(value.asString());
pageBean_.alertRules.push_back(alertRuleObject);
alertRuleEntityObject.alertWays.push_back(value.asString());
pageBean_.alertRules.push_back(alertRuleEntityObject);
}
}