Software /
code /
prosody-modules
Comparison
mod_server_status/mod_server_status.lua @ 1343:7dbde05b48a9
all the things: Remove trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Tue, 11 Mar 2014 18:44:01 +0100 |
parent | 658:39306c770d7d |
comparison
equal
deleted
inserted
replaced
1342:0ae065453dc9 | 1343:7dbde05b48a9 |
---|---|
23 response_table.header = '<?xml version="1.0" encoding="UTF-8" ?>' | 23 response_table.header = '<?xml version="1.0" encoding="UTF-8" ?>' |
24 response_table.doc_header = '<document>' | 24 response_table.doc_header = '<document>' |
25 response_table.doc_closure = '</document>' | 25 response_table.doc_closure = '</document>' |
26 response_table.stanzas = { | 26 response_table.stanzas = { |
27 elem_header = ' <stanzas>', elem_closure = ' </stanzas>', | 27 elem_header = ' <stanzas>', elem_closure = ' </stanzas>', |
28 incoming = ' <incoming iq="%d" message="%d" presence="%d" />', | 28 incoming = ' <incoming iq="%d" message="%d" presence="%d" />', |
29 outgoing = ' <outgoing iq="%d" message="%d" presence="%d" />' | 29 outgoing = ' <outgoing iq="%d" message="%d" presence="%d" />' |
30 } | 30 } |
31 response_table.hosts = { | 31 response_table.hosts = { |
32 elem_header = ' <hosts>', elem_closure = ' </hosts>', | 32 elem_header = ' <hosts>', elem_closure = ' </hosts>', |
33 status = ' <status name="%s" current="%s" />' | 33 status = ' <status name="%s" current="%s" />' |
42 | 42 |
43 local function t_builder(t,r) for _, bstring in ipairs(t) do r[#r+1] = bstring end end | 43 local function t_builder(t,r) for _, bstring in ipairs(t) do r[#r+1] = bstring end end |
44 | 44 |
45 if show_hosts then t_builder(show_hosts, hosts_s) end | 45 if show_hosts then t_builder(show_hosts, hosts_s) end |
46 if show_comps then t_builder(show_comps, components) end | 46 if show_comps then t_builder(show_comps, components) end |
47 | 47 |
48 -- build stanza stats if there | 48 -- build stanza stats if there |
49 if prosody.stanza_counter then | 49 if prosody.stanza_counter then |
50 stats[1] = response_table.stanzas.elem_header | 50 stats[1] = response_table.stanzas.elem_header |
51 stats[2] = response_table.stanzas.incoming:format(prosody.stanza_counter.iq["incoming"], | 51 stats[2] = response_table.stanzas.incoming:format(prosody.stanza_counter.iq["incoming"], |
52 prosody.stanza_counter.message["incoming"], | 52 prosody.stanza_counter.message["incoming"], |
58 end | 58 end |
59 | 59 |
60 -- build hosts stats if there | 60 -- build hosts stats if there |
61 if hosts_s[1] then | 61 if hosts_s[1] then |
62 hosts_stats[1] = response_table.hosts.elem_header | 62 hosts_stats[1] = response_table.hosts.elem_header |
63 for _, name in ipairs(hosts_s) do | 63 for _, name in ipairs(hosts_s) do |
64 hosts_stats[#hosts_stats+1] = response_table.hosts.status:format( | 64 hosts_stats[#hosts_stats+1] = response_table.hosts.status:format( |
65 name, hosts[name] and "online" or "offline") | 65 name, hosts[name] and "online" or "offline") |
66 end | 66 end |
67 hosts_stats[#hosts_stats+1] = response_table.hosts.elem_closure | 67 hosts_stats[#hosts_stats+1] = response_table.hosts.elem_closure |
68 end | 68 end |
69 | 69 |
70 -- build components stats if there | 70 -- build components stats if there |
71 if components[1] then | 71 if components[1] then |
72 comps_stats[1] = response_table.comps.elem_header | 72 comps_stats[1] = response_table.comps.elem_header |
73 for _, name in ipairs(components) do | 73 for _, name in ipairs(components) do |
74 comps_stats[#comps_stats+1] = response_table.comps.status:format( | 74 comps_stats[#comps_stats+1] = response_table.comps.status:format( |
75 name, hosts[name] and hosts[name].modules.component and hosts[name].modules.component.connected and "online" or | 75 name, hosts[name] and hosts[name].modules.component and hosts[name].modules.component.connected and "online" or |
76 hosts[name] and hosts[name].modules.component == nil and "online" or "offline") | 76 hosts[name] and hosts[name].modules.component == nil and "online" or "offline") |
77 end | 77 end |
78 comps_stats[#comps_stats+1] = response_table.comps.elem_closure | 78 comps_stats[#comps_stats+1] = response_table.comps.elem_closure |
79 end | 79 end |
80 | 80 |
95 result.hosts = {} | 95 result.hosts = {} |
96 for _,n in ipairs(show_hosts) do result.hosts[n] = hosts[n] and "online" or "offline" end | 96 for _,n in ipairs(show_hosts) do result.hosts[n] = hosts[n] and "online" or "offline" end |
97 end | 97 end |
98 if show_comps then | 98 if show_comps then |
99 result.components = {} | 99 result.components = {} |
100 for _,n in ipairs(show_comps) do | 100 for _,n in ipairs(show_comps) do |
101 result.components[n] = hosts[n] and hosts[n].modules.component and hosts[n].modules.component.connected and "online" or | 101 result.components[n] = hosts[n] and hosts[n].modules.component and hosts[n].modules.component.connected and "online" or |
102 hosts[n] and hosts[n].modules.component == nil and "online" or "offline" | 102 hosts[n] and hosts[n].modules.component == nil and "online" or "offline" |
103 end | 103 end |
104 end | 104 end |
105 | 105 |
110 | 110 |
111 local function request(event) | 111 local function request(event) |
112 local response = event.response | 112 local response = event.response |
113 if not json_output then | 113 if not json_output then |
114 response.headers.content_type = "text/xml" | 114 response.headers.content_type = "text/xml" |
115 response:send(forge_response_xml()) | 115 response:send(forge_response_xml()) |
116 else | 116 else |
117 response.headers.content_type = "application/json" | 117 response.headers.content_type = "application/json" |
118 response:send(forge_response_json()) | 118 response:send(forge_response_json()) |
119 end | 119 end |
120 end | 120 end |