Merge pull request #773 from aboron/dev
Added Hipchat integration notifier.
This commit is contained in:
1
API.md
1
API.md
@@ -1737,6 +1737,7 @@ Required parameters:
|
|||||||
10 # Email
|
10 # Email
|
||||||
16 # Facebook
|
16 # Facebook
|
||||||
0 # Growl
|
0 # Growl
|
||||||
|
19 # Hipchat
|
||||||
12 # IFTTT
|
12 # IFTTT
|
||||||
18 # Join
|
18 # Join
|
||||||
4 # NotifyMyAndroid
|
4 # NotifyMyAndroid
|
||||||
|
@@ -212,6 +212,25 @@ _CONFIG_DEFINITIONS = {
|
|||||||
'HTTP_PROXY': (int, 'General', 0),
|
'HTTP_PROXY': (int, 'General', 0),
|
||||||
'HTTP_ROOT': (str, 'General', ''),
|
'HTTP_ROOT': (str, 'General', ''),
|
||||||
'HTTP_USERNAME': (str, 'General', ''),
|
'HTTP_USERNAME': (str, 'General', ''),
|
||||||
|
'HIPCHAT_URL': (str, 'Hipchat', ''),
|
||||||
|
'HIPCHAT_COLOR': (str, 'Hipchat', ''),
|
||||||
|
'HIPCHAT_INCL_SUBJECT': (int, 'Hipchat', 1),
|
||||||
|
'HIPCHAT_EMOTICON': (str, 'Hipchat', ''),
|
||||||
|
'HIPCHAT_ENABLED': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_PLAY': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_STOP': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_PAUSE': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_RESUME': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_BUFFER': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_WATCHED': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_CREATED': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_EXTDOWN': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_INTDOWN': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_EXTUP': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_INTUP': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_PMSUPDATE': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_CONCURRENT': (int, 'Hipchat', 0),
|
||||||
|
'HIPCHAT_ON_NEWDEVICE': (int, 'Hipchat', 0),
|
||||||
'INTERFACE': (str, 'General', 'default'),
|
'INTERFACE': (str, 'General', 'default'),
|
||||||
'IP_LOGGING_ENABLE': (int, 'General', 0),
|
'IP_LOGGING_ENABLE': (int, 'General', 0),
|
||||||
'IFTTT_KEY': (str, 'IFTTT', ''),
|
'IFTTT_KEY': (str, 'IFTTT', ''),
|
||||||
|
@@ -62,7 +62,8 @@ AGENT_IDS = {"Growl": 0,
|
|||||||
"Scripts": 15,
|
"Scripts": 15,
|
||||||
"Facebook": 16,
|
"Facebook": 16,
|
||||||
"Browser": 17,
|
"Browser": 17,
|
||||||
"Join": 18}
|
"Join": 18,
|
||||||
|
"Hipchat": 19}
|
||||||
|
|
||||||
|
|
||||||
def available_notification_agents():
|
def available_notification_agents():
|
||||||
@@ -425,6 +426,26 @@ def available_notification_agents():
|
|||||||
'on_pmsupdate': plexpy.CONFIG.JOIN_ON_PMSUPDATE,
|
'on_pmsupdate': plexpy.CONFIG.JOIN_ON_PMSUPDATE,
|
||||||
'on_concurrent': plexpy.CONFIG.JOIN_ON_CONCURRENT,
|
'on_concurrent': plexpy.CONFIG.JOIN_ON_CONCURRENT,
|
||||||
'on_newdevice': plexpy.CONFIG.JOIN_ON_NEWDEVICE
|
'on_newdevice': plexpy.CONFIG.JOIN_ON_NEWDEVICE
|
||||||
|
},
|
||||||
|
{'name': 'Hipchat',
|
||||||
|
'id': AGENT_IDS['Hipchat'],
|
||||||
|
'config_prefix': 'hipchat',
|
||||||
|
'has_config': True,
|
||||||
|
'state': checked(plexpy.CONFIG.HIPCHAT_ENABLED),
|
||||||
|
'on_play': plexpy.CONFIG.HIPCHAT_ON_PLAY,
|
||||||
|
'on_stop': plexpy.CONFIG.HIPCHAT_ON_STOP,
|
||||||
|
'on_pause': plexpy.CONFIG.HIPCHAT_ON_PAUSE,
|
||||||
|
'on_resume': plexpy.CONFIG.HIPCHAT_ON_RESUME,
|
||||||
|
'on_buffer': plexpy.CONFIG.HIPCHAT_ON_BUFFER,
|
||||||
|
'on_watched': plexpy.CONFIG.HIPCHAT_ON_WATCHED,
|
||||||
|
'on_created': plexpy.CONFIG.HIPCHAT_ON_CREATED,
|
||||||
|
'on_extdown': plexpy.CONFIG.HIPCHAT_ON_EXTDOWN,
|
||||||
|
'on_intdown': plexpy.CONFIG.HIPCHAT_ON_INTDOWN,
|
||||||
|
'on_extup': plexpy.CONFIG.HIPCHAT_ON_EXTUP,
|
||||||
|
'on_intup': plexpy.CONFIG.HIPCHAT_ON_INTUP,
|
||||||
|
'on_pmsupdate': plexpy.CONFIG.HIPCHAT_ON_PMSUPDATE,
|
||||||
|
'on_concurrent': plexpy.CONFIG.HIPCHAT_ON_CONCURRENT,
|
||||||
|
'on_newdevice': plexpy.CONFIG.HIPCHAT_ON_NEWDEVICE
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -516,6 +537,9 @@ def get_notification_agent_config(agent_id):
|
|||||||
elif agent_id == 18:
|
elif agent_id == 18:
|
||||||
join = JOIN()
|
join = JOIN()
|
||||||
return join.return_config_options()
|
return join.return_config_options()
|
||||||
|
elif agent_id == 19:
|
||||||
|
hipchat = HIPCHAT()
|
||||||
|
return hipchat.return_config_options()
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
@@ -583,6 +607,9 @@ def send_notification(agent_id, subject, body, notify_action, **kwargs):
|
|||||||
elif agent_id == 18:
|
elif agent_id == 18:
|
||||||
join = JOIN()
|
join = JOIN()
|
||||||
return join.notify(message=body, subject=subject)
|
return join.notify(message=body, subject=subject)
|
||||||
|
elif agent_id == 19:
|
||||||
|
hipchat = HIPCHAT()
|
||||||
|
return hipchat.notify(message=body, subject=subject)
|
||||||
else:
|
else:
|
||||||
logger.debug(u"PlexPy Notifiers :: Unknown agent id received.")
|
logger.debug(u"PlexPy Notifiers :: Unknown agent id received.")
|
||||||
else:
|
else:
|
||||||
@@ -2721,3 +2748,96 @@ class JOIN(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
return config_option
|
return config_option
|
||||||
|
|
||||||
|
class HIPCHAT(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.apiurl = plexpy.CONFIG.HIPCHAT_URL
|
||||||
|
self.color = plexpy.CONFIG.HIPCHAT_COLOR
|
||||||
|
self.incl_subject = plexpy.CONFIG.HIPCHAT_INCL_SUBJECT
|
||||||
|
self.emoticon = plexpy.CONFIG.HIPCHAT_EMOTICON
|
||||||
|
|
||||||
|
def notify(self, message, subject):
|
||||||
|
if not message or not subject:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.incl_subject:
|
||||||
|
text = subject.encode('utf-8') + ': ' + message.encode('utf-8')
|
||||||
|
else:
|
||||||
|
text = message.encode('utf-8')
|
||||||
|
|
||||||
|
if self.emoticon:
|
||||||
|
text = self.emoticon + ' ' + text
|
||||||
|
|
||||||
|
data = {'message': text,
|
||||||
|
'notify': 'false',
|
||||||
|
'message_format': 'text'}
|
||||||
|
|
||||||
|
if self.color:
|
||||||
|
data['color'] = self.color
|
||||||
|
|
||||||
|
hiphost = urlparse(self.apiurl).hostname
|
||||||
|
hippath = urlparse(self.apiurl).path
|
||||||
|
hipquery = urlparse(self.apiurl).query
|
||||||
|
hipfullq = hippath + '?' + hipquery
|
||||||
|
|
||||||
|
http_handler = HTTPSConnection(hiphost)
|
||||||
|
http_handler.request("POST",
|
||||||
|
"%s" % (hipfullq),
|
||||||
|
headers={'Content-type': "application/json"},
|
||||||
|
body=json.dumps(data))
|
||||||
|
response = http_handler.getresponse()
|
||||||
|
request_status = response.status
|
||||||
|
|
||||||
|
if request_status == 200 or request_status == 204:
|
||||||
|
logger.info(u"PlexPy Notifiers :: Hipchat notification sent.")
|
||||||
|
return True
|
||||||
|
elif request_status >= 400 and request_status < 500:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: Hipchat notification failed: [%s] %s" % (request_status, response.reason))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: Hipchat notification failed.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def test(self, apiurl, color, hipchat_emoticon, hipchat_incl_subject):
|
||||||
|
|
||||||
|
self.enabled = True
|
||||||
|
self.apiurl = apiurl
|
||||||
|
self.color = color
|
||||||
|
self.emoticon = hipchat_emoticon
|
||||||
|
self.incl_subject = hipchat_incl_subject
|
||||||
|
|
||||||
|
return self.notify('PlexPy', 'Test Message')
|
||||||
|
|
||||||
|
def return_config_options(self):
|
||||||
|
config_option = [{'label': 'Hipchat Custom Integrations Full URL',
|
||||||
|
'value': self.apiurl,
|
||||||
|
'name': 'hipchat_url',
|
||||||
|
'description': 'Your Hipchat integration URL. You can get a key from'
|
||||||
|
' <a href="' + helpers.anon_url('https://www.hipchat.com/addons/') + '" target="_blank">here</a>.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Hipchat Color',
|
||||||
|
'value': self.color,
|
||||||
|
'name': 'hipchat_color',
|
||||||
|
'description': 'Background color for the message.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': {'yellow': 'yellow', 'green': 'green', 'red': 'red', 'purple': 'purple', 'gray': 'gray', 'random': 'random'}
|
||||||
|
},
|
||||||
|
{'label': 'Hipchat emoticon',
|
||||||
|
'value': self.emoticon,
|
||||||
|
'name': 'hipchat_emoticon',
|
||||||
|
'description': 'Include an emoticon tag at the beginning of all notifications. Leave blank for none.'
|
||||||
|
' Use a stock emoticon or create a custom emoticon'
|
||||||
|
' <a href="' + helpers.anon_url('https://www.hipchat.com/emoticons/') + '" target="_blank">here</a>.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Include Subject Line',
|
||||||
|
'value': self.incl_subject,
|
||||||
|
'name': 'hipchat_incl_subject',
|
||||||
|
'description': 'Include the subject line with the notifications.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return config_option
|
@@ -2884,6 +2884,7 @@ class WebInterface(object):
|
|||||||
10 # Email
|
10 # Email
|
||||||
16 # Facebook
|
16 # Facebook
|
||||||
0 # Growl
|
0 # Growl
|
||||||
|
19 # Hipchat
|
||||||
12 # IFTTT
|
12 # IFTTT
|
||||||
18 # Join
|
18 # Join
|
||||||
4 # NotifyMyAndroid
|
4 # NotifyMyAndroid
|
||||||
|
Reference in New Issue
Block a user