1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace OpenCloud\CloudMonitoring\Resource;
12:
13: use OpenCloud\CloudMonitoring\Exception;
14: use OpenCloud\Common\Http\Message\Formatter;
15:
16: 17: 18:
19: class Alarm extends AbstractResource
20: {
21: 22: 23:
24: private $id;
25:
26: 27: 28:
29: private $check_id;
30:
31: 32: 33:
34: private $notification_plan_id;
35:
36: 37: 38:
39: private $criteria;
40:
41: 42: 43:
44: private $disabled;
45:
46: 47: 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: }