|
| 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