1 -- (C) 2011, Marco Cirillo (LW.Org)
2 -- Exposes stats on HTTP for the stanza counter module.
6 local base_path
= module
:get_option_string("stanza_counter_basepath", "/stanza-counter/")
10 local r_200
= "\n<html>\n<head>\n<title>Prosody's Stanza Counter</title>\n<meta name=\"robots\" content=\"noindex, nofollow\" />\n</head>\n\n<body>\n<h3>Incoming and Outgoing stanzas divided per type</h3>\n<p><strong>Incoming IQs</strong>: %d<br/>\n<strong>Outgoing IQs</strong>: %d<br/>\n<strong>Incoming Messages</strong>: %d<br/>\n<strong>Outgoing Messages</strong>: %d<br/>\n<strong>Incoming Presences</strong>: %d<br/>\n<strong>Outgoing Presences</strong>: %d<p>\n</body>\n\n</html>\n"
12 local r_err
= "\n<html>\n<head>\n<title>Prosody's Stanza Counter - Error %s</title>\n<meta name=\"robots\" content=\"noindex, nofollow\" />\n</head>\n\n<body>\n<h3>%s</h3>\n</body>\n\n</html>\n"
14 local function res(event
, code
, body
, extras
)
15 local response
= event
.response
18 for header
, data
in pairs(extras
) do response
.headers
[header
] = data
end
21 response
.status_code
= code
25 local function req(event
)
26 if not prosody
.stanza_counter
then
27 local err500
= r_err
:format(event
, 500, "Stats not found, is the counter module loaded?")
28 return res(500, err500
) end
29 if method
== "GET" then
30 local forge_res
= r_200
:format(prosody
.stanza_counter
.iq
["incoming"],
31 prosody
.stanza_counter
.iq
["outgoing"],
32 prosody
.stanza_counter
.message
["incoming"],
33 prosody
.stanza_counter
.message
["outgoing"],
34 prosody
.stanza_counter
.presence
["incoming"],
35 prosody
.stanza_counter
.presence
["outgoing"])
36 return res(event
, 200, forge_res
)
38 local err405
= r_err
:format(405, "Only GET is supported")
39 return res(event
, 405, err405
, {["Allow"] = "GET"})
45 module
:provides("http", {
46 default_path
= base_path
,