uptrends 0.3.0 → 0.4.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: 69a8350abcaf27e3eb580f7d57966bbdb33383c0
4
- data.tar.gz: 657d3938ead33d2be4b33edcb7380e8361d3f938
3
+ metadata.gz: 746c1068cf00e9f2f419d3188c0a16f71834ff4e
4
+ data.tar.gz: eb43107d3d62e94e7489c0e976943cbd4293c367
5
5
  SHA512:
6
- metadata.gz: 7d4e7c9662118f8a2028e72f8798ddecb0ec6fbbb728e48fb369af38cee7f08126e6919b9eaf68943a6be086fc1b4a875e8642b824f48d3a19979e818793c52e
7
- data.tar.gz: b8518d4d9d8765cd5fdcb1f5b69ed71e58316b34e478fb8f681b72316013bd597a021fe937850c83898fbb2427525d5991bc9b970dd3d8c3229b0daeaac6d8ee
6
+ metadata.gz: 3bbf3f9381879d87824d8f23db448193fa622bc313c4989e9cc70c24881a760aa0448c63df0413203ebb4868195a4327100fbf3296b0ecfa554086072d638d98
7
+ data.tar.gz: bd898163b685d2f0b6422d42e96540aa56371839a48c146c63fd950d4aa5b815c948b3089c080f8c70cda1d77bfad760aa08bad5d417ae459a5e309d406ae0b6
data/README.md CHANGED
@@ -22,9 +22,9 @@ Or install it yourself as:
22
22
 
23
23
  First initialize an instance of the API Client and then we play with it:
24
24
 
25
- require 'uptrends/api_client'
26
- u = Uptrends::ApiClient.new(username: 'my@email.com', password: 'MyP@sswo0rd')
27
- # => #<Uptrends::ApiClient:0x00000101309e48 @username="my@email.com">
25
+ require 'uptrends'
26
+ u = Uptrends::Client.new(username: 'my@email.com', password: 'MyP@sswo0rd')
27
+ # => #<Uptrends::Client:0x00000101309e48 @username="my@email.com">
28
28
 
29
29
  Query your account for all probes:
30
30
 
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ require 'uptrends/client'
3
+ require 'uri'
4
+ require 'rack'
5
+
6
+ def parse_uri_for_db(url)
7
+ begin
8
+ uri = URI(url)
9
+ Rack::Utils.parse_query(uri.query)['dbname'].downcase
10
+ rescue URI::InvalidURIError
11
+ return nil
12
+ end
13
+ end
14
+
15
+ def parse_uri(url)
16
+ begin
17
+ uri = URI(url)
18
+ "#{uri.scheme}://#{uri.host}".downcase
19
+ rescue URI::InvalidURIError
20
+ return nil
21
+ end
22
+ end
23
+
24
+ (puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
25
+
26
+ u = Uptrends::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
27
+
28
+ filename = ARGV.first
29
+ site_urls = File.open(filename)
30
+ site_urls = site_urls.readlines.map { |x| x.delete("\n") }.compact
31
+
32
+ # Build array of URLs to possibly add to Uptrends
33
+ uri_array = site_urls.map do |url|
34
+ uri = parse_uri(url)
35
+ db = parse_uri_for_db(url)
36
+ next unless uri && db
37
+ [uri, db]
38
+ end.compact.uniq
39
+
40
+ # Build array of Uptrends Probe URLs that already exist
41
+ probe_uri_array = u.probes.map do |x|
42
+ next unless x.probe_type =~ /Https?/
43
+ parse_uri(x.url)
44
+ end.compact
45
+
46
+ uri_array.each do |uri|
47
+ url = uri[0]
48
+ db = uri[1]
49
+
50
+ # If URL contains certain things we don't want to add it Uptrends
51
+ next if url =~ /\.xxx/i ||
52
+ url =~ /backup/i ||
53
+ url =~ /clusterbogota/i ||
54
+ url =~ /archive/i ||
55
+ url =~ /thebigawards/i ||
56
+ url =~ /staging/i ||
57
+ url =~ /qa(languages)?[0-9gaspb]+(prod)?\./i
58
+ # If the URL already exists at Uptrends we don't want to add it again!
59
+ next if probe_uri_array.include?(url)
60
+
61
+ url = "#{uri[0]}/User/Login"
62
+ db = uri[1]
63
+
64
+ puts "Adding a \"#{url}\" probe"
65
+ begin
66
+ new_probe = u.create_http_probe(name: db, url: url, match_pattern: 'j_username')
67
+ rescue Uptrends::ApiError => e
68
+ puts e.message
69
+ end
70
+ end
71
+
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'uptrends/api_client'
2
+ require 'uptrends/client'
3
3
 
4
4
  (puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
5
5
 
6
- u = Uptrends::ApiClient.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
6
+ u = Uptrends::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
7
7
 
8
8
  # select our probe group by name
9
9
  linux_probe_group = u.probe_groups.select { |x| x.name =~ /Linux/}.first
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'uptrends/api_client'
2
+ require 'uptrends/client'
3
3
 
4
4
  (puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
5
5
 
6
- u = Uptrends::ApiClient.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
6
+ u = Uptrends::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
7
7
 
8
8
  u.probes.each do |x|
9
9
  next if x.dns_lookup_mode == 'Local' && x.timeout == 20000 && x.tcp_connect_timeout == 5000
@@ -1,4 +1,5 @@
1
1
  require "uptrends/version"
2
+ require "uptrends/client"
2
3
 
3
4
  module Uptrends
4
5
  # Your code goes here...
@@ -0,0 +1,4 @@
1
+ module Uptrends
2
+ class ApiError < ::StandardError
3
+ end
4
+ end
@@ -0,0 +1,161 @@
1
+ require "httparty"
2
+ require "uptrends/probe"
3
+ require "uptrends/probe_group"
4
+ require "uptrends/utils"
5
+ require "uptrends/api_error"
6
+
7
+ module Uptrends
8
+ class Client
9
+ include HTTParty
10
+ format :json
11
+ base_uri('https://api.uptrends.com/v3')
12
+
13
+ attr_reader :username
14
+
15
+ def initialize(opts = {})
16
+ @username = opts[:username] ? opts[:username] : fail("You must specify the :username option")
17
+ password = opts[:password] ? opts[:password] : fail("You must specify the :password option")
18
+
19
+ # This makes it so that every request uses basic auth
20
+ self.class.basic_auth(@username, password)
21
+ # This makes it so that every request uses ?format=json
22
+ self.class.default_params({format: 'json'})
23
+ # This makes it so that every request uses ?format=json
24
+ self.class.headers({'Content-Type' => 'application/json', 'Accept' => 'application/json'})
25
+ end
26
+
27
+ def probes(opts = {})
28
+ if opts[:refresh]
29
+ @probes = get_probes
30
+ else
31
+ @probes ||= get_probes
32
+ end
33
+ end
34
+
35
+ def probe_groups
36
+ @probe_groups ||= get_probe_groups
37
+ end
38
+
39
+ def get_probe_group_members(opts = {})
40
+ group = opts[:group]
41
+ fail("You must pass a probe group using group: option.") unless Uptrends::ProbeGroup === group
42
+ group_guid = opts[:group].guid ? opts[:group].guid : fail("The probe group you passed does not have a guid.")
43
+
44
+ res = self.class.get("/probegroups/#{group_guid}/members")
45
+ parsed_response = raise_or_return(res)
46
+ probe_group_members = parsed_response.inject([]) do |memo, x|
47
+ memo << Uptrends::Probe.new(x)
48
+ memo
49
+ end
50
+ end
51
+
52
+ def add_probe(opts = {})
53
+ probe = Uptrends::Probe.new(opts)
54
+ res = self.class.post("/probes", body: Uptrends::Utils.gen_request_body(probe))
55
+ parsed_response = raise_or_return(res)
56
+ new_probe = Uptrends::Probe.new(parsed_response)
57
+
58
+ probes << new_probe
59
+
60
+ new_probe
61
+ end
62
+
63
+ def add_probe_to_group(opts = {})
64
+ probe = opts[:probe]
65
+ group = opts[:group]
66
+
67
+ fail("You must pass a probe and probe group using probe: and group: opts.") unless Uptrends::Probe === probe && Uptrends::ProbeGroup === group
68
+
69
+ probe_guid = opts[:probe].guid ? opts[:probe].guid : fail("The probe you passed does not have a guid.")
70
+ group_guid = opts[:group].guid ? opts[:group].guid : fail("The probe group you passed does not have a guid.")
71
+
72
+
73
+ post_body = JSON.dump({"ProbeGuid" => probe_guid})
74
+ res = self.class.post("/probegroups/#{group_guid}/members", body: post_body)
75
+ raise_or_return(res)
76
+ end
77
+
78
+ def update_probe(probe)
79
+ res = self.class.put("/probes/#{probe.guid}", body: Uptrends::Utils.gen_request_body(probe))
80
+ raise_or_return(res)
81
+ end
82
+
83
+ def delete_probe(probe)
84
+ res = self.class.delete("/probes/#{probe.guid}")
85
+ raise_or_return(res)
86
+
87
+ probes.delete_if { |x| x.guid == probe.guid }
88
+ end
89
+
90
+ def create_http_probe(opts = {})
91
+ name = opts[:name] ? opts[:name] : fail("You must provide a name!")
92
+ url = opts[:url] ? opts[:url] : fail("You must provide a URL!")
93
+ check_frequency = opts[:check_frequency] ? opts[:check_frequency] : 15
94
+ match_pattern = opts[:match_pattern]
95
+
96
+ probe = Uptrends::Probe.new(gen_new_probe_hash(name, url, check_frequency, match_pattern))
97
+ res = self.class.post("/probes", body: Uptrends::Utils.gen_request_body(probe))
98
+ parsed_response = raise_or_return(res)
99
+ new_probe = Uptrends::Probe.new(parsed_response)
100
+
101
+ probes << new_probe
102
+
103
+ new_probe
104
+ end
105
+
106
+ private
107
+ def get_probes
108
+ get_all(Uptrends::Probe)
109
+ end
110
+
111
+ def get_probe_groups
112
+ get_all(Uptrends::ProbeGroup)
113
+ end
114
+
115
+ def get_all(type)
116
+ case type.new
117
+ when Uptrends::ProbeGroup
118
+ uri = '/probegroups'
119
+ when Uptrends::Probe
120
+ uri = '/probes'
121
+ else
122
+ fail("You passed an unknown type. Try Uptrends::Probe or Uptrends::ProbeGroup")
123
+ end
124
+
125
+ res = self.class.get(uri)
126
+
127
+ parsed_response = raise_or_return(res)
128
+ all = parsed_response.inject([]) do |memo, x|
129
+ memo << type.new(x)
130
+ memo
131
+ end
132
+ end
133
+
134
+ def gen_new_probe_hash(name, url, check_frequency = 15, match_pattern = nil)
135
+ base_hash = {"Name"=>"", "URL"=>"", "CheckFrequency"=>check_frequency, "IsActive"=>true, "GenerateAlert"=>true, "Notes"=>"", "PerformanceLimit1"=>60000, "PerformanceLimit2"=>60000, "ErrorOnLimit1"=>false, "ErrorOnLimit2"=>false, "MinBytes"=>0, "ErrorOnMinBytes"=>false, "Timeout"=>30000, "TcpConnectTimeout"=>10000, "MatchPattern"=>"", "DnsLookupMode"=>"Local", "UserAgent"=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)", "UserName"=>"", "Password"=>"", "IsCompetitor"=>false, "Checkpoints"=>"", "HttpMethod"=>"Get", "PostData"=>""}
136
+
137
+ if url =~ %r{^https:}i
138
+ base_hash.merge!({"Name"=>name, "URL"=>url, "ProbeType"=>"Https", "Port"=>443})
139
+ elsif url =~ %r{^http:}i
140
+ base_hash.merge!({"Name"=>name, "URL"=>url, "ProbeType"=>"Http", "Port"=>80})
141
+ else
142
+ fail("The URL you provided didn't start with http or https!")
143
+ end
144
+
145
+ base_hash.merge!({"MatchPattern"=>match_pattern}) unless match_pattern.nil?
146
+
147
+ base_hash
148
+ end
149
+
150
+ def raise_or_return(result)
151
+ response_code = result.response.code.to_i
152
+ case response_code
153
+ when 200...300
154
+ result.parsed_response
155
+ else
156
+ raise Uptrends::ApiError.new(result.parsed_response)
157
+ end
158
+ end
159
+
160
+ end
161
+ end
@@ -5,10 +5,10 @@ module Uptrends
5
5
  class Utils
6
6
  def self.gen_request_body(object)
7
7
  new_hash = object.original_hash.inject({}) do |memo,(k,v)|
8
- if k == 'Guid'
8
+ if k.to_s.underscore == 'guid'
9
9
  memo
10
10
  else
11
- memo[k] = object.send(k.underscore)
11
+ memo[k.to_s.camelize] = object.send(k.to_s.underscore)
12
12
  memo
13
13
  end
14
14
  end
@@ -30,12 +30,14 @@ module Uptrends
30
30
  attributes = []
31
31
  object.original_hash.each_pair do |k,v|
32
32
 
33
- k = k.underscore
33
+ k = k.to_s.underscore
34
34
  case k
35
35
  when "guid"
36
+ # setup attr_reader for guid and set it's value.
36
37
  object.class.send(:attr_reader, k)
37
38
  object.instance_variable_set("@#{k}", v)
38
39
  else
40
+ # setup a attr_accessor for all other attributes
39
41
  object.class.send(:attr_accessor, k)
40
42
  object.send("#{k}=", v)
41
43
  end
@@ -1,3 +1,3 @@
1
1
  module Uptrends
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "codeclimate-test-reporter"
2
2
  CodeClimate::TestReporter.start
3
3
  require_relative '../lib/uptrends'
4
- require_relative '../lib/uptrends/api_client'
4
+ require_relative '../lib/uptrends/client'
5
5
  require_relative '../lib/uptrends/probe'
6
6
  require_relative '../lib/uptrends/probe_group'
7
7
  require_relative '../lib/uptrends/utils'
@@ -1,6 +1,6 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
- describe Uptrends::ApiClient do
3
+ describe Uptrends::Client do
4
4
  let(:username) { ENV['UPTRENDS_USERNAME'] }
5
5
  let(:password) { ENV['UPTRENDS_PASSWORD'] }
6
6
 
@@ -14,36 +14,36 @@ describe Uptrends::ApiClient do
14
14
  end
15
15
  end
16
16
 
17
- it "must be an instance of Uptrends::ApiClient" do
18
- Uptrends::ApiClient.new(username: username, password: password).must_be_instance_of Uptrends::ApiClient
17
+ it "must be an instance of Uptrends::Client" do
18
+ Uptrends::Client.new(username: username, password: password).must_be_instance_of Uptrends::Client
19
19
  end
20
20
 
21
21
  describe "Initializing with a username and password is required" do
22
22
  it "should raise RuntimeError when username is not provided." do
23
- proc { Uptrends::ApiClient.new(password: password) }.must_raise RuntimeError
23
+ proc { Uptrends::Client.new(password: password) }.must_raise RuntimeError
24
24
  end
25
25
 
26
26
  it "should raise excepetion when password is not provided." do
27
- proc { Uptrends::ApiClient.new(username: username) }.must_raise RuntimeError
27
+ proc { Uptrends::Client.new(username: username) }.must_raise RuntimeError
28
28
  end
29
29
  end
30
30
 
31
31
  describe "default attributes" do
32
32
  it "must include httparty methods" do
33
- Uptrends::ApiClient.must_include HTTParty
33
+ Uptrends::Client.must_include HTTParty
34
34
  end
35
35
 
36
36
  it "must have the base url set to the Uptrends API endpoint" do
37
- Uptrends::ApiClient.base_uri.must_equal 'https://api.uptrends.com/v3'
37
+ Uptrends::Client.base_uri.must_equal 'https://api.uptrends.com/v3'
38
38
  end
39
39
 
40
40
  it "must have the format set to json" do
41
- Uptrends::ApiClient.format.must_equal :json
41
+ Uptrends::Client.format.must_equal :json
42
42
  end
43
43
  end
44
44
 
45
45
  describe "When initializing a new Uptrends::Client with a username and password" do
46
- let(:uac) { Uptrends::ApiClient.new(username: username, password: password) }
46
+ let(:uac) { Uptrends::Client.new(username: username, password: password) }
47
47
 
48
48
  it "auth[:username] should match the username provided" do
49
49
  uac.class.default_options[:basic_auth][:username].must_equal username
@@ -63,7 +63,7 @@ describe Uptrends::ApiClient do
63
63
  end
64
64
 
65
65
  describe "querying Uptrends" do
66
- let(:uac) { Uptrends::ApiClient.new(username: username, password: password) }
66
+ let(:uac) { Uptrends::Client.new(username: username, password: password) }
67
67
 
68
68
  describe "GET Probes" do
69
69
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uptrends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Barnett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -53,17 +53,19 @@ files:
53
53
  - LICENSE.txt
54
54
  - README.md
55
55
  - Rakefile
56
+ - examples/add_new_probes.rb
56
57
  - examples/add_probes_to_probe_group.rb
57
58
  - examples/update_all_probe_attributes.rb
58
59
  - lib/uptrends.rb
59
- - lib/uptrends/api_client.rb
60
+ - lib/uptrends/api_error.rb
61
+ - lib/uptrends/client.rb
60
62
  - lib/uptrends/probe.rb
61
63
  - lib/uptrends/probe_group.rb
62
64
  - lib/uptrends/utils.rb
63
65
  - lib/uptrends/version.rb
64
66
  - spec/fixtures/vcr_cassettes/GET_Probes.yml
65
67
  - spec/spec_helper.rb
66
- - spec/uptrends/api_client_spec.rb
68
+ - spec/uptrends/client_spec.rb
67
69
  - spec/uptrends/probe_group_spec.rb
68
70
  - spec/uptrends/probe_spec.rb
69
71
  - uptrends.gemspec
@@ -87,13 +89,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
89
  version: '0'
88
90
  requirements: []
89
91
  rubyforge_project:
90
- rubygems_version: 2.2.2
92
+ rubygems_version: 2.4.1
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: Ruby wrapper around the Uptrends API, http://www.uptrends.com/
94
96
  test_files:
95
97
  - spec/fixtures/vcr_cassettes/GET_Probes.yml
96
98
  - spec/spec_helper.rb
97
- - spec/uptrends/api_client_spec.rb
99
+ - spec/uptrends/client_spec.rb
98
100
  - spec/uptrends/probe_group_spec.rb
99
101
  - spec/uptrends/probe_spec.rb
@@ -1,130 +0,0 @@
1
- require "httparty"
2
- require "uptrends/probe"
3
- require "uptrends/probe_group"
4
- require "uptrends/utils"
5
-
6
- module Uptrends
7
- class ApiClient
8
- include HTTParty
9
- format :json
10
- base_uri('https://api.uptrends.com/v3')
11
-
12
- attr_reader :username
13
-
14
- def initialize(options = {})
15
- @username = options[:username] ? options[:username] : fail("You must specify the :username option")
16
- password = options[:password] ? options[:password] : fail("You must specify the :password option")
17
-
18
- # This makes it so that every request uses basic auth
19
- self.class.basic_auth(@username, password)
20
- # This makes it so that every request uses ?format=json
21
- self.class.default_params({format: 'json'})
22
- # This makes it so that every request uses ?format=json
23
- self.class.headers({'Content-Type' => 'application/json', 'Accept' => 'application/json'})
24
- end
25
-
26
- def probes
27
- @probes ||= get_probes
28
- end
29
-
30
- def probe_groups
31
- @probe_groups ||= get_probe_groups
32
- end
33
-
34
- private
35
- def get_probes
36
- get_all(Uptrends::Probe)
37
- end
38
-
39
- def get_probe_groups
40
- get_all(Uptrends::ProbeGroup)
41
- end
42
-
43
- def get_all(type)
44
- case type.new
45
- when Uptrends::ProbeGroup
46
- uri = '/probegroups'
47
- when Uptrends::Probe
48
- uri = '/probes'
49
- else
50
- fail("You passed an unknown type. Try Uptrends::Probe or Uptrends::ProbeGroup")
51
- end
52
-
53
- parsed_response = self.class.get(uri).parsed_response
54
-
55
- all = parsed_response.inject([]) do |memo, x|
56
- memo << type.new(x)
57
- memo
58
- end
59
- end
60
-
61
- public
62
- def get_probe_group_members(options = {})
63
- group = options[:group]
64
- fail("You must pass a probe group using group: option.") unless Uptrends::ProbeGroup === group
65
- group_guid = options[:group].guid ? options[:group].guid : fail("The probe group you passed does not have a guid.")
66
-
67
- parsed_response = self.class.get("/probegroups/#{group_guid}/members").parsed_response
68
- probe_group_members = parsed_response.inject([]) do |memo, x|
69
- memo << Uptrends::Probe.new(x)
70
- memo
71
- end
72
- end
73
-
74
- def add_probe_to_group(options = {})
75
- probe = options[:probe]
76
- group = options[:group]
77
-
78
- fail("You must pass a probe and probe group using probe: and group: options.") unless Uptrends::Probe === probe && Uptrends::ProbeGroup === group
79
-
80
- probe_guid = options[:probe].guid ? options[:probe].guid : fail("The probe you passed does not have a guid.")
81
- group_guid = options[:group].guid ? options[:group].guid : fail("The probe group you passed does not have a guid.")
82
-
83
-
84
- post_body = JSON.dump({"ProbeGuid" => probe_guid})
85
- self.class.post("/probegroups/#{group_guid}/members", body: post_body)
86
- end
87
-
88
- def update_probe(probe)
89
- self.class.put("/probes/#{probe.guid}", body: Uptrends::Utils.gen_request_body(probe))
90
- end
91
-
92
- def delete_probe(probe)
93
- self.class.delete("/probes/#{probe.guid}")
94
-
95
- @probes ||= get_probes
96
- @probes.delete_if { |x| x.guid == probe.guid }
97
- end
98
-
99
- def create_http_probe(options = {})
100
- name = options[:name] ? options[:name] : fail("You must provide a name!")
101
- url = options[:url] ? options[:url] : fail("You must provide a URL!")
102
- match_pattern = options[:match_pattern]
103
-
104
- probe = Uptrends::Probe.new(gen_new_probe_hash(name, url, match_pattern))
105
- response = self.class.post("/probes", body: Uptrends::Utils.gen_request_body(probe))
106
- new_probe = Uptrends::Probe.new(response.parsed_response)
107
-
108
- @probes ||= get_probes
109
- @probes << new_probe
110
- end
111
-
112
- private
113
- def gen_new_probe_hash(name, url, match_pattern = nil)
114
- base_hash = {"Name"=>"", "URL"=>"", "CheckFrequency"=>5, "IsActive"=>true, "GenerateAlert"=>true, "Notes"=>"", "PerformanceLimit1"=>60000, "PerformanceLimit2"=>60000, "ErrorOnLimit1"=>false, "ErrorOnLimit2"=>false, "MinBytes"=>0, "ErrorOnMinBytes"=>false, "Timeout"=>30000, "TcpConnectTimeout"=>10000, "MatchPattern"=>"", "DnsLookupMode"=>"Local", "UserAgent"=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)", "UserName"=>"", "Password"=>"", "IsCompetitor"=>false, "Checkpoints"=>"", "HttpMethod"=>"Get", "PostData"=>""}
115
-
116
- if url =~ %r{^https:}i
117
- base_hash.merge!({"Name"=>name, "URL"=>url, "ProbeType"=>"Https", "Port"=>443})
118
- elsif url =~ %r{^http:}i
119
- base_hash.merge!({"Name"=>name, "URL"=>url, "ProbeType"=>"Http", "Port"=>80})
120
- else
121
- fail("The URL you provided didn't start with http or https!")
122
- end
123
-
124
- base_hash.merge!({"MatchPattern"=>match_pattern}) unless match_pattern.nil?
125
-
126
- base_hash
127
- end
128
-
129
- end
130
- end