Class: URLhausMonitor::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Entry

Returns a new instance of Entry.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
# File 'lib/urlhaus_monitor/entry.rb', line 16

def initialize(line)
  parts = CSV.parse(line.chomp).flatten
  raise ArgumentError, "#{line} is not valid." unless parts.length == 8 || parts.length == 9

  if parts.length == 8
    parse_without_tags parts
  else
    parse_with_tags parts
  end
end

Instance Attribute Details

#asnumberObject (readonly)

Returns the value of attribute asnumber.



13
14
15
# File 'lib/urlhaus_monitor/entry.rb', line 13

def asnumber
  @asnumber
end

#countryObject (readonly)

Returns the value of attribute country.



14
15
16
# File 'lib/urlhaus_monitor/entry.rb', line 14

def country
  @country
end

#date_addedObject (readonly)

Returns the value of attribute date_added.



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

def date_added
  @date_added
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



12
13
14
# File 'lib/urlhaus_monitor/entry.rb', line 12

def ip_address
  @ip_address
end

#threatObject (readonly)

Returns the value of attribute threat.



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

def threat
  @threat
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#url_statusObject (readonly)

Returns the value of attribute url_status.



9
10
11
# File 'lib/urlhaus_monitor/entry.rb', line 9

def url_status
  @url_status
end

Instance Method Details

#actionsObject



69
70
71
# File 'lib/urlhaus_monitor/entry.rb', line 69

def actions
  [vt_link, urlscan_link, urlhaus_link].compact
end

#defanged_hostObject



31
32
33
# File 'lib/urlhaus_monitor/entry.rb', line 31

def defanged_host
  @defanged_host ||= host.gsub(/\./, "[.]")
end

#defanged_urlObject



27
28
29
# File 'lib/urlhaus_monitor/entry.rb', line 27

def defanged_url
  @defanged_url ||= url.gsub(/\./, "[.]")
end

#titleObject



35
36
37
# File 'lib/urlhaus_monitor/entry.rb', line 35

def title
  "#{defanged_url} (#{defanged_host} / #{ip_address} / #{date_added}) : #{threat}"
end

#to_attachementsObject



73
74
75
76
77
78
79
80
81
# File 'lib/urlhaus_monitor/entry.rb', line 73

def to_attachements
  [
    {
      text: defanged_host,
      fallback: "VT & urlscan.io links",
      actions: actions
    }
  ]
end


59
60
61
62
63
64
65
66
67
# File 'lib/urlhaus_monitor/entry.rb', line 59

def urlhaus_link
  return nil unless _urlhaus_link

  {
    type: "button",
    text: "Lookup on URLhaus",
    url: _urlhaus_link,
  }
end


49
50
51
52
53
54
55
56
57
# File 'lib/urlhaus_monitor/entry.rb', line 49

def urlscan_link
  return nil unless _urlscan_link

  {
    type: "button",
    text: "Lookup on urlscan.io",
    url: _urlscan_link,
  }
end


39
40
41
42
43
44
45
46
47
# File 'lib/urlhaus_monitor/entry.rb', line 39

def vt_link
  return nil unless _vt_link

  {
    type: "button",
    text: "Lookup on VirusTotal",
    url: _vt_link,
  }
end