mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Ganglia info now uses dispatch tables and SLAXML to parse the XML response.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
local comm = require "comm"
|
local comm = require "comm"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
local shortport = require "shortport"
|
local shortport = require "shortport"
|
||||||
|
local slaxml = require "slaxml"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
@@ -32,62 +33,177 @@ For more information about Ganglia, see:
|
|||||||
-- About 5KB-10KB of data is returned for each host in the cluster.
|
-- About 5KB-10KB of data is returned for each host in the cluster.
|
||||||
--
|
--
|
||||||
-- @output
|
-- @output
|
||||||
-- PORT STATE SERVICE VERSION
|
-- 8649/tcp open unknown syn-ack
|
||||||
-- 8649/tcp open ganglia Ganglia XML Grid monitor 2.5.7 (Cluster name: unspecified; Owner: unspecified; Source: gmond)
|
|
||||||
-- | ganglia-info:
|
-- | ganglia-info:
|
||||||
-- | Service: Ganglia Monitoring Daemon
|
-- | Ganglia Version: 3.1.7
|
||||||
-- | Version: 2.5.7
|
-- | Cluster 1:
|
||||||
-- | Cluster Name: unspecified
|
-- | Name: unspecified
|
||||||
-- | Owner: unspecified
|
-- | Owner: unspecified
|
||||||
-- | Hostname: localhost
|
-- | Host 1:
|
||||||
-- | IP: 127.0.0.1
|
-- | Name: sled9735.sd.dreamhost.com
|
||||||
-- | cpu nice: 0.0%
|
-- | IP: 10.208.42.221
|
||||||
-- | cpu user: 2.0%
|
-- | load_one: 0.53
|
||||||
-- | proc total: 182
|
-- | mem_total: 24685564KB
|
||||||
-- | proc run: 0
|
-- | os_release: 3.1.9-vs2.3.2.5
|
||||||
-- | load fifteen: 0.13
|
-- | proc_run: 0
|
||||||
-- | pkts in: 0.12packets/sec
|
-- | load_five: 0.52
|
||||||
-- | swap total: 9928700KB
|
|
||||||
-- | load five: 0.15
|
|
||||||
-- | machine type: x86_64
|
|
||||||
-- | disk total: 236.111GB
|
|
||||||
-- | mem buffers: 33148KB
|
|
||||||
-- | mem total: 3845028KB
|
|
||||||
-- | bytes in: 6.57bytes/sec
|
|
||||||
-- | load one: 0.22
|
|
||||||
-- | sys clock: 1317692483s
|
|
||||||
-- | mem free: 3280956KB
|
|
||||||
-- | mtu: 1280B
|
|
||||||
-- | mem shared: 0KB
|
|
||||||
-- | cpu aidle: 97.0%
|
|
||||||
-- | cpu idle: 99.1%
|
|
||||||
-- | cpu speed: 2266MHz
|
|
||||||
-- | mem cached: 271924KB
|
|
||||||
-- | cpu num: 4
|
|
||||||
-- | part max used: 55.9%
|
|
||||||
-- | bytes out: 5.48bytes/sec
|
|
||||||
-- | os release: 2.6.34
|
|
||||||
-- | gexec: OFF
|
-- | gexec: OFF
|
||||||
-- | disk free: 104.075GB
|
-- | disk_free: 305.765GB
|
||||||
-- | cpu system: 0.1%
|
-- | mem_cached: 18857264KB
|
||||||
-- | boottime: 1317692167s
|
-- | pkts_in: 821.73packets/sec
|
||||||
-- | swap free: 9928700KB
|
-- | bytes_in: 72686.10bytes/sec
|
||||||
-- | os name: Linux
|
-- | bytes_out: 5612221.50bytes/sec
|
||||||
-- |_ pkts out: 0.06packets/sec
|
-- | swap_total: 1998844KB
|
||||||
|
-- | mem_free: 187964KB
|
||||||
-- Version 0.1
|
-- | load_fifteen: 0.57
|
||||||
|
-- | os_name: Linux
|
||||||
|
-- | boottime: 1429708366s
|
||||||
|
-- | cpu_idle: 96.3%
|
||||||
|
-- | cpu_user: 2.7%
|
||||||
|
-- | cpu_nice: 0.0%
|
||||||
|
-- | cpu_aidle: 94.7%
|
||||||
|
-- | mem_buffers: 169588KB
|
||||||
|
-- | cpu_system: 0.8%
|
||||||
|
-- | part_max_used: 31.5%
|
||||||
|
-- | disk_total: 435.962GB
|
||||||
|
-- | mem_shared: 0KB
|
||||||
|
-- | cpu_wio: 0.2%
|
||||||
|
-- | machine_type: x86_64
|
||||||
|
-- | proc_total: 1027
|
||||||
|
-- | cpu_num: 8CPUs
|
||||||
|
-- | cpu_speed: 2400MHz
|
||||||
|
-- | pkts_out: 3977.13packets/sec
|
||||||
|
-- | swap_free: 1393392KB
|
||||||
|
--
|
||||||
|
-- @xmloutput
|
||||||
|
-- <elem key="Ganglia Version">3.1.7</elem>
|
||||||
|
-- <table key="Cluster 1">
|
||||||
|
-- <elem key="Name">unspecified</elem>
|
||||||
|
-- <elem key="Owner">unspecified</elem>
|
||||||
|
-- <table key="Host 1">
|
||||||
|
-- <elem key="Name">sled9735.sd.dreamhost.com</elem>
|
||||||
|
-- <elem key="IP">10.208.42.221</elem>
|
||||||
|
-- <elem key="load_one">0.53</elem>
|
||||||
|
-- <elem key="mem_total">24685564KB</elem>
|
||||||
|
-- <elem key="os_release">3.1.9-vs2.3.2.5</elem>
|
||||||
|
-- <elem key="proc_run">0</elem>
|
||||||
|
-- <elem key="load_five">0.52</elem>
|
||||||
|
-- <elem key="gexec">OFF</elem>
|
||||||
|
-- <elem key="disk_free">305.765GB</elem>
|
||||||
|
-- <elem key="mem_cached">18857264KB</elem>
|
||||||
|
-- <elem key="pkts_in">821.73packets/sec</elem>
|
||||||
|
-- <elem key="bytes_in">72686.10bytes/sec</elem>
|
||||||
|
-- <elem key="bytes_out">5612221.50bytes/sec</elem>
|
||||||
|
-- <elem key="swap_total">1998844KB</elem>
|
||||||
|
-- <elem key="mem_free">187964KB</elem>
|
||||||
|
-- <elem key="load_fifteen">0.57</elem>
|
||||||
|
-- <elem key="os_name">Linux</elem>
|
||||||
|
-- <elem key="boottime">1429708366s</elem>
|
||||||
|
-- <elem key="cpu_idle">96.3%</elem>
|
||||||
|
-- <elem key="cpu_user">2.7%</elem>
|
||||||
|
-- <elem key="cpu_nice">0.0%</elem>
|
||||||
|
-- <elem key="cpu_aidle">94.7%</elem>
|
||||||
|
-- <elem key="mem_buffers">169588KB</elem>
|
||||||
|
-- <elem key="cpu_system">0.8%</elem>
|
||||||
|
-- <elem key="part_max_used">31.5%</elem>
|
||||||
|
-- <elem key="disk_total">435.962GB</elem>
|
||||||
|
-- <elem key="mem_shared">0KB</elem>
|
||||||
|
-- <elem key="cpu_wio">0.2%</elem>
|
||||||
|
-- <elem key="machine_type">x86_64</elem>
|
||||||
|
-- <elem key="proc_total">1027</elem>
|
||||||
|
-- <elem key="cpu_num">8CPUs</elem>
|
||||||
|
-- <elem key="cpu_speed">2400MHz</elem>
|
||||||
|
-- <elem key="pkts_out">3977.13packets/sec</elem>
|
||||||
|
-- <elem key="swap_free">1393392KB</elem>
|
||||||
|
-- </table>
|
||||||
|
-- </table>
|
||||||
|
--
|
||||||
|
-- Version 0.2
|
||||||
-- Created 2011-06-28 - v0.1 - created by Brendan Coles - itsecuritysolutions.org
|
-- Created 2011-06-28 - v0.1 - created by Brendan Coles - itsecuritysolutions.org
|
||||||
|
-- Created 2015-07-30 - v0.2 - Added Support for SLAXML by Gyanendra Mishra
|
||||||
|
|
||||||
author = "Brendan Coles"
|
author = {"Brendan Coles", "Gyanendra Mishra"}
|
||||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||||
categories = {"default", "discovery", "safe"}
|
categories = {"default", "discovery", "safe"}
|
||||||
|
|
||||||
|
|
||||||
portrule = shortport.port_or_service ({8649,8651}, "ganglia", {"tcp"})
|
portrule = shortport.port_or_service ({8649,8651}, "ganglia", {"tcp"})
|
||||||
|
|
||||||
|
local function set_name_value(name)
|
||||||
|
return function(value, state)
|
||||||
|
state.result[name] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_cluster(name)
|
||||||
|
return function(value, state)
|
||||||
|
local current = state[#state]
|
||||||
|
if not current.out then
|
||||||
|
state.cc = state.cc + 1
|
||||||
|
current.out = stdnse.output_table()
|
||||||
|
current.hc = 0
|
||||||
|
state.result["Cluster " .. state.cc] = current.out
|
||||||
|
end
|
||||||
|
state.result["Cluster " .. state.cc][name] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_current_cluster(state)
|
||||||
|
for i=#state, 1, -1 do
|
||||||
|
if state[i][1] == "CLUSTER" then
|
||||||
|
return state[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_host(name)
|
||||||
|
return function(value, state)
|
||||||
|
local current = state[#state]
|
||||||
|
local current_cluster = get_current_cluster(state)
|
||||||
|
if not current.out then
|
||||||
|
current_cluster.hc = current_cluster.hc + 1
|
||||||
|
current.out = stdnse.output_table()
|
||||||
|
state.result["Cluster " .. state.cc]["Host " .. current_cluster.hc] = current.out
|
||||||
|
end
|
||||||
|
state.result["Cluster " .. state.cc]["Host " .. current_cluster.hc][name] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_metric(name)
|
||||||
|
return function(value, state)
|
||||||
|
local current = state[#state]
|
||||||
|
local current_cluster = get_current_cluster(state)
|
||||||
|
current[name] = value
|
||||||
|
if current["name"] and current["value"] and current["unit"] then
|
||||||
|
state.result["Cluster " .. state.cc]["Host " .. current_cluster.hc][current["name"]] = current["value"] .. current["unit"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local P = {
|
||||||
|
GANGLIA_XML = {
|
||||||
|
VERSION = set_name_value("Ganglia Version"),
|
||||||
|
},
|
||||||
|
GRID = {
|
||||||
|
NAME = set_name_value("Grid Name"),
|
||||||
|
},
|
||||||
|
CLUSTER = {
|
||||||
|
NAME = set_cluster("Name"),
|
||||||
|
OWNER = set_cluster("Owner"),
|
||||||
|
},
|
||||||
|
HOST = {
|
||||||
|
NAME = set_host("Name"),
|
||||||
|
IP = set_host("IP"),
|
||||||
|
},
|
||||||
|
METRIC = {
|
||||||
|
NAME = set_metric("name"),
|
||||||
|
UNITS = set_metric("unit"),
|
||||||
|
VAL = set_metric("value"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
action = function( host, port )
|
action = function( host, port )
|
||||||
|
|
||||||
local result = {}
|
local result = stdnse.output_table()
|
||||||
|
|
||||||
-- Set timeout
|
-- Set timeout
|
||||||
local timeout = stdnse.parse_timespec(stdnse.get_script_args(SCRIPT_NAME .. '.timeout'))
|
local timeout = stdnse.parse_timespec(stdnse.get_script_args(SCRIPT_NAME .. '.timeout'))
|
||||||
@@ -105,37 +221,27 @@ action = function( host, port )
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parse daemon info
|
local state = {
|
||||||
if not string.match(data, "<!DOCTYPE GANGLIA_XML") then
|
cc = 0,
|
||||||
stdnse.debug1("%s:%s is not a Ganglia Daemon.", host.targetname or host.ip, port.number)
|
result=stdnse.output_table()
|
||||||
return
|
}
|
||||||
elseif string.match(data, '<GANGLIA_XML VERSION="([^"]*)" SOURCE="gmond"') then
|
|
||||||
table.insert(result, "Service: Ganglia Monitoring Daemon")
|
|
||||||
local version = string.match(data, '<GANGLIA_XML VERSION="([^"]*)" SOURCE="gmond"')
|
|
||||||
if version then table.insert(result, string.format("Version: %s\n", version)) end
|
|
||||||
elseif string.match(data, '<GANGLIA_XML VERSION="([^"]*)" SOURCE="gmetad"') then
|
|
||||||
table.insert(result, "Service: Ganglia Meta Daemon")
|
|
||||||
local version = string.match(data, '<GANGLIA_XML VERSION="([^"]*)" SOURCE="gmetad"')
|
|
||||||
if version then table.insert(result, string.format("Version: %s\n", version)) end
|
|
||||||
local grid = string.match(data, '<GRID NAME="([^"]*)" ')
|
|
||||||
if grid then table.insert(result, string.format("Grid Name: %s", grid)) end
|
|
||||||
else
|
|
||||||
stdnse.debug1("%s:%s did not supply Ganglia daemon details.", host.targetname or host.ip, port.number)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Extract cluster details and system details for each cluster in the grid
|
local parser = slaxml.parser:new()
|
||||||
for line in string.gmatch(data, "[^\n]+") do
|
parser._call = {
|
||||||
if string.match(line, '<CLUSTER NAME="([^"]*)" ') and string.match(line, '<CLUSTER [^>]+ OWNER="([^"]*)" ') then
|
startElement = function(name) table.insert(state, {name}) end,
|
||||||
table.insert(result, string.format("Cluster Name: %s\n\tOwner: %s\n", string.match(line, '<CLUSTER NAME="([^"]*)" '), string.match(line, '<CLUSTER [^>]+ OWNER="([^"]*)" ')))
|
closeElement = function(name) assert(state[#state][1] == name) state[#state] = nil end,
|
||||||
elseif string.match(line, '<HOST NAME="([^"]*)" IP="([^"]*)"') then
|
attribute = function(name, value)
|
||||||
table.insert(result, string.format("\tHostname: %s\n\t\tIP: %s\n", string.match(line, '<HOST NAME="([^"]*)" IP="[^"]*"'), string.match(line, '<HOST NAME="[^"]*" IP="([^"]*)"')))
|
local p_elem = P[state[#state][1]]
|
||||||
elseif string.match(line, '<METRIC NAME="([^"]*)" VAL="[^"]*" [^>]+ UNITS="[^"]*"') then
|
if not (p_elem and p_elem[name]) then return end
|
||||||
table.insert(result, string.format("\t\t%s: %s%s", string.gsub(string.match(line, '<METRIC NAME="([^"]*)" VAL="[^"]*" [^>]+ UNITS="[^"]*"'), "_", " "), string.match(line, '<METRIC NAME="[^"]*" VAL="([^"]*)" [^>]+ UNITS="[^"]*"'), string.match(line, '<METRIC NAME="[^"]*" VAL="[^"]*" [^>]+ UNITS="([^"]*)"')))
|
local p_attr = p_elem[name]
|
||||||
end
|
if not p_attr then return end
|
||||||
end
|
p_attr(value, state)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
-- Return results
|
parser:parseSAX(data, {stripWhitespace=true})
|
||||||
return stdnse.format_output(true, result)
|
|
||||||
|
if #state.result then return state.result end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user