librato-alerts 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.
- checksums.yaml +7 -0
- data/README.md +22 -0
- data/lib/librato-alerts.rb +59 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba59ef56c07f3a866a2204e07eb804569638e5d9
|
4
|
+
data.tar.gz: 1ae63c087e0e4c9a6ea130ab7b2d79e9c0b78ba4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee2cd137c46aaae699c4a069fd5a51d3bb958beb5e9f89b863556b936b209123a212c1334b66f658e0899b81554a8ab725e036b8073e856c0ea2b143d7ef6293
|
7
|
+
data.tar.gz: eab89b64a68df47bc1d7b1eb370bedd1e7a31664ffe5e15dd422b0c7ef907ea34b122f103979ab9cdc86612ae0e1417758a1db03e1f32833848c6dd0df61f570
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# LibratoAlerts
|
2
|
+
|
3
|
+
A small library that allows retrieving, enabling and disabling librato alerts.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require "librato-alerts"
|
9
|
+
|
10
|
+
LibratoAlerts.configure do |config|
|
11
|
+
config.user = "librato email"
|
12
|
+
config.token = "librato token" # https://metrics.librato.com/tokens
|
13
|
+
end
|
14
|
+
|
15
|
+
LibratoAlerts.all
|
16
|
+
# => [{ :id => 1, :name => "alert.name", :description => nil, :conditions => [], :services => [], :attributes => {}, :active => true,
|
17
|
+
# :created_at => 646099200, :updated_at => 646099200, :version => 2, :rearm_seconds => 600, :rearm_per_signal => false }, ...]
|
18
|
+
|
19
|
+
LibratoAlerts.disable(1) # => nil
|
20
|
+
|
21
|
+
LibratoAlerts.enable(1) # => nil
|
22
|
+
```
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "nestful"
|
2
|
+
|
3
|
+
module LibratoAlerts
|
4
|
+
extend self
|
5
|
+
|
6
|
+
API_HOST = "https://metrics-api.librato.com/v1"
|
7
|
+
DEFAULT_VERSION = 2
|
8
|
+
|
9
|
+
attr_writer :user, :token
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
|
15
|
+
def all
|
16
|
+
get("alerts")[:alerts]
|
17
|
+
end
|
18
|
+
|
19
|
+
def enable(alert_id)
|
20
|
+
put("alerts/#{alert_id}", active: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def disable(alert_id)
|
24
|
+
put("alerts/#{alert_id}", active: false)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def get(endpoint, parameters = {})
|
30
|
+
request(endpoint, :get, parameters)
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(endpoint, parameters = {})
|
34
|
+
request(endpoint, :put, parameters)
|
35
|
+
end
|
36
|
+
|
37
|
+
def request(endpoint, method, parameters)
|
38
|
+
options = {
|
39
|
+
method: method,
|
40
|
+
params: default_parameters.merge(parameters),
|
41
|
+
auth_type: :basic,
|
42
|
+
user: @user,
|
43
|
+
password: @token,
|
44
|
+
format: :json
|
45
|
+
}
|
46
|
+
|
47
|
+
request = Nestful::Request.new("#{API_HOST}/#{endpoint}", options)
|
48
|
+
|
49
|
+
response = request.execute
|
50
|
+
|
51
|
+
return if response.body.nil? || response.body.empty?
|
52
|
+
|
53
|
+
JSON.parse(response.body, symbolize_names: true)
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_parameters
|
57
|
+
{ version: DEFAULT_VERSION }
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: librato-alerts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Guerrero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nestful
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: Interacts with Librato's Alerts API.
|
42
|
+
email:
|
43
|
+
- juan@chicisimo.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- lib/librato-alerts.rb
|
51
|
+
homepage: http://github.com/juanxo/librato-alerts
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.1.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.5.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Interacts with Librato's Alerts API.
|
75
|
+
test_files: []
|