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

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

#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

#historicdataObject



88
89
90
# File 'lib/prtg/client.rb', line 88

def historicdata
  Prtg::HistoricDataQuery.new(@host, auth_params)
end

#live_data(content) ⇒ Object



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

def live_data(content)
  warn "[DEPRECATION] Client#live_data is depricated. Please use 'Client#table.content(#{ content }) instead."
  table.content(content)
end

#tableObject



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

def table
  Prtg::TableQuery.new(@host, auth_params)
end