Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • AbstractResource
  • Agent
  • AgentConnection
  • AgentHost
  • AgentHostInfo
  • AgentTarget
  • AgentToken
  • Alarm
  • Changelog
  • Check
  • CheckType
  • Entity
  • Metric
  • Notification
  • NotificationHistory
  • NotificationPlan
  • NotificationType
  • ReadonlyResource
  • View
  • Zone
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
  7:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\CloudMonitoring\Resource;
 12: 
 13: use OpenCloud\CloudMonitoring\Exception;
 14: 
 15: /**
 16:  * Check class.
 17:  */
 18: class Check extends AbstractResource
 19: {
 20:     /**
 21:      * @var string
 22:      */
 23:     private $id;
 24: 
 25:     /**
 26:      * @var string|CheckType The type of check.
 27:      */
 28:     private $type;
 29: 
 30:     /**
 31:      * @var array Details specific to the check type.
 32:      */
 33:     private $details;
 34: 
 35:     /**
 36:      * @var bool Disables the check.
 37:      */
 38:     private $disabled;
 39: 
 40:     /**
 41:      * @var string A friendly label for a check.
 42:      */
 43:     private $label;
 44: 
 45:     /**
 46:      * @var int The period in seconds for a check. The value must be greater than the minimum period set on your account.
 47:      */
 48:     private $period;
 49: 
 50:     /**
 51:      * @var int The timeout in seconds for a check. This has to be less than the period.
 52:      */
 53:     private $timeout;
 54: 
 55:     /**
 56:      * For remote checks only. List of monitoring zones to poll from. Note: This argument is only required for remote
 57:      * (non-agent) checks.
 58:      *
 59:      * @var array
 60:      */
 61:     private $monitoring_zones_poll;
 62: 
 63:     /**
 64:      * For remote checks only. A key in the entity's 'ip_addresses' hash used to resolve this check to an IP address.
 65:      * This parameter is mutually exclusive with target_hostname.
 66:      *
 67:      * @var string
 68:      */
 69:     private $target_alias;
 70: 
 71:     /**
 72:      * For remote checks only. The hostname this check should target. This parameter is mutually exclusive with target_alias.
 73:      *
 74:      * @var string
 75:      */
 76:     private $target_hostname;
 77: 
 78:     /**
 79:      * For remote checks only. Determines how to resolve the check target.
 80:      * @var string
 81:      */
 82:     private $target_resolver;
 83: 
 84:     protected static $json_name = false;
 85:     protected static $json_collection_name = 'values';
 86:     protected static $url_resource = 'checks';
 87: 
 88:     protected static $emptyObject = array(
 89:         'type',
 90:         'details',
 91:         'disabled',
 92:         'label',
 93:         'period',
 94:         'timeout',
 95:         'monitoring_zones_poll',
 96:         'target_alias',
 97:         'target_hostname',
 98:         'target_resolver'
 99:     );
100: 
101:     protected static $requiredKeys = array('type');
102:     
103:     protected $associatedResources = array('CheckType' => 'CheckType');
104: 
105:     protected $dataPointParams = array(
106:         'from',
107:         'to',
108:         'points',
109:         'resolution',
110:         'select'
111:     );
112: 
113:     public function testUrl($debug = false)
114:     {
115:         $params = array();
116:         if ($debug === true) {
117:             $params['debug'] = 'true';
118:         }
119:         return $this->getParent()->url('test-check', $params); 
120:     }
121: 
122:     public function testExistingUrl($debug = false)
123:     {
124:         return $this->getUrl()->addPath('test');
125:     }
126: 
127:     public function getMetrics()
128:     {
129:         return $this->getService()->resourceList('Metric', null, $this);
130:     }
131: 
132:     public function getMetric($info = null)
133:     {
134:         return $this->getService()->resource('Metric', $info, $this);
135:     }
136: 
137:     /**
138:      * Fetch particular data points.
139:      *
140:      * @param string $metricName
141:      * @param array  $options
142:      * @return mixed
143:      * @throws \OpenCloud\CloudMonitoring\Exception\MetricException
144:      */
145:     public function fetchDataPoints($metricName, array $options = array())
146:     {
147:         $metric = $this->getService()->resource('Metric', null, $this);
148: 
149:         $url = clone $metric->getUrl();
150:         $url->addPath($metricName)->addPath('plot');
151: 
152:         $parts = array();
153: 
154:         // Timestamps
155:         foreach (array('to', 'from', 'points') as $param) {
156:             if (isset($options[$param])) {
157:                 $parts[$param] = $options[$param];
158:             }
159:         }
160: 
161:         if (!isset($parts['to'])) {
162:             throw new Exception\MetricException(sprintf(
163:                 'Please specify a "to" value'
164:             ));
165:         }
166: 
167:         if (!isset($parts['from'])) {
168:             throw new Exception\MetricException(sprintf(
169:                 'Please specify a "from" value'
170:             ));
171:         }
172: 
173:         if (isset($options['resolution'])) {
174:             $allowedResolutions = array('FULL', 'MIN5', 'MIN20', 'MIN60', 'MIN240', 'MIN1440');
175:             if (!in_array($options['resolution'], $allowedResolutions)) {
176:                 throw new Exception\MetricException(sprintf(
177:                     '%s is an invalid resolution type. Please use one of the following: %s',
178:                     $options['resolution'],
179:                     implode(', ', $allowedResolutions)
180:                 ));
181:             }
182:             $parts['resolution'] = $options['resolution'];
183:         }
184: 
185:         if (isset($options['select'])) {
186:             $allowedStats = array('average', 'variance', 'min', 'max');
187:             if (!in_array($options['select'], $allowedStats)) {
188:                 throw new Exception\MetricException(sprintf(
189:                     '%s is an invalid stat type. Please use one of the following: %s',
190:                     $options['select'],
191:                     implode(', ', $allowedStats)
192:                 ));
193:             }
194:             $parts['select'] = $options['select'];
195:         }
196: 
197:         if (!isset($parts['points']) && !isset($parts['resolution'])) {
198:             throw new Exception\MetricException(sprintf(
199:                 'Please specify at least one point or resolution value'
200:             ));
201:         }
202: 
203:         $url->setQuery($parts);
204: 
205:         return $this->getService()->resourceList('Metric', $url, $this);
206:     }
207: 
208: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0