Mercurial > prosody-modules
annotate mod_incidents_handling/incidents_handling/incidents_handling.lib.lua @ 4813:0a257d1402c3
mod_muc_rtbl: Optimize case with zero hashes
On the assumption that during quiet times between torrents of spam,
the hash set would be empty. There would be no point in doing the
operations and hashes to check for a match in that case.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 06 Dec 2021 18:19:19 +0100 |
parents | 7dbde05b48a9 |
children |
rev | line source |
---|---|
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
1 -- This contains the auxiliary functions for the Incidents Handling module. |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
2 -- (C) 2012-2013, Marco Cirillo (LW.Org) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
3 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
4 local pairs, ipairs, os_date, string, table, tonumber = pairs, ipairs, os.date, string, table, tonumber |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
5 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
6 local dataforms_new = require "util.dataforms".new |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
7 local st = require "util.stanza" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
8 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
9 local xmlns_inc = "urn:xmpp:incident:2" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
10 local xmlns_iodef = "urn:ietf:params:xml:ns:iodef-1.0" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
11 local my_host = nil |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
12 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
13 -- // Util and Functions // |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
14 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
15 local function ft_str() |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
16 local d = os_date("%FT%T%z"):gsub("^(.*)(%+%d+)", function(dt, z) |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
17 if z == "+0000" then return dt.."Z" else return dt..z end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
18 end) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
19 return d |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
20 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
21 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
22 local function get_incident_layout(i_type) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
23 local layout = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
24 title = (i_type == "report" and "Incident report form") or (i_type == "request" and "Request for assistance with incident form"), |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
25 instructions = "Started/Ended Time, Contacts, Sources and Targets of the attack are mandatory. See RFC 5070 for further format instructions.", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
26 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/commands" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
27 |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
28 { name = "name", type = "hidden", value = my_host }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
29 { name = "entity", type ="text-single", label = "Remote entity to query" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
30 { name = "started", type = "text-single", label = "Incident Start Time" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
31 { name = "ended", type = "text-single", label = "Incident Ended Time" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
32 { name = "reported", type = "hidden", value = ft_str() }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
33 { name = "description", type = "text-single", label = "Description", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
34 desc = "Description syntax is: <lang (in xml:lang format)> <short description>" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
35 { name = "contacts", type = "text-multi", label = "Contacts", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
36 desc = "Contacts entries format is: <address> <type> <role> - separated by new lines" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
37 { name = "related", type = "text-multi", label = "Related Incidents", |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
38 desc = "Related incidents entries format is: <CSIRT's FQDN> <Incident ID> - separated by new lines" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
39 { name = "impact", type = "text-single", label = "Impact Assessment", |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
40 desc = "Impact assessment format is: <severity> <completion> <type>" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
41 { name = "sources", type = "text-multi", label = "Attack Sources", |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
42 desc = "Attack sources format is: <address> <category> <count> <count-type>" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
43 { name = "targets", type = "text-multi", label = "Attack Targets", |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
44 desc = "Attack target format is: <address> <category> <noderole>" } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
45 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
46 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
47 if i_type == "request" then |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
48 table.insert(layout, { |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
49 name = "expectation", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
50 type = "list-single", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
51 label = "Expected action from remote entity", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
52 value = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
53 { value = "nothing", label = "No action" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
54 { value = "contact-sender", label = "Contact us, regarding the incident" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
55 { value = "investigate", label = "Investigate the entities listed into the incident" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
56 { value = "block-host", label = "Block the involved accounts" }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
57 { value = "other", label = "Other action, filling the description field is required" } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
58 }}) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
59 table.insert(layout, { name = "description", type = "text-single", label = "Description" }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
60 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
61 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
62 return dataforms_new(layout) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
63 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
64 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
65 local function render_list(incidents) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
66 local layout = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
67 title = "Stored Incidents List", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
68 instructions = "You can select and view incident reports here, if a followup/response is possible it'll be noted in the step after selection.", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
69 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/commands" }, |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
70 { |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
71 name = "ids", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
72 type = "list-single", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
73 label = "Stored Incidents", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
74 value = {} |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
75 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
76 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
77 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
78 -- Render stored incidents list |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
79 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
80 for id in pairs(incidents) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
81 table.insert(layout[2].value, { value = id, label = id }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
82 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
83 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
84 return dataforms_new(layout) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
85 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
86 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
87 local function insert_fixed(t, item) table.insert(t, { type = "fixed", value = item }) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
88 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
89 local function render_single(incident) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
90 local layout = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
91 title = string.format("Incident ID: %s - Friendly Name: %s", incident.data.id.text, incident.data.id.name), |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
92 instructions = incident.data.desc.text, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
93 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/commands" } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
94 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
95 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
96 insert_fixed(layout, "Start Time: "..incident.data.start_time) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
97 insert_fixed(layout, "End Time: "..incident.data.end_time) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
98 insert_fixed(layout, "Report Time: "..incident.data.report_time) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
99 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
100 insert_fixed(layout, "Contacts --") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
101 for _, contact in ipairs(incident.data.contacts) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
102 insert_fixed(layout, string.format("Role: %s Type: %s", contact.role, contact.type)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
103 if contact.jid then insert_fixed(layout, "--> JID: "..contact.jid..(contact.xmlns and ", XMLNS: "..contact.xmlns or "")) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
104 if contact.email then insert_fixed(layout, "--> E-Mail: "..contact.email) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
105 if contact.telephone then insert_fixed(layout, "--> Telephone: "..contact.telephone) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
106 if contact.postaladdr then insert_fixed(layout, "--> Postal Address: "..contact.postaladdr) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
107 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
108 |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
109 insert_fixed(layout, "Related Activity --") |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
110 for _, related in ipairs(incident.data.related) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
111 insert_fixed(layout, string.format("Name: %s ID: %s", related.name, related.text)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
112 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
113 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
114 insert_fixed(layout, "Assessment --") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
115 insert_fixed(layout, string.format("Language: %s Severity: %s Completion: %s Type: %s", |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
116 incident.data.assessment.lang, incident.data.assessment.severity, incident.data.assessment.completion, incident.data.assessment.type)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
117 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
118 insert_fixed(layout, "Sources --") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
119 for _, source in ipairs(incident.data.event_data.sources) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
120 insert_fixed(layout, string.format("Address: %s Counter: %s", source.address.text, source.counter.value)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
121 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
122 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
123 insert_fixed(layout, "Targets --") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
124 for _, target in ipairs(incident.data.event_data.targets) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
125 insert_fixed(layout, string.format("For NodeRole: %s", (target.noderole.cat == "ext-category" and target.noderole.ext) or targets.noderole.cat)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
126 for _, address in ipairs(target.addresses) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
127 insert_fixed(layout, string.format("---> Address: %s Type: %s", address.text, (address.cat == "ext-category" and address.ext) or address.cat)) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
128 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
129 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
130 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
131 if incident.data.expectation then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
132 insert_fixed(layout, "Expected Action: "..incident.data.expectation.action) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
133 if incident.data.expectation.desc then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
134 insert_fixed(layout, "Expected Action Description: "..incident.data.expectation.desc) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
135 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
136 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
137 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
138 if incident.type == "request" and incident.status == "open" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
139 table.insert(layout, { name = "response-datetime", type = "hidden", value = ft_str() }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
140 table.insert(layout, { name = "response", type = "text-single", label = "Respond to the request" }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
141 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
142 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
143 return dataforms_new(layout) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
144 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
145 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
146 local function get_type(var, typ) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
147 if typ == "counter" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
148 local count_type, count_ext = var, nil |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
149 if count_type ~= "byte" or count_type ~= "packet" or count_type ~= "flow" or count_type ~= "session" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
150 count_type ~= "alert" or count_type ~= "message" or count_type ~= "event" or count_type ~= "host" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
151 count_type ~= "site" or count_type ~= "organization" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
152 count_ext = count_type |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
153 count_type = "ext-type" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
154 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
155 return count_type, count_ext |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
156 elseif typ == "category" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
157 local cat, cat_ext = var, nil |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
158 if cat ~= "asn" or cat ~= "atm" or cat ~= "e-mail" or cat ~= "ipv4-addr" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
159 cat ~= "ipv4-net" or cat ~= "ipv4-net-mask" or cat ~= "ipv6-addr" or cat ~= "ipv6-net" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
160 cat ~= "ipv6-net-mask" or cat ~= "mac" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
161 cat_ext = cat |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
162 cat = "ext-category" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
163 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
164 return cat, cat_ext |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
165 elseif type == "noderole" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
166 local noderole_ext = nil |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
167 if cat ~= "client" or cat ~= "server-internal" or cat ~= "server-public" or cat ~= "www" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
168 cat ~= "mail" or cat ~= "messaging" or cat ~= "streaming" or cat ~= "voice" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
169 cat ~= "file" or cat ~= "ftp" or cat ~= "p2p" or cat ~= "name" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
170 cat ~= "directory" or cat ~= "credential" or cat ~= "print" or cat ~= "application" or |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
171 cat ~= "database" or cat ~= "infra" or cat ~= "log" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
172 noderole_ext = true |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
173 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
174 return noderole_ext |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
175 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
176 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
177 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
178 local function do_tag_mapping(tag, object) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
179 if tag.name == "IncidentID" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
180 object.id = { text = tag:get_text(), name = tag.attr.name } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
181 elseif tag.name == "StartTime" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
182 object.start_time = tag:get_text() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
183 elseif tag.name == "EndTime" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
184 object.end_time = tag:get_text() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
185 elseif tag.name == "ReportTime" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
186 object.report_time = tag:get_text() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
187 elseif tag.name == "Description" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
188 object.desc = { text = tag:get_text(), lang = tag.attr["xml:lang"] } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
189 elseif tag.name == "Contact" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
190 local jid = tag:get_child("AdditionalData").tags[1] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
191 local email = tag:get_child("Email") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
192 local telephone = tag:get_child("Telephone") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
193 local postaladdr = tag:get_child("PostalAddress") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
194 if not object.contacts then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
195 object.contacts = {} |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
196 object.contacts[1] = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
197 role = tag.attr.role, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
198 ext_role = (tag.attr["ext-role"] and true) or nil, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
199 type = tag.attr.type, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
200 ext_type = (tag.attr["ext-type"] and true) or nil, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
201 xmlns = jid.attr.xmlns, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
202 jid = jid:get_text(), |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
203 email = email, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
204 telephone = telephone, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
205 postaladdr = postaladdr |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
206 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
207 else |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
208 object.contacts[#object.contacts + 1] = { |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
209 role = tag.attr.role, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
210 ext_role = (tag.attr["ext-role"] and true) or nil, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
211 type = tag.attr.type, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
212 ext_type = (tag.attr["ext-type"] and true) or nil, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
213 xmlns = jid.attr.xmlns, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
214 jid = jid:get_text(), |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
215 email = email, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
216 telephone = telephone, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
217 postaladdr = postaladdr |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
218 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
219 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
220 elseif tag.name == "RelatedActivity" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
221 object.related = {} |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
222 for _, t in ipairs(tag.tags) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
223 if tag.name == "IncidentID" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
224 object.related[#object.related + 1] = { text = t:get_text(), name = tag.attr.name } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
225 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
226 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
227 elseif tag.name == "Assessment" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
228 local impact = tag:get_child("Impact") |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
229 object.assessment = { lang = impact.attr.lang, severity = impact.attr.severity, completion = impact.attr.completion, type = impact.attr.type } |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
230 elseif tag.name == "EventData" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
231 local source = tag:get_child("Flow").tags[1] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
232 local target = tag:get_child("Flow").tags[2] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
233 local expectation = tag:get_child("Flow").tags[3] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
234 object.event_data = { sources = {}, targets = {} } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
235 for _, t in ipairs(source.tags) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
236 local addr = t:get_child("Address") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
237 local cntr = t:get_child("Counter") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
238 object.event_data.sources[#object.event_data.sources + 1] = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
239 address = { cat = addr.attr.category, ext = addr.attr["ext-category"], text = addr:get_text() }, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
240 counter = { type = cntr.attr.type, ext_type = cntr.attr["ext-type"], value = cntr:get_text() } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
241 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
242 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
243 for _, entry in ipairs(target.tags) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
244 local noderole = { cat = entry:get_child("NodeRole").attr.category, ext = entry:get_child("NodeRole").attr["ext-category"] } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
245 local current = #object.event_data.targets + 1 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
246 object.event_data.targets[current] = { addresses = {}, noderole = noderole } |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
247 for _, tag in ipairs(entry.tags) do |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
248 object.event_data.targets[current].addresses[#object.event_data.targets[current].addresses + 1] = { text = tag:get_text(), cat = tag.attr.category, ext = tag.attr["ext-category"] } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
249 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
250 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
251 if expectation then |
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
252 object.event_data.expectation = { |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
253 action = expectation.attr.action, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
254 desc = expectation:get_child("Description") and expectation:get_child("Description"):get_text() |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
255 } |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
256 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
257 elseif tag.name == "History" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
258 object.history = {} |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
259 for _, t in ipairs(tag.tags) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
260 object.history[#object.history + 1] = { |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
261 action = t.attr.action, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
262 date = t:get_child("DateTime"):get_text(), |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
263 desc = t:get_chilld("Description"):get_text() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
264 } |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
265 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
266 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
267 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
268 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
269 local function stanza_parser(stanza) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
270 local object = {} |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
271 |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
272 if stanza:get_child("report", xmlns_inc) then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
273 local report = st.clone(stanza):get_child("report", xmlns_inc):get_child("Incident", xmlns_iodef) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
274 for _, tag in ipairs(report.tags) do do_tag_mapping(tag, object) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
275 elseif stanza:get_child("request", xmlns_inc) then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
276 local request = st.clone(stanza):get_child("request", xmlns_inc):get_child("Incident", xmlns_iodef) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
277 for _, tag in ipairs(request.tags) do do_tag_mapping(tag, object) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
278 elseif stanza:get_child("response", xmlns_inc) then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
279 local response = st.clone(stanza):get_child("response", xmlns_inc):get_child("Incident", xmlns_iodef) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
280 for _, tag in ipairs(response.tags) do do_tag_mapping(tag, object) end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
281 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
282 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
283 return object |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
284 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
285 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
286 local function stanza_construct(id) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
287 if not id then return nil |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
288 else |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
289 local object = incidents[id].data |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
290 local s_type = incidents[id].type |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
291 local stanza = st.iq():tag(s_type or "report", { xmlns = xmlns_inc }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
292 stanza:tag("Incident", { xmlns = xmlns_iodef, purpose = incidents[id].purpose }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
293 :tag("IncidentID", { name = object.id.name }):text(object.id.text):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
294 :tag("StartTime"):text(object.start_time):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
295 :tag("EndTime"):text(object.end_time):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
296 :tag("ReportTime"):text(object.report_time):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
297 :tag("Description", { ["xml:lang"] = object.desc.lang }):text(object.desc.text):up():up(); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
298 |
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
299 local incident = stanza:get_child(s_type, xmlns_inc):get_child("Incident", xmlns_iodef) |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
300 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
301 for _, contact in ipairs(object.contacts) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
302 incident:tag("Contact", { role = (contact.ext_role and "ext-role") or contact.role, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
303 ["ext-role"] = (contact.ext_role and contact.role) or nil, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
304 type = (contact.ext_type and "ext-type") or contact.type, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
305 ["ext-type"] = (contact.ext_type and contact.type) or nil }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
306 :tag("Email"):text(contact.email):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
307 :tag("Telephone"):text(contact.telephone):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
308 :tag("PostalAddress"):text(contact.postaladdr):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
309 :tag("AdditionalData") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
310 :tag("jid", { xmlns = contact.xmlns }):text(contact.jid):up():up():up() |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
311 |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
312 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
313 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
314 incident:tag("RelatedActivity"):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
315 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
316 for _, related in ipairs(object.related) do |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
317 incident:get_child("RelatedActivity") |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
318 :tag("IncidentID", { name = related.name }):text(related.text):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
319 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
320 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
321 incident:tag("Assessment") |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
322 :tag("Impact", { |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
323 lang = object.assessment.lang, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
324 severity = object.assessment.severity, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
325 completion = object.assessment.completion, |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
326 type = object.assessment.type |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
327 }):up():up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
328 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
329 incident:tag("EventData") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
330 :tag("Flow") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
331 :tag("System", { category = "source" }):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
332 :tag("System", { category = "target" }):up():up():up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
333 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
334 local e_data = incident:get_child("EventData") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
335 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
336 local sources = e_data:get_child("Flow").tags[1] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
337 local targets = e_data:get_child("Flow").tags[2] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
338 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
339 for _, source in ipairs(object.event_data.sources) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
340 sources:tag("Node") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
341 :tag("Address", { category = source.address.cat, ["ext-category"] = source.address.ext }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
342 :text(source.address.text):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
343 :tag("Counter", { type = source.counter.type, ["ext-type"] = source.counter.ext_type }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
344 :text(source.counter.value):up():up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
345 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
346 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
347 for _, target in ipairs(object.event_data.targets) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
348 targets:tag("Node"):up() ; local node = targets.tags[#targets.tags] |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
349 for _, address in ipairs(target.addresses) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
350 node:tag("Address", { category = address.cat, ["ext-category"] = address.ext }):text(address.text):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
351 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
352 node:tag("NodeRole", { category = target.noderole.cat, ["ext-category"] = target.noderole.ext }):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
353 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
354 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
355 if object.event_data.expectation then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
356 e_data:tag("Expectation", { action = object.event_data.expectation.action }):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
357 if object.event_data.expectation.desc then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
358 local expectation = e_data:get_child("Expectation") |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
359 expectation:tag("Description"):text(object.event_data.expectation.desc):up(); |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
360 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
361 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
362 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
363 if object.history then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
364 local history = incident:tag("History"):up(); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
365 |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
366 for _, item in ipairs(object.history) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
367 history:tag("HistoryItem", { action = item.action }) |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
368 :tag("DateTime"):text(item.date):up() |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
369 :tag("Description"):text(item.desc):up():up(); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
370 end |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
371 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
372 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
373 -- Sanitize contact empty tags |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
374 for _, tag in ipairs(incident) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
375 if tag.name == "Contact" then |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
376 for i, check in ipairs(tag) do |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
377 if (check.name == "Email" or check.name == "PostalAddress" or check.name == "Telephone") and |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
378 not check:get_text() then |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
379 table.remove(tag, i) |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
380 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
381 end |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
382 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
383 end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
384 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
385 if s_type == "request" then stanza.attr.type = "get" |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
386 elseif s_type == "response" then stanza.attr.type = "set" |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
387 else stanza.attr.type = "set" end |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
388 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
389 return stanza |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
390 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
913
diff
changeset
|
391 end |
913
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
392 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
393 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
394 _M = {} -- wraps methods into the library. |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
395 _M.ft_str = ft_str |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
396 _M.get_incident_layout = get_incident_layout |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
397 _M.render_list = render_list |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
398 _M.render_single = render_single |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
399 _M.get_type = get_type |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
400 _M.stanza_parser = stanza_parser |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
401 _M.stanza_construct = stanza_construct |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
402 _M.set_my_host = function(host) my_host = host end |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
403 |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
404 return _M |
f42837829d5f
mod_incidents_handling: commiting its auxiliary library.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
405 |