zeusclient 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6de2b427eec1b61a32dca4dd4db821f5757bcc43
4
+ data.tar.gz: 3ec31374ecedd07fa548713da44306981531fe38
5
+ SHA512:
6
+ metadata.gz: 65d27734ac92912a91f689342037a4faf9528348af1e42f04bfc5e0907241ff6e6e5263f2f1d794a92819f273e382c0a738ec56fc75b18903cab97389505347c
7
+ data.tar.gz: 0596048bd3d412b4f861bea183d02d798be717b8f02139b9f2568b9967916d641ee6c142f079a249f01db214ff409f8e5c72eb10a4f450627a053324f753d7cb
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ .idea
2
+ *.swp
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ source 'https://rubygems.org'
16
+
17
+ # Specify your gem's dependencies in zeus.gemspec
18
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zeusclient (0.1.1)
5
+ json
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ domain_name (0.5.24)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.2)
14
+ domain_name (~> 0.5)
15
+ json (1.8.2)
16
+ mime-types (2.6.1)
17
+ netrc (0.10.3)
18
+ rake (10.4.2)
19
+ rest-client (1.8.0)
20
+ http-cookie (>= 1.0.2, < 2.0)
21
+ mime-types (>= 1.16, < 3.0)
22
+ netrc (~> 0.7)
23
+ unf (0.1.4)
24
+ unf_ext
25
+ unf_ext (0.0.7.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.8)
32
+ rake (~> 10.0)
33
+ zeusclient!
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Ruby Zeus Client [![license](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
2
+
3
+ ![Alt text](/icons/zeus-logo.png?raw=true "Zeus Logo")
4
+
5
+ Ruby client for [Cisco Zeus](http://www.ciscozeus.io/). This allows us to send and recieve data to and from Zeus.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'zeusclient'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zeusclient
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'zeus/api_client'
27
+ zeus_client = Zeus::APIClient.new({
28
+ :access_token => "your_token_here"
29
+ })
30
+ ```
31
+
32
+ List All Metrics
33
+ ```ruby
34
+ result = zeus_client.list_metrics()
35
+ p result.code # 200
36
+ p result.success? # true
37
+ p result.data # => {}
38
+ ```
39
+
40
+ Get Metric
41
+ ```ruby
42
+ result = zeus_client.get_metrics()
43
+ p result.code # 200
44
+ p result.success? # true
45
+ p result.data # => {}
46
+ ```
47
+
48
+ Push Metric
49
+ ```ruby
50
+ result = zeus_client.send_metrics([{point: {value: 1, ...}}, ...])
51
+ p result.code # 200
52
+ p result.success? # true
53
+ p result.data # => {}
54
+ ```
55
+
56
+ Delete metric
57
+ ```ruby
58
+ result = zeus_client.delete_metrics()
59
+ p result.code # 200
60
+ p result.success? # true
61
+ p result.data # => {}
62
+ ```
63
+
64
+ Get logs
65
+ ```ruby
66
+ result = zeus_client.get_logs("log_name_here")
67
+ p result.code # 200
68
+ p result.success? # true
69
+ p result.data # => {}
70
+ ```
71
+
72
+ Push logs
73
+ ```ruby
74
+ result = zeus_client.send_logs([{},{}, ...])
75
+ p result.code # 200
76
+ p result.success? # true
77
+ p result.data # => {}
78
+ ```
79
+
80
+ ## Development
81
+
82
+ 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.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it ( https://github.com/CiscoZeus/zeusclient/fork )
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "bundler/gem_tasks"
16
+
data/bin/console ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 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 "bundler/setup"
18
+ require "zeus/api_client"
19
+
20
+ # You can add fixtures and/or initialization code here to make experimenting
21
+ # with your gem easier. You can also use a different console, if you like.
22
+
23
+ # (If you use this, don't forget to add pry to your Gemfile!)
24
+ # require "pry"
25
+ # Pry.start
26
+
27
+ require "irb"
28
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ # Copyright 2015 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
+ set -euo pipefail
18
+ IFS=$'\n\t'
19
+
20
+ bundle install
21
+
22
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'json'
16
+
17
+ module Zeus
18
+ class APIClient
19
+ class Result
20
+
21
+ def initialize(response)
22
+ @response = response
23
+ end
24
+
25
+ def success?
26
+ @response.code == 200 || @response.code == 201
27
+ end
28
+
29
+ def error?
30
+ !self.success?
31
+ end
32
+
33
+ def code
34
+ @response.code
35
+ end
36
+
37
+ def data
38
+ JSON.parse(@response)
39
+ end
40
+
41
+ def header
42
+ @response.headers
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,19 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Zeus
16
+ class APIClient
17
+ VERSION = "0.1.2"
18
+ end
19
+ end
@@ -0,0 +1,121 @@
1
+ # Copyright 2015 Cisco Systems, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'rest-client'
16
+ require 'zeus/api_client/result'
17
+ require 'zeus/api_client/version'
18
+
19
+ module Zeus
20
+
21
+ class APIClient
22
+
23
+ def initialize(opts={})
24
+ @access_token = opts[:access_token]
25
+ @endpoint = opts[:endpoint] || "http://api.ciscozeus.io"
26
+ end
27
+
28
+ def list_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
29
+ params = {}
30
+ params.merge!(metric_name: regex) if regex
31
+ params.merge!(from: from_date) if from_date
32
+ params.merge!(to: to_date) if to_date
33
+ params.merge!(aggregator_function: aggregator) if aggregator
34
+ params.merge!(group_interval: group_interval) if group_interval
35
+ params.merge!(filter_condition: filter_condition) if filter_condition
36
+ params.merge!(limit: limit) if limit
37
+ begin
38
+ response = self.get("/metrics/#{@access_token}/_names/", params)
39
+ Result.new(response)
40
+ rescue => e
41
+ Result.new(e.response)
42
+ end
43
+ end
44
+
45
+ def send_metrics(name, metrics)
46
+ params = {metrics: metrics}
47
+ begin
48
+ response = self.post("/metrics/#{@access_token}/#{name}/", params)
49
+ Result.new(response)
50
+ rescue => e
51
+ Result.new(e.response)
52
+ end
53
+ end
54
+
55
+ def get_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
56
+ params = {}
57
+ params.merge!(metric_name: regex) if regex
58
+ params.merge!(from: from_date) if from_date
59
+ params.merge!(to: to_date) if to_date
60
+ params.merge!(aggregator_function: aggregator) if aggregator
61
+ params.merge!(group_interval: group_interval) if group_interval
62
+ params.merge!(filter_condition: filter_condition) if filter_condition
63
+ params.merge!(limit: limit) if limit
64
+ begin
65
+ response = self.get("/metrics/#{@access_token}/_values/", params)
66
+ Result.new(response)
67
+ rescue => e
68
+ Result.new(e.response)
69
+ end
70
+ end
71
+
72
+ def delete_metrics(name)
73
+ response = self.delete("/metrics/#{@access_token}/#{name}/")
74
+ Result.new(response)
75
+ end
76
+
77
+ def send_logs(name, logs)
78
+ params = {logs:logs}
79
+ begin
80
+ response = self.post("/logs/#{@access_token}/#{name}/", params)
81
+ Result.new(response)
82
+ rescue => e
83
+ Result.new(e.response)
84
+ end
85
+ end
86
+
87
+ def get_logs(name, pattern=nil, from_date=nil, to_date=nil, offset=nil, limit=nil)
88
+ params = {log_name: name} # required fields
89
+ params.merge!(pattern: pattern) if pattern
90
+ params.merge!(from: from_date) if from_date
91
+ params.merge!(to: to_date) if to_date
92
+ params.merge!(offset: offset) if offset
93
+ params.merge!(limit: limit) if limit
94
+ begin
95
+ response = self.get("/logs/#{@access_token}", params)
96
+ Result.new(response)
97
+ rescue => e
98
+ Result.new(e.response)
99
+ end
100
+ end
101
+
102
+ def get(path, params={})
103
+ RestClient.get "#{@endpoint}#{path}", {params: params}
104
+ end
105
+
106
+ def post(path, data={})
107
+ p "#{@endpoint}#{path}"
108
+ p data
109
+ RestClient.post "#{@endpoint}#{path}", data.to_json, :content_type => :json, :accept => :json
110
+ end
111
+
112
+ def put(path, data={})
113
+ RestClient.put "#{@endpoint}#{path}", data.to_json, :content_type => :json, :accept => :json
114
+ end
115
+
116
+ def delete(path={})
117
+ RestClient.delete "#{@endpoint}#{path}"
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2015 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
+ lib = File.expand_path('../lib', __FILE__)
18
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
+ require 'zeus/api_client'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = "zeusclient"
23
+ spec.version = Zeus::APIClient::VERSION
24
+ spec.authors = ["Komei Shimamura"]
25
+ spec.email = ["komei.t.f@gmail.com"]
26
+
27
+ if spec.respond_to?(:metadata)
28
+ # spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
29
+ end
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"
35
+
36
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|icons)/}) }
37
+ spec.bindir = "exe"
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ["lib"]
40
+
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
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zeusclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Komei Shimamura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
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: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Client for Cisco Zeus. This allows users to send and receive data to
70
+ and from Cisco Zeus.
71
+ email:
72
+ - komei.t.f@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/zeus/api_client.rb
86
+ - lib/zeus/api_client/result.rb
87
+ - lib/zeus/api_client/version.rb
88
+ - zeusclient.gemspec
89
+ homepage: https://github.com/CiscoZeus/ruby-zeusclient
90
+ licenses:
91
+ - Apache 2.0
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby Client for Cisco Zeus
113
+ test_files: []