Class: Risu::Graphs::TopVulnGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/risu/graphs/top_vuln_graph.rb,
lib/risu/graphs/windows_os_graph.rb

Overview

TopVulnGraph

Instance Method Summary collapse

Instance Method Details

#graphObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/risu/graphs/top_vuln_graph.rb', line 28

def graph
  g = Gruff::Bar.new(GRAPH_WIDTH)
  g.title = sprintf "Top 10 Hosts with Notable Findings Count"
  g.sort = false
  g.marker_count = 1
  g.theme = {
    :colors => Risu::GRAPH_COLORS,
    :background_colors => %w(white white)
  }

  Item.risks_by_host(limit).to_a.each do |item|
    ip = Host.find_by_id(item.host_id).name
    count = Item.where(:host_id => item.host_id).where(:severity => 4).count

    if count > 0
      g.data(ip, count)
    end
  end

  StringIO.new(g.to_blob)
end

#graph_textObject



50
51
# File 'lib/risu/graphs/top_vuln_graph.rb', line 50

def graph_text
end

#has_data?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/risu/graphs/windows_os_graph.rb', line 109

def has_data?
  nt = Host.os_windows_nt.to_a.size
  w2k = Host.os_windows_2k.to_a.size
  xp = Host.os_windows_xp.to_a.size
  w2k3 = Host.os_windows_2k3.to_a.size
  vista = Host.os_windows_vista.to_a.size
  w2k8 = Host.os_windows_2k8.to_a.size
  w2k12 = Host.os_windows_2k12.to_a.size
  w7 = Host.os_windows_7.to_a.size
  w8 = Host.os_windows_8.to_a.size
  other = (Host.os_windows.os_windows_other).to_a.size

  if nt == 0 && w2k == 0 && xp == 0 && w2k3 == 0 && vista == 0 && w2k8 == 0 && w2k12 == 0 && w7 == 0 && w8 == 0 && other == 0
    return false
  else
    return true
  end
end

#textObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/risu/graphs/windows_os_graph.rb', line 63

def text
  nt = Host.os_windows_nt.to_a.count
  w2k = Host.os_windows_2k.to_a.count
  xp = Host.os_windows_xp.to_a.count
  w2k3 = Host.os_windows_2k3.to_a.count
  vista = Host.os_windows_vista.to_a.count
  w2k8 = Host.os_windows_2k8.to_a.count
  w2k12 = Host.os_windows_2k12.to_a.count
  w7 = Host.os_windows_7.to_a.count
  w8 = Host.os_windows_8.to_a.count
  other = (Host.os_windows.os_windows_other).to_a.count

  windows_os_count = nt + w2k + xp + w2k3 + vista + w7 + w8 + w2k8 + w2k12 + other

  nt_percent = (nt.to_f / windows_os_count.to_f) * 100
  w2k_percent = (w2k.to_f / windows_os_count.to_f) * 100
  xp_percent = (xp.to_f / windows_os_count.to_f) * 100
  w2k3_percent = (w2k3.to_f / windows_os_count.to_f) * 100
  vista_percent = (vista.to_f / windows_os_count.to_f) * 100

  w2k8_percent = (w2k8.to_f / windows_os_count.to_f) * 100
  w7_percent = (w7.to_f / windows_os_count.to_f) * 100
  w8_percent = (w8.to_f / windows_os_count.to_f) * 100
  w2k12_percent = (w2k12.to_f / windows_os_count.to_f) * 100

  text = "This graph shows the percentage of the different Microsoft Windows based operating systems " +
  "found on the #{Report.title} network.\n\n"

  text << "#{nt_percent.round.to_i}% of the network is Windows NT. " if nt_percent >= 1
  text << "#{w2k_percent.round.to_i}% of the network is Windows 2000. " if w2k_percent >= 1
  text << "#{xp_percent.round.to_i}% of the network is Windows XP. " if xp_percent >= 1
  text << "#{w2k3_percent.round.to_i}% of the network is Windows Server 2003. " if w2k3_percent >= 1
  text << "#{vista_percent.round.to_i}% of the network is Windows Vista. " if vista_percent >= 1
  text << "#{w2k8_percent.round.to_i}% of the network is Windows Server 2008. " if w2k8_percent >= 1
  text << "#{w7_percent.round.to_i}% of the network is Windows 7. " if w7_percent >= 1
  text << "#{w8_percent.round.to_i}% of the network is Windows 8. " if w8_percent >= 1
  text << "#{w2k12_percent.round.to_i}% of the network is Windows Server 20012. " if w2k12_percent >= 1

  text << "\n\n" << unsupported_os_windows if nt > 0 or w2k > 0

  return text
end