boundary_event 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b1e2d7f6f991c41bc4697cdb7d03f5506d50493
4
+ data.tar.gz: 7b968d0802a2f800146be5b145f09af09b0a9f86
5
+ SHA512:
6
+ metadata.gz: 7898649325043634cd138d37b117b3c1e8fa02d2ac33bf7bac4961da45bf12add9f16ec65fcf3ab5e437e3e1ec6ae66658391ab848033ede09499f6ebfca390d
7
+ data.tar.gz: 2b63167bfe0f9c32d3bbdb4041099413483b542b821a0b0ffdaea521c398fafd1f6e718956af128ee230e31aa54514f0f10a219acf72f39b44619d615c011d4b
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ driver.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boundary_event.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nolan Davidson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # BoundaryEvent
2
+
3
+ Wrapper for the Boundary Event API. Currently only event creation is implemented.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'boundary_event'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install boundary_event
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boundary_event/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boundary_event"
8
+ spec.version = BoundaryEvent::VERSION
9
+ spec.authors = ["Nolan Davidson"]
10
+ spec.email = ["nolan.davidson@gmail.com"]
11
+ spec.description = "Wrapper for Boundary Event API"
12
+ spec.summary = "Wrapper for Boundary Event API"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 1.8.7"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_dependency "json"
25
+ end
@@ -0,0 +1,82 @@
1
+ require "boundary_event/version"
2
+ require "base64"
3
+ require "uri"
4
+ require "net/http"
5
+ require "net/https"
6
+ require "json"
7
+
8
+ BOUNDARY_API_URL = "api.boundary.com"
9
+
10
+ class BoundaryEvent
11
+ # Attributes to hold credential data
12
+ attr_accessor :api_key, :org_id
13
+
14
+ # Attributes to hold event data
15
+ attr_accessor :event_data
16
+
17
+ def initialize(params = {})
18
+ @api_key = params.fetch(:api_key, nil)
19
+ @org_id = params.fetch(:org_id, nil)
20
+ populate_event(params)
21
+ end
22
+
23
+ def populate_event(params = {})
24
+ @event_data = {
25
+ :title => (params.fetch(:title, nil) unless !params.has_key?(:title)),
26
+ :tags => (params.fetch(:tags, nil) unless !params.has_key?(:tags)),
27
+ :status => (params.fetch(:status, nil) unless !params.has_key?(:status)),
28
+ :severity => (params.fetch(:severity, nil) unless !params.has_key?(:severity)),
29
+ :message => (params.fetch(:message, nil) unless !params.has_key?(:message)),
30
+ :properties => (params.fetch(:properties, nil) unless !params.has_key?(:properties)),
31
+ :source => (params.fetch(:source, nil) unless !params.has_key?(:source)),
32
+ :sender => (params.fetch(:sender, nil) unless !params.has_key?(:sender)),
33
+ :fingerprintFields => (params.fetch(:fingerprint_fields, nil) unless !params.has_key?(:fingerprint_fields)),
34
+ :message => (params.fetch(:message, nil) unless !params.has_key?(:message)),
35
+ }
36
+ end
37
+
38
+ def send_event
39
+ # Encode API key
40
+ key = api_key_encode("#{@api_key}:")
41
+
42
+ # Set headers for HTTP request
43
+ headers = {
44
+ "Authorization" => "Basic #{key}",
45
+ "Content-Type" => "application/json"
46
+ }
47
+
48
+ uri = URI("https://#{BOUNDARY_API_URL}/#{org_id}/events")
49
+ http_conn = Net::HTTP.new(uri.host, uri.port)
50
+ http_conn.use_ssl = true
51
+
52
+ begin
53
+ timeout(10) do
54
+ request = Net::HTTP::Post.new(uri.request_uri)
55
+ request.body = @event_data.delete_if { |k,v| v.nil? }.to_json
56
+
57
+ # Set HTTP headers (credentials, content type)
58
+ headers.each{|k,v|
59
+ request[k] = v
60
+ }
61
+
62
+ event_create = http_conn.request(request)
63
+
64
+ if event_create.kind_of?(Net::HTTPSuccess)
65
+ puts "Boundary event successfully created"
66
+ else
67
+ $stderr.print "Request to #{uri.request_uri} responded with #{event_create.code}\n"
68
+ $stderr.print "#{event_create.body}\n"
69
+ end
70
+ end
71
+ rescue Timeout::Error
72
+ $stderr.print "Timed out while creating Boundary Event"
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def api_key_encode(key)
79
+ encoded_key = Base64.encode64(key).strip
80
+ encoded_key.gsub("\n", "")
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ class BoundaryEvent
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boundary_event
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nolan Davidson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Wrapper for Boundary Event API
56
+ email:
57
+ - nolan.davidson@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - boundary_event.gemspec
68
+ - lib/boundary_event.rb
69
+ - lib/boundary_event/version.rb
70
+ homepage: ''
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.7
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.1.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Wrapper for Boundary Event API
94
+ test_files: []