Class: URLhausMonitor::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/urlhaus_monitor/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonitor

Returns a new instance of Monitor.



10
11
12
13
# File 'lib/urlhaus_monitor/monitor.rb', line 10

def initialize
  @checker = Checker.new
  @cache = Lightly.new(dir: "/tmp/urlhause_monitor", life: "180d")
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/urlhaus_monitor/monitor.rb', line 8

def cache
  @cache
end

#checkerObject (readonly)

Returns the value of attribute checker.



7
8
9
# File 'lib/urlhaus_monitor/monitor.rb', line 7

def checker
  @checker
end

Instance Method Details

#lookup_by_asn(asn) ⇒ Object



25
26
27
28
# File 'lib/urlhaus_monitor/monitor.rb', line 25

def lookup_by_asn(asn)
  entries = checker.lookup_by_asn(asn)
  process entries
end

#lookup_by_country(country) ⇒ Object



15
16
17
18
# File 'lib/urlhaus_monitor/monitor.rb', line 15

def lookup_by_country(country)
  entries = checker.lookup_by_country(country)
  process entries
end

#lookup_by_tld(tld) ⇒ Object



20
21
22
23
# File 'lib/urlhaus_monitor/monitor.rb', line 20

def lookup_by_tld(tld)
  entries = checker.lookup_by_tld(tld)
  process entries
end

#process(entries) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/urlhaus_monitor/monitor.rb', line 30

def process(entries)
  return nil unless entries

  entries.each do |entry|
    next if cache.cached? entry.url

    Notifier.notify entry.title, entry.to_attachements
    cache.save entry.url, true
  end
end