Skip to content

Commit e670d7b

Browse files
author
aaron.wu
committed
Added custome monitor for disk
1 parent 1315317 commit e670d7b

File tree

5 files changed

+128
-21
lines changed

5 files changed

+128
-21
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "tencentcloud/tencentcloud-sdk-php",
3-
"description": "TencentCloudApi php sdk",
2+
"name": "anchnetpkg/tencentcloud-sdk-php",
3+
"description": "TencentCloudApi php sdk for anchnet",
44
"type": "library",
5-
"homepage": "https://github.com/TencentCloud/tencentcloud-sdk-php",
5+
"homepage": "https://github.com/anchnet/tencentcloud-sdk-php",
66
"license": "Apache-2.0",
77
"authors": [
88
{

src/QcloudApi/Module/Base.php

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ abstract class QcloudApi_Module_Base extends QcloudApi_Common_Base
3030
* @var string
3131
*/
3232
protected $_secretId = "";
33-
33+
/**
34+
* 自定义扩展信息传入
35+
*/
36+
protected $_ext = [];
3437
/**
3538
* $_secretKey
3639
* secretKey
@@ -58,8 +61,9 @@ abstract class QcloudApi_Module_Base extends QcloudApi_Common_Base
5861
*/
5962
public function __construct($config = array())
6063
{
61-
if (!empty($config))
64+
if (!empty($config)) {
6265
$this->setConfig($config);
66+
}
6367
}
6468

6569
/**
@@ -69,8 +73,9 @@ public function __construct($config = array())
6973
*/
7074
public function setConfig($config)
7175
{
72-
if (!is_array($config) || !count($config))
76+
if (!is_array($config) || !count($config)) {
7377
return false;
78+
}
7479

7580
foreach ($config as $key => $val) {
7681
switch ($key) {
@@ -89,7 +94,9 @@ public function setConfig($config)
8994
case 'RequestMethod':
9095
$this->setConfigRequestMethod($val);
9196
break;
92-
97+
case 'Ext':
98+
$this->_ext = $val;
99+
break;
93100
default:
94101
;
95102
break;
@@ -179,11 +186,18 @@ public function generateUrl($name, $params)
179186
$action = ucfirst($name);
180187
$params['Action'] = $action;
181188

182-
if (!isset($params['Region']))
189+
if (!isset($params['Region'])) {
183190
$params['Region'] = $this->_defaultRegion;
191+
}
184192

185-
return QcloudApi_Common_Request::generateUrl($params, $this->_secretId, $this->_secretKey, $this->_requestMethod,
186-
$this->_serverHost, $this->_serverUri);
193+
return QcloudApi_Common_Request::generateUrl(
194+
$params,
195+
$this->_secretId,
196+
$this->_secretKey,
197+
$this->_requestMethod,
198+
$this->_serverHost,
199+
$this->_serverUri
200+
);
187201
}
188202

189203
/**
@@ -217,13 +231,25 @@ protected function _dispatchRequest($name, $arguments)
217231
}
218232
$params['Action'] = $action;
219233

220-
if (!isset($params['Region']))
234+
if (!isset($params['Region'])) {
221235
$params['Region'] = $this->_defaultRegion;
236+
}
237+
if (!empty($this->_ext)) {
238+
foreach ($this->_ext as $item => $value) {
239+
$params[$item] = $value;
240+
}
241+
}
222242

223243
require_once QCLOUDAPI_ROOT_PATH . '/Common/Request.php';
224244

225-
$response = QcloudApi_Common_Request::send($params, $this->_secretId, $this->_secretKey, $this->_requestMethod,
226-
$this->_serverHost, $this->_serverUri);
245+
$response = QcloudApi_Common_Request::send(
246+
$params,
247+
$this->_secretId,
248+
$this->_secretKey,
249+
$this->_requestMethod,
250+
$this->_serverHost,
251+
$this->_serverUri
252+
);
227253

228254
return $response;
229255
}
@@ -241,7 +267,8 @@ protected function _dealResponse($rawResponse)
241267
return false;
242268
}
243269

244-
if ($rawResponse['code']) {
270+
if ((isset($rawResponse['code']) && $rawResponse['code'] != 0)
271+
|| (isset($rawResponse['codeDesc']) && $rawResponse['codeDesc'] != 'Success')) {
245272
$ext = '';
246273
require_once QCLOUDAPI_ROOT_PATH . '/Common/Error.php';
247274
if (isset($rawResponse['detail'])) {
@@ -254,9 +281,10 @@ protected function _dealResponse($rawResponse)
254281

255282
unset($rawResponse['code'], $rawResponse['message']);
256283

257-
if (count($rawResponse))
284+
if (count($rawResponse)) {
258285
return $rawResponse;
259-
else
286+
} else {
260287
return true;
288+
}
261289
}
262290
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require_once QCLOUDAPI_ROOT_PATH . '/Module/Base.php';
4+
/**
5+
* QcloudApi_Module_Monitor
6+
* 云监控模块类
7+
*/
8+
class QcloudApi_Module_MonitorDisk extends QcloudApi_Module_Base
9+
{
10+
/**
11+
* $_serverHost
12+
* 接口域名
13+
* @var string
14+
*/
15+
protected $_serverHost = 'monitor.tencentcloudapi.com';
16+
public function __construct(array $config = array())
17+
{
18+
parent::__construct($config);
19+
$this->_serverUri = '/';
20+
}
21+
}

src/QcloudApi/QcloudApi.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class QcloudApi
6060
* 云监控
6161
*/
6262
const MODULE_MONITOR = 'monitor';
63-
63+
/**
64+
* MODULE_MONITOR_DISK
65+
* 云监控 硬盘
66+
*/
67+
const MODULE_MONITOR_DISK = 'monitorDisk';
6468
/**
6569
* MODULE_CDN
6670
* CDN
@@ -84,12 +88,12 @@ class QcloudApi
8488
*/
8589
const MODULE_YUNSOU = 'yunsou';
8690

87-
/**
91+
/**
8892
* cns
8993
*/
9094
const MODULE_CNS = 'cns';
9195

92-
/**
96+
/**
9397
* wenzhi
9498
*/
9599
const MODULE_WENZHI = 'wenzhi';
@@ -141,7 +145,7 @@ class QcloudApi
141145
*/
142146
const MODULE_TDSQL = 'tdsql';
143147

144-
/**
148+
/**
145149
* MODULE_BM
146150
* 黑石BM
147151
*/
@@ -234,7 +238,7 @@ class QcloudApi
234238
/**
235239
* MODULE_STS
236240
*/
237-
const MODULE_STS = "sts";
241+
const MODULE_STS = "sts";
238242

239243
/**
240244
* MODULE_ATHENA
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/*
3+
* Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace TencentCloud\Monitor\V20170312;
19+
20+
use TencentCloud\Common\AbstractClient;
21+
use TencentCloud\Common\Profile\ClientProfile;
22+
use TencentCloud\Common\Credential;
23+
24+
class MonitorClient extends AbstractClient
25+
{
26+
/**
27+
* @var string 产品默认域名
28+
*/
29+
protected $endpoint = "monitor.tencentcloudapi.com";
30+
31+
/**
32+
* @var string api版本号
33+
*/
34+
protected $version = "2017-03-12";
35+
36+
/**
37+
* CvmClient constructor.
38+
* @param Credential $credential 认证类实例
39+
* @param string $region 地域
40+
* @param ClientProfile $profile client配置
41+
*/
42+
public function __construct($credential, $region, $profile=null)
43+
{
44+
parent::__construct($this->endpoint, $this->version, $credential, $region, $profile);
45+
}
46+
47+
public function returnResponse($action, $response)
48+
{
49+
$respClass = "TencentCloud"."\\".ucfirst("monitor")."\\"."V20170312\\Models"."\\".ucfirst($action)."Response";
50+
$obj = new $respClass();
51+
$obj->deserialize($response);
52+
return $obj;
53+
}
54+
}

0 commit comments

Comments
 (0)