1: <?php
2:
3: namespace OpenCloud\CloudMonitoring\Resource;
4:
5: use OpenCloud\Common\PersistentObject;
6: use OpenCloud\CloudMonitoring\Exception;
7:
8: 9: 10: 11: 12:
13: class Alarm extends AbstractResource implements ResourceInterface
14: {
15: public $id;
16: public $check_id;
17: public $notification_plan_id;
18: public $criteria;
19: public $disabled;
20: public $label;
21: public $metadata;
22:
23: protected static $json_name = false;
24: protected static $json_collection_name = 'values';
25: protected static $url_resource = 'alarms';
26:
27: protected static $requiredKeys = array(
28: 'check_id',
29: 'notification_plan_id'
30: );
31:
32: protected static $emptyObject = array(
33: 'check_id',
34: 'notification_plan_id',
35: 'criteria',
36: 'disabled',
37: 'label',
38: 'metadata'
39: );
40:
41:
42: public function baseUrl()
43: {
44: return $this->getParent()->Url() . '/' . $this->getParent()->id . '/' . $this->resourceName();
45: }
46:
47: public function createUrl()
48: {
49: return $this->baseUrl();
50: }
51:
52: public function test($params = array(), $debug = false)
53: {
54: if (!isset($params['criteria'])) {
55: throw new Exception\AlarmException(
56: 'Please specify a "criteria" value'
57: );
58: }
59:
60: if (!isset($params['check_data']) || !is_array($params['check_data'])) {
61: throw new Exception\AlarmException(
62: 'Please specify a "check data" array'
63: );
64: }
65:
66: $url = $this->getParent()->Url() . '/' . $this->getParent()->id . '/test-alarm';
67:
68: return $this->request($url, 'POST', array(), json_encode((object) $params));
69: }
70:
71: }