|
|
|
@ -182,19 +182,6 @@ class NotifyJSON(NotifyBase):
|
|
|
|
|
self.logger.warning(msg)
|
|
|
|
|
raise TypeError(msg)
|
|
|
|
|
|
|
|
|
|
# A payload map allows users to over-ride the default mapping if
|
|
|
|
|
# they're detected with the :overide=value. Normally this would
|
|
|
|
|
# create a new key and assign it the value specified. However
|
|
|
|
|
# if the key you specify is actually an internally mapped one,
|
|
|
|
|
# then a re-mapping takes place using the value
|
|
|
|
|
self.payload_map = {
|
|
|
|
|
JSONPayloadField.VERSION: JSONPayloadField.VERSION,
|
|
|
|
|
JSONPayloadField.TITLE: JSONPayloadField.TITLE,
|
|
|
|
|
JSONPayloadField.MESSAGE: JSONPayloadField.MESSAGE,
|
|
|
|
|
JSONPayloadField.ATTACHMENTS: JSONPayloadField.ATTACHMENTS,
|
|
|
|
|
JSONPayloadField.MESSAGETYPE: JSONPayloadField.MESSAGETYPE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.params = {}
|
|
|
|
|
if params:
|
|
|
|
|
# Store our extra headers
|
|
|
|
@ -205,21 +192,10 @@ class NotifyJSON(NotifyBase):
|
|
|
|
|
# Store our extra headers
|
|
|
|
|
self.headers.update(headers)
|
|
|
|
|
|
|
|
|
|
self.payload_overrides = {}
|
|
|
|
|
self.payload_extras = {}
|
|
|
|
|
if payload:
|
|
|
|
|
# Store our extra payload entries
|
|
|
|
|
self.payload_extras.update(payload)
|
|
|
|
|
for key in list(self.payload_extras.keys()):
|
|
|
|
|
# Any values set in the payload to alter a system related one
|
|
|
|
|
# alters the system key. Hence :message=msg maps the 'message'
|
|
|
|
|
# variable that otherwise already contains the payload to be
|
|
|
|
|
# 'msg' instead (containing the payload)
|
|
|
|
|
if key in self.payload_map:
|
|
|
|
|
self.payload_map[key] = self.payload_extras[key].strip()
|
|
|
|
|
self.payload_overrides[key] = \
|
|
|
|
|
self.payload_extras[key].strip()
|
|
|
|
|
del self.payload_extras[key]
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
@ -245,8 +221,6 @@ class NotifyJSON(NotifyBase):
|
|
|
|
|
# Append our payload extra's into our parameters
|
|
|
|
|
params.update(
|
|
|
|
|
{':{}'.format(k): v for k, v in self.payload_extras.items()})
|
|
|
|
|
params.update(
|
|
|
|
|
{':{}'.format(k): v for k, v in self.payload_overrides.items()})
|
|
|
|
|
|
|
|
|
|
# Determine Authentication
|
|
|
|
|
auth = ''
|
|
|
|
@ -320,22 +294,30 @@ class NotifyJSON(NotifyBase):
|
|
|
|
|
self.logger.debug('I/O Exception: %s' % str(e))
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# prepare JSON Object
|
|
|
|
|
payload = {}
|
|
|
|
|
for key, value in (
|
|
|
|
|
(JSONPayloadField.VERSION, self.json_version),
|
|
|
|
|
(JSONPayloadField.TITLE, title),
|
|
|
|
|
(JSONPayloadField.MESSAGE, body),
|
|
|
|
|
(JSONPayloadField.ATTACHMENTS, attachments),
|
|
|
|
|
(JSONPayloadField.MESSAGETYPE, notify_type)):
|
|
|
|
|
|
|
|
|
|
if not self.payload_map[key]:
|
|
|
|
|
# Do not store element in payload response
|
|
|
|
|
continue
|
|
|
|
|
payload[self.payload_map[key]] = value
|
|
|
|
|
|
|
|
|
|
# Apply any/all payload over-rides defined
|
|
|
|
|
payload.update(self.payload_extras)
|
|
|
|
|
# Prepare JSON Object
|
|
|
|
|
payload = {
|
|
|
|
|
JSONPayloadField.VERSION: self.json_version,
|
|
|
|
|
JSONPayloadField.TITLE: title,
|
|
|
|
|
JSONPayloadField.MESSAGE: body,
|
|
|
|
|
JSONPayloadField.ATTACHMENTS: attachments,
|
|
|
|
|
JSONPayloadField.MESSAGETYPE: notify_type,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for key, value in self.payload_extras.items():
|
|
|
|
|
|
|
|
|
|
if key in payload:
|
|
|
|
|
if not value:
|
|
|
|
|
# Do not store element in payload response
|
|
|
|
|
del payload[key]
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# Re-map
|
|
|
|
|
payload[value] = payload[key]
|
|
|
|
|
del payload[key]
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# Append entry
|
|
|
|
|
payload[key] = value
|
|
|
|
|
|
|
|
|
|
auth = None
|
|
|
|
|
if self.user:
|
|
|
|
|