copperegg 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/LICENSE +1 -1
- data/README.md +49 -12
- data/copperegg.gemspec +2 -2
- data/lib/copperegg.rb +1 -0
- data/lib/copperegg/mixins/persistence.rb +11 -1
- data/lib/copperegg/tag.rb +94 -0
- data/lib/copperegg/ver.rb +1 -1
- data/test/tag_test.rb +59 -0
- metadata +10 -8
- data/copperegg-0.6.2.gem +0 -0
- data/copperegg-0.6.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59b70ed5f945021c7dfe5684b46eb70422effc51
|
4
|
+
data.tar.gz: 2eb98a496a3a433cae923714fdcdca3c5efe0100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 193356a9428c2ef79df3cc01d124ae08bd010182755448c127fc89092e7f76e08ddf1d574e3e71720f9f72223629a9049a35dd0d0994ad61718bcbdb9a9541e0
|
7
|
+
data.tar.gz: 0afbce8c5665297c495f11f580deb7b058d86f4a0d7804292cfa98bb5295360218eadfb98de82b3fa850d837ee258432ad048074e6195466cb44c0887ae15a27
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CopperEgg Gem
|
2
2
|
|
3
|
-
The CopperEgg gem allows programmatic access to the
|
3
|
+
The CopperEgg gem allows programmatic access to the Uptime Cloud Monitor API.
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
@@ -21,7 +21,7 @@ $ gem install copperegg-{version}.gem
|
|
21
21
|
|
22
22
|
## Getting Started
|
23
23
|
|
24
|
-
|
24
|
+
#### Setup
|
25
25
|
|
26
26
|
``` ruby
|
27
27
|
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
|
@@ -29,7 +29,9 @@ require 'copperegg'
|
|
29
29
|
CopperEgg::Api.apikey = "sdf87xxxxxxxxxxxxxxxxxxxxx" # from the web UI
|
30
30
|
```
|
31
31
|
|
32
|
-
|
32
|
+
## Metric Groups:
|
33
|
+
|
34
|
+
#### Get a metric group:
|
33
35
|
|
34
36
|
``` ruby
|
35
37
|
metric_group = CopperEgg::MetricGroup.find("my_metric_group")
|
@@ -41,7 +43,7 @@ metric_group.metrics
|
|
41
43
|
# => [#<CopperEgg::MetricGroup::Metric:0x007fb43aab2570 @position=0, @type="ce_gauge", @name="metric1", @label="Metric 1", @unit="b">]
|
42
44
|
```
|
43
45
|
|
44
|
-
|
46
|
+
#### Create a metric group:
|
45
47
|
|
46
48
|
``` ruby
|
47
49
|
metric_group = CopperEgg::MetricGroup.new(:name => "my_new_metric_group", :label => "Cool New Group Visible Name", :frequency => 60) # data is sent every 60 seconds
|
@@ -66,7 +68,7 @@ metric_group2.name
|
|
66
68
|
# => "my_metric_group"
|
67
69
|
```
|
68
70
|
|
69
|
-
|
71
|
+
#### Updating a metric group:
|
70
72
|
|
71
73
|
Labels, frequency, metric types and metric units can be updated and additional metrics can be added. Changes to the metric group name or names of metrics within will be ignored.
|
72
74
|
|
@@ -85,20 +87,21 @@ metric_group.frequency
|
|
85
87
|
# => 5
|
86
88
|
```
|
87
89
|
|
88
|
-
|
90
|
+
#### Delete a metric group
|
89
91
|
|
90
92
|
```ruby
|
91
93
|
metric_group.delete
|
92
94
|
```
|
93
95
|
|
96
|
+
## Samples
|
94
97
|
|
95
|
-
|
98
|
+
#### Post samples for a metric group
|
96
99
|
|
97
100
|
```ruby
|
98
101
|
CopperEgg::MetricSample.save(metric_group.name, "custom_identifier1", Time.now.to_i, "active_connections" => 2601, "connections_accepts" => 154, "connections_handled" => 128, "connections_requested" => 1342, ...)
|
99
102
|
```
|
100
103
|
|
101
|
-
|
104
|
+
#### Get samples
|
102
105
|
|
103
106
|
```ruby
|
104
107
|
# Get the most recent samples for a single metric
|
@@ -113,7 +116,9 @@ CopperEgg::MetricSample.samples(metric_group.name, ["connections_accepts", "conn
|
|
113
116
|
|
114
117
|
The raw JSON response is returned as specified in the [API docs][sample_docs].
|
115
118
|
|
116
|
-
|
119
|
+
## Dashboards
|
120
|
+
|
121
|
+
#### Create a dashboard from a metric group
|
117
122
|
|
118
123
|
By default, the dashboard created will be named "_MetricGroupLabel_ Dashboard" and will have one timeline widget per metric matching all sources.
|
119
124
|
|
@@ -146,13 +151,13 @@ You can limit the widgets created by metric.
|
|
146
151
|
dashboard = CopperEgg::CustomDashboard.create(metric_group, :name => "Cloud Servers", :identifiers => ["custom_identifier1", "custom_identifier2"], :metrics => ["reading", "writing", "waiting"])
|
147
152
|
```
|
148
153
|
|
149
|
-
|
154
|
+
#### Get a dashboard
|
150
155
|
|
151
156
|
```ruby
|
152
157
|
dashboard = CopperEgg::CustomDashboard.find_by_name("My Metric Group Dashboard")
|
153
158
|
```
|
154
159
|
|
155
|
-
|
160
|
+
#### Delete a dashboard
|
156
161
|
|
157
162
|
Dashboards can be deleted like metric groups:
|
158
163
|
|
@@ -160,6 +165,38 @@ Dashboards can be deleted like metric groups:
|
|
160
165
|
dashboard.delete
|
161
166
|
```
|
162
167
|
|
168
|
+
## Tags
|
169
|
+
|
170
|
+
#### Getting all or specific tags
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
tags_list = CopperEgg::Tag.find
|
174
|
+
tag = CopperEgg::Tag.find_by_name("my-tag")
|
175
|
+
```
|
176
|
+
|
177
|
+
#### Create a tag
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
tag = CopperEgg::Tag.new({:name => "my-tag"})
|
181
|
+
tag.objects = ["object-identifier-1", "object-identifier-2"]
|
182
|
+
tag.save
|
183
|
+
```
|
184
|
+
|
185
|
+
#### Update a tag
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
tag.objects = ["object-identifier-1", "object-identifier-2", "object-identifier-3"]
|
189
|
+
tag.save
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Delete a tag
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
tag.delete
|
196
|
+
```
|
197
|
+
|
198
|
+
|
199
|
+
|
163
200
|
## Questions / Problems?
|
164
201
|
|
165
202
|
There are more detailed examples in the [test classes][test_classes].
|
@@ -171,4 +208,4 @@ Full [API docs][docs] are available.
|
|
171
208
|
[docs]:http://dev.copperegg.com
|
172
209
|
|
173
210
|
## Copyright
|
174
|
-
Copyright 2013
|
211
|
+
Copyright 2013 IDERA.
|
data/copperegg.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.author = 'Eric Anderson'
|
7
7
|
s.email = 'anderson@copperegg.com'
|
8
8
|
|
9
|
-
s.description = 'Library for using the
|
10
|
-
s.summary = 'Library for using the
|
9
|
+
s.description = 'Library for using the Uptime Cloud Monitor REST API'
|
10
|
+
s.summary = 'Library for using the Uptime Cloud Monitor REST API'
|
11
11
|
s.homepage = 'http://github.com/copperegg/copperegg-ruby'
|
12
12
|
s.license = 'MIT'
|
13
13
|
|
data/lib/copperegg.rb
CHANGED
@@ -6,6 +6,7 @@ require File.dirname(__FILE__) + "/copperegg/mixins/persistence"
|
|
6
6
|
require File.dirname(__FILE__) + "/copperegg/metric_group"
|
7
7
|
require File.dirname(__FILE__) + "/copperegg/custom_dashboard"
|
8
8
|
require File.dirname(__FILE__) + "/copperegg/metric_sample"
|
9
|
+
require File.dirname(__FILE__) + "/copperegg/tag"
|
9
10
|
require File.dirname(__FILE__) + "/copperegg/api"
|
10
11
|
|
11
12
|
module CopperEgg
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module CopperEgg
|
2
2
|
class ValidationError < Exception; end
|
3
3
|
|
4
|
+
class HttpError < Exception; end
|
5
|
+
|
4
6
|
module Mixins
|
5
7
|
module Persistence
|
6
8
|
def self.included(klass)
|
@@ -34,7 +36,7 @@ module CopperEgg
|
|
34
36
|
|
35
37
|
def request(params={})
|
36
38
|
request_type = params.delete(:request_type)
|
37
|
-
raise "invalid type" if !%w(get post put delete).include?(request_type)
|
39
|
+
raise "invalid type `#{request_type}`" if !%w(get post put delete).include?(request_type)
|
38
40
|
id = params.delete(:id)
|
39
41
|
|
40
42
|
uri = id ? URI.parse("#{Api.uri}/#{self.resource_name}/#{id}.json") : URI.parse("#{Api.uri}/#{self.resource_name}.json")
|
@@ -57,6 +59,14 @@ module CopperEgg
|
|
57
59
|
response
|
58
60
|
end
|
59
61
|
|
62
|
+
def request_200(params={})
|
63
|
+
response = request(params)
|
64
|
+
unless response.code === "200"
|
65
|
+
raise HttpError.new("HTTP request failed with code `#{response.code}`: `#{response.body}`")
|
66
|
+
end
|
67
|
+
response
|
68
|
+
end
|
69
|
+
|
60
70
|
private
|
61
71
|
|
62
72
|
def resource(value)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module CopperEgg
|
2
|
+
class Tag
|
3
|
+
include CopperEgg::Mixins::Persistence
|
4
|
+
|
5
|
+
resource 'tags'
|
6
|
+
|
7
|
+
attr_accessor :name, :objects
|
8
|
+
|
9
|
+
def load_attributes(attributes)
|
10
|
+
@objects_original = []
|
11
|
+
|
12
|
+
attributes.each do |name, value|
|
13
|
+
if name.to_s == 'id'
|
14
|
+
@id = value
|
15
|
+
elsif !respond_to?("#{name}=")
|
16
|
+
next
|
17
|
+
elsif name.to_s == 'objects'
|
18
|
+
@objects = value.map { |object| object['idv'].to_s.gsub(/\|$/, '') }
|
19
|
+
@objects_original = @objects.clone
|
20
|
+
else
|
21
|
+
send "#{name}=", value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
@name || @id
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
@error = nil
|
32
|
+
|
33
|
+
if self.name.nil? || self.name.to_s.strip.empty?
|
34
|
+
@error = "Name can't be blank."
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
if self.name.to_s.match(/[^\w-]/)
|
39
|
+
@error = 'Name contains invalid characters.'
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
|
43
|
+
if self.objects.nil? || self.objects.empty?
|
44
|
+
@error = 'You must define at least one object.'
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
|
48
|
+
unless self.objects.kind_of?(Array)
|
49
|
+
@error = 'Invalid objects field.'
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
|
53
|
+
if self.objects.any? { |object| !object.kind_of?(String) }
|
54
|
+
@error = 'Invalid object identifier.'
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete
|
62
|
+
self.class.request_200({:id => name, :request_type => 'delete'})
|
63
|
+
end
|
64
|
+
|
65
|
+
def save
|
66
|
+
unless valid?
|
67
|
+
raise ValidationError.new(@error)
|
68
|
+
end
|
69
|
+
|
70
|
+
remove_objects(@objects_original - @objects)
|
71
|
+
add_objects(@objects - @objects_original)
|
72
|
+
@objects_original = @objects
|
73
|
+
end
|
74
|
+
|
75
|
+
def update
|
76
|
+
save
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_hash
|
80
|
+
{ 'tag' => name, 'ids' => objects }
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def remove_objects(ids)
|
86
|
+
self.class.request_200({ id: name, ids: ids, request_type: 'delete' }) unless ids.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_objects(ids)
|
90
|
+
self.class.request_200({ tag: name, ids: ids, request_type: 'post' }) unless ids.empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
data/lib/copperegg/ver.rb
CHANGED
data/test/tag_test.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "copperegg"
|
3
|
+
|
4
|
+
class TagTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_name_accessor_and_setter
|
7
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
8
|
+
|
9
|
+
assert_equal "my_tag", tag.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_save_should_fail_if_name_is_blank
|
13
|
+
tag = CopperEgg::Tag.new
|
14
|
+
|
15
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
16
|
+
assert_equal "Name can't be blank.", error.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_save_should_fail_if_name_contains_invalid_characters
|
20
|
+
tag = CopperEgg::Tag.new(:name => "my%%%tag")
|
21
|
+
|
22
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
23
|
+
assert_equal "Name contains invalid characters.", error.message
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_objects_accessor_and_setter
|
27
|
+
tag = CopperEgg::Tag.new(:name => "my_tag", :objects => [{"idv" => "obj1"}, {"idv" => "obj2"}])
|
28
|
+
|
29
|
+
assert_equal ["obj1", "obj2"], tag.objects
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_save_should_fail_if_no_objects_are_declared
|
33
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
34
|
+
|
35
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
36
|
+
assert_equal "You must define at least one object.", error.message
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_save_should_fail_if_objects_include_non_strings
|
40
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
41
|
+
tag.objects = ["obj1", 12323]
|
42
|
+
|
43
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
44
|
+
assert_equal "Invalid object identifier.", error.message
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_hash
|
48
|
+
tag = CopperEgg::Tag.new(:name => "test")
|
49
|
+
tag.objects = ["obj1", "obj2"]
|
50
|
+
|
51
|
+
assert tag.valid?
|
52
|
+
hash = tag.to_hash
|
53
|
+
|
54
|
+
assert_nil hash["id"]
|
55
|
+
assert_equal "test", hash["tag"]
|
56
|
+
assert_equal ["obj1", "obj2"], hash["ids"]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copperegg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.7.6
|
33
|
-
description: Library for using the
|
33
|
+
description: Library for using the Uptime Cloud Monitor REST API
|
34
34
|
email: anderson@copperegg.com
|
35
35
|
executables: []
|
36
36
|
extensions: []
|
@@ -41,8 +41,6 @@ files:
|
|
41
41
|
- "./LICENSE"
|
42
42
|
- "./README.md"
|
43
43
|
- "./Rakefile"
|
44
|
-
- "./copperegg-0.6.2.gem"
|
45
|
-
- "./copperegg-0.6.3.gem"
|
46
44
|
- "./copperegg.gemspec"
|
47
45
|
- "./lib/copperegg.rb"
|
48
46
|
- "./lib/copperegg/api.rb"
|
@@ -50,14 +48,17 @@ files:
|
|
50
48
|
- "./lib/copperegg/metric_group.rb"
|
51
49
|
- "./lib/copperegg/metric_sample.rb"
|
52
50
|
- "./lib/copperegg/mixins/persistence.rb"
|
51
|
+
- "./lib/copperegg/tag.rb"
|
53
52
|
- "./lib/copperegg/ver.rb"
|
54
53
|
- "./supplemental/release_version.sh"
|
55
54
|
- "./test/custom_dashboard_test.rb"
|
56
55
|
- "./test/metric_group_test.rb"
|
57
56
|
- "./test/metric_sample_test.rb"
|
57
|
+
- "./test/tag_test.rb"
|
58
58
|
- test/custom_dashboard_test.rb
|
59
59
|
- test/metric_group_test.rb
|
60
60
|
- test/metric_sample_test.rb
|
61
|
+
- test/tag_test.rb
|
61
62
|
homepage: http://github.com/copperegg/copperegg-ruby
|
62
63
|
licenses:
|
63
64
|
- MIT
|
@@ -84,11 +85,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
version: '0'
|
85
86
|
requirements: []
|
86
87
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.6.12
|
88
89
|
signing_key:
|
89
90
|
specification_version: 4
|
90
|
-
summary: Library for using the
|
91
|
+
summary: Library for using the Uptime Cloud Monitor REST API
|
91
92
|
test_files:
|
93
|
+
- test/tag_test.rb
|
94
|
+
- test/metric_group_test.rb
|
92
95
|
- test/custom_dashboard_test.rb
|
93
96
|
- test/metric_sample_test.rb
|
94
|
-
- test/metric_group_test.rb
|
data/copperegg-0.6.2.gem
DELETED
Binary file
|
data/copperegg-0.6.3.gem
DELETED
Binary file
|