Class: Poke::Checks::Blacklist::SpamhausBlacklistCheck

Inherits:
Poke::Check
  • Object
show all
Defined in:
lib/poke/checks/blacklist/spamhaus_blacklist_check.rb

Instance Attribute Summary

Attributes inherited from Poke::Check

#name

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ SpamhausBlacklistCheck

Returns a new instance of SpamhausBlacklistCheck.



17
18
19
20
21
# File 'lib/poke/checks/blacklist/spamhaus_blacklist_check.rb', line 17

def initialize(ip)
  name = "Blacklist of #{ip} (Spamhaus)"
  @ip = ip
  super name
end

Instance Method Details

#runObject

Run the check



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/poke/checks/blacklist/spamhaus_blacklist_check.rb', line 24

def run
  html = URI.parse("http://www.spamhaus.org/query/ip/#{@ip}").read
  doc = Nokogiri::HTML(html)
  nodes = doc.search("//span[@class='body']//b/font")

  spamhaus_nodes = {
      0 => "SBL",
      1 => "PBL",
      2 => "XBL"
  }

  global_returncode = :ok
  global_message = ""

  spamhaus_nodes.each do |index, spamtype|
    returncode, message = test_node(nodes, index)
    global_returncode = :error if returncode == :error

    global_message += "[#{spamtype}] #{message} | "
  end

  # Find a better way to do this...
  global_message = global_message.chop.chop

  return global_returncode, global_message
end