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.

Parameters:

  • the (String)

    url of your stashboard instance (this should use https)

  • the (String)

    oauth_token generated by your Stashboard instance (this is the long one)

  • the (String)

    oauth_secret generated by your Stashboard instance (this is the shorter one)



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.

Parameters:

  • the (String)

    id of the service

  • the (String)

    id of an already existing status (i.e. "up", "down", "warning")

  • a (String)

    descriptive message

Returns:

  • (Hash)

    the event details



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.

Parameters:

  • the (String)

    name of the service

  • the (String)

    description of the service

Returns:

  • (Hash)

    response containing the complete service details generated by Stashboard



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

Parameters:

  • the (String)

    name of this status

  • description (String)

    of the status

  • level (String)

    string. Must be one of the levels returned from #levels

  • name (String)

    of an image to use for this status. The complete list of images can be retrieved using #status_images, and this value should just be the image name without the directory name or the file extension.

Returns:

  • (Hash)

    hash containing the created statuses details



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.

Parameters:

  • the (String)

    id of the service

Returns:

  • (Hash)

    hash containing the current event details



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.

Parameters:

  • the (String)

    service id to delete

Returns:

  • (Hash)

    details of the service we've just deleted



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

Parameters:

  • the (String)

    id of the service

  • the (String)

    sid of the event. This is a unique key returned in the response when an event is created

Returns:

  • (Hash)

    hash containing the current event details



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.

Parameters:

  • the (String)

    service id we wer interested in

  • optional (Hash)

    hash that restricts the returned events. Only keys that do anything are "start" and "end" which can be used to constrain the time period from which events will be returned.

Returns:

  • (Hash)

    an array of event hashes describing events for the service, or an error hash



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.

Returns:

  • (Array)

    an array of the level strings



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.

Parameters:

  • the (String)

    unique id of the service (generated by Stashboard)

Returns:

  • (Hash)

    hash containing the service details



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

Returns:

  • (Array)

    containing just the service ids



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

Returns:

  • (Hash)

    containing an array of service detail hashes, or an error message



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.

Parameters:

  • the (String)

    id of the status

Returns:

  • (Hash)

    hash containing the status details



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.

Returns:

  • (Array)

    an array of 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.

Returns:

  • (Array)

    array of image hashes



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.

Returns:

  • (Array)

    an array of status hashes, each hash is an individual status



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.

Parameters:

  • the (String)

    id of the service to update

  • the (String)

    new name

  • the (String)

    new description

Returns:

  • (Hash)

    the updated service details



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