prtg 0.0.7 → 0.1.0
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.
- data/lib/prtg.rb +4 -2
- data/lib/prtg/client.rb +6 -24
- data/lib/prtg/historic_data_query.rb +16 -0
- data/lib/prtg/query.rb +63 -42
- data/lib/prtg/table_query.rb +18 -0
- metadata +6 -3
data/lib/prtg.rb
CHANGED
@@ -4,6 +4,8 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
|
|
4
4
|
require "rubygems"
|
5
5
|
require "#{dir}/prtg/client"
|
6
6
|
require "#{dir}/prtg/query"
|
7
|
+
require "#{dir}/prtg/table_query"
|
8
|
+
require "#{dir}/prtg/historic_data_query"
|
7
9
|
require "#{dir}/prtg/utils"
|
8
10
|
|
9
11
|
# This is a wrapper for the api of paessler's prtg monitoring tool.
|
@@ -14,7 +16,7 @@ require "#{dir}/prtg/utils"
|
|
14
16
|
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
15
17
|
#
|
16
18
|
# client = Prtg::Client.new(:host => http, :username => "foo", :password => "bar")
|
17
|
-
# p client.
|
19
|
+
# p client.table(:sensors)
|
18
20
|
module Prtg
|
19
|
-
VERSION = "0.0
|
21
|
+
VERSION = "0.1.0"
|
20
22
|
end
|
data/lib/prtg/client.rb
CHANGED
@@ -77,35 +77,17 @@ module Prtg # :nodoc:
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def live_data(content)
|
80
|
-
|
80
|
+
warn "[DEPRECATION] Client#live_data is depricated. Please use 'Client#table.content(#{ content }) instead."
|
81
|
+
table.content(content)
|
81
82
|
end
|
82
83
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
response = host.get(
|
87
|
-
"/api/table.xml?#{ url_params }",
|
88
|
-
{ "Accept-Encoding" => "*"}
|
89
|
-
)
|
90
|
-
|
91
|
-
parse_response(response)
|
84
|
+
def table
|
85
|
+
Prtg::TableQuery.new(@host, auth_params)
|
92
86
|
end
|
93
87
|
|
94
|
-
def
|
95
|
-
|
88
|
+
def historicdata
|
89
|
+
Prtg::HistoricDataQuery.new(@host, auth_params)
|
96
90
|
end
|
97
91
|
|
98
|
-
private
|
99
|
-
|
100
|
-
def parse_response(response)
|
101
|
-
hash = XmlSimple.xml_in(response.body, "ForceArray" => false)
|
102
|
-
|
103
|
-
if hash["error"]
|
104
|
-
raise hash["error"]
|
105
|
-
|
106
|
-
else
|
107
|
-
hash["item"]
|
108
|
-
end
|
109
|
-
end
|
110
92
|
end
|
111
93
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "prtg/query"
|
2
|
+
|
3
|
+
module Prtg # :nodoc
|
4
|
+
|
5
|
+
# Proxy class to caspule request
|
6
|
+
class HistoricDataQuery
|
7
|
+
|
8
|
+
include Prtg::Query
|
9
|
+
|
10
|
+
api_url '/api/historicdata.xml'
|
11
|
+
|
12
|
+
VALUES = [:id, :sdate, :edate, :avg]
|
13
|
+
VALUES.each { |k| api_value k }
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/prtg/query.rb
CHANGED
@@ -1,60 +1,81 @@
|
|
1
1
|
module Prtg # :nodoc:
|
2
2
|
|
3
|
-
|
4
|
-
class Query
|
3
|
+
module Query
|
5
4
|
|
6
|
-
|
7
|
-
instance_methods.each { |m| undef_method m unless m =~ /^(__|send|object_id)/ }
|
5
|
+
module ClassMethods
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@query_hash[:output] = :xml
|
13
|
-
@query_hash[:content] = content
|
14
|
-
end
|
7
|
+
def api_url(url)
|
8
|
+
define_method(:api_url) { url }
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
def api_value(name)
|
12
|
+
define_method name do |value|
|
13
|
+
@query[name] = value
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def api_list(name)
|
19
|
+
define_method name do |*args|
|
20
|
+
@query[name] = (@query[name] || []) | args
|
21
|
+
self
|
22
|
+
end
|
28
23
|
end
|
24
|
+
|
29
25
|
end
|
30
26
|
|
31
|
-
|
27
|
+
module InstanceMethods
|
28
|
+
|
29
|
+
def initialize(host, auth_params={})
|
30
|
+
@host = host
|
31
|
+
@query = {}.merge(auth_params)
|
32
|
+
@query[:output] = :xml
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
def execute
|
36
|
+
url_params = Utils.url_params(@query)
|
37
|
+
|
38
|
+
parse_response @host.get(
|
39
|
+
"#{ api_url }?#{ url_params }",
|
40
|
+
{ "Accept-Encoding" => "*"}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_filter(name, value)
|
45
|
+
@query[name.to_sym] = value
|
36
46
|
self
|
37
47
|
end
|
38
|
-
end
|
39
48
|
|
40
|
-
|
41
|
-
|
42
|
-
|
49
|
+
def method_missing(*args, &block)
|
50
|
+
if args.first.to_s.start_with? "filter"
|
51
|
+
add_filter(*args)
|
52
|
+
else
|
53
|
+
execute.send(*args, &block)
|
54
|
+
end
|
55
|
+
end
|
43
56
|
|
44
|
-
|
57
|
+
private
|
45
58
|
|
46
|
-
|
47
|
-
|
48
|
-
self
|
49
|
-
end
|
59
|
+
def parse_response(response)
|
60
|
+
hash = XmlSimple.xml_in(response.body, "ForceArray" => false)
|
50
61
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
if hash["error"]
|
63
|
+
raise hash["error"]
|
64
|
+
|
65
|
+
else
|
66
|
+
hash["item"]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.included(receiver)
|
72
|
+
receiver.class_exec do
|
73
|
+
# BlankSlate
|
74
|
+
instance_methods.each { |m| undef_method m unless m =~ /^(__|send|object_id)/ }
|
75
|
+
end
|
76
|
+
receiver.extend ClassMethods
|
77
|
+
receiver.send :include, InstanceMethods
|
78
|
+
end
|
58
79
|
|
59
80
|
end
|
60
81
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "prtg/query"
|
2
|
+
module Prtg # :nodoc:
|
3
|
+
|
4
|
+
# Proxy class to caspule request
|
5
|
+
class TableQuery
|
6
|
+
|
7
|
+
include Prtg::Query
|
8
|
+
|
9
|
+
api_url '/api/table.xml'
|
10
|
+
|
11
|
+
VALUES = [:content, :count, :start, :output, :id]
|
12
|
+
VALUES.each { |k| api_value k }
|
13
|
+
|
14
|
+
MULTIPLE_VALUES = [:columns]
|
15
|
+
MULTIPLE_VALUES.each { |k| api_list k }
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prtg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xml-simple
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.1.1
|
30
|
-
description: This gem is a wrapper around the
|
30
|
+
description: This gem is a wrapper around the prtg http api.Prtg is an network monitoring
|
31
31
|
solution which provides a api to retrieve several information about monitored devices.
|
32
32
|
email: k@kanello.de
|
33
33
|
executables: []
|
@@ -38,6 +38,8 @@ files:
|
|
38
38
|
- lib/prtg/query.rb
|
39
39
|
- lib/prtg/client.rb
|
40
40
|
- lib/prtg/utils.rb
|
41
|
+
- lib/prtg/historic_data_query.rb
|
42
|
+
- lib/prtg/table_query.rb
|
41
43
|
homepage: http://github.com/ikaros/Prtg-for-Ruby
|
42
44
|
licenses: []
|
43
45
|
post_install_message:
|
@@ -63,3 +65,4 @@ signing_key:
|
|
63
65
|
specification_version: 3
|
64
66
|
summary: Wrapper for the prtg network monitor api (http://www.paessler.com/prtg)
|
65
67
|
test_files: []
|
68
|
+
has_rdoc:
|