zeusclient 0.1.3 → 0.3.0

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: 2c9b1fe09cdda854fc306b53d850844882fcfb8c
4
- data.tar.gz: 67609f973c1bb564d651d09e684e5cd02e423389
3
+ metadata.gz: d04cab72b6da4d93b3b969a696b13fa304c4d7c9
4
+ data.tar.gz: 14a16ea6fba4e7f91168f48ea34b1e83bf041d10
5
5
  SHA512:
6
- metadata.gz: 3ebb415c828ccb35f9146ba6d85b15893538fabcaed53f44c61f91b480a90f66d2909f4e06274b4b833267842e3a36c01d0e1b3f86d7a57ad9ccdd21332b2eaf
7
- data.tar.gz: 8a291264fc2236aa6fd0968135518621d9f1e38d00e9fac8301988f5ae80903ca7b1211c7d0527776a7ffdceabaa3bf3eb0c5d4a9579d7f5adc0099c9285941b
6
+ metadata.gz: 9759a9c03cc1c73b5e5e20644af98eda593bd1e99b0e1817972c76a41244f007159a38ccc2f222bbfbf5db272f07107886da3cf0c3616aa3c9bfc62a8ba35282
7
+ data.tar.gz: 11775b0f901a4782e9d58203db59a1677041069126e092122eca804bbbbb6d19b06a1b8db0d8f4834dbf1b3e819bb80200be96c7fd355ea9fa8822a112e06644
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ script:
5
+ - "bundle exec rspec"
6
+ - "bundle exec rubocop"
data/Gemfile CHANGED
@@ -14,5 +14,6 @@
14
14
 
15
15
  source 'https://rubygems.org'
16
16
 
17
- # Specify your gem's dependencies in zeus.gemspec
17
+ # Specify your gem's dependencies in zeusclient.gemspec
18
+
18
19
  gemspec
data/Gemfile.lock CHANGED
@@ -1,28 +1,52 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zeusclient (0.1.3)
5
- json
6
- rest-client
4
+ zeusclient (0.3.0)
5
+ rest-client (~> 1.8.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- domain_name (0.5.24)
10
+ ast (2.3.0)
11
+ diff-lcs (1.2.5)
12
+ domain_name (0.5.20161021)
12
13
  unf (>= 0.0.5, < 1.0.0)
13
- http-cookie (1.0.2)
14
+ http-cookie (1.0.3)
14
15
  domain_name (~> 0.5)
15
- json (1.8.2)
16
- mime-types (2.6.1)
17
- netrc (0.10.3)
16
+ mime-types (2.99.3)
17
+ netrc (0.11.0)
18
+ parser (2.3.1.4)
19
+ ast (~> 2.2)
20
+ powerpack (0.1.1)
21
+ rainbow (2.1.0)
18
22
  rake (10.4.2)
19
23
  rest-client (1.8.0)
20
24
  http-cookie (>= 1.0.2, < 2.0)
21
25
  mime-types (>= 1.16, < 3.0)
22
26
  netrc (~> 0.7)
27
+ rspec (3.0.0)
28
+ rspec-core (~> 3.0.0)
29
+ rspec-expectations (~> 3.0.0)
30
+ rspec-mocks (~> 3.0.0)
31
+ rspec-core (3.0.4)
32
+ rspec-support (~> 3.0.0)
33
+ rspec-expectations (3.0.4)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.0.0)
36
+ rspec-mocks (3.0.4)
37
+ rspec-support (~> 3.0.0)
38
+ rspec-support (3.0.4)
39
+ rubocop (0.45.0)
40
+ parser (>= 2.3.1.1, < 3.0)
41
+ powerpack (~> 0.1)
42
+ rainbow (>= 1.99.1, < 3.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (~> 1.0, >= 1.0.1)
45
+ ruby-progressbar (1.8.1)
23
46
  unf (0.1.4)
24
47
  unf_ext
25
- unf_ext (0.0.7.1)
48
+ unf_ext (0.0.7.2)
49
+ unicode-display_width (1.1.1)
26
50
  yard (0.8.7.6)
27
51
 
28
52
  PLATFORMS
@@ -31,5 +55,10 @@ PLATFORMS
31
55
  DEPENDENCIES
32
56
  bundler (~> 1.8)
33
57
  rake (~> 10.0)
58
+ rspec (~> 3.0.0)
59
+ rubocop (~> 0.45.0)
34
60
  yard (~> 0.8.0)
35
61
  zeusclient!
62
+
63
+ BUNDLED WITH
64
+ 1.13.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Ruby Zeus Client [![license](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
1
+ # Ruby Zeus Client [![license](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![Build Status](https://travis-ci.org/CiscoZeus/ruby-zeusclient.svg)](https://travis-ci.org/CiscoZeus/ruby-zeusclient)
2
2
 
3
- ![Alt text](/icons/zeus-logo.png?raw=true "Zeus Logo")
3
+ ![Alt text](https://github.com/CiscoZeus/ruby-zeusclient/blob/master/icons/zeus-logo.png?raw=true "Zeus Logo")
4
4
 
5
5
  Ruby client for [Cisco Zeus](http://www.ciscozeus.io/). This allows us to send and recieve data to and from Zeus.
6
6
 
@@ -25,27 +25,48 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  require 'zeus/api_client'
27
27
  zeus_client = Zeus::APIClient.new({
28
- :access_token => "your_token_here"
28
+ :access_token => "your_token_here",
29
+ :endpoint => "zeus_endpoint_here"
29
30
  })
30
31
  ```
31
32
 
32
33
  List All Metrics
34
+
33
35
  ```ruby
34
- result = zeus_client.list_metrics()
36
+ result = zeus_client.list_metrics(
37
+ # optional parameters
38
+ {
39
+ regex: "metric.name*" # regex for filtering metrics names
40
+ from_date: "2016-06-12", # YYYY-MM-DD
41
+ to_date: "2017-12-20", # YYYY-MM-DD
42
+ aggregator_function: "sum", # Aggregator function to be applied to the metric values.
43
+ # Available options. count, min, max, sum, mean, mode, median
44
+ group_interval: "100m", # Interval for grouping, when applying aggregations via the aggregator_function parameter.
45
+ # The aggregator_function parameter must be specific for this parameter to work.
46
+ # Examples: 1000s, 100m, 10h, 1d , 1w. Use 's' for seconds, 'm' for minutes, 'h' for hours,
47
+ # 'd' for days and 'w' for weeks.
48
+ filter_condition: "column1 > 0", # Filters to be applied to metric values.
49
+ # Examples: "column1 > 0", "column1 > 50 AND column2 = 10".
50
+ offset: 100,
51
+ limit: 10
52
+ }
53
+ )
35
54
  p result.code # 200
36
55
  p result.success? # true
37
56
  p result.data # => {}
38
57
  ```
39
58
 
40
59
  Get Metric
60
+
41
61
  ```ruby
42
- result = zeus_client.get_metrics()
62
+ result = zeus_client.get_metrics( # same optional arguments as list_metrics)
43
63
  p result.code # 200
44
64
  p result.success? # true
45
65
  p result.data # => {}
46
66
  ```
47
67
 
48
68
  Push Metric
69
+
49
70
  ```ruby
50
71
  result = zeus_client.send_metrics([{point: {value: 1, ...}}, ...])
51
72
  p result.code # 200
@@ -54,6 +75,7 @@ p result.data # => {}
54
75
  ```
55
76
 
56
77
  Delete metric
78
+
57
79
  ```ruby
58
80
  result = zeus_client.delete_metrics()
59
81
  p result.code # 200
@@ -62,14 +84,27 @@ p result.data # => {}
62
84
  ```
63
85
 
64
86
  Get logs
87
+
65
88
  ```ruby
66
- result = zeus_client.get_logs("log_name_here")
89
+ result = zeus_client.get_logs(
90
+ "log_name_here",
91
+ #optional parameters
92
+ {
93
+ attribute_name: "cpu", # name of the attribute within the log to be searched
94
+ pattern: "memory.*", # a pattern for name filtering
95
+ from_date: "2016-06-12", # YYYY-MM-DD
96
+ to_date: "2017-12-20", # YYYY-MM-DD
97
+ offset: 200,
98
+ limit: 10
99
+ }
100
+ )
67
101
  p result.code # 200
68
102
  p result.success? # true
69
103
  p result.data # => {}
70
104
  ```
71
105
 
72
106
  Push logs
107
+
73
108
  ```ruby
74
109
  result = zeus_client.send_logs([{},{}, ...])
75
110
  p result.code # 200
@@ -77,6 +112,90 @@ p result.success? # true
77
112
  p result.data # => {}
78
113
  ```
79
114
 
115
+ Get alerts
116
+
117
+ ```ruby
118
+ result = zeus_client.get_alerts()
119
+ p result.code # 200
120
+ p result.success? # true
121
+ p result.data # => {}
122
+ ```
123
+
124
+ Create alert
125
+
126
+ ```ruby
127
+ result = zeus_client.create_alert(
128
+ {
129
+ alert_name: "name of the alert",
130
+ username: "username associated with alert",
131
+ alert_expression: "cpu.value > 80", # expression to match alert against
132
+ # optional params
133
+ alerts_type: "metrics", # Either metric or log
134
+ alert_severity: "S1", # severity of the alert, S1-S5
135
+ metric_name: "name of the metrics associated with the alert",
136
+ emails: "email@provider.com", # email to be notified when alert triggers
137
+ status: "active", # either active or disabled
138
+ frequency: 60, # frequency for alert to be checked
139
+ }
140
+ )
141
+ p result.code # 201
142
+ p result.success? # true
143
+ p result.data # => {}
144
+ ```
145
+
146
+ Modify alert
147
+
148
+ ```ruby
149
+ result = zeus_client.modify_alert(
150
+ alert_id,
151
+ {
152
+ # parameter you wish to modify
153
+ alert_name: "name of the alert",
154
+ username: "username associated with alert",
155
+ alert_expression: "cpu.value > 80", # expression to match alert against
156
+ alerts_type: "metric", # Either metric or log
157
+ alert_severity: "S1", # severity of the alert, S1-S5
158
+ metric_name: "name of the metrics associated with the alert",
159
+ emails: "email@provider.com", # email to be notified when alert triggers
160
+ status: "active", # either active or disabled
161
+ frequency: 60, # frequency for alert to be checked
162
+ }
163
+ )
164
+ p result.code # 200
165
+ p result.success? # true
166
+ p result.data # => {}
167
+ ```
168
+
169
+ Delete alert
170
+
171
+ ```ruby
172
+ result = zeus_client.delete_alert(alert_id)
173
+ p result.code # 204
174
+ p result.success? # true
175
+ p result.data # => {}
176
+ ```
177
+
178
+ Get triggered alerts
179
+
180
+ ```ruby
181
+ result = zeus_client.triggered_alerts()
182
+ p result.code # 200
183
+ p result.success? # true
184
+ p result.data # => {}
185
+ Get triggered alerts
186
+ ```
187
+
188
+ Get triggered alerts in the last 24 hours
189
+
190
+ ```ruby
191
+ result = zeus_client.triggered_alerts_last_24_hours()
192
+ p result.code # 200
193
+ p result.success? # true
194
+ p result.data # => {}
195
+ ```
196
+
197
+ For more details, refer to [this documentation](http://www.rubydoc.info/github/CiscoZeus/ruby-zeusclient/)
198
+
80
199
  ## Development
81
200
 
82
201
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -12,5 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require "bundler/gem_tasks"
16
-
15
+ require 'bundler/gem_tasks'
data/bin/console CHANGED
@@ -14,8 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "bundler/setup"
18
- require "zeus/api_client"
17
+ require 'bundler/setup'
18
+ require 'zeus/api_client'
19
19
 
20
20
  # You can add fixtures and/or initialization code here to make experimenting
21
21
  # with your gem easier. You can also use a different console, if you like.
@@ -24,5 +24,5 @@ require "zeus/api_client"
24
24
  # require "pry"
25
25
  # Pry.start
26
26
 
27
- require "irb"
27
+ require 'irb'
28
28
  IRB.start
@@ -0,0 +1,136 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2016 Cisco Systems, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'zeus/api_client/rest_interface'
19
+ require 'zeus/api_client/result'
20
+
21
+ module Zeus
22
+ # Interface for dealing with alerts api calls
23
+ module AlertsInterface
24
+ include RestInterface
25
+
26
+ # create alert
27
+ # @param [Hash] alert_data must contain:
28
+ # @param [String] alert_name name of the alert
29
+ # @param [String] username account username
30
+ # @param [String] token account token
31
+ # @param [String] alerts_type alert type, metrics or logs
32
+ # @param [String] alert_expression expression to evaluate the alert
33
+ # @param [String] alert_severity severity level of the alert
34
+ # @param [String] metric_name <TODO add description>
35
+ # @param [String] emails recipients to receive notifications
36
+ # @param [String] status if the alerts is enabled or not
37
+ # @param [Integer] frequency <TODO add description>
38
+ # @return [Zeus::APIClient::Result]
39
+
40
+ def create_alert(alert_data)
41
+ alert_data[:token] = @access_token
42
+ response = post("/alerts/#{@access_token}", alert_data)
43
+ Result.new(response)
44
+ rescue => e
45
+ Result.new(e.response)
46
+ end
47
+
48
+ # modify alert
49
+ # @param [Integer] alert_id id of the alert to be modified
50
+ # @param [Hash] alert_data must contain:
51
+ # @param [String] alert_name name of the alert
52
+ # @param [String] username account username
53
+ # @param [String] token account token
54
+ # @param [String] alert_expression expression to evaluate the alert
55
+ # Optional params:
56
+ # @param [String] alerts_type alert type, metrics or logs
57
+ # @param [String] alert_severity severity level of the alert
58
+ # @param [String] metric_name <TODO add description>
59
+ # @param [String] emails recipients to receive notifications
60
+ # @param [String] status if the alerts is enabled or not
61
+ # @param [Integer] frequency <TODO add description>
62
+ # @return [Zeus::APIClient::Result]
63
+
64
+ def modify_alert(alert_id, alert_data)
65
+ alert_data[:token] = @access_token
66
+ response = put("/alerts/#{@access_token}/#{alert_id}", alert_data)
67
+ Result.new(response)
68
+ rescue => e
69
+ Result.new(e.response)
70
+ end
71
+
72
+ # get alerts
73
+ # @param [String] metric Name of metric that alerts are associated with
74
+ # @return [Zeus::APIClient::Result]
75
+
76
+ def get_alerts(metric = nil)
77
+ params = { metric: metric }
78
+ begin
79
+ response = get("/alerts/#{@access_token}", params)
80
+ Result.new(response)
81
+ rescue => e
82
+ Result.new(e.response)
83
+ end
84
+ end
85
+
86
+ # get alert
87
+ # @param [Integer] alert_id id of alert to be retrieved
88
+ # @return [Zeus::APIClient::Result]
89
+
90
+ def get_alert(alert_id)
91
+ response = get("/alerts/#{@access_token}/#{alert_id}")
92
+ Result.new(response)
93
+ rescue => e
94
+ Result.new(e.response)
95
+ end
96
+
97
+ # delete alert
98
+ # @param [Integer] alert_id id of alert to be deleted
99
+ # @return [Zeus::APIClient::Result]
100
+
101
+ def delete_alert(alert_id)
102
+ response = delete("/alerts/#{@access_token}/#{alert_id}")
103
+ Result.new(response)
104
+ rescue => e
105
+ Result.new(e.response)
106
+ end
107
+
108
+ # enable alerts
109
+ # @param [Array[Integer]] alert_id_list list of alert ids to be enabled
110
+ # @return [Zeus::APIClient::Result]
111
+
112
+ def enable_alerts(alert_id_array)
113
+ params = { id: alert_id_array }
114
+ begin
115
+ response = post("/alerts/#{@access_token}/enable", params)
116
+ Result.new(response)
117
+ rescue => e
118
+ Result.new(e.response)
119
+ end
120
+ end
121
+
122
+ # disable alerts
123
+ # @param [Array[Integer]] alert_id_list list of alert ids to be disabled
124
+ # @return [Zeus::APIClient::Result]
125
+
126
+ def disable_alerts(alert_id_array)
127
+ params = { id: alert_id_array }
128
+ begin
129
+ response = post("/alerts/#{@access_token}/disable", params)
130
+ Result.new(response)
131
+ rescue => e
132
+ Result.new(e.response)
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2016 Cisco Systems, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'zeus/api_client/rest_interface'
18
+ require 'zeus/api_client/result'
19
+
20
+ module Zeus
21
+ # Interface for dealing with logs api calls
22
+ module LogsInterface
23
+ include RestInterface
24
+ # send logs
25
+ # @param [String] name a log name
26
+ # @param [Array] logs a list of hash objects
27
+ # @return [Zeus::APIClient::Result]
28
+ def send_logs(name, logs)
29
+ params = { logs: logs }
30
+ begin
31
+ response = post("/logs/#{@access_token}/#{name}/", params)
32
+ Result.new(response)
33
+ rescue => e
34
+ Result.new(e.response)
35
+ end
36
+ end
37
+
38
+ # get logs
39
+ # @param [String] name a log name
40
+ # @param [Hash] options can contain:
41
+ # @param [String] attribute_name Name of the attribute within
42
+ # the log to be searched.
43
+ # @param [String] pattern a factor for filtering by name
44
+ # @param [String] from_date a factor for filtering by start timestamp
45
+ # @param [String] to_date a factor for filtering by end timestamp
46
+ # @param [Integer] offset a factor for filtering by metrics name
47
+ # @param [Integer] limit a maximum number of returning values
48
+ # @return [Zeus::APIClient::Result]
49
+ def get_logs(name, options = {})
50
+ options[:log_name] = name
51
+ response = get("/logs/#{@access_token}", options)
52
+ Result.new(response)
53
+ rescue => e
54
+ Result.new(e.response)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2016 Cisco Systems, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'zeus/api_client/rest_interface'
18
+ require 'zeus/api_client/result'
19
+
20
+ module Zeus
21
+ # Interface for dealing with metrics api calls
22
+ module MetricsInterface
23
+ include RestInterface
24
+ # Get metrics list
25
+ # @param [Hash] options can contain:
26
+ # @param [String] regex a factor for filtering by metrics name.
27
+ # eg: metric.name, metric.name*, metric.name.* etc.
28
+ # @param [String] from_date a factor for filtering by start timestamp
29
+ # @param [String] to_date a factor for filtering by end timestamp
30
+ # @param [String] aggregator an aggregation methods
31
+ # @param [String] group_interval grouping values by time interval.
32
+ # For example, 1000s, 100m, 10h, 1d , 1w
33
+ # @param [String] filter_condition a factor for filtering by metrics name
34
+ # @param [String] limit a maximum number of returning values
35
+ # @return [Zeus::APIClient::Result]
36
+ def list_metrics(options = {})
37
+ response = get("/metrics/#{@access_token}/_names/", options)
38
+ Result.new(response)
39
+ rescue => e
40
+ Result.new(e.response)
41
+ end
42
+
43
+ # Send metrics list
44
+ # @param [String] name a name of metrics.
45
+ # For example, metric.name, metric.name*, metric.name.* etc.
46
+ # @param [Array] metrics a list of hash objects
47
+ # @return [Zeus::APIClient::Result]
48
+ def send_metrics(name, metrics)
49
+ params = { metrics: metrics }
50
+ begin
51
+ response = post("/metrics/#{@access_token}/#{name}/", params)
52
+ Result.new(response)
53
+ rescue => e
54
+ Result.new(e.response)
55
+ end
56
+ end
57
+
58
+ # Get metrics
59
+ # @param [Hash] options can contain:
60
+ # @param [String] regex a factor for filtering by metrics name
61
+ # @param [String] from_date a factor for filtering by start timestamp
62
+ # @param [String] to_date a factor for filtering by end timestamp
63
+ # @param [String] aggregator an aggregation methods
64
+ # @param [String] group_interval grouping values by time interval.
65
+ # For example, 1000s, 100m, 10h, 1d , 1w
66
+ # @param [String] filter_condition filters to be applied to metric values.
67
+ # eg: "column1 > 0", "column1 > 50 AND column2 = 10"
68
+ # @param [Integer] limit a maximum number of returning values
69
+ # @return [Zeus::APIClient::Result]
70
+ def get_metrics(options = {})
71
+ response = get("/metrics/#{@access_token}/_values/", options)
72
+ Result.new(response)
73
+ rescue => e
74
+ Result.new(e.response)
75
+ end
76
+
77
+ # delete metrics
78
+ # @param [String] name a target metrics name
79
+ # @return [Zeus::APIClient::Result]
80
+ def delete_metrics(name)
81
+ response = delete("/metrics/#{@access_token}/#{name}/")
82
+ Result.new(response)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2016 Cisco Systems, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'rest-client'
19
+
20
+ # Wrapper around rest-client
21
+ module RestInterface
22
+ private
23
+
24
+ def get(path, params = {})
25
+ RestClient.get "#{@endpoint}#{path}", params: params
26
+ end
27
+
28
+ def post(path, data = {})
29
+ RestClient.post "#{@endpoint}#{path}", data.to_json,
30
+ content_type: :json, accept: :json
31
+ end
32
+
33
+ def put(path, params = {})
34
+ RestClient.put "#{@endpoint}#{path}", params: params
35
+ end
36
+
37
+ def delete(path = {})
38
+ RestClient.delete "#{@endpoint}#{path}"
39
+ end
40
+ end
@@ -15,41 +15,36 @@
15
15
  require 'json'
16
16
 
17
17
  module Zeus
18
- class APIClient
19
- # Wrapper for a response of REST API
20
- class Result
21
-
22
- # constructor for Result class
23
- def initialize(response)
24
- @response = response
25
- end
26
-
27
- # request is successed?
28
- def success?
29
- @response.code == 200 || @response.code == 201
30
- end
18
+ # Wrapper to interface with return values from the api
19
+ class Result
20
+ # constructor for Result class
21
+ def initialize(response)
22
+ @response = response
23
+ end
31
24
 
32
- # request is error?
33
- def error?
34
- !self.success?
35
- end
25
+ # request is successed?
26
+ def success?
27
+ @response.code == 200 || @response.code == 201
28
+ end
36
29
 
37
- # response code
38
- def code
39
- @response.code
40
- end
30
+ # request is error?
31
+ def error?
32
+ !success?
33
+ end
41
34
 
42
- # response header
43
- def header
44
- @response.headers
45
- end
35
+ # response code
36
+ def code
37
+ @response.code
38
+ end
46
39
 
47
- # response body
48
- def data
49
- JSON.parse(@response)
50
- end
40
+ # response header
41
+ def header
42
+ @response.headers
43
+ end
51
44
 
45
+ # response body
46
+ def data
47
+ JSON.parse(@response)
52
48
  end
53
49
  end
54
50
  end
55
-
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2016 Cisco Systems, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'zeus/api_client/rest_interface'
19
+ require 'zeus/api_client/result'
20
+
21
+ module Zeus
22
+ # Interface for dealing with triggered alerts api calls
23
+ module TrigalertsInterface
24
+ include RestInterface
25
+
26
+ # get triggered alerts
27
+ # @return [Zeus::APIClient::Result]
28
+
29
+ def triggered_alerts
30
+ response = get("/trigalerts/#{@access_token}")
31
+ Result.new(response)
32
+ rescue => e
33
+ Result.new(e.response)
34
+ end
35
+
36
+ # get triggered alerts in last 24 hours
37
+ # @return [Zeus::APIClient::Result]
38
+
39
+ def triggered_alerts_last_24_hours
40
+ response = get("/trigalerts/#{@access_token}/last24")
41
+ Result.new(response)
42
+ rescue => e
43
+ Result.new(e.response)
44
+ end
45
+ end
46
+ end
@@ -15,6 +15,6 @@
15
15
  module Zeus
16
16
  class APIClient
17
17
  # package version number
18
- VERSION = "0.1.3"
18
+ VERSION = '0.3.0'.freeze
19
19
  end
20
20
  end
@@ -12,179 +12,27 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'rest-client'
16
- require 'zeus/api_client/result'
17
- require 'zeus/api_client/version'
15
+ require 'zeus/api_client/alerts_interface'
16
+ require 'zeus/api_client/metrics_interface'
17
+ require 'zeus/api_client/logs_interface'
18
+ require 'zeus/api_client/trigalerts_interface'
18
19
 
19
20
  module Zeus
20
-
21
21
  # API Client for Zeus Service
22
22
  class APIClient
23
+ include AlertsInterface, MetricsInterface,
24
+ LogsInterface, TrigalertsInterface
23
25
 
24
26
  # constructor for Zeus::APIClient
25
27
  # @param [Hash] opts the options to create z Zeus::APIClient instance
26
28
  # @option opts [String] :access_token The tokens for Zeus Service
27
29
  # @option opts [String] :endpoint The base url for API endpoint
28
- def initialize(opts={})
30
+ def initialize(opts = {})
29
31
  @access_token = opts[:access_token]
30
- @endpoint = opts[:endpoint] || "http://api.ciscozeus.io"
31
- end
32
-
33
- # Get metrics list
34
- # @param [String] regex a factor for filtering by metrics name
35
- # [optional]
36
- # [Examples] metric.name, metric.name*, metric.name.* etc.
37
- # @param [String] from_date a factor for filtering by start timestamp
38
- # [optional]
39
- # @param [String] to_date a factor for filtering by end timestamp
40
- # [optional]
41
- # @param [String] aggregator an aggregation methods
42
- # [optional]
43
- # @param [String] group_interval grouping values by time interval
44
- # [optional]
45
- # [Examples] 1000s, 100m, 10h, 1d , 1w. Use 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days and 'w' for weeks.
46
- # @param [String] filter_condition a factor for filtering by metrics name
47
- # [optional]
48
- # @param [String] limit a maximum number of returning values
49
- # [optional]
50
- # @return [Zeus::APIClient::Result]
51
- def list_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
52
- params = {}
53
- params.merge!(metric_name: regex) if regex
54
- params.merge!(from: from_date) if from_date
55
- params.merge!(to: to_date) if to_date
56
- params.merge!(aggregator_function: aggregator) if aggregator
57
- params.merge!(group_interval: group_interval) if group_interval
58
- params.merge!(filter_condition: filter_condition) if filter_condition
59
- params.merge!(limit: limit) if limit
60
- begin
61
- response = get("/metrics/#{@access_token}/_names/", params)
62
- Result.new(response)
63
- rescue => e
64
- Result.new(e.response)
65
- end
66
- end
67
-
68
- # Send metrics list
69
- # @param [String] name a name of metrics
70
- # [Examples] metric.name, metric.name*, metric.name.* etc.
71
- # @param [Array] metrics a list of hash objects
72
- # @return [Zeus::APIClient::Result]
73
- def send_metrics(name, metrics)
74
- params = {metrics: metrics}
75
- begin
76
- response = post("/metrics/#{@access_token}/#{name}/", params)
77
- Result.new(response)
78
- rescue => e
79
- Result.new(e.response)
80
- end
81
- end
82
-
83
- # Get metrics
84
- # @param [String] regex a factor for filtering by metrics name
85
- # [optional]
86
- # @param [String] from_date a factor for filtering by start timestamp
87
- # [optional]
88
- # @param [String] to_date a factor for filtering by end timestamp
89
- # [optional]
90
- # @param [String] aggregator an aggregation methods
91
- # [optional]
92
- # @param [String] group_interval grouping values by time interval
93
- # [optional]
94
- # [Examples] 1000s, 100m, 10h, 1d , 1w. Use 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days and 'w' for weeks.
95
- # @param [String] filter_condition filters to be applied to metric values
96
- # [optional]
97
- # [Examples] "column1 > 0", "column1 > 50 AND column2 = 10".
98
- # @param [Integer] limit a maximum number of returning values
99
- # [optional]
100
- # @return [Zeus::APIClient::Result]
101
- def get_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
102
- params = {}
103
- params.merge!(metric_name: regex) if regex
104
- params.merge!(from: from_date) if from_date
105
- params.merge!(to: to_date) if to_date
106
- params.merge!(aggregator_function: aggregator) if aggregator
107
- params.merge!(group_interval: group_interval) if group_interval
108
- params.merge!(filter_condition: filter_condition) if filter_condition
109
- params.merge!(limit: limit) if limit
110
- begin
111
- response = get("/metrics/#{@access_token}/_values/", params)
112
- Result.new(response)
113
- rescue => e
114
- Result.new(e.response)
115
- end
116
- end
117
-
118
- # delete metrics
119
- # @param [String] name a target metrics name
120
- # @return [Zeus::APIClient::Result]
121
- def delete_metrics(name)
122
- response = delete("/metrics/#{@access_token}/#{name}/")
123
- Result.new(response)
124
- end
125
-
126
- # send logs
127
- # @param [String] name a log name
128
- # @param [Array] logs a list of hash objects
129
- # @return [Zeus::APIClient::Result]
130
- def send_logs(name, logs)
131
- params = {logs:logs}
132
- begin
133
- response = post("/logs/#{@access_token}/#{name}/", params)
134
- Result.new(response)
135
- rescue => e
136
- Result.new(e.response)
137
- end
32
+ # makes sure its using https
33
+ uri_parts = URI.split(opts[:endpoint])
34
+ uri_parts[0] = 'https://'
35
+ @endpoint = uri_parts.join
138
36
  end
139
-
140
- # get logs
141
- # @param [String] name a log name
142
- # @param [String] attribute_name Name of the attribute within the log to be searched.
143
- # [optional]
144
- # [Examples] if the submitted log has the format {"key1": "value1", "key2": "value2", "timestamp": 1430268064} then the value of this field can be "key1" or "key2"
145
- # @param [String] pattern a factor for fitering by name
146
- # [optional]
147
- # @param [String] from_date a factor for filtering by start timestamp
148
- # [optional]
149
- # @param [String] to_date a factor for filtering by end timestamp
150
- # [optional]
151
- # @param [Integer] offset a factor for filtering by metrics name
152
- # [optional]
153
- # @param [Integer] limit a maximum number of returning values
154
- # [optional]
155
- # @return [Zeus::APIClient::Result]
156
- def get_logs(name, attribute_name=nil, pattern=nil, from_date=nil, to_date=nil, offset=nil, limit=nil)
157
- params = {log_name: name} # required fields
158
- params.merge!(attribute_name: attribute_name) if attribute_name
159
- params.merge!(pattern: pattern) if pattern
160
- params.merge!(from: from_date) if from_date
161
- params.merge!(to: to_date) if to_date
162
- params.merge!(offset: offset) if offset
163
- params.merge!(limit: limit) if limit
164
- begin
165
- response = get("/logs/#{@access_token}", params)
166
- Result.new(response)
167
- rescue => e
168
- Result.new(e.response)
169
- end
170
- end
171
-
172
- private
173
- def get(path, params={})
174
- RestClient.get "#{@endpoint}#{path}", {params: params}
175
- end
176
-
177
- def post(path, data={})
178
- RestClient.post "#{@endpoint}#{path}", data.to_json, :content_type => :json, :accept => :json
179
- end
180
-
181
- def put(path, data={})
182
- RestClient.put "#{@endpoint}#{path}", data.to_json, :content_type => :json, :accept => :json
183
- end
184
-
185
- def delete(path={})
186
- RestClient.delete "#{@endpoint}#{path}"
187
- end
188
-
189
37
  end
190
38
  end
data/zeusclient.gemspec CHANGED
@@ -16,31 +16,36 @@
16
16
 
17
17
  lib = File.expand_path('../lib', __FILE__)
18
18
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
- require 'zeus/api_client'
19
+ require 'zeus/api_client/version'
20
20
 
21
21
  Gem::Specification.new do |spec|
22
- spec.name = "zeusclient"
22
+ spec.name = 'zeusclient'
23
23
  spec.version = Zeus::APIClient::VERSION
24
- spec.authors = ["Komei Shimamura"]
25
- spec.email = ["komei.t.f@gmail.com"]
24
+ spec.authors = ['Cisco Zeus']
25
+ spec.email = ['info@ciscozeus.io']
26
26
 
27
27
  if spec.respond_to?(:metadata)
28
28
  # spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
29
29
  end
30
30
 
31
- spec.summary = %q{Ruby Client for Cisco Zeus}
32
- spec.description = %q{Client for Cisco Zeus. This allows users to send and receive data to and from Cisco Zeus.}
33
- spec.homepage = "https://github.com/CiscoZeus/ruby-zeusclient"
34
- spec.license = "Apache 2.0"
31
+ spec.summary = 'Ruby Client for Cisco Zeus'
32
+ spec.description = 'Client for Cisco Zeus. This allows users to send'\
33
+ 'and receive data to and from Cisco Zeus.'
34
+ spec.homepage = 'https://github.com/CiscoZeus/ruby-zeusclient'
35
+ spec.license = 'Apache 2.0'
35
36
 
36
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|icons)/}) }
37
- spec.bindir = "exe"
37
+ spec.files =
38
+ `git ls-files -z`.split("\x0").reject { |f|
39
+ f.match(%r{^(test|spec|features|icons)/})
40
+ }
41
+ spec.bindir = 'exe'
38
42
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
- spec.require_paths = ["lib"]
43
+ spec.require_paths = ['lib']
40
44
 
41
- spec.add_dependency "json"
42
- spec.add_dependency "rest-client"
43
- spec.add_development_dependency "bundler", "~> 1.8"
44
- spec.add_development_dependency "rake", "~> 10.0"
45
- spec.add_development_dependency "yard", "~> 0.8.0"
45
+ spec.add_runtime_dependency 'rest-client', '~> 1.8.0'
46
+ spec.add_development_dependency 'bundler', '~> 1.8'
47
+ spec.add_development_dependency 'rake', '~> 10.0'
48
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
49
+ spec.add_development_dependency 'yard', '~> 0.8.0'
50
+ spec.add_development_dependency 'rubocop', '~> 0.45.0'
46
51
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeusclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Komei Shimamura
7
+ - Cisco Zeus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.8.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rest-client
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
33
+ version: '1.8'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.8'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.8'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: 3.0.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: 3.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,15 +80,30 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.8.0
83
- description: Client for Cisco Zeus. This allows users to send and receive data to
84
- and from Cisco Zeus.
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.45.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.45.0
97
+ description: Client for Cisco Zeus. This allows users to sendand receive data to and
98
+ from Cisco Zeus.
85
99
  email:
86
- - komei.t.f@gmail.com
100
+ - info@ciscozeus.io
87
101
  executables: []
88
102
  extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - ".gitignore"
106
+ - ".travis.yml"
92
107
  - Gemfile
93
108
  - Gemfile.lock
94
109
  - LICENSE
@@ -97,7 +112,12 @@ files:
97
112
  - bin/console
98
113
  - bin/setup
99
114
  - lib/zeus/api_client.rb
115
+ - lib/zeus/api_client/alerts_interface.rb
116
+ - lib/zeus/api_client/logs_interface.rb
117
+ - lib/zeus/api_client/metrics_interface.rb
118
+ - lib/zeus/api_client/rest_interface.rb
100
119
  - lib/zeus/api_client/result.rb
120
+ - lib/zeus/api_client/trigalerts_interface.rb
101
121
  - lib/zeus/api_client/version.rb
102
122
  - zeusclient.gemspec
103
123
  homepage: https://github.com/CiscoZeus/ruby-zeusclient
@@ -120,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
140
  version: '0'
121
141
  requirements: []
122
142
  rubyforge_project:
123
- rubygems_version: 2.4.5
143
+ rubygems_version: 2.5.1
124
144
  signing_key:
125
145
  specification_version: 4
126
146
  summary: Ruby Client for Cisco Zeus