pingdom 0.1.4 → 0.1.6

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: ec0019c8887e2600c0ad0b892ebd9e00ccd427d1
4
- data.tar.gz: d9f0c1b704fa686b34720798c4d2f53f440aa1e5
3
+ metadata.gz: 903ee6f2adac2105596099e2105ff22c8b4f681b
4
+ data.tar.gz: b2744b0aee1013468c80c82d5a8d379722bcac79
5
5
  SHA512:
6
- metadata.gz: 3e2cdb42f5084b038f8ccba8f03fa6d5bfb09893b0dde8576fb076269485930ed80092a06c8811895d8f3aca041e724661c9483ae88fc69c06fe0cbfeef86ced
7
- data.tar.gz: 5d9fd6ddfca6d3fde03125758c94032f5563b867d269d9773e21837152baae904e85cf952162d28a568df4c0197591bf3baa9b8f7a63ae18634ab9efc90bb101
6
+ metadata.gz: 1f68477de6fb1fab126a899c48c30eb20fadfad26b7ac2f7b91e1e608dd15f4360f0d62c6acbd65afbe58fa0ad47dd0bcebf1f8934b168139c02ab5a52ff4b6e
7
+ data.tar.gz: 9d3cbcb180811f3bb49f9c718b562e6ed553bc7522aa0881e5d6a4483b53d75923e18a556de6d47fc166fae318a08364a7e6e84f19efdd3fc22ad2afd5a396d5
data/README.md CHANGED
@@ -55,8 +55,74 @@ checks.each do |check|
55
55
  To get one check using find, you need the id
56
56
 
57
57
  ```ruby
58
- check = Pingom::Check.find 85975
58
+ check = Pingdom::Check.find 85975
59
59
  # return a check or raise an error if the chech is not found
60
+
61
+ # with tags
62
+ check = Pingdom::Check.find 85975, include_tags: true
63
+ ```
64
+
65
+ ### Summary Average
66
+
67
+ Get the Sumary Average by check id:
68
+
69
+ ```ruby
70
+ average = Pingdom::SummaryAverage.find check_id
71
+
72
+ average.from # is a Time
73
+ => 1970-01-01 01:00:00 +0100
74
+
75
+ average.to # is a Time
76
+ => 2017-09-05 15:43:53 +0100
77
+
78
+ average.avgresponse # is a Integer
79
+ => 381
80
+
81
+ # with parameters
82
+
83
+ average = Pingdom::SummaryAverage.find check_id, from: 10.days.ago , to: 1.day.ago, probes: '44,33'
84
+
85
+ # includeuptime
86
+
87
+ average = Pingdom::SummaryAverage.find check_id, includeuptime: true
88
+ # get status data
89
+ average.status.totalup
90
+ average.status.totaldown
91
+ average.status.totalunknown
92
+
93
+ # bycountry
94
+
95
+ average = Pingdom::SummaryAverage.find check_id, bycountry: true
96
+
97
+ average.avgresponse # is an Array of Struct::AvgResponse
98
+ r = average.avgresponse.firt
99
+ r.country
100
+ => 'UK'
101
+
102
+ r.avgresponse
103
+ => 92
104
+
105
+ r.from # and r.to are Times
106
+ => 1970-01-01 01:00:00 +0100
107
+
108
+ # byprobe
109
+
110
+ average = Pingdom::SummaryAverage.find check_id, byprobe: true
111
+ a=average.probe_responses # is array of Struct::ProbeResponse
112
+
113
+ # Get data of each probe response
114
+ r=a.first
115
+ r.id # the id of the probe
116
+ r.avgresponse
117
+ r.n # integer
118
+ r.from
119
+ r.to
120
+
121
+ average.from # Time of request filter
122
+ => 1970-01-01 01:00:00 +0100
123
+ average.to # Time of request filter
124
+ => 2017-09-05 15:43:53 +0100
125
+
60
126
  ```
61
127
 
62
128
  ### Summary Outages
@@ -69,7 +135,7 @@ summary_outage = Pingdom::SummaryOutage.find check_id
69
135
 
70
136
  # With params from, to and order are not mandatory params
71
137
 
72
- summary_outage = Pingdom::SummaryOutage.find check_id , from: 2.days.ago, to: 1.days.ago, order: 'ask'
138
+ summary_outage = Pingdom::SummaryOutage.find check_id , from: 2.days.ago, to: 1.days.ago, order: 'desc'
73
139
 
74
140
  # get up and down times
75
141
  summary_outage.ups
@@ -87,6 +153,44 @@ summary_outage.downs min_interval: 180 # more than 3 minutes
87
153
 
88
154
  ```
89
155
 
156
+ ### Summary Performance
157
+
158
+ Get the Summary Performance by check id:
159
+
160
+ ```ruby
161
+
162
+ summary_performance= Pingodm::SummaryPerformance find check_id
163
+
164
+ # available params from: Time , to: Time, resolution: 'hour' | 'day'| 'week' , includeuptime: true | false
165
+
166
+ # When you find by a hour resolution you can get hours
167
+ summary_performance.hours.each do |h|
168
+ puts h.starttime # Time
169
+ puts h.avgresponse # Integer
170
+ puts h.uptime # Integer
171
+ puts h.downtime # Integer
172
+ puts h.unmonitored # Integer
173
+ end
174
+
175
+ # the same behavior with 'week' and 'day' resolutions, you can get the data of each one use the same methods.
176
+
177
+ summary_performance.weeks.is_a
178
+ => Array # of Struct::Week
179
+
180
+ summary_performance.day.is_a
181
+ => Array # of Struct::Day
182
+
183
+ ```
184
+
185
+ ### ServerTime
186
+
187
+ Easy way to get the servertime
188
+
189
+ ```ruby
190
+ Pingdom::ServerTime.time
191
+ => 2017-09-05 17:47:56 +0100 #Time object of the servertime
192
+ ```
193
+
90
194
  ## Development
91
195
 
92
196
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/pingdom/base.rb CHANGED
@@ -1,4 +1,7 @@
1
+ require 'json'
2
+
1
3
  module Pingdom
4
+
2
5
  class Base
3
6
 
4
7
  @@client = Client.new
data/lib/pingdom/check.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module Pingdom
4
2
 
5
3
  class Check < Pingdom::Base
@@ -0,0 +1,38 @@
1
+ module Pingdom
2
+
3
+ class ServerTime < Pingdom::Base
4
+
5
+ class << self
6
+
7
+ def path
8
+ '/servertime'
9
+ end
10
+
11
+ def get
12
+ parse client.get( path: path )
13
+
14
+ if body.include?('servertime')
15
+ server_time=self.new body
16
+ end
17
+
18
+ server_time
19
+
20
+ end
21
+
22
+ def time
23
+ get.servertime
24
+ end
25
+
26
+
27
+ end
28
+
29
+ attr_accessor :servertime
30
+
31
+ private
32
+
33
+ def time_attributes
34
+ %q{servertime}
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ module Pingdom
2
+
3
+ Struct.new('AvgResponse',:countryiso, :avgresponse)
4
+ Struct.new('ProbeResponse',:id, :avgresponse,:from,:n, :to)
5
+
6
+ class SummaryAverage < Pingdom::Base
7
+
8
+ class << self
9
+
10
+ def path
11
+ '/summary.average'
12
+ end
13
+
14
+ def collection_type
15
+ 'summary'
16
+ end
17
+
18
+ def permit
19
+ {
20
+ to: :valid_time?,
21
+ from: :valid_time?,
22
+ probes: :valid_int_list?,
23
+ includeuptime: :valid_boolean?,
24
+ bycountry: :valid_boolean?,
25
+ byprobe: :valid_boolean?
26
+ }
27
+ end
28
+
29
+ end
30
+
31
+ attr_accessor :responsetime, :status, :probe_responses
32
+
33
+ def avgresponse
34
+ data = responsetime['avgresponse'] || []
35
+ data.map do |v|
36
+ Struct::AvgResponse.new(v['countryiso'], v['avgresponse'])
37
+ end
38
+ end
39
+
40
+ def probe_responses
41
+ responsetime.each_pair.map do |k,v|
42
+ next if %q(from to).include?(k)
43
+ Struct::ProbeResponse.new(k.to_i,v['avgresponse'],Time.at(v['from']),v['n'], Time.at(v['to']))
44
+ end
45
+ end
46
+
47
+ def from
48
+ Time.at responsetime['from']
49
+ end
50
+
51
+ def to
52
+ Time.at responsetime['to']
53
+ end
54
+
55
+ end
56
+ end
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module Pingdom
4
2
 
5
3
  Struct.new('State',:status, :timefrom, :timeto) do
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module Pingdom
4
2
 
5
3
  Struct.new('Week',:starttime, :avgresponse, :uptime, :downtime, :unmonitored)
@@ -25,7 +23,7 @@ module Pingdom
25
23
  from: :valid_time?,
26
24
  resolution: :valid_resolution?,
27
25
  order: :valid_order?,
28
- includeuptime: :valid_boolean_str?
26
+ includeuptime: :valid_boolean?
29
27
  }
30
28
  end
31
29
 
@@ -28,6 +28,7 @@ module Pingdom
28
28
  def format
29
29
  validate_all.each_pair.map do |key, value|
30
30
  value=value.to_i if permit[key]==:valid_time?
31
+ value=value.to_s if permit[key]==:valid_boolean?
31
32
  [key, value]
32
33
  end.to_h
33
34
  end
@@ -48,8 +49,8 @@ module Pingdom
48
49
  %q(hour day week).include? resolution
49
50
  end
50
51
 
51
- def valid_boolean_str? boolstring
52
- ['true','false'].include? boolstring
52
+ def valid_boolean? bool
53
+ bool.is_a?(TrueClass) || bool.is_a?(FalseClass)
53
54
  end
54
55
 
55
56
  def valid_int_list? int_list
@@ -1,3 +1,3 @@
1
1
  module Pingdom
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/pingdom.rb CHANGED
@@ -5,7 +5,9 @@ require "pingdom/base"
5
5
  require 'pingdom/check'
6
6
  require 'pingdom/summary_outage'
7
7
  require 'pingdom/summary_performance'
8
+ require 'pingdom/summary_average'
8
9
  require 'pingdom/validator'
10
+ require 'pingdom/server_time'
9
11
  require 'active_support/core_ext/numeric/time'
10
12
  require 'active_support/core_ext/time/acts_like'
11
13
  require 'active_support/core_ext/time/calculations'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingdom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Piccinini Lagos
@@ -129,6 +129,8 @@ files:
129
129
  - lib/pingdom/base.rb
130
130
  - lib/pingdom/check.rb
131
131
  - lib/pingdom/client.rb
132
+ - lib/pingdom/server_time.rb
133
+ - lib/pingdom/summary_average.rb
132
134
  - lib/pingdom/summary_outage.rb
133
135
  - lib/pingdom/summary_performance.rb
134
136
  - lib/pingdom/validator.rb