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: use OpenCloud\Common\Http\Message\Formatter;
 15: 
 16: /**
 17:  * Alarm class.
 18:  */
 19: class Alarm extends AbstractResource
 20: {
 21:     /**
 22:      * @var string
 23:      */
 24:     private $id;
 25: 
 26:     /**
 27:      * @var string The ID of the check to alert on.
 28:      */
 29:     private $check_id;
 30: 
 31:     /**
 32:      * @var string The id of the notification plan to execute when the state changes.
 33:      */
 34:     private $notification_plan_id;
 35: 
 36:     /**
 37:      * @var string The alarm DSL for describing alerting conditions and their output states.
 38:      */
 39:     private $criteria;
 40: 
 41:     /**
 42:      * @var bool Disable processing and alerts on this alarm.
 43:      */
 44:     private $disabled;
 45: 
 46:     /**
 47:      * @var string A friendly label for an alarm.
 48:      */
 49:     private $label;
 50:     
 51:     protected static $json_name = false;
 52:     protected static $json_collection_name = 'values';
 53:     protected static $url_resource = 'alarms';
 54:     
 55:     protected static $requiredKeys = array(
 56:         'check_id',
 57:         'notification_plan_id'
 58:     );
 59:     
 60:     protected static $emptyObject = array(
 61:         'check_id',
 62:         'notification_plan_id',
 63:         'criteria',
 64:         'disabled',
 65:         'label',
 66:         'metadata'
 67:     );
 68:     
 69:     public function test($params = array(), $debug = false)
 70:     {
 71:         if (!isset($params['criteria'])) {
 72:             throw new Exception\AlarmException(
 73:                 'Please specify a "criteria" value'
 74:             );
 75:         }
 76:         
 77:         if (!isset($params['check_data']) || !is_array($params['check_data'])) {
 78:             throw new Exception\AlarmException(
 79:                 'Please specify a "check_data" array'
 80:             );
 81:         }
 82:         
 83:         $url  = $this->getParent()->url('test-alarm');
 84:         $body = json_encode((object) $params);
 85: 
 86:         $response = $this->getService()
 87:             ->getClient()
 88:             ->post($url, array(), $body)
 89:             ->send();
 90: 
 91:         return Formatter::decode($response);
 92:     }
 93: 
 94:     public function getHistoryUrl()
 95:     {
 96:         return $this->getUrl()->addPath(NotificationHistory::resourceName());
 97:     }
 98: 
 99:     public function getRecordedChecks()
100:     {
101:         $response = $this->getService()
102:             ->getClient()
103:             ->get($this->getHistoryUrl())
104:             ->send();
105: 
106:         $body = Formatter::decode($response);
107: 
108:         return (isset($body->check_ids)) ? $body->check_ids : false;
109:     }
110: 
111:     public function getNotificationHistoryForCheck($checkId)
112:     {
113:         $url = $this->getHistoryUrl()->addPath($checkId);
114:         return $this->getService()->resourceList('NotificationHistory', $url, $this);
115:     }
116: 
117:     public function getNotificationHistoryItem($checkId, $uuid)
118:     {
119:         $resource = $this->getService()->resource('NotificationHistory', null, $this);
120: 
121:         $url = clone $resource->getUrl();
122:         $url->addPath($checkId)->addPath($uuid);
123:         $resource->refresh(null, $url);
124: 
125:         return $resource;
126:     }
127: 
128:     public function notificationHistory($info)
129:     {
130:         return $this->getService()->resource('NotificationHistory', $info, $this);
131:     }
132: 
133:     public function isDisabled()
134:     {
135:         return $this->getDisabled() === true;
136:     }
137:     
138: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0