Class: Fushin::Monitor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonitor

Returns a new instance of Monitor.



6
7
8
# File 'lib/fushin/monitor.rb', line 6

def initialize
  @rss = RSS.new
end

Instance Attribute Details

#rssObject (readonly)

Returns the value of attribute rss.



5
6
7
# File 'lib/fushin/monitor.rb', line 5

def rss
  @rss
end

Class Method Details

.checkObject



30
31
32
# File 'lib/fushin/monitor.rb', line 30

def self.check
  new.check
end

Instance Method Details

#checkObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fushin/monitor.rb', line 10

def check
  rss.items.each do |item|
    next if Cache.cached?(item.link)

    attachements = [].tap do |out|
      out << item.post.btcs.map(&:to_attachements)
      out << item.post.urls.map(&:to_attachements)
      out << item.post.attachements.map(&:to_attachements)
    end.flatten
    attachements << { text: "IoC is not found." } if attachements.empty?
    Notifier.notify("#{item.title} (#{item.link})", attachements)
  rescue StandardError => e
    attachements = []
    attachements << { text: "#{e.class} (#{e}) is happened during processing." }
    Notifier.notify("#{item.title} (#{item.link})", attachements)
  ensure
    Cache.save(item.link, true)
  end
end