Class: Stashboard::Stashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/stashboard/stashboard.rb

Overview

Main class for interacting with Stashboard.

Instance Method Summary (collapse)

Constructor Details

- (Stashboard) initialize(base_url, oauth_token, oauth_secret)

Create a new Stashboard instance.



14
15
16
17
# File 'lib/stashboard/stashboard.rb', line 14

def initialize(base_url, oauth_token, oauth_secret)
  @consumer = OAuth::Consumer.new("anonymous", "anonymous", { :site => base_url })
  @client = OAuth::AccessToken.new(@consumer, oauth_token, oauth_secret)
end

Instance Method Details

- (Hash) create_event(service_id, status_id, message)

Create an event of a service. Events are the main way we indicate problems or resolutions of issues.



99
100
101
102
# File 'lib/stashboard/stashboard.rb', line 99

def create_event(service_id, status_id, message)
  response = @client.post("/api/v1/services/#{service_id}/events", { "status" => status_id, "message" => message })
  return JSON.parse(response.body)
end

- (Hash) create_service(name, description)

Create a new service.



48
49
50
51
# File 'lib/stashboard/stashboard.rb', line 48

def create_service(name, description)
  response = @client.post("/api/v1/services", { "name" => name, "description" => description })
  return JSON.parse(response.body)
end

- (Hash) create_status(name, description, level, image)

Create a new status. Statuses exist independently of any Service, and are required before creating any events that use this status



163
164
165
166
# File 'lib/stashboard/stashboard.rb', line 163

def create_status(name, description, level, image)
  response = @client.post("/api/v1/statuses", { "name" => name, "description" => description, "level" => level, "image" => image })
  return JSON.parse(response.body)
end

- (Hash) current_event(service_id)

Get the current event for the specified service.



108
109
110
111
# File 'lib/stashboard/stashboard.rb', line 108

def current_event(service_id)
  response = @client.get("/api/v1/services/#{service_id}/events/current")
  return JSON.parse(response.body)
end

- (Object) delete_event(service_id, event_sid)

Delete an event.

(see #event)



126
127
128
129
# File 'lib/stashboard/stashboard.rb', line 126

def delete_event(service_id, event_sid)
  response = @client.delete("/api/v1/services/#{service_id}/events/#{event_sid}")
  return JSON.parse(response.body)
end

- (Hash) delete_service(service_id)

Delete a service. This will delete all alerts for this service, so be careful.



57
58
59
60
# File 'lib/stashboard/stashboard.rb', line 57

def delete_service(service_id)
  response = @client.delete("/api/v1/services/#{service_id}")
  return JSON.parse(response.body)
end

- (Hash) event(service_id, event_sid)

Get details of an individual event



118
119
120
121
# File 'lib/stashboard/stashboard.rb', line 118

def event(service_id, event_sid)
  response = @client.get("/api/v1/services/#{service_id}/events/#{event_sid}")
  return JSON.parse(response.body)
end

- (Hash) events(service_id, options = {})

Get events for the specified service.



87
88
89
90
# File 'lib/stashboard/stashboard.rb', line 87

def events(service_id, options = {})
  response = JSON.parse(@client.get("/api/v1/services/#{service_id}/events", options).body)
  return response["events"] || response
end

- (Array) levels

Returns the different levels that new statuses can use.



77
78
79
80
# File 'lib/stashboard/stashboard.rb', line 77

def levels
  response = JSON.parse(@client.get("/api/v1/levels").body)
  return response["levels"] || response
end

- (Hash) service(service_id)

Get the details of an individual service managed by the Stashboard instance.



38
39
40
41
# File 'lib/stashboard/stashboard.rb', line 38

def service(service_id)
  response = @client.get("/api/v1/services/#{service_id}")
  return JSON.parse(response.body)
end

- (Array) service_ids

Gets an array of service ids. This is just for convenience



30
31
32
# File 'lib/stashboard/stashboard.rb', line 30

def service_ids
  services.collect { |s| s["id"] }
end

- (Hash) services

Gets a list of all services currently managed by the Stashboard instance



22
23
24
25
# File 'lib/stashboard/stashboard.rb', line 22

def services
  response = JSON.parse(@client.get("/api/v1/services").body)
  return response["services"] || response
end

- (Hash) status(status_id)

Get the details of the individual status.



150
151
152
153
# File 'lib/stashboard/stashboard.rb', line 150

def status(status_id)
  response = @client.get("/api/v1/statuses/#{status_id}")
  return JSON.parse(response.body)
end

- (Array) status_ids

Convenience method to return just the status ids.



142
143
144
# File 'lib/stashboard/stashboard.rb', line 142

def status_ids
  statuses.collect { |s| s["id"] }
end

- (Array) status_images

Return a list of all the status images that the Stashboard server knows about.



171
172
173
174
# File 'lib/stashboard/stashboard.rb', line 171

def status_images
  response = JSON.parse(@client.get("/api/v1/status-images").body)
  return response["images"] || response
end

- (Array) statuses

Get all statuses.



134
135
136
137
# File 'lib/stashboard/stashboard.rb', line 134

def statuses
  response = JSON.parse(@client.get("/api/v1/statuses").body)
  return response["statuses"] || response
end

- (Hash) update_service(service_id, name, description)

Updates details of an existing service with a new name or description. You can't change the service_id however.



69
70
71
72
# File 'lib/stashboard/stashboard.rb', line 69

def update_service(service_id, name, description)
  response = @client.post("/api/v1/services/#{service_id}", { "name" => name, "description" => description })
  return JSON.parse(response.body)
end