Class: Prtg::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/prtg/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
30
31
# File 'lib/prtg/client.rb', line 25

def initialize(args)
  args.each do |k,v|
    send("#{k}=", v)
  end

  @host or raise ArgumentError.new("Need host")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



90
91
92
# File 'lib/prtg/client.rb', line 90

def method_missing(*args)
  super(*args)
end

Instance Attribute Details

#hostObject

The host is a Net:Http(s) instance



12
13
14
# File 'lib/prtg/client.rb', line 12

def host
  @host
end

#passhashObject

The passhash in comibnation with the username is used for authentication. The passhash gets generated by the prtg instance.

If no passhash is set he gets lazy converted using password



37
38
39
# File 'lib/prtg/client.rb', line 37

def passhash
  @passhash
end

#password=(value) ⇒ Object (writeonly)

Password for prtg user

The password is just temporary because of the intension to use passhash as auth method.



21
22
23
# File 'lib/prtg/client.rb', line 21

def password=(value)
  @password = value
end

#usernameObject

Username of the prtg user



15
16
17
# File 'lib/prtg/client.rb', line 15

def username
  @username
end

Instance Method Details

#api_request(params) ⇒ Object



83
84
85
86
87
88
# File 'lib/prtg/client.rb', line 83

def api_request(params)
  url_params = Utils.url_params(auth_params.merge(params))
  response   = host.get("/api/table.xml?" + url_params)

  parse_response(response)
end

#auth_paramsObject



75
76
77
# File 'lib/prtg/client.rb', line 75

def auth_params
  {:username => @username, :passhash => passhash}
end

#devicesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/prtg/client.rb', line 52

def devices
  params = {
    :content => "devices",
    :output  => "xml",
    :columns => %w(
      objid
      probe
      group
      device
      host
      downsens
      partialdownsens
      downacksens
      upsens
      warnsens
      pausedsens
      unusualsens
      undefinedsens).join(",")
  }

  api_request(params)
end

#getpasshashObject



41
42
43
44
45
# File 'lib/prtg/client.rb', line 41

def getpasshash
  url = "/api/getpasshash.htm?"+
    Utils.url_params(:username => @username, :password => @password)
  host.get(url, {"accept-encoding" => "gzip"}).body
end

#getstatusObject



47
48
49
50
# File 'lib/prtg/client.rb', line 47

def getstatus
  url_params = Utils.url_params(auth_params)
  parse_response(host.get("/api/getstatus.xml" + url_params))
end

#live_data(content) ⇒ Object



79
80
81
# File 'lib/prtg/client.rb', line 79

def live_data(content)
  Prtg::Query.new(self, content)
end