mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Added Hipchat integration notifier.
This commit is contained in:
parent
3ccc82f343
commit
2b6fa769f7
4 changed files with 115 additions and 1 deletions
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
|
||||||
|
|
|
@ -250,6 +250,23 @@ _CONFIG_DEFINITIONS = {
|
||||||
'JOIN_ON_PMSUPDATE': (int, 'Join', 0),
|
'JOIN_ON_PMSUPDATE': (int, 'Join', 0),
|
||||||
'JOIN_ON_CONCURRENT': (int, 'Join', 0),
|
'JOIN_ON_CONCURRENT': (int, 'Join', 0),
|
||||||
'JOIN_ON_NEWDEVICE': (int, 'Join', 0),
|
'JOIN_ON_NEWDEVICE': (int, 'Join', 0),
|
||||||
|
'HIPCHAT_URL': (str, 'Hipchat', ''),
|
||||||
|
'HIPCHAT_COLOR': (str, 'Hipchat', 'green'),
|
||||||
|
'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),
|
||||||
'JOURNAL_MODE': (str, 'Advanced', 'wal'),
|
'JOURNAL_MODE': (str, 'Advanced', 'wal'),
|
||||||
'LAUNCH_BROWSER': (int, 'General', 1),
|
'LAUNCH_BROWSER': (int, 'General', 1),
|
||||||
'LOG_BLACKLIST': (int, 'General', 1),
|
'LOG_BLACKLIST': (int, 'General', 1),
|
||||||
|
|
|
@ -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,71 @@ 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
|
||||||
|
|
||||||
|
def notify(self, message, subject):
|
||||||
|
if not message or not subject:
|
||||||
|
return
|
||||||
|
|
||||||
|
text = '(plex) ' + subject.encode('utf-8') + ': ' + message.encode('utf-8')
|
||||||
|
|
||||||
|
data = {'color': self.color,
|
||||||
|
'message': text,
|
||||||
|
'notify': 'false',
|
||||||
|
'message_format': 'text'}
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
||||||
|
self.enabled = True
|
||||||
|
self.apiurl = apiurl
|
||||||
|
self.color = color
|
||||||
|
|
||||||
|
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': 'Color for the message to show up in your room. You'
|
||||||
|
' may use any valid Hipchat message color value.',
|
||||||
|
'input_type': 'text'
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue