prtg 0.0.1p1

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.
@@ -0,0 +1,91 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require "cgi"
4
+ require "prtg/query"
5
+ require "prtg/utils"
6
+ require 'xmlsimple'
7
+
8
+ module Prtg # :nodoc:
9
+ class Client
10
+
11
+ # The host is a Net:Http(s) instance
12
+ attr_accessor :host
13
+
14
+ # Username of the prtg user
15
+ attr_accessor :username
16
+
17
+ # Password for prtg user
18
+ #
19
+ # The password is just temporary because of the intension to
20
+ # use +passhash+ as auth method.
21
+ attr_writer :password
22
+
23
+ attr_accessor :passhash
24
+
25
+ def initialize(args)
26
+ args.each do |k,v|
27
+ send("#{k}=", v)
28
+ end
29
+
30
+ @host or raise ArgumentError.new("Need host")
31
+ end
32
+
33
+ # The +passhash+ in comibnation with the +username+ is used for
34
+ # authentication. The passhash gets generated by the prtg instance.
35
+ #
36
+ # If no passhash is set he gets lazy converted using +password+
37
+ def passhash
38
+ @passhash ||= getpasshash
39
+ end
40
+
41
+ def getpasshash
42
+ url = "/api/getpasshash.htm?"+
43
+ Utils.url_params(:username => @username, :password => @password)
44
+ host.get(url, {"accept-encoding" => "gzip"}).body
45
+ end
46
+
47
+ def getstatus
48
+ host.get("/api/getstatus.xml")
49
+ end
50
+
51
+ def devices
52
+ params = {
53
+ :content => "devices",
54
+ :output => "xml",
55
+ :columns => %w(
56
+ objid
57
+ probe
58
+ group
59
+ device
60
+ host
61
+ downsens
62
+ partialdownsens
63
+ downacksens
64
+ upsens
65
+ warnsens
66
+ pausedsens
67
+ unusualsens
68
+ undefinedsens).join(",")
69
+ }
70
+
71
+ api_request(params)
72
+ end
73
+
74
+ def auth_params
75
+ {:username => @username, :passhash => passhash}
76
+ end
77
+
78
+ def live_data(content)
79
+ Prtg::Query.new(self, content)
80
+ end
81
+
82
+ def api_request(params)
83
+ resp_body = host.get("/api/table.xml?" + Utils.url_params(auth_params.merge(params))).body
84
+ XmlSimple.xml_in(resp_body)
85
+ end
86
+
87
+ def method_missing(*args)
88
+ super(*args)
89
+ end
90
+ end
91
+ end
data/lib/prtg/query.rb ADDED
@@ -0,0 +1,60 @@
1
+ module Prtg # :nodoc:
2
+
3
+ # Proxy class to caspule request
4
+ class Query
5
+
6
+ # BlankSlate
7
+ instance_methods.each { |m| undef_method m unless m =~ /^(__|send|object_id)/ }
8
+
9
+ def initialize(client, content)
10
+ @prtg_client = client
11
+ @query_hash = {}
12
+ @query_hash[:output] = :xml
13
+ @query_hash[:content] = content
14
+ end
15
+
16
+ # This single values for the query.
17
+ # They are pretty much like sql.
18
+ #
19
+ # content is like a table
20
+ # count is like LIMIT
21
+ # start is like OFFSET
22
+ VALUES = [:count, :start, :output, :id]
23
+
24
+ VALUES.each do |key|
25
+ define_method key do |value|
26
+ @query_hash[key] = value
27
+ self
28
+ end
29
+ end
30
+
31
+ MULTIPLE_VALUES = [:columns]
32
+
33
+ MULTIPLE_VALUES.each do |key|
34
+ define_method key do |*args|
35
+ @query_hash[key] = (@query_hash[key] || []) | args
36
+ self
37
+ end
38
+ end
39
+
40
+ def execute
41
+ @prtg_client.api_request(@query_hash)
42
+ end
43
+
44
+ private
45
+
46
+ def add_filter(name, value)
47
+ @query_hash[name.to_sym] = value
48
+ self
49
+ end
50
+
51
+ def method_missing(*args)
52
+ if args.first.to_s.start_with? "filter"
53
+ add_filter(*args)
54
+ else
55
+ execute.send(*args)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
data/lib/prtg/utils.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "cgi"
2
+
3
+ module Prtg # :nodoc:
4
+
5
+ module Utils
6
+
7
+ # Convert hashes to get parameters
8
+ #
9
+ # Example:
10
+ # Utils.url_params(name: "foo", login: "bar") #=> "name=foo&login=bar"
11
+ #
12
+ def self.url_params(params)
13
+ url_params = []
14
+
15
+ params.each do |key, value|
16
+ url_params << "#{CGI.escape(key.to_s)}=#{[*value].map{|v| CGI.escape(v.to_s)}.join(",")}"
17
+ end
18
+
19
+ url_params.join("&")
20
+ end
21
+ end
22
+ end
data/lib/prtg.rb ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require "rubygems"
3
+ require "happymapper"
4
+
5
+ require "prtg/client"
6
+ require "prtg/query"
7
+ require "prtg/live_data_response"
8
+ require "prtg/utils"
9
+
10
+ # This is a wrapper for the api of paessler's prtg monitoring tool.
11
+ #
12
+ # Simple Example:
13
+ # http = Net::HTTP.new("subdomain.domain.tld", 443)
14
+ # http.use_ssl = true
15
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+ #
17
+ # client = Prtg::Client.new(:host => http, :username => "foo", :password => "bar")
18
+ # p client.live_data(:sensors)
19
+ module Prtg
20
+ VERSION = "0.0.1"
21
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prtg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1p1
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Konstantin Kanellopoulos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xml-simple
16
+ requirement: &70286691700740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70286691700740
25
+ description: This gem is a wrapper around the prth http api.Prtg is an network monitoring
26
+ solution which provides a api to retrieve several information about monitored devices.
27
+ email: k@kanello.de
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/prtg/client.rb
33
+ - lib/prtg/query.rb
34
+ - lib/prtg/utils.rb
35
+ - lib/prtg.rb
36
+ homepage: http://github.com/ikaros/Prtg-for-Ruby
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.2
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.6
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.10
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Wrapper for the prtg network monitor api (http://www.paessler.com/prtg)
60
+ test_files: []