statusio 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 877f843331586d5fd846c23feac7b26210a9cca2
4
- data.tar.gz: 8b68a7615090aface50e0de3d1af31601355cd00
3
+ metadata.gz: 792ed4b80a0dc438bc682280f33190ddc2d2ec7a
4
+ data.tar.gz: 68a6292fd3798cfe36b74dc42a7e920b0d4860b3
5
5
  SHA512:
6
- metadata.gz: f5bda2f3b2d0fa0c8b9e45a3f2b4e37d0adb973c87c4d8a185503046bbdc7ecfdc346cac45a399f073d576d5dc3ced77bcf9d20561c068d82859dab449375f8d
7
- data.tar.gz: 616f8780ae19780b8c1e1ef361551a3bf23774ef4eeaa2aaad04d36118088d69d48bd5fdec0f150946482b5c0978ce936a46fc79617f735a988f172325e80a5c
6
+ metadata.gz: 52c7c727a9bc1732ee0a2fe58046d8a624596e027fbb0d1632ca97aa0d991797100c5fbfaab3ccdf0bfdb70a85ea5d9f32d913756e3590e297d6de297e071723
7
+ data.tar.gz: 4d6bc66d2af34f2553822a287f6fa7dfff463f9f5905c9ea3d5de1b96f15e0d805ec727a82dfc191c62d8a855c7d9810c0449f1c0bacb172a66159ad4e6f66da
@@ -1,6 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 1.9.3
5
- - jruby-19mode
6
- - rbx-2
4
+
data/README.md CHANGED
@@ -25,27 +25,14 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  ```ruby
28
- # Sign up an account and get your api_id, api_key from developer tab
28
+ # Sign up for an account and get your api_id and api_key from the API tab
29
29
  statusioclient = StatusioClient.new(api_key, api_id)
30
30
  ```
31
31
 
32
- To work with component method
33
-
34
- To work with maintenance methods
35
-
36
- To work with subscriber methods
37
-
38
- To work with metric methods
39
-
40
- Please refer to Status.io API v2 for more details.
32
+ View the last release API documentation at: http://developers.status.io/
41
33
 
42
34
  ## Development
43
35
 
44
36
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
37
 
46
38
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
-
48
- ## Contributing
49
-
50
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/statusio-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
51
-
@@ -5,577 +5,528 @@ require 'uri'
5
5
  require 'json'
6
6
 
7
7
  class StatusioClient
8
- STATUS_OPERATIONAL = 100
9
- STATUS_DEGRADED_PERFORMANCE = 300
10
- STATUS_PARTIAL_SERVICE_DISRUPTION = 400
11
- STATUS_SERVICE_DISRUPTION = 500
12
- STATUS_SECURITY_EVENT = 600
13
-
14
- STATE_INVESTIGATING = 100
15
- STATE_IDENTIFIED = 200
16
- STATE_MONITORING = 300
17
-
18
- NOTIFY_EMAIL = 1
19
- NOTIFY_SMS = 2
20
- NOTIFY_WEBHOOK = 4
21
- NOTIFY_SOCIAL = 8
22
- NOTIFY_IRC = 16
23
- NOTIFY_HIPCHAT = 32
24
- NOTIFY_SLACK = 64
25
-
26
- def initialize(api_key, api_id)
27
- @api_key = api_key
28
- @api_id = api_id
29
-
30
- @url = 'https://api.status.io/v2/'
31
-
32
- @headers = {
33
- 'x-api-id' => @api_id,
34
- 'x-api-key' => @api_key,
35
- 'Content-Type' => 'application/json',
36
- 'Accept' => 'application/json'
37
- }
38
- end
39
-
40
- private
41
-
42
- def get_notify(notifications)
43
- notify = {
44
- 'notify_email' => '0',
45
- 'notify_sms' => '0',
46
- 'notify_webhook' => '0',
47
- 'social' => '0',
48
- 'irc' => '0',
49
- 'hipchat' => '0',
50
- 'slack' => '0'
51
- }
52
-
53
- if notifications & NOTIFY_EMAIL == NOTIFY_EMAIL
54
- notify['notify_email'] = '1'
55
- end
56
-
57
- if notifications & NOTIFY_SMS == NOTIFY_SMS
58
- notify['notify_sms'] = '1'
59
- end
60
-
61
- if notifications & NOTIFY_WEBHOOK == NOTIFY_WEBHOOK
62
- notify['notify_webhook'] = '1'
63
- end
64
-
65
- if notifications & NOTIFY_SOCIAL == NOTIFY_SOCIAL
66
- notify['social'] = '1'
67
- end
68
-
69
- if notifications & NOTIFY_IRC == NOTIFY_IRC
70
- notify['irc'] = '1'
71
- end
72
-
73
- if notifications & NOTIFY_HIPCHAT == NOTIFY_HIPCHAT
74
- notify['hipchat'] = '1'
75
- end
76
-
77
- if notifications & NOTIFY_SLACK == NOTIFY_SLACK
78
- notify['slack'] = '1'
79
- end
80
-
81
- return notify
82
- end
83
-
84
- public
85
-
86
- ##
87
- # List all components.
88
- #
89
- # @param statuspage_id(string) Status page ID
90
- # @return object
91
-
92
- def component_list(statuspage_id)
93
- response = RestClient::Request.execute(
94
- :method => :get,
95
- :url => @url + 'component/list/' + statuspage_id,
96
- :headers => @headers)
97
-
98
- if response.code == 200
99
- return JSON.parse(response.body)
100
- end
101
- end
102
-
103
- ##
104
- # Update the status of a component on the fly without creating an incident or maintenance.
105
- #
106
- # @param statuspage_id(string) string Status page ID
107
- # @param components(array) ID of each affected component
108
- # @param containers(array) ID of each affected container
109
- # @param details(string) A brief message describing this update
110
- # @param current_status(int) Any numeric status code.
111
- # @return object
112
-
113
- def component_status_update(statuspage_id, components, containers, details, current_status)
114
- data = {
115
- 'statuspage_id' => statuspage_id,
116
- 'components' => components,
117
- 'containers' => containers,
118
- 'details' => details,
119
- 'current_status' => current_status
120
- }
121
-
122
- response = RestClient.post(@url + 'component/status/update', data, @headers)
123
-
124
- if response.code == 200
125
- return JSON.parse(response.body)
126
- end
127
- end
128
-
129
- # INCIDENT
130
-
131
- ##
132
- # List all active and resolved incidents.
133
- #
134
- # @param statuspage_id(string) Status page ID
135
- # @return object
136
-
137
- def incident_list(statuspage_id)
138
- response = RestClient::Request.execute(
139
- :method => :get,
140
- :url => @url + 'incident/list/' + statuspage_id,
141
- :headers => @headers)
142
-
143
- if response.code == 200
144
- return JSON.parse(response.body)
145
- end
146
- end
147
-
148
-
149
- ##
150
- # Display incident message.
151
- #
152
- # @param statuspage_id(string) Status page ID
153
- # @param message_id(string) Message ID
154
- # @return object
155
-
156
- def incident_message(statuspage_id, message_id)
157
- response = RestClient::Request.execute(
158
- :method => :get,
159
- :url => @url + 'incident/message/' + statuspage_id + '/' + message_id,
160
- :headers => @headers
161
- )
162
-
163
- if response.code == 200
164
- return JSON.parse(response.body)
165
- end
166
- end
167
-
168
- ##
169
- # Create a new incident.
170
- #
171
- # @param statuspage_id(string) Status page ID
172
- # @param incident_name(string) A descriptive title for the incident
173
- # @param incident_details(string) Message describing this incident
174
- # @param components(array) ID of each affected component
175
- # @param containers(array) ID of each affected container
176
- # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
177
- # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
178
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
179
- # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
180
- # @return object
181
-
182
- def incident_create(statuspage_id, incident_name, incident_details, components, containers, current_status, current_state, notifications = 0, all_infrastructure_affected = 0)
183
- data = get_notify(notifications)
184
- data['statuspage_id'] = statuspage_id
185
- data['incident_name'] = incident_name
186
- data['incident_details'] = incident_details
187
- data['components'] = components
188
- data['containers'] = containers
189
- data['current_status'] = current_status
190
- data['current_state'] = current_state
191
- data['all_infrastructure_affected'] = all_infrastructure_affected
192
-
193
- response = RestClient.post(@url + 'incident/create', data, @headers)
194
- if (response.code == 200)
195
- return JSON.parse(response.body)
196
- end
197
- end
198
-
199
- ##
200
- # Update an existing incident
201
- #
202
- # @param statuspage_id(string) Status page ID
203
- # @param incident_id(string) Incident ID
204
- # @param incident_details(string) Message describing this incident
205
- # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
206
- # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
207
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
208
- # @return object
209
-
210
- def incident_update(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
211
- data = get_notify(notifications)
212
- data['statuspage_id'] = statuspage_id
213
- data['incident_id'] = incident_id
214
- data['incident_details'] = incident_details
215
- data['current_status'] = current_status
216
- data['current_state'] = current_state
217
-
218
- response = RestClient.post(@url + 'incident/update', data, @headers)
219
- if (response.code == 200)
220
- return JSON.parse(response.body)
221
- end
222
- end
223
-
224
- ##
225
- # Resolve an existing incident. The incident will be shown in the history instead of on the main page.
226
- #
227
- # @param statuspage_id(string) Status page ID
228
- # @param incident_id(string) Incident ID
229
- # @param incident_details(string) Message describing this incident
230
- # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
231
- # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
232
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
233
- # @return object
234
-
235
- def incident_resolve(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
236
- data = get_notify(notifications)
237
- data['statuspage_id'] = statuspage_id
238
- data['incident_id'] = incident_id
239
- data['incident_details'] = incident_details
240
- data['current_status'] = current_status
241
- data['current_state'] =current_state
242
-
243
- response = RestClient.post(@url + 'incident/resolve', data, @headers)
244
- if (response.code == 200)
245
- return JSON.parse(response.body)
246
- end
247
- end
248
-
249
- ##
250
- # Delete an existing incident. The incident will be deleted forever and cannot be recovered.
251
- #
252
- # @param statuspage_id(string) Status page ID
253
- # @param incident_id(string) Incident ID
254
- # @return object
255
-
256
- def incident_delete(statuspage_id, incident_id)
257
- data = {}
258
- data['statuspage_id'] = statuspage_id
259
- data['incident_id'] = incident_id
260
-
261
- response = RestClient.post(@url + 'incident/delete', data, @headers)
262
- if (response.code == 200)
263
- return JSON.parse(response.body)
264
- end
265
- end
266
-
267
- # MAINTENANCE
268
-
269
- ##
270
- # List all active, resolved and upcoming maintenances
271
- #
272
- # @param statuspage_id(string) Status page ID
273
- # @return object
274
- #/
275
-
276
- def maintenance_list(statuspage_id)
277
- response = RestClient::Request.execute(
278
- :method => :get,
279
- :url => @url + 'maintenance/list/' + statuspage_id,
280
- :headers => @headers
281
- )
282
-
283
- if response.code == 200
284
- return JSON.parse(response.body)
285
- end
286
- end
287
-
288
- ##
289
- # Display maintenance message
290
- #
291
- # @param statuspage_id(string) Status page ID
292
- # @param message_id(string) Message ID
293
- # @return object
294
-
295
- def maintenance_message(statuspage_id, message_id)
296
- response = RestClient::Request.execute(
297
- :method => :get,
298
- :url => @url + 'maintenance/message/' + statuspage_id + '/' + message_id,
299
- :headers => @headers
300
- )
301
-
302
- if response.code == 200
303
- return JSON.parse(response.body)
304
- end
305
- end
306
-
307
- ##
308
- # Schedule a new maintenance
309
- #
310
- # @param statuspage_id(string) Status page ID
311
- # @param maintenance_name(string) A descriptive title for this maintenance
312
- # @param maintenance_details(string) Message describing this maintenance
313
- # @param components(array) ID of each affected component
314
- # @param containers(array) ID of each affected container
315
- # @param date_planned_start(string) Date maintenance is expected to start
316
- # @param time_planned_start(string) Time maintenance is expected to start
317
- # @param date_planned_end(string) Date maintenance is expected to end
318
- # @param time_planned_end(string) Time maintenance is expected to end
319
- # @param automation(int) Automatically start and end the maintenance (default = 0)
320
- # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
321
- # @param maintenance_notify_now(int) Notify subscribers now (1 = Send notification)
322
- # @param maintenance_notify_1_hr(int) Notify subscribers 1 hour before scheduled maintenance start time (1 = Send notification)
323
- # @param maintenance_notify_24_hr(int) Notify subscribers 24 hours before scheduled maintenance start time (1 = Send notification)
324
- # @param maintenance_notify_72_hr(int) Notify subscribers 72 hours before scheduled maintenance start time (1 = Send notification)
325
- # @return object
326
-
327
- def maintenance_schedule(statuspage_id, maintenance_name, maintenance_details, components, containers,
328
- date_planned_start, time_planned_start, date_planned_end, time_planned_end,
329
- automation = 0, all_infrastructure_affected = 0,
330
- maintenance_notify_now = 0, maintenance_notify_1_hr = 0,
331
- maintenance_notify_24_hr = 0, maintenance_notify_72_hr = 0)
332
- data = {}
333
- data['statuspage_id'] = statuspage_id
334
- data['maintenance_name'] = maintenance_name
335
- data['maintenance_details'] = maintenance_details
336
- data['components'] = components
337
- data['containers'] = containers
338
- data['all_infrastructure_affected'] = all_infrastructure_affected
339
- data['date_planned_start'] = date_planned_start
340
- data['time_planned_start'] = time_planned_start
341
- data['date_planned_end'] = date_planned_end
342
- data['time_planned_end'] = time_planned_end
343
- data['automation'] = automation
344
- data['maintenance_notify_now'] = maintenance_notify_now
345
- data['maintenance_notify_1_hr'] = maintenance_notify_1_hr
346
- data['maintenance_notify_24_hr'] = maintenance_notify_24_hr
347
- data['maintenance_notify_72_hr'] = maintenance_notify_72_hr
348
-
349
- response = RestClient.post(@url + 'maintenance/schedule', data, @headers)
350
- if (response.code == 200)
351
- return JSON.parse(response.body)
352
- end
353
- end
354
-
355
- ##
356
- # Begin a scheduled maintenance now
357
- #
358
- # @param statuspage_id(string) Status page ID
359
- # @param maintenance_id(string) Maintenance ID
360
- # @param maintenance_details(string) Message describing this maintenance update
361
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
362
- # @return object
363
-
364
- def maintenance_start(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
365
- data = get_notify(notifications)
366
- data['statuspage_id'] = statuspage_id
367
- data['maintenance_id'] = maintenance_id
368
- data['maintenance_details'] = maintenance_details
369
-
370
- response = RestClient.post(@url + 'maintenance/start', data, @headers)
371
- if (response.code == 200)
372
- return JSON.parse(response.body)
373
- end
374
- end
375
-
376
- ##
377
- # Update an active maintenance
378
- #
379
- # @param statuspage_id(string) Status page ID
380
- # @param maintenance_id(string) Maintenance ID
381
- # @param maintenance_details(string) Message describing this maintenance
382
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
383
- # @return object
384
-
385
- def maintenance_update(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
386
- data = get_notify(notifications)
387
- data['statuspage_id'] = statuspage_id
388
- data['maintenance_id'] = maintenance_id
389
- data['maintenance_details'] = maintenance_details
390
-
391
- response = RestClient.post(@url + 'maintenance/update', data, @headers)
392
- if (response.code == 200)
393
- return JSON.parse(response.body)
394
- end
395
- end
396
-
397
- ##
398
- # Close an active maintenance. The maintenance will be moved to the history.
399
- #
400
- # @param statuspage_id(string) Status page ID
401
- # @param maintenance_id(string) Maintenance ID
402
- # @param maintenance_details(string) Message describing this maintenance
403
- # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
404
- # @return object
405
-
406
- def maintenance_finish(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
407
- data = get_notify(notifications)
408
- data['statuspage_id'] = statuspage_id
409
- data['maintenance_id'] = maintenance_id
410
- data['maintenance_details'] = maintenance_details
411
-
412
- response = RestClient.post(@url + 'maintenance/finish', data, @headers)
413
- if (response.code == 200)
414
- return JSON.parse(response.body)
415
- end
416
- end
417
-
418
- ##
419
- # Delete an existing maintenance. The maintenance will be deleted forever and cannot be recovered.
420
- #
421
- # @param statuspage_id(string) Status page ID
422
- # @param maintenance_id(string) Maintenance ID
423
- # @return object
424
- #/
425
- def maintenance_delete(statuspage_id, maintenance_id)
426
- data = {}
427
- data['statuspage_id'] = statuspage_id
428
- data['maintenance_id'] = maintenance_id
429
-
430
- response = RestClient.post(@url + 'maintenance/delete', data, @headers)
431
- if (response.code == 200)
432
- return JSON.parse(response.body)
433
- end
434
- end
435
-
436
- # METRIC
437
-
438
- ##
439
- # Update custom metric data
440
- #
441
- # @param statuspage_id(string) Status page ID
442
- # @param metric_id(string) Metric ID
443
- # @param day_avg(float) Average value for past 24 hours
444
- # @param day_start(int) UNIX timestamp for start of metric timeframe
445
- # @param day_dates(array) An array of timestamps for the past 24 hours (2014-03-28T05:43:00+00:00)
446
- # @param day_values(array) An array of values matching the timestamps (Must be 24 values)
447
- # @param week_avg(float) Average value for past 7 days
448
- # @param week_start(int) UNIX timestamp for start of metric timeframe
449
- # @param week_dates(array) An array of timestamps for the past 7 days (2014-03-28T05:43:00+00:00)
450
- # @param week_values(array) An array of values matching the timestamps (Must be 7 values)
451
- # @param month_avg(float) Average value for past 30 days
452
- # @param month_start(int) UNIX timestamp for start of metric timeframe
453
- # @param month_dates(array) An array of timestamps for the past 30 days (2014-03-28T05:43:00+00:00)
454
- # @param month_values(array) An array of values matching the timestamps (Must be 30 values)
455
- # @return object
456
-
457
- def metric_update(statuspage_id, metric_id, day_avg, day_start, day_dates, day_values,
458
- week_avg, week_start, week_dates, week_values,
459
- month_avg, month_start, month_dates, month_values)
460
- data = {}
461
- data['statuspage_id'] = statuspage_id
462
- data['metric_id'] = metric_id
463
- data['day_avg'] = day_avg
464
- data['day_start'] = day_start
465
- data['day_dates'] = day_dates
466
- data['day_values'] = day_values
467
- data['week_avg'] = week_avg
468
- data['week_start'] = week_start
469
- data['week_dates'] = week_dates
470
- data['week_values'] =week_values
471
- data['month_avg'] = month_avg
472
- data['month_start'] = month_start
473
- data['month_dates'] = month_dates
474
- data['month_values'] = month_values
475
-
476
- response = RestClient.post(@url + 'metric/update', data, @headers)
477
- if (response.code == 200)
478
- return JSON.parse(response.body)
479
- end
480
- end
481
-
482
- # STATUS
483
-
484
- ##
485
- # Show the summary status for all components and containers
486
- #
487
- # @param statuspage_id(string) Status page ID
488
- # @return object
489
-
490
- def status_summary(statuspage_id)
491
- response = RestClient::Request.execute(
492
- :method => :get,
493
- :url => @url + 'status/summary/' + statuspage_id,
494
- :headers => @headers
495
- )
496
-
497
- if response.code == 200
498
- return JSON.parse(response.body)
499
- end
500
- end
501
-
502
- # SUBSCRIBER
503
-
504
- ##
505
- # List all subscribers
506
- #
507
- # @param statuspage_id(string) Status page ID
508
- # @return object
509
-
510
- def subscriber_list(statuspage_id)
511
- response = RestClient::Request.execute(
512
- :method => :get,
513
- :url => @url + 'subscriber/list/' + statuspage_id,
514
- :headers => @headers
515
- )
516
-
517
- if response.code == 200
518
- return JSON.parse(response.body)
519
- end
520
- end
521
-
522
- ##
523
- # Add a new subscriber
524
- #
525
- # @param statuspage_id(string) Status page ID
526
- # @param method(string) Communication method of subscriber. Valid methods are `email`, `sms` or `webhook`
527
- # @param address(string) Subscriber address (SMS number must include country code ie. +1)
528
- # @param silent(int) Supress the welcome message (1 = Do not send notification)
529
- # @param granular(string) List of component_container combos
530
- # @return object
531
-
532
- def subscriber_add(statuspage_id, method, address, silent = 1, granular = '')
533
- data = {}
534
- data['statuspage_id'] = statuspage_id
535
- data['method'] = method
536
- data['address'] = address
537
- data['silent'] = silent
538
- data['granular'] = granular
539
-
540
- response = RestClient.post(@url + 'subscriber/add', data, @headers)
541
- if (response.code == 200)
542
- return JSON.parse(response.body)
543
- end
544
- end
545
-
546
- ##
547
- # Update existing subscriber
548
- #
549
- # @param statuspage_id(string) Status page ID
550
- # @param subscriber_id(string) Subscriber ID
551
- # @param address(string) Subscriber address (SMS number must include country code ie. +1)
552
- # @param granular(string) List of component_container combos
553
- # @return object
554
-
555
- def subscriber_update(statuspage_id, subscriber_id, address, granular = '')
556
- data = {}
557
- data['statuspage_id'] = statuspage_id
558
- data['subscriber_id'] = subscriber_id
559
- data['address'] = address
560
- data['granular'] = granular
561
-
562
- response = RestClient.patch(@url + 'subscriber/update', data, @headers)
563
- if (response.code == 200)
564
- return JSON.parse(response.body)
565
- end
566
- end
567
-
568
- ##
569
- # Delete subscriber
570
- #
571
- # @param statuspage_id(string) Status page ID
572
- # @param subscriber_id(string) Subscriber ID
573
- # @return object
574
-
575
- def subscriber_remove(statuspage_id, subscriber_id)
576
- response = RestClient.delete(@url + 'subscriber/remove/' + statuspage_id + '/' + subscriber_id, @headers)
577
- if (response.code == 200)
578
- return JSON.parse(response.body)
579
- end
580
- end
8
+
9
+ class Error < StandardError; end
10
+
11
+ STATUS_OPERATIONAL = 100
12
+ STATUS_DEGRADED_PERFORMANCE = 300
13
+ STATUS_PARTIAL_SERVICE_DISRUPTION = 400
14
+ STATUS_SERVICE_DISRUPTION = 500
15
+ STATUS_SECURITY_EVENT = 600
16
+
17
+ STATE_INVESTIGATING = 100
18
+ STATE_IDENTIFIED = 200
19
+ STATE_MONITORING = 300
20
+
21
+ NOTIFY_EMAIL = 1
22
+ NOTIFY_SMS = 2
23
+ NOTIFY_WEBHOOK = 4
24
+ NOTIFY_SOCIAL = 8
25
+ NOTIFY_IRC = 16
26
+ NOTIFY_HIPCHAT = 32
27
+ NOTIFY_SLACK = 64
28
+
29
+ def initialize(api_key, api_id)
30
+ @api_key = api_key
31
+ @api_id = api_id
32
+
33
+ @url = 'https://api.status.io/v2/'
34
+
35
+ @headers = {
36
+ 'x-api-id' => @api_id,
37
+ 'x-api-key' => @api_key,
38
+ 'Content-Type' => 'application/json',
39
+ 'Accept' => 'application/json'
40
+ }
41
+ end
42
+
43
+ private
44
+
45
+ def get_notify(notifications)
46
+ notify = {
47
+ 'notify_email' => '0',
48
+ 'notify_sms' => '0',
49
+ 'notify_webhook' => '0',
50
+ 'social' => '0',
51
+ 'irc' => '0',
52
+ 'hipchat' => '0',
53
+ 'slack' => '0'
54
+ }
55
+
56
+ if notifications & NOTIFY_EMAIL == NOTIFY_EMAIL
57
+ notify['notify_email'] = '1'
58
+ end
59
+
60
+ if notifications & NOTIFY_SMS == NOTIFY_SMS
61
+ notify['notify_sms'] = '1'
62
+ end
63
+
64
+ if notifications & NOTIFY_WEBHOOK == NOTIFY_WEBHOOK
65
+ notify['notify_webhook'] = '1'
66
+ end
67
+
68
+ if notifications & NOTIFY_SOCIAL == NOTIFY_SOCIAL
69
+ notify['social'] = '1'
70
+ end
71
+
72
+ if notifications & NOTIFY_IRC == NOTIFY_IRC
73
+ notify['irc'] = '1'
74
+ end
75
+
76
+ if notifications & NOTIFY_HIPCHAT == NOTIFY_HIPCHAT
77
+ notify['hipchat'] = '1'
78
+ end
79
+
80
+ if notifications & NOTIFY_SLACK == NOTIFY_SLACK
81
+ notify['slack'] = '1'
82
+ end
83
+
84
+ return notify
85
+ end
86
+
87
+ def request(params)
88
+ response = RestClient::Request.execute(params.merge(:headers => @headers))
89
+ body = JSON.parse(response.body)
90
+
91
+ if body['status'] && body['status']['error'] == 'yes'
92
+ raise StatusioClient::Error, body['status']['message']
93
+ elsif response.code == 200
94
+ return body
95
+ else
96
+ raise Net::HTTPError, response.inspect
97
+ end
98
+ end
99
+
100
+ public
101
+
102
+ ##
103
+ # List all components.
104
+ #
105
+ # @param statuspage_id(string) Status page ID
106
+ # @return object
107
+
108
+ def component_list(statuspage_id)
109
+ request :method => :get,
110
+ :url => @url + 'component/list/' + statuspage_id
111
+ end
112
+
113
+ ##
114
+ # Update the status of a component on the fly without creating an incident or maintenance.
115
+ #
116
+ # @param statuspage_id(string) string Status page ID
117
+ # @param components(array) ID of each affected component
118
+ # @param containers(array) ID of each affected container
119
+ # @param details(string) A brief message describing this update
120
+ # @param current_status(int) Any numeric status code.
121
+ # @return object
122
+
123
+ def component_status_update(statuspage_id, components, containers, details, current_status)
124
+ request :method => :post,
125
+ :url => @url + 'component/status/update',
126
+ :payload => {
127
+ 'statuspage_id' => statuspage_id,
128
+ 'components' => components,
129
+ 'containers' => containers,
130
+ 'details' => details,
131
+ 'current_status' => current_status
132
+ }
133
+ end
134
+
135
+ # INCIDENT
136
+
137
+ ##
138
+ # List all active and resolved incidents.
139
+ #
140
+ # @param statuspage_id(string) Status page ID
141
+ # @return object
142
+
143
+ def incident_list(statuspage_id)
144
+ request :method => :get,
145
+ :url => @url + 'incident/list/' + statuspage_id
146
+ end
147
+
148
+
149
+ ##
150
+ # Display incident message.
151
+ #
152
+ # @param statuspage_id(string) Status page ID
153
+ # @param message_id(string) Message ID
154
+ # @return object
155
+
156
+ def incident_message(statuspage_id, message_id)
157
+ request :method => :get,
158
+ :url => @url + 'incident/message/' + statuspage_id + '/' + message_id
159
+ end
160
+
161
+ ##
162
+ # Create a new incident.
163
+ #
164
+ # @param statuspage_id(string) Status page ID
165
+ # @param incident_name(string) A descriptive title for the incident
166
+ # @param incident_details(string) Message describing this incident
167
+ # @param components(array) ID of each affected component
168
+ # @param containers(array) ID of each affected container
169
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
170
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
171
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
172
+ # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
173
+ # @return object
174
+
175
+ def incident_create(statuspage_id, incident_name, incident_details, components, containers, current_status, current_state, notifications = 0, all_infrastructure_affected = 0)
176
+ data = get_notify(notifications)
177
+ data['statuspage_id'] = statuspage_id
178
+ data['incident_name'] = incident_name
179
+ data['incident_details'] = incident_details
180
+ data['components'] = components
181
+ data['containers'] = containers
182
+ data['current_status'] = current_status
183
+ data['current_state'] = current_state
184
+ data['all_infrastructure_affected'] = all_infrastructure_affected
185
+
186
+ request :method => :post,
187
+ :url => @url + 'incident/create',
188
+ :payload => data
189
+ end
190
+
191
+ ##
192
+ # Update an existing incident
193
+ #
194
+ # @param statuspage_id(string) Status page ID
195
+ # @param incident_id(string) Incident ID
196
+ # @param incident_details(string) Message describing this incident
197
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
198
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
199
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
200
+ # @return object
201
+
202
+ def incident_update(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
203
+ data = get_notify(notifications)
204
+ data['statuspage_id'] = statuspage_id
205
+ data['incident_id'] = incident_id
206
+ data['incident_details'] = incident_details
207
+ data['current_status'] = current_status
208
+ data['current_state'] = current_state
209
+
210
+ request :method => :post,
211
+ :url => @url + 'incident/update',
212
+ :payload => data
213
+ end
214
+
215
+ ##
216
+ # Resolve an existing incident. The incident will be shown in the history instead of on the main page.
217
+ #
218
+ # @param statuspage_id(string) Status page ID
219
+ # @param incident_id(string) Incident ID
220
+ # @param incident_details(string) Message describing this incident
221
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
222
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
223
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
224
+ # @return object
225
+
226
+ def incident_resolve(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
227
+ data = get_notify(notifications)
228
+ data['statuspage_id'] = statuspage_id
229
+ data['incident_id'] = incident_id
230
+ data['incident_details'] = incident_details
231
+ data['current_status'] = current_status
232
+ data['current_state'] =current_state
233
+
234
+ request :method => :post,
235
+ :url => @url + 'incident/resolve',
236
+ :payload => data
237
+ end
238
+
239
+ ##
240
+ # Delete an existing incident. The incident will be deleted forever and cannot be recovered.
241
+ #
242
+ # @param statuspage_id(string) Status page ID
243
+ # @param incident_id(string) Incident ID
244
+ # @return object
245
+
246
+ def incident_delete(statuspage_id, incident_id)
247
+ data = {}
248
+ data['statuspage_id'] = statuspage_id
249
+ data['incident_id'] = incident_id
250
+
251
+ request :method => :post,
252
+ :url => @url + 'incident/delete',
253
+ :payload => data
254
+ end
255
+
256
+ # MAINTENANCE
257
+
258
+ ##
259
+ # List all active, resolved and upcoming maintenances
260
+ #
261
+ # @param statuspage_id(string) Status page ID
262
+ # @return object
263
+ #/
264
+
265
+ def maintenance_list(statuspage_id)
266
+ request :method => :get,
267
+ :url => @url + 'maintenance/list/' + statuspage_id
268
+ end
269
+
270
+ ##
271
+ # Display maintenance message
272
+ #
273
+ # @param statuspage_id(string) Status page ID
274
+ # @param message_id(string) Message ID
275
+ # @return object
276
+
277
+ def maintenance_message(statuspage_id, message_id)
278
+ request :method => :get,
279
+ :url => @url + 'maintenance/message/' + statuspage_id + '/' + message_id
280
+ end
281
+
282
+ ##
283
+ # Schedule a new maintenance
284
+ #
285
+ # @param statuspage_id(string) Status page ID
286
+ # @param maintenance_name(string) A descriptive title for this maintenance
287
+ # @param maintenance_details(string) Message describing this maintenance
288
+ # @param components(array) ID of each affected component
289
+ # @param containers(array) ID of each affected container
290
+ # @param date_planned_start(string) Date maintenance is expected to start
291
+ # @param time_planned_start(string) Time maintenance is expected to start
292
+ # @param date_planned_end(string) Date maintenance is expected to end
293
+ # @param time_planned_end(string) Time maintenance is expected to end
294
+ # @param automation(int) Automatically start and end the maintenance (default = 0)
295
+ # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
296
+ # @param maintenance_notify_now(int) Notify subscribers now (1 = Send notification)
297
+ # @param maintenance_notify_1_hr(int) Notify subscribers 1 hour before scheduled maintenance start time (1 = Send notification)
298
+ # @param maintenance_notify_24_hr(int) Notify subscribers 24 hours before scheduled maintenance start time (1 = Send notification)
299
+ # @param maintenance_notify_72_hr(int) Notify subscribers 72 hours before scheduled maintenance start time (1 = Send notification)
300
+ # @return object
301
+
302
+ def maintenance_schedule(statuspage_id, maintenance_name, maintenance_details, components, containers,
303
+ date_planned_start, time_planned_start, date_planned_end, time_planned_end,
304
+ automation = 0, all_infrastructure_affected = 0,
305
+ maintenance_notify_now = 0, maintenance_notify_1_hr = 0,
306
+ maintenance_notify_24_hr = 0, maintenance_notify_72_hr = 0)
307
+ data = {}
308
+ data['statuspage_id'] = statuspage_id
309
+ data['maintenance_name'] = maintenance_name
310
+ data['maintenance_details'] = maintenance_details
311
+ data['components'] = components
312
+ data['containers'] = containers
313
+ data['all_infrastructure_affected'] = all_infrastructure_affected
314
+ data['date_planned_start'] = date_planned_start
315
+ data['time_planned_start'] = time_planned_start
316
+ data['date_planned_end'] = date_planned_end
317
+ data['time_planned_end'] = time_planned_end
318
+ data['automation'] = automation
319
+ data['maintenance_notify_now'] = maintenance_notify_now
320
+ data['maintenance_notify_1_hr'] = maintenance_notify_1_hr
321
+ data['maintenance_notify_24_hr'] = maintenance_notify_24_hr
322
+ data['maintenance_notify_72_hr'] = maintenance_notify_72_hr
323
+
324
+ request :method => :post,
325
+ :url => @url + 'maintenance/schedule',
326
+ :payload => data
327
+ end
328
+
329
+ ##
330
+ # Begin a scheduled maintenance now
331
+ #
332
+ # @param statuspage_id(string) Status page ID
333
+ # @param maintenance_id(string) Maintenance ID
334
+ # @param maintenance_details(string) Message describing this maintenance update
335
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
336
+ # @return object
337
+
338
+ def maintenance_start(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
339
+ data = get_notify(notifications)
340
+ data['statuspage_id'] = statuspage_id
341
+ data['maintenance_id'] = maintenance_id
342
+ data['maintenance_details'] = maintenance_details
343
+
344
+ request :method => :post,
345
+ :url => @url + 'maintenance/start',
346
+ :payload => data
347
+ end
348
+
349
+ ##
350
+ # Update an active maintenance
351
+ #
352
+ # @param statuspage_id(string) Status page ID
353
+ # @param maintenance_id(string) Maintenance ID
354
+ # @param maintenance_details(string) Message describing this maintenance
355
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
356
+ # @return object
357
+
358
+ def maintenance_update(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
359
+ data = get_notify(notifications)
360
+ data['statuspage_id'] = statuspage_id
361
+ data['maintenance_id'] = maintenance_id
362
+ data['maintenance_details'] = maintenance_details
363
+
364
+ request :method => :post,
365
+ :url => @url + 'maintenance/update',
366
+ :payload => data
367
+ end
368
+
369
+ ##
370
+ # Close an active maintenance. The maintenance will be moved to the history.
371
+ #
372
+ # @param statuspage_id(string) Status page ID
373
+ # @param maintenance_id(string) Maintenance ID
374
+ # @param maintenance_details(string) Message describing this maintenance
375
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
376
+ # @return object
377
+
378
+ def maintenance_finish(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
379
+ data = get_notify(notifications)
380
+ data['statuspage_id'] = statuspage_id
381
+ data['maintenance_id'] = maintenance_id
382
+ data['maintenance_details'] = maintenance_details
383
+
384
+ request :method => :post,
385
+ :url => @url + 'maintenance/finish',
386
+ :payload => data
387
+ end
388
+
389
+ ##
390
+ # Delete an existing maintenance. The maintenance will be deleted forever and cannot be recovered.
391
+ #
392
+ # @param statuspage_id(string) Status page ID
393
+ # @param maintenance_id(string) Maintenance ID
394
+ # @return object
395
+ #/
396
+ def maintenance_delete(statuspage_id, maintenance_id)
397
+ data = {}
398
+ data['statuspage_id'] = statuspage_id
399
+ data['maintenance_id'] = maintenance_id
400
+
401
+ request :method => :post,
402
+ :url => @url + 'maintenance/delete',
403
+ :payload => data
404
+ end
405
+
406
+ # METRIC
407
+
408
+ ##
409
+ # Update custom metric data
410
+ #
411
+ # @param statuspage_id(string) Status page ID
412
+ # @param metric_id(string) Metric ID
413
+ # @param day_avg(float) Average value for past 24 hours
414
+ # @param day_start(int) UNIX timestamp for start of metric timeframe
415
+ # @param day_dates(array) An array of timestamps for the past 24 hours (2014-03-28T05:43:00+00:00)
416
+ # @param day_values(array) An array of values matching the timestamps (Must be 24 values)
417
+ # @param week_avg(float) Average value for past 7 days
418
+ # @param week_start(int) UNIX timestamp for start of metric timeframe
419
+ # @param week_dates(array) An array of timestamps for the past 7 days (2014-03-28T05:43:00+00:00)
420
+ # @param week_values(array) An array of values matching the timestamps (Must be 7 values)
421
+ # @param month_avg(float) Average value for past 30 days
422
+ # @param month_start(int) UNIX timestamp for start of metric timeframe
423
+ # @param month_dates(array) An array of timestamps for the past 30 days (2014-03-28T05:43:00+00:00)
424
+ # @param month_values(array) An array of values matching the timestamps (Must be 30 values)
425
+ # @return object
426
+
427
+ def metric_update(statuspage_id, metric_id, day_avg, day_start, day_dates, day_values,
428
+ week_avg, week_start, week_dates, week_values,
429
+ month_avg, month_start, month_dates, month_values)
430
+ data = {}
431
+ data['statuspage_id'] = statuspage_id
432
+ data['metric_id'] = metric_id
433
+ data['day_avg'] = day_avg
434
+ data['day_start'] = day_start
435
+ data['day_dates'] = day_dates
436
+ data['day_values'] = day_values
437
+ data['week_avg'] = week_avg
438
+ data['week_start'] = week_start
439
+ data['week_dates'] = week_dates
440
+ data['week_values'] =week_values
441
+ data['month_avg'] = month_avg
442
+ data['month_start'] = month_start
443
+ data['month_dates'] = month_dates
444
+ data['month_values'] = month_values
445
+
446
+ request :method => :post,
447
+ :url => @url + 'metric/update',
448
+ :payload => data
449
+ end
450
+
451
+ # STATUS
452
+
453
+ ##
454
+ # Show the summary status for all components and containers
455
+ #
456
+ # @param statuspage_id(string) Status page ID
457
+ # @return object
458
+
459
+ def status_summary(statuspage_id)
460
+ request :method => :get,
461
+ :url => @url + 'status/summary/' + statuspage_id
462
+ end
463
+
464
+ # SUBSCRIBER
465
+
466
+ ##
467
+ # List all subscribers
468
+ #
469
+ # @param statuspage_id(string) Status page ID
470
+ # @return object
471
+
472
+ def subscriber_list(statuspage_id)
473
+ request :method => :get,
474
+ :url => @url + 'subscriber/list/' + statuspage_id
475
+ end
476
+
477
+ ##
478
+ # Add a new subscriber
479
+ #
480
+ # @param statuspage_id(string) Status page ID
481
+ # @param method(string) Communication method of subscriber. Valid methods are `email`, `sms` or `webhook`
482
+ # @param address(string) Subscriber address (SMS number must include country code ie. +1)
483
+ # @param silent(int) Supress the welcome message (1 = Do not send notification)
484
+ # @param granular(string) List of component_container combos
485
+ # @return object
486
+
487
+ def subscriber_add(statuspage_id, method, address, silent = 1, granular = '')
488
+ data = {}
489
+ data['statuspage_id'] = statuspage_id
490
+ data['method'] = method
491
+ data['address'] = address
492
+ data['silent'] = silent
493
+ data['granular'] = granular
494
+
495
+ request :method => :post,
496
+ :url => @url + 'subscriber/add',
497
+ :payload => data
498
+ end
499
+
500
+ ##
501
+ # Update existing subscriber
502
+ #
503
+ # @param statuspage_id(string) Status page ID
504
+ # @param subscriber_id(string) Subscriber ID
505
+ # @param address(string) Subscriber address (SMS number must include country code ie. +1)
506
+ # @param granular(string) List of component_container combos
507
+ # @return object
508
+
509
+ def subscriber_update(statuspage_id, subscriber_id, address, granular = '')
510
+ data = {}
511
+ data['statuspage_id'] = statuspage_id
512
+ data['subscriber_id'] = subscriber_id
513
+ data['address'] = address
514
+ data['granular'] = granular
515
+
516
+ request :method => :patch,
517
+ :url => @url + 'subscriber/update',
518
+ :payload => data
519
+ end
520
+
521
+ ##
522
+ # Delete subscriber
523
+ #
524
+ # @param statuspage_id(string) Status page ID
525
+ # @param subscriber_id(string) Subscriber ID
526
+ # @return object
527
+
528
+ def subscriber_remove(statuspage_id, subscriber_id)
529
+ request :method => :delete,
530
+ :url => @url + 'subscriber/remove/' + statuspage_id + '/' + subscriber_id
531
+ end
581
532
  end
@@ -1,3 +1,3 @@
1
1
  class StatusioClient
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = 'exe'
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
+ spec.add_runtime_dependency 'rest-client'
30
31
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statusio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Status.io
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Ruby library wrapper for Status.io - A Complete Status Platform - Status
14
28
  pages, incident tracking, subscriber notifications and more
15
29
  email:
@@ -48,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
62
  version: '0'
49
63
  requirements: []
50
64
  rubyforge_project:
51
- rubygems_version: 2.0.14
65
+ rubygems_version: 2.0.14.1
52
66
  signing_key:
53
67
  specification_version: 4
54
68
  summary: Ruby library wrapper for Status.io