pingdom 0.1.0.pre → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +66 -3
- data/lib/pingdom/base.rb +126 -0
- data/lib/pingdom/check.rb +16 -9
- data/lib/pingdom/client.rb +5 -13
- data/lib/pingdom/summary_outage.rb +45 -0
- data/lib/pingdom/summary_performance.rb +50 -0
- data/lib/pingdom/version.rb +1 -1
- data/lib/pingdom.rb +13 -1
- data/pingdom.gemspec +1 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a45132f86fb8147a8460e7d24e5e1e59a54e6b13
|
4
|
+
data.tar.gz: 546aaf6606c793da5747fcecbac4f20fd5b7b3ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34324306c1c34ddb73626181e5cf7e8155b3cea840059340429ca167fce604866964bf5a73a1d0ea3f42ab4c2dac121fd91c3ec53579ad7aac3e0c89e811a34e
|
7
|
+
data.tar.gz: 14605b20900211985c6d38c524e732b29e07ca2272b0d02c48d6802fe7cfab180f39379ae9625d64a4079f7ed384cd0e76ec6168e1a60a158d071703cbe27736
|
data/README.md
CHANGED
@@ -1,8 +1,26 @@
|
|
1
1
|
# Pingdom
|
2
|
+
This a free software library to get data from api.pingdom.com, is a Diego Piccinini and BookingBug contribution to the free software and open source community.
|
2
3
|
|
3
|
-
|
4
|
+
It is not oficial. It has 2 ways to setup the client
|
4
5
|
|
5
|
-
|
6
|
+
- Using a dotenv file `.env` file
|
7
|
+
|
8
|
+
```bash
|
9
|
+
#.env
|
10
|
+
PINGDOM_USERNAME=your pingodom email here
|
11
|
+
PINGDOM_PASSWORD=your pingdom password here
|
12
|
+
PINGDOM_KEY=your pingdom key here
|
13
|
+
#PINGDOM_VERSION= optional you cuould change the api/{version} here
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
- Or udate the client like:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
|
21
|
+
Pingdom::Check.update_client username: 'your pingdom@email here', password: 'your pingdom password here' , key: 'your pingdom key here'
|
22
|
+
|
23
|
+
```
|
6
24
|
|
7
25
|
## Installation
|
8
26
|
|
@@ -22,7 +40,52 @@ Or install it yourself as:
|
|
22
40
|
|
23
41
|
## Usage
|
24
42
|
|
25
|
-
|
43
|
+
### Checks
|
44
|
+
|
45
|
+
To get all checks
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
checks = Pingdom::Check.all
|
49
|
+
checks.each do |check|
|
50
|
+
puts check.name
|
51
|
+
puts check.id
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
To get one check using find, you need the id
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
check = Pingom::Check.find 85975
|
59
|
+
# return a check or raise an error if the chech is not found
|
60
|
+
```
|
61
|
+
|
62
|
+
### Summary Outages
|
63
|
+
|
64
|
+
Get the Summary Outage by check id:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
|
68
|
+
summary_outage = Pingdom::SummaryOutage.find check_id
|
69
|
+
|
70
|
+
# With params from, to and order are not mandatory params
|
71
|
+
|
72
|
+
summary_outage = Pingdom::SummaryOutage.find check_id , from: 2.days.ago, to: 1.days.ago, order: 'ask'
|
73
|
+
|
74
|
+
# get up and down times
|
75
|
+
summary_outage.ups
|
76
|
+
=> 120
|
77
|
+
|
78
|
+
summary_outage.downs
|
79
|
+
=> 4
|
80
|
+
|
81
|
+
# get up and down times with min_interval to filter (in seconds)
|
82
|
+
summary_outage.ups min_interval: 300 # more than 5 minuts
|
83
|
+
=> 10
|
84
|
+
|
85
|
+
summary_outage.downs min_interval: 180 # more than 3 minutes
|
86
|
+
=> 2
|
87
|
+
|
88
|
+
```
|
26
89
|
|
27
90
|
## Development
|
28
91
|
|
data/lib/pingdom/base.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Pingdom
|
2
|
+
class Base
|
3
|
+
|
4
|
+
@@client = Client.new
|
5
|
+
@@params= {}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def update_client username: , password: , key:
|
10
|
+
@@client = Client.new u: username, p: password, k: key
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
parse client.get( params: params , path: path )
|
15
|
+
collection.map do |data|
|
16
|
+
self.new data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find id, from: nil, to: nil, order: nil, resolution: nil, includeuptime: nil
|
21
|
+
|
22
|
+
@@params={}
|
23
|
+
|
24
|
+
@@params[:from]= from.to_i if from
|
25
|
+
@@params[:to]= to.to_i if to
|
26
|
+
@@params[:order]= order if order and %q(ask desc).include?(order)
|
27
|
+
@@params[:resolution]= resolution if resolution and %q(hour day week).include?(resolution)
|
28
|
+
@@params[:includeuptime]= includeuptime if includeuptime and %q(true false).include?(includeuptime)
|
29
|
+
|
30
|
+
parse client.get( path: "#{path}/#{id}" , params: params)
|
31
|
+
|
32
|
+
@@params={}
|
33
|
+
raise "#{id} not found" if status!=200
|
34
|
+
self.new body[collection_type]
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def path
|
39
|
+
end
|
40
|
+
|
41
|
+
def collection_type
|
42
|
+
path[1..-2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse response
|
46
|
+
@@body= JSON.parse response.body
|
47
|
+
@@status = response.status
|
48
|
+
end
|
49
|
+
|
50
|
+
def client
|
51
|
+
@@client
|
52
|
+
end
|
53
|
+
|
54
|
+
def error?
|
55
|
+
body.has_key?'error'
|
56
|
+
end
|
57
|
+
|
58
|
+
def body
|
59
|
+
@@body
|
60
|
+
end
|
61
|
+
|
62
|
+
def status
|
63
|
+
@@status
|
64
|
+
end
|
65
|
+
|
66
|
+
def params
|
67
|
+
@@params
|
68
|
+
end
|
69
|
+
|
70
|
+
def params= value
|
71
|
+
@@params=value
|
72
|
+
end
|
73
|
+
|
74
|
+
def collection
|
75
|
+
body[path[1..-1]]
|
76
|
+
end
|
77
|
+
|
78
|
+
def total
|
79
|
+
body['counts']['total']
|
80
|
+
end
|
81
|
+
|
82
|
+
def limited
|
83
|
+
body['counts']['limited']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
attr_accessor :additional_field
|
88
|
+
|
89
|
+
def initialize data
|
90
|
+
@additional_field={}
|
91
|
+
data.each_pair do |k,v|
|
92
|
+
v=Time.at(v) if is_time_attribute?(k)
|
93
|
+
|
94
|
+
method="#{k}=".to_sym
|
95
|
+
if self.methods.include?(method)
|
96
|
+
self.send(method,v)
|
97
|
+
else
|
98
|
+
self.add(k, v)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def add key, value
|
104
|
+
additional_field[key.to_sym]=value
|
105
|
+
end
|
106
|
+
|
107
|
+
def get key
|
108
|
+
key=key.to_sym
|
109
|
+
if self.methods.include?(key)
|
110
|
+
self.send key
|
111
|
+
else
|
112
|
+
additional_field[key]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
def time_attributes
|
118
|
+
[]
|
119
|
+
end
|
120
|
+
|
121
|
+
def is_time_attribute? key
|
122
|
+
time_attributes.include?(key)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
data/lib/pingdom/check.rb
CHANGED
@@ -2,21 +2,28 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Pingdom
|
4
4
|
|
5
|
-
class Check
|
5
|
+
class Check < Pingdom::Base
|
6
6
|
|
7
7
|
class << self
|
8
|
-
attr_accessor :body, :status
|
9
8
|
|
10
|
-
def
|
11
|
-
|
12
|
-
@@status = response.status
|
13
|
-
end
|
14
|
-
|
15
|
-
def error?
|
16
|
-
@@body.has_key?'error'
|
9
|
+
def path
|
10
|
+
'/checks'
|
17
11
|
end
|
18
12
|
|
19
13
|
end
|
20
14
|
|
15
|
+
attr_accessor :id, :created, :name, :hostname, :use_legacy_notifications,
|
16
|
+
:resolution, :type, :ipv6, :lasterrortime, :lasttesttime, :lastresponsetime,
|
17
|
+
:status, :alert_policy, :alert_policy_name, :acktimeout, :autoresolve, :tags,
|
18
|
+
:sendtoemail, :sendtosms, :sendtoiphone, :sendtotwitter, :sendnotificationwhendown,
|
19
|
+
:sendtoandroid, :notifyagainevery,:notifywhenbackup, :contactids, :integrationids,
|
20
|
+
:probe_filters
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def time_attributes
|
25
|
+
%q{created lasttesttime lastresponsetime }
|
26
|
+
end
|
27
|
+
|
21
28
|
end
|
22
29
|
end
|
data/lib/pingdom/client.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'pingdom/check'
|
3
2
|
|
4
3
|
module Pingdom
|
5
4
|
|
@@ -7,25 +6,18 @@ module Pingdom
|
|
7
6
|
|
8
7
|
attr_accessor :username, :password, :key, :conn
|
9
8
|
|
10
|
-
def initialize
|
11
|
-
@username= ENV['PINGDOM_USERNAME']
|
12
|
-
@password= ENV['PINGDOM_PASSWORD']
|
13
|
-
@key= ENV['PINGDOM_KEY']
|
9
|
+
def initialize u: nil , p: nil, k: nil
|
10
|
+
@username= u || ENV['PINGDOM_USERNAME']
|
11
|
+
@password= p || ENV['PINGDOM_PASSWORD']
|
12
|
+
@key= k || ENV['PINGDOM_KEY']
|
14
13
|
@conn = Faraday.new(url: 'https://api.pingdom.com' )
|
15
14
|
@conn.basic_auth(username, password)
|
16
15
|
end
|
17
16
|
|
18
17
|
def has_connection?
|
19
|
-
|
20
|
-
!Check.error?
|
18
|
+
get( params: { limit: 1 }, path: '/checks').status == 200
|
21
19
|
end
|
22
20
|
|
23
|
-
def checks params: {}
|
24
|
-
Check.parse get params: params, path: '/checks'
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
21
|
def get( params: {} , path: '' )
|
30
22
|
|
31
23
|
conn.get do |req|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Pingdom
|
4
|
+
|
5
|
+
Struct.new('State',:status, :timefrom, :timeto) do
|
6
|
+
def interval
|
7
|
+
timeto.to_i - timefrom.to_i
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SummaryOutage < Pingdom::Base
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def path
|
16
|
+
'/summary.outage'
|
17
|
+
end
|
18
|
+
|
19
|
+
def collection_type
|
20
|
+
'summary'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :states
|
26
|
+
|
27
|
+
def states= values
|
28
|
+
|
29
|
+
@states=values.map do |v|
|
30
|
+
Struct::State.new( v['status'], Time.at(v['timefrom']), Time.at(v['timeto']))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def ups min_interval: 0
|
37
|
+
states.count { |s| s.status == 'up' and s.interval > min_interval }
|
38
|
+
end
|
39
|
+
|
40
|
+
def downs min_interval: 0
|
41
|
+
states.count { |s| s.status == 'down' and s.interval > min_interval }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Pingdom
|
4
|
+
|
5
|
+
Struct.new('Week',:starttime, :avgresponse, :uptime, :downtime, :unmonitored)
|
6
|
+
Struct.new('Day',:starttime, :avgresponse, :uptime, :downtime, :unmonitored)
|
7
|
+
Struct.new('Hour',:starttime, :avgresponse, :uptime, :downtime, :unmonitored)
|
8
|
+
|
9
|
+
class SummaryPerformance < Pingdom::Base
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def path
|
14
|
+
'/summary.performance'
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_type
|
18
|
+
'summary'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :hours, :days, :weeks
|
24
|
+
|
25
|
+
def weeks= values
|
26
|
+
|
27
|
+
@weeks=values.map do |v|
|
28
|
+
Struct::Week.new( Time.at(v['starttime']), v['avgresponse'], v['uptime'], v['downtime'], v['unmonitored'])
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def days= values
|
34
|
+
|
35
|
+
@days=values.map do |v|
|
36
|
+
Struct::Day.new( Time.at(v['starttime']), v['avgresponse'], v['uptime'], v['downtime'], v['unmonitored'])
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def hours= values
|
42
|
+
|
43
|
+
@hours=values.map do |v|
|
44
|
+
Struct::Hour.new( Time.at(v['starttime']), v['avgresponse'], v['uptime'], v['downtime'], v['unmonitored'])
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/pingdom/version.rb
CHANGED
data/lib/pingdom.rb
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
require "dotenv/load"
|
1
2
|
require "pingdom/version"
|
2
3
|
require "pingdom/client"
|
3
|
-
require "
|
4
|
+
require "pingdom/base"
|
5
|
+
require 'pingdom/check'
|
6
|
+
require 'pingdom/summary_outage'
|
7
|
+
require 'pingdom/summary_performance'
|
8
|
+
require 'active_support/core_ext/numeric/time'
|
9
|
+
require 'active_support/core_ext/time/acts_like'
|
10
|
+
require 'active_support/core_ext/time/calculations'
|
11
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
12
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
13
|
+
require 'active_support/core_ext/array/wrap'
|
14
|
+
require 'active_support/core_ext/hash/slice'
|
15
|
+
require 'active_support/inflector'
|
4
16
|
|
5
17
|
module Pingdom
|
6
18
|
# Your code goes here...
|
data/pingdom.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pingdom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Piccinini Lagos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.13'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.1'
|
97
111
|
description: Set up the username, password and key using dotenv. Get checks, results
|
98
112
|
email:
|
99
113
|
- diego@guiasrails.es
|
@@ -112,8 +126,11 @@ files:
|
|
112
126
|
- bin/console
|
113
127
|
- bin/setup
|
114
128
|
- lib/pingdom.rb
|
129
|
+
- lib/pingdom/base.rb
|
115
130
|
- lib/pingdom/check.rb
|
116
131
|
- lib/pingdom/client.rb
|
132
|
+
- lib/pingdom/summary_outage.rb
|
133
|
+
- lib/pingdom/summary_performance.rb
|
117
134
|
- lib/pingdom/version.rb
|
118
135
|
- pingdom.gemspec
|
119
136
|
homepage: https://github.com/diegopiccinini/pingdom
|
@@ -132,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
149
|
version: '0'
|
133
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
151
|
requirements:
|
135
|
-
- - "
|
152
|
+
- - ">="
|
136
153
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
154
|
+
version: '0'
|
138
155
|
requirements: []
|
139
156
|
rubyforge_project:
|
140
157
|
rubygems_version: 2.6.11
|