File: host_dns_breakdown.lua

package info (click to toggle)
ntopng 5.2.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,832 kB
  • sloc: javascript: 143,431; cpp: 71,175; ansic: 11,108; sh: 4,687; makefile: 911; python: 587; sql: 512; pascal: 234; perl: 118; ruby: 52; exp: 4
file content (106 lines) | stat: -rw-r--r-- 3,766 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
--
-- (C) 2013-22 - ntop.org
--

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

require "lua_utils"

sendHTTPContentTypeHeader('text/html')

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

local what = "rcvd"
if mode == "sent" then
   what = "sent"
end

local host = interface.getHostInfo(host_info["host"],host_info["vlan"])
local tot = 0
local left = 0

print "[\n"

if(host ~= nil) then
   if(host["dns"][what]["queries"] ~= 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"] + host["dns"][what]["queries"]["num_other"]
   else
      tot = 0
   end

   if(tot > 0) then
      local min = 0 -- Show all the queries, they are just a buch and fit well in the pie chart
      local 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

      local 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]"