File: host_dns_breakdown.lua

package info (click to toggle)
ntopng 2.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 15,888 kB
  • ctags: 8,091
  • sloc: cpp: 21,442; ansic: 10,999; sh: 1,627; makefile: 423; pascal: 312; ruby: 34; exp: 4
file content (113 lines) | stat: -rw-r--r-- 3,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
50
51
52
53
54
55
56
57
58
59
60
61
62
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
105
106
107
108
109
110
111
112
113
--
-- (C) 2013-16 - ntop.org
--

dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path

require "lua_utils"

sendHTTPHeader('text/html; charset=iso-8859-1')

interface.select(ifname)

host_info = url2hostinfo(_GET)
mode = _GET["mode"]

if(mode == "sent") then
   what = "sent"
else
   what = "rcvd"
end

host = interface.getHostInfo(host_info["host"],host_info["vlan"])

left = 0

print "[\n"

--for k,v in pairs(host["dns"][what]) do
--   print(k.."="..v.."<br>\n")
--end

if(host ~= nil) then
   tot = host["dns"][what]["queries"]["num_a"] + host["dns"][what]["queries"]["num_ns"] + host["dns"][what]["queries"]["num_cname"] + host["dns"][what]["queries"]["num_soa"] + host["dns"][what]["queries"]["num_ptr"] + host["dns"][what]["queries"]["num_mx"]  + host["dns"][what]["queries"]["num_txt"] + host["dns"][what]["queries"]["num_aaaa"] + host["dns"][what]["queries"]["num_any"]
   
   if(tot > 0) then
      min = (tot * 3)/100
      comma = ""

      if(host["dns"][what]["queries"]["num_a"] > min) then 
	 print('\t { "label": "A", "value": '.. host["dns"][what]["queries"]["num_a"] .. '}\n')
	 comma = "," 
      else 
	 left = left + host["dns"][what]["queries"]["num_a"]
      end

      if(host["dns"][what]["queries"]["num_ns"] > min) then
	 print(comma..'\t { "label": "NS", "value": '.. host["dns"][what]["queries"]["num_ns"] .. '}\n')
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_ns"]
      end

      if(host["dns"][what]["queries"]["num_cname"] > min) then
	 print(comma..'\t { "label": "CNAME", "value": '.. host["dns"][what]["queries"]["num_cname"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_cname"] 
      end

      if(host["dns"][what]["queries"]["num_soa"] > min) then
	 print(comma..'\t { "label": "SOA", "value": '.. host["dns"][what]["queries"]["num_soa"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_soa"] 
      end

      if(host["dns"][what]["queries"]["num_ptr"] > min) then
	 print(comma..'\t { "label": "PTR", "value": '.. host["dns"][what]["queries"]["num_ptr"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_ptr"]
      end

      if(host["dns"][what]["queries"]["num_mx"] > min) then
	 print(comma..'\t { "label": "MX", "value": '.. host["dns"][what]["queries"]["num_mx"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_mx"] 
      end

      if(host["dns"][what]["queries"]["num_txt"] > min) then
	 print(comma..'\t { "label": "TXT", "value": '.. host["dns"][what]["queries"]["num_txt"] .. '}\n')
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_txt"]
      end

      if(host["dns"][what]["queries"]["num_aaaa"] > min) then
	 print(comma..'\t { "label": "AAAA", "value": '.. host["dns"][what]["queries"]["num_aaaa"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_aaaa"]
      end

      if(host["dns"][what]["queries"]["num_any"] > min) then
	 print(comma..'\t { "label": "ANY", "value": '.. host["dns"][what]["queries"]["num_any"] .. '}\n') 
	 comma = "," 
      else
	 left = left + host["dns"][what]["queries"]["num_any"] 
      end
      
      other = host["dns"][what]["queries"]["num_other"] + left
      if(other > 0) then print(comma..'\t { "label": "Other", "value": '.. other .. '}\n') 
      end
   end
end
	 
print "\n]"