Skip to content

Commit b3b1035

Browse files
authored
Merge pull request #451 from nue-digital/lm-sdk
Logic Monitor SDK changes for ping
2 parents eaaf8ee + ea3b34e commit b3b1035

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/eCloud/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,12 @@ public function loadBalancers()
320320
{
321321
return (new LoadBalancerClient($this->httpClient))->auth($this->token);
322322
}
323+
324+
/**
325+
* @return BaseClient
326+
*/
327+
public function monitorings()
328+
{
329+
return (new MonitoringClient($this->httpClient))->auth($this->token);
330+
}
323331
}

src/eCloud/MonitoringClient.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace UKFast\SDK\eCloud;
4+
5+
use UKFast\SDK\Entities\ClientEntityInterface;
6+
use UKFast\SDK\Traits\PageItems;
7+
use UKFast\SDK\eCloud\Entities\Instance;
8+
9+
class MonitoringClient extends Client implements ClientEntityInterface
10+
{
11+
use PageItems;
12+
13+
protected $collectionPath = 'v2/monitoring';
14+
15+
public function getEntityMap()
16+
{
17+
return [
18+
'id' => 'id',
19+
'name' => 'name',
20+
];
21+
}
22+
23+
/**
24+
* @param $data
25+
* @return Instance
26+
*/
27+
public function loadEntity($data)
28+
{
29+
return new Instance(
30+
$this->apiToFriendly($data, $this->getEntityMap())
31+
);
32+
}
33+
34+
/**
35+
* @param string $vmId
36+
* @return array|string
37+
* @throws \GuzzleHttp\Exception\GuzzleException
38+
*/
39+
public function getAvailableMetrics(string $vmId)
40+
{
41+
try {
42+
$data = $this->get($this->collectionPath . "/{$vmId}");
43+
} catch (\Exception $e) {
44+
return [];
45+
}
46+
return $data->getBody()->getContents();
47+
}
48+
49+
/**
50+
* @param int $widgetId
51+
* @param $additionalQueryParams
52+
* @return array|string
53+
* @throws \GuzzleHttp\Exception\GuzzleException
54+
*/
55+
public function getMetrics(int $widgetId, $additionalQueryParams)
56+
{
57+
try {
58+
$data = $this->get($this->collectionPath . "/{$widgetId}/widget?{$additionalQueryParams}");
59+
} catch (\Exception $e) {
60+
return [];
61+
}
62+
return $data->getBody()->getContents();
63+
}
64+
65+
/**
66+
* @param int $pingId
67+
* @param int $instanceId
68+
* @param $additionalQueryParams
69+
* @return string
70+
* @throws \GuzzleHttp\Exception\GuzzleException
71+
*/
72+
public function getPingMetrics(int $pingId, int $instanceId, $additionalQueryParams)
73+
{
74+
try {
75+
$data = $this->get($this->collectionPath . "/{$pingId}/{$instanceId}/ping?{$additionalQueryParams}");
76+
} catch (\Exception $e) {
77+
return $e->getMessage();
78+
return [];
79+
}
80+
return $data->getBody()->getContents();
81+
}
82+
}

0 commit comments

Comments
 (0)