Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • AbstractResource
  • Account
  • Agent
  • AgentConnection
  • AgentHost
  • AgentHostInfo
  • AgentTarget
  • AgentToken
  • Alarm
  • Changelog
  • Check
  • CheckType
  • Entity
  • Metric
  • Notification
  • NotificationHistory
  • NotificationPlan
  • NotificationType
  • ReadonlyResource
  • View
  • Zone

Interfaces

  • ResourceInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
 1: <?php
 2: 
 3: namespace OpenCloud\CloudMonitoring\Resource;
 4: 
 5: use OpenCloud\Common\PersistentObject;
 6: use OpenCloud\CloudMonitoring\Exception;
 7: 
 8: /**
 9:  * Agent class.
10:  * 
11:  * @extends ReadOnlyResource
12:  * @implements ResourceInterface
13:  */
14: class AgentTarget extends ReadOnlyResource implements ResourceInterface
15: {
16:     
17:     public $type = 'agent.filesystem';
18:     
19:     protected static $json_name = 'targets';
20:     protected static $json_collection_name = 'targets';
21:     protected static $url_resource = 'targets';
22: 
23:     private $allowedTypes = array(
24:         'agent.filesystem',
25:         'agent.memory',
26:         'agent.load_average',
27:         'agent.cpu',
28:         'agent.disk',
29:         'agent.network',
30:         'agent.plugin'
31:     );
32: 
33:     public function baseUrl()
34:     {
35:         $resourceUrl = "agent/check_types/{$this->type}/{$this->ResourceName()}";
36:         return $this->Parent()->Url($this->Parent()->id . '/' . $resourceUrl);
37:     }
38: 
39:     public function setType($type)
40:     {
41:         if (!in_array($type, $this->allowedTypes)) {
42:             throw new Exception\AgentException(sprintf(
43:                 'Incorrect target type. Please specify one of the following: %s',
44:                 implode(', ', $this->allowedTypes)
45:             ));
46:         }
47: 
48:         $this->type = $type;
49:     }
50: 
51:     public function listAll()
52:     {
53:         if (!$this->type) {
54:             throw new Exception\AgentException(sprintf(
55:                 'Please specify a target type'
56:             ));
57:         }
58: 
59:         $response = json_decode($this->Service()->Request($this->Url())->HttpBody());
60:         
61:         if (isset($response->{self::$json_collection_name})) {
62:             $response = $response->{self::$json_collection_name};
63:         }
64: 
65:         return $response;
66:     } 
67:     
68: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0