Class: Uptrends::Probe

Inherits:
Object
  • Object
show all
Defined in:
lib/uptrends/probe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(probe_hash = {}) ⇒ Probe

Returns a new instance of Probe.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/uptrends/probe.rb', line 8

def initialize(probe_hash = {})
  @original_hash     = probe_hash
  @original_keys     = probe_hash.keys
  @attributes        = probe_hash.keys.map{|x| x.downcase.to_sym }

  @guid              = probe_hash["Guid"]              ? probe_hash["Guid"]              : nil
  @name              = probe_hash["Name"]              ? probe_hash["Name"]              : nil
  @url               = probe_hash["URL"]               ? probe_hash["URL"]               : nil
  @port              = probe_hash["Port"]              ? probe_hash["Port"]              : nil
  @checkfrequency    = probe_hash["CheckFrequency"]    ? probe_hash["CheckFrequency"]    : nil
  @probetype         = probe_hash["ProbeType"]         ? probe_hash["ProbeType"]         : nil
  @isactive          = probe_hash["IsActive"]          ? probe_hash["IsActive"]          : nil
  @generatealert     = probe_hash["GenerateAlert"]     ? probe_hash["GenerateAlert"]     : nil
  @notes             = probe_hash["Notes"]             ? probe_hash["Notes"]             : nil
  @performancelimit1 = probe_hash["PerformanceLimit1"] ? probe_hash["PerformanceLimit1"] : nil
  @performancelimit2 = probe_hash["PerformanceLimit2"] ? probe_hash["PerformanceLimit2"] : nil
  @erroronlimit1     = probe_hash["ErrorOnLimit1"]     ? probe_hash["ErrorOnLimit1"]     : nil
  @erroronlimit2     = probe_hash["ErrorOnLimit2"]     ? probe_hash["ErrorOnLimit2"]     : nil
  @minbytes          = probe_hash["MinBytes"]          ? probe_hash["MinBytes"]          : nil
  @erroronminbytes   = probe_hash["ErrorOnMinBytes"]   ? probe_hash["ErrorOnMinBytes"]   : nil
  @timeout           = probe_hash["Timeout"]           ? probe_hash["Timeout"]           : nil
  @tcpconnecttimeout = probe_hash["TcpConnectTimeout"] ? probe_hash["TcpConnectTimeout"] : nil
  @matchpattern      = probe_hash["MatchPattern"]      ? probe_hash["MatchPattern"]      : nil
  @dnslookupmode     = probe_hash["DnsLookupMode"]     ? probe_hash["DnsLookupMode"]     : nil
  @useragent         = probe_hash["UserAgent"]         ? probe_hash["UserAgent"]         : nil
  @username          = probe_hash["UserName"]          ? probe_hash["UserName"]          : nil
  @password          = probe_hash["Password"]          ? probe_hash["Password"]          : nil
  @iscompetitor      = probe_hash["IsCompetitor"]      ? probe_hash["IsCompetitor"]      : nil
  @checkpoints       = probe_hash["Checkpoints"]       ? probe_hash["Checkpoints"]       : nil

  if probetype == "Http"
    @httpmethod = probe_hash["HttpMethod"]
    @postdata   = probe_hash["PostData"]
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/uptrends/probe.rb', line 5

def attributes
  @attributes
end

#checkfrequencyObject

Returns the value of attribute checkfrequency.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def checkfrequency
  @checkfrequency
end

#checkpointsObject

Returns the value of attribute checkpoints.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def checkpoints
  @checkpoints
end

#dnslookupmodeObject

Returns the value of attribute dnslookupmode.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def dnslookupmode
  @dnslookupmode
end

#erroronlimit1Object

Returns the value of attribute erroronlimit1.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def erroronlimit1
  @erroronlimit1
end

#erroronlimit2Object

Returns the value of attribute erroronlimit2.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def erroronlimit2
  @erroronlimit2
end

#erroronminbytesObject

Returns the value of attribute erroronminbytes.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def erroronminbytes
  @erroronminbytes
end

#generatealertObject

Returns the value of attribute generatealert.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def generatealert
  @generatealert
end

#guidObject (readonly)

Returns the value of attribute guid.



5
6
7
# File 'lib/uptrends/probe.rb', line 5

def guid
  @guid
end

#httpmethodObject

Returns the value of attribute httpmethod.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def httpmethod
  @httpmethod
end

#isactiveObject

Returns the value of attribute isactive.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def isactive
  @isactive
end

#iscompetitorObject

Returns the value of attribute iscompetitor.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def iscompetitor
  @iscompetitor
end

#matchpatternObject

Returns the value of attribute matchpattern.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def matchpattern
  @matchpattern
end

#minbytesObject

Returns the value of attribute minbytes.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def minbytes
  @minbytes
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def name
  @name
end

#notesObject

Returns the value of attribute notes.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def notes
  @notes
end

#original_hashObject (readonly)

Returns the value of attribute original_hash.



5
6
7
# File 'lib/uptrends/probe.rb', line 5

def original_hash
  @original_hash
end

#original_keysObject (readonly)

Returns the value of attribute original_keys.



5
6
7
# File 'lib/uptrends/probe.rb', line 5

def original_keys
  @original_keys
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def password
  @password
end

#performancelimit1Object

Returns the value of attribute performancelimit1.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def performancelimit1
  @performancelimit1
end

#performancelimit2Object

Returns the value of attribute performancelimit2.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def performancelimit2
  @performancelimit2
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def port
  @port
end

#postdataObject

Returns the value of attribute postdata.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def postdata
  @postdata
end

#probetypeObject Also known as: type

Returns the value of attribute probetype.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def probetype
  @probetype
end

#tcpconnecttimeoutObject

Returns the value of attribute tcpconnecttimeout.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def tcpconnecttimeout
  @tcpconnecttimeout
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def url
  @url
end

#useragentObject

Returns the value of attribute useragent.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def useragent
  @useragent
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/uptrends/probe.rb', line 6

def username
  @username
end

Instance Method Details

#gen_request_bodyObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/uptrends/probe.rb', line 47

def gen_request_body
  new_hash = original_keys.inject({}) do |memo,key|
    if key == 'Guid'
      memo
    else
      memo[key] = self.send(key.downcase.to_sym)
      memo
    end
  end

  request_body = JSON.dump(new_hash)
end

#to_sObject



60
61
62
63
64
65
66
67
# File 'lib/uptrends/probe.rb', line 60

def to_s
  string = []
  original_keys.each do |key|
    string << "#{key}: #{self.send(key.downcase.to_sym)}"
  end

  "#{string.join("\n")}"
end