xcal-parktronic 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +7 -0
  3. data/README.md +73 -7
  4. data/lib/xcal/parktronic.rb +11 -0
  5. data/lib/xcal/parktronic/api_client.rb +8 -5
  6. data/lib/xcal/parktronic/generic_response.rb +18 -2
  7. data/lib/xcal/parktronic/routes.rb +9 -2
  8. data/lib/xcal/parktronic/routes/alarms.rb +115 -34
  9. data/lib/xcal/parktronic/routes/command_notifications.rb +56 -0
  10. data/lib/xcal/parktronic/routes/custom_queries.rb +80 -0
  11. data/lib/xcal/parktronic/routes/event_history_items.rb +36 -0
  12. data/lib/xcal/parktronic/routes/events.rb +67 -0
  13. data/lib/xcal/parktronic/routes/metrics.rb +120 -0
  14. data/lib/xcal/parktronic/routes/nested/alarm_actions.rb +84 -0
  15. data/lib/xcal/parktronic/routes/nested/device_errors.rb +35 -0
  16. data/lib/xcal/parktronic/routes/nested/events.rb +57 -0
  17. data/lib/xcal/parktronic/routes/nested/metric_values.rb +35 -0
  18. data/lib/xcal/parktronic/routes/outages.rb +34 -0
  19. data/lib/xcal/parktronic/routes/stack_changes.rb +53 -0
  20. data/lib/xcal/parktronic/version.rb +1 -1
  21. data/spec/lib/xcal/parktronic/api_client_spec.rb +12 -2
  22. data/spec/lib/xcal/parktronic/routes/alarms_route_spec.rb +16 -1
  23. data/spec/lib/xcal/parktronic/routes/command_notifications_routes_spec.rb +32 -0
  24. data/spec/lib/xcal/parktronic/routes/event_history_items_routes_spec.rb +28 -0
  25. data/spec/lib/xcal/parktronic/routes/events_route_spec.rb +33 -0
  26. data/spec/lib/xcal/parktronic/routes/metrics_routes_spec.rb +92 -49
  27. data/spec/lib/xcal/parktronic/routes/nested/alarm_actions_spec.rb +58 -0
  28. data/spec/lib/xcal/parktronic/routes/nested/events_spec.rb +24 -0
  29. data/spec/lib/xcal/parktronic/routes/outages_routes_spec.rb +25 -0
  30. data/spec/lib/xcal/parktronic/routes/stack_changes_routes_spec.rb +38 -0
  31. data/spec/support/api_mock.rb +147 -2
  32. data/spec/support/fixtures/responses/alarm_action.json +19 -0
  33. data/spec/support/fixtures/responses/alarm_actions.json +40 -0
  34. data/spec/support/fixtures/responses/alarm_events.json +180 -0
  35. data/spec/support/fixtures/responses/alarm_post.json +12 -0
  36. data/spec/support/fixtures/responses/alarm_tags.json +1 -0
  37. data/spec/support/fixtures/responses/command_notification.json +7 -0
  38. data/spec/support/fixtures/responses/command_notifications.json +45 -0
  39. data/spec/support/fixtures/responses/event.json +22 -0
  40. data/spec/support/fixtures/responses/event_tags.json +1 -0
  41. data/spec/support/fixtures/responses/events.json +42 -0
  42. data/spec/support/fixtures/responses/events_history_page_1.json +55 -0
  43. data/spec/support/fixtures/responses/events_history_page_2.json +55 -0
  44. data/spec/support/fixtures/responses/metric.json +8 -0
  45. data/spec/support/fixtures/responses/metric_device_errors.json +610 -0
  46. data/spec/support/fixtures/responses/metric_metric_values.json +586 -0
  47. data/spec/support/fixtures/responses/metric_post.json +12 -0
  48. data/spec/support/fixtures/responses/metrics_page_1.json +90 -0
  49. data/spec/support/fixtures/responses/metrics_page_2.json +90 -0
  50. data/spec/support/fixtures/responses/outages_page_1.json +55 -0
  51. data/spec/support/fixtures/responses/outages_page_2.json +55 -0
  52. data/spec/support/fixtures/responses/stack_changes_page_1.json +80 -0
  53. data/spec/support/fixtures/responses/stack_changes_page_2.json +80 -0
  54. data/spec/support/fixtures/responses/stack_changes_post.json +12 -0
  55. data/xcal-parktronic.gemspec +1 -1
  56. metadata +76 -2
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xcal::Parktronic::ApiClient do
4
+
5
+ let(:api_http_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock', access_token: 'access_token') }
6
+ let(:api_invalid_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock') }
7
+
8
+ context 'alarms route' do
9
+ describe '#get_all_events' do
10
+ it 'should return events for alarm' do
11
+ expect{ api_http_client.alarm(2).get_all_events }.not_to raise_error
12
+ expect(api_http_client.alarm(2).get_all_events.count).to eql(10)
13
+ end
14
+ end
15
+
16
+ describe '#post_event' do
17
+ it 'should create event for alarm' do
18
+ expect{ api_http_client.alarm(2).post_event({}) }.not_to raise_error
19
+ expect{ api_http_client.alarm(2).post_event(service_impacted: 'Redis Hitrate') }.not_to raise_error
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xcal::Parktronic::ApiClient do
4
+
5
+ let(:api_http_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock', access_token: 'access_token') }
6
+ let(:api_invalid_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock') }
7
+
8
+ context 'outages routes' do
9
+
10
+ it 'is not allowed without access_token' do
11
+ expect{ api_invalid_client.get_paged_outages(page: 1, per_page: 10) }.not_to raise_error
12
+ end
13
+
14
+ context 'getting' do
15
+ it 'responds with the correct set of incidents' do
16
+ outages = api_http_client.get_paged_outages(page: 1, per_page: 5)
17
+ expect(outages.first.ifs_ticket).to eql('IFS-1')
18
+ expect(outages.first.summary).to eql('Incident 1')
19
+
20
+ expect(outages.last.ifs_ticket).to eql('IFS-5')
21
+ expect(outages.last.summary).to eql('Incident 5')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xcal::Parktronic::ApiClient do
4
+
5
+ let(:api_http_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock', access_token: 'access_token') }
6
+ let(:api_invalid_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock') }
7
+
8
+ context 'stack_changes routes' do
9
+
10
+ it 'is not allowed without access_token' do
11
+ expect{ api_invalid_client.get_paged_stack_changes(page: 1, per_page: 10) }.not_to raise_error
12
+ expect{ api_invalid_client.post_stack_change({}) }.not_to raise_error
13
+ end
14
+
15
+ context 'getting' do
16
+ it 'responds with the correct set of stack_changes' do
17
+ stack_changes = api_http_client.get_paged_stack_changes(page: 1, per_page: 10)
18
+ expect(stack_changes.first.ticket_id).to eql('CHANGE-1')
19
+ expect(stack_changes.first.element).to eql('STACK1')
20
+
21
+ expect(stack_changes.last.ticket_id).to eql('CHANGE-10')
22
+ expect(stack_changes.last.element).to eql('STACK1')
23
+ end
24
+ end
25
+
26
+ context 'posting' do
27
+ let(:stack_change) do
28
+ { ticket_id: 'CHANGE-100', ticket_summary: 'stack change 100', element: 'STACK100', resolution_date: '2013-11-22T01:00:24Z' }
29
+ end
30
+
31
+ it 'posts stack_change successfully' do
32
+ expect{ api_invalid_client.post_stack_change({ stack_change: stack_change }) }.not_to raise_error
33
+ expect{ api_http_client.post_stack_change({ stack_change: stack_change }) }.not_to raise_error
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -2,7 +2,7 @@ require 'sinatra/base'
2
2
 
3
3
  class ApiMock < Sinatra::Base
4
4
 
5
- before /.*/ do
5
+ before(/.*/) do
6
6
  request_body = JSON.parse(request.body.read) rescue {}
7
7
 
8
8
  if params[:access_token].nil? || params[:access_token].empty?
@@ -12,6 +12,8 @@ class ApiMock < Sinatra::Base
12
12
  end
13
13
  end
14
14
 
15
+ # Alarms
16
+
15
17
  get '/:version/alarms' do
16
18
  if params[:page].nil? || params[:page].empty?
17
19
  json_response 200, 'alarms_page_1.json'
@@ -24,14 +26,157 @@ class ApiMock < Sinatra::Base
24
26
  json_response 200, 'alarm.json'
25
27
  end
26
28
 
29
+ get '/:version/alarms/:id/tags' do
30
+ json_response 200, 'alarm_tags.json'
31
+ end
32
+
33
+ get '/:version/alarms/:id/events' do
34
+ json_response 200, 'alarm_events.json'
35
+ end
36
+
27
37
  post '/:version/alarms' do
28
38
  json_response 201, 'alarms_post.json'
29
39
  end
30
40
 
41
+ post '/:version/alarms/create_without_events' do
42
+ json_response 201, 'alarms_post.json'
43
+ end
44
+
45
+ # Alarm Actions
46
+ get '/:version/alarms/:alarm_id/alarm_actions' do
47
+ json_response 200, 'alarm_actions.json'
48
+ end
49
+
50
+ get '/:version/alarms/:alarm_id/alarm_actions/:id' do
51
+ json_response 200, 'alarm_action.json'
52
+ end
53
+
54
+ post '/:version/alarms/:alarm_id/alarm_actions' do
55
+ json_response 201, 'alarm_action.json'
56
+ end
57
+
58
+ patch '/:version/alarms/:alarm_id/alarm_actions/:id' do
59
+ json_response 201, 'alarm_action.json'
60
+ end
61
+
62
+ # ruby 1.9.2
63
+ put '/:version/alarms/:alarm_id/alarm_actions/:id' do
64
+ json_response 201, 'alarm_action.json'
65
+ end
66
+
67
+ post '/:version/alarms/:alarm_id/alarm_actions/:id/insert_at' do
68
+ json_response 201, 'alarm_action.json'
69
+ end
70
+
71
+ # Metrics
72
+
73
+ get '/:version/metrics' do
74
+ if params[:page].nil? || params[:page].empty?
75
+ json_response 200, 'metrics_page_1.json'
76
+ else
77
+ json_response 200, "metrics_page_#{params[:page]}.json"
78
+ end
79
+ end
80
+
81
+ get '/:version/metrics/:id' do
82
+ json_response 200, 'metric.json'
83
+ end
84
+
85
+ get '/:version/metrics/:id/metric_values' do
86
+ json_response 200, 'metric_metric_values.json'
87
+ end
88
+
89
+ get '/:version/metrics/:id/device_errors' do
90
+ json_response 200, 'metric_device_errors.json'
91
+ end
92
+
93
+ post '/:version/metrics' do
94
+ json_response 201, 'metric_post.json'
95
+ end
96
+
97
+ # Events
98
+ get '/:version/events' do
99
+ if params[:page].nil? || params[:page].empty?
100
+ json_response 200, 'events_page_1.json'
101
+ else
102
+ json_response 200, "events_page_#{params[:page]}.json"
103
+ end
104
+ end
105
+
106
+ get '/:version/events/:id' do
107
+ json_response 200, 'event.json'
108
+ end
109
+
110
+ get '/:version/events/:id/tags' do
111
+ json_response 200, 'event_tags.json'
112
+ end
113
+
114
+ patch '/:version/events/:id' do
115
+ json_response 201, 'event.json'
116
+ end
117
+
118
+ # for ruby 1.9.2
119
+ put '/:version/events/:id' do
120
+ json_response 201, 'event.json'
121
+ end
122
+
123
+ post '/:version/update_event/:id' do
124
+ json_response 200, 'event_update.json'
125
+ end
126
+
127
+ post '/:version/alarms/:id/events' do
128
+ json_response 201, 'event.json'
129
+ end
130
+
131
+ # Outages
132
+
133
+ get '/:version/outages' do
134
+ if params[:page].nil? || params[:page].empty?
135
+ json_response 200, 'outages_page_1.json'
136
+ else
137
+ json_response 200, "outages_page_#{params[:page]}.json"
138
+ end
139
+ end
140
+
141
+ get '/:version/stack_changes' do
142
+ if params[:page].nil? || params[:page].empty?
143
+ json_response 200, 'stack_changes_page_1.json'
144
+ else
145
+ json_response 200, "stack_changes_page_#{params[:page]}.json"
146
+ end
147
+ end
148
+
149
+ post '/:version/stack_changes' do
150
+ json_response 201, 'stack_changes_post.json'
151
+ end
152
+
153
+ get '/:version/events_history' do
154
+ if params[:page].nil? || params[:page].empty?
155
+ json_response 200, 'events_history_page_1.json'
156
+ else
157
+ json_response 200, "events_history_page_#{params[:page]}.json"
158
+ end
159
+ end
160
+
161
+ # Command Notifications
162
+
163
+ get '/:version/command_notifications' do
164
+ json_response 200, 'command_notifications.json'
165
+ end
166
+
167
+ patch '/:version/command_notifications/:id' do
168
+ json_response 200, 'command_notification.json'
169
+ end
170
+
171
+ # ruby 1.9.2
172
+ put '/:version/command_notifications/:id' do
173
+ json_response 200, 'command_notification.json'
174
+ end
175
+
31
176
  private
32
177
 
33
178
  def json_response(response_code, file_name)
34
179
  content_type :json
35
180
  halt response_code, File.open(File.dirname(__FILE__) + '/fixtures/responses/' + file_name, 'rb').read
36
181
  end
37
- end
182
+ end
@@ -0,0 +1,19 @@
1
+ {
2
+ "id": 2,
3
+ "alarm_id": 2,
4
+ "action_id":1,
5
+ "position":1,
6
+ "rule": {
7
+ "attribute":"aggregated_count",
8
+ "operator":"NOT IN",
9
+ "value":"OPEN"
10
+ },
11
+ "jira_username":"",
12
+ "jira_password":"",
13
+ "jira_endpoint":"https://www.teamccp.com/jira",
14
+ "jira_project":"",
15
+ "jira_issue_type":"",
16
+ "jira_issue_key":"",
17
+ "jira_fields":{},
18
+ "remote_command":""
19
+ }
@@ -0,0 +1,40 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "alarm_id": 2,
5
+ "action_id":1,
6
+ "position":1,
7
+ "rule": {
8
+ "attribute":"aggregated_count",
9
+ "operator":"NOT IN",
10
+ "value":"OPEN"
11
+ },
12
+ "jira_username":"",
13
+ "jira_password":"",
14
+ "jira_endpoint":"https://www.teamccp.com/jira",
15
+ "jira_project":"",
16
+ "jira_issue_type":"",
17
+ "jira_issue_key":"",
18
+ "jira_fields":{},
19
+ "remote_command":""
20
+ },
21
+
22
+ {
23
+ "id":2,
24
+ "alarm_id":3199,
25
+ "action_id":5,
26
+ "position":1,
27
+ "rule": {
28
+ "attribute":"subject",
29
+ "operator":"IN",
30
+ "value":"qwr"},
31
+ "jira_username":"",
32
+ "jira_password":"",
33
+ "jira_endpoint":"https://www.teamccp.com/jira",
34
+ "jira_project":"",
35
+ "jira_issue_type":"",
36
+ "jira_issue_key":"",
37
+ "jira_fields":{},
38
+ "remote_command":""
39
+ }
40
+ ]
@@ -0,0 +1,180 @@
1
+ [
2
+ {
3
+ "total_count":10,
4
+ "total_pages":1,
5
+ "page":1,
6
+ "per_page":10,
7
+ "events":[
8
+ {
9
+ "event":{
10
+ "id":73,
11
+ "subject":"Event Subject",
12
+ "description":"Event description",
13
+ "host_impacted":"Host Impacted 1",
14
+ "service_impacted":"Service Impacted 1",
15
+ "aggregated_count":1,
16
+ "event_hash":"eec76bed3421a056cf09b4360372e5373268e2f1",
17
+ "alarm_id":16,
18
+ "threshold_value":null,
19
+ "external_incident_id":null,
20
+ "incident_status":null,
21
+ "initiated_at":"2013-04-02T00:02:44.000Z",
22
+ "created_at":"2013-04-02T00:03:30.000Z"
23
+ }
24
+ },
25
+ {
26
+ "event":{
27
+ "id":74,
28
+ "subject":"Event Subject",
29
+ "description":"Event description",
30
+ "host_impacted":"Host Impacted 1",
31
+ "service_impacted":"Service Impacted 2",
32
+ "aggregated_count":1,
33
+ "event_hash":"d05a978a8c840bcadf1ccddb9cb8f2c3f07d035e",
34
+ "alarm_id":16,
35
+ "threshold_value":null,
36
+ "external_incident_id":null,
37
+ "incident_status":null,
38
+ "initiated_at":"2013-04-02T00:03:52.000Z",
39
+ "created_at":"2013-04-02T00:04:37.000Z"
40
+ }
41
+ },
42
+ {
43
+ "event":{
44
+ "id":93,
45
+ "subject":"Event Subject",
46
+ "description":"Event description",
47
+ "host_impacted":"Host Impacted 3",
48
+ "service_impacted":"Service Impacted 3",
49
+ "aggregated_count":1,
50
+ "event_hash":"9432e80681573d1dc8e70f1f85dd9e16f0b8463e",
51
+ "alarm_id":16,
52
+ "threshold_value":null,
53
+ "external_incident_id":null,
54
+ "incident_status":null,
55
+ "initiated_at":"2013-04-02T01:00:45.000Z",
56
+ "created_at":"2013-04-02T01:01:31.000Z"
57
+ }
58
+ },
59
+ {
60
+ "event":{
61
+ "id":190,
62
+ "subject":"Event Subject",
63
+ "description":"Event description",
64
+ "host_impacted":"Host Impacted 4",
65
+ "service_impacted":"Service Impacted 4",
66
+ "aggregated_count":1,
67
+ "event_hash":"83bf0f09c9e5f5e8f264ec61cd65be3ddc290638",
68
+ "alarm_id":16,
69
+ "threshold_value":null,
70
+ "external_incident_id":null,
71
+ "incident_status":null,
72
+ "initiated_at":"2013-04-02T05:44:31.000Z",
73
+ "created_at":"2013-04-02T05:45:18.000Z"
74
+ }
75
+ },
76
+ {
77
+ "event":{
78
+ "id":201,
79
+ "subject":"Event Subject",
80
+ "description":"Event description",
81
+ "host_impacted":"Host Impacted 5",
82
+ "service_impacted":"Service Impacted 5",
83
+ "aggregated_count":1,
84
+ "event_hash":"760af4948d19341edc31c175e344250ce5b41386",
85
+ "alarm_id":16,
86
+ "threshold_value":null,
87
+ "external_incident_id":null,
88
+ "incident_status":null,
89
+ "initiated_at":"2013-04-02T06:04:48.000Z",
90
+ "created_at":"2013-04-02T06:05:36.000Z"
91
+ }
92
+ },
93
+ {
94
+ "event":{
95
+ "id":240,
96
+ "subject":"Event Subject",
97
+ "description":"Event description",
98
+ "host_impacted":"Host Impacted 6",
99
+ "service_impacted":"Service Impacted 6",
100
+ "aggregated_count":1,
101
+ "event_hash":"8ab45225aa58dea1623b6ad509288ed772008351",
102
+ "alarm_id":16,
103
+ "threshold_value":null,
104
+ "external_incident_id":null,
105
+ "incident_status":null,
106
+ "initiated_at":"2013-04-02T08:22:52.000Z",
107
+ "created_at":"2013-04-02T08:23:38.000Z"
108
+ }
109
+ },
110
+ {
111
+ "event":{
112
+ "id":312,
113
+ "subject":"Event Subject",
114
+ "description":"Event description",
115
+ "host_impacted":"Host Impacted 7",
116
+ "service_impacted":"Service Impacted 7",
117
+ "aggregated_count":1,
118
+ "event_hash":"27a4af37bd5a6eb313caaa99b74875bfa236e747",
119
+ "alarm_id":16,
120
+ "threshold_value":null,
121
+ "external_incident_id":null,
122
+ "incident_status":null,
123
+ "initiated_at":"2013-04-02T11:36:52.000Z",
124
+ "created_at":"2013-04-02T11:37:38.000Z"
125
+ }
126
+ },
127
+ {
128
+ "event":{
129
+ "id":318,
130
+ "subject":"Event Subject",
131
+ "description":"Event description",
132
+ "host_impacted":"Host Impacted 8",
133
+ "service_impacted":"Service Impacted 8",
134
+ "aggregated_count":1,
135
+ "event_hash":"6635e822c4ec83c4d9e4645afaec9efa14c21a34",
136
+ "alarm_id":16,
137
+ "threshold_value":null,
138
+ "external_incident_id":null,
139
+ "incident_status":null,
140
+ "initiated_at":"2013-04-02T12:03:48.000Z",
141
+ "created_at":"2013-04-02T12:04:36.000Z"
142
+ }
143
+ },
144
+ {
145
+ "event":{
146
+ "id":334,
147
+ "subject":"Event Subject",
148
+ "description":"Event description",
149
+ "host_impacted":"Host Impacted 9",
150
+ "service_impacted":"Service Impacted 9",
151
+ "aggregated_count":1,
152
+ "event_hash":"942e7ffc8df42dbf634fbcebd8bbe6d9400c55cd",
153
+ "alarm_id":16,
154
+ "threshold_value":null,
155
+ "external_incident_id":null,
156
+ "incident_status":null,
157
+ "initiated_at":"2013-04-02T12:53:18.000Z",
158
+ "created_at":"2013-04-02T12:54:03.000Z"
159
+ }
160
+ },
161
+ {
162
+ "event":{
163
+ "id":370,
164
+ "subject":"Event Subject",
165
+ "description":"Event description",
166
+ "host_impacted":"Host Impacted 11",
167
+ "service_impacted":"Service Impacted 11",
168
+ "aggregated_count":1,
169
+ "event_hash":"5f96a3b2cf595fb8316bd1d20503f46e7da99286",
170
+ "alarm_id":16,
171
+ "threshold_value":null,
172
+ "external_incident_id":null,
173
+ "incident_status":null,
174
+ "initiated_at":"2013-04-02T14:27:18.000Z",
175
+ "created_at":"2013-04-02T14:28:03.000Z"
176
+ }
177
+ }
178
+ ]
179
+ }
180
+ ]