mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 06:13:25 -07:00
Fix IPv6 comparisson for concurrent streams
This commit is contained in:
parent
c761e6e8d0
commit
efa97fb445
3 changed files with 26 additions and 1 deletions
|
@ -177,6 +177,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
'NOTIFY_RECENTLY_ADDED_UPGRADE': (int, 'Monitoring', 0),
|
'NOTIFY_RECENTLY_ADDED_UPGRADE': (int, 'Monitoring', 0),
|
||||||
'NOTIFY_REMOTE_ACCESS_THRESHOLD': (int, 'Monitoring', 60),
|
'NOTIFY_REMOTE_ACCESS_THRESHOLD': (int, 'Monitoring', 60),
|
||||||
'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0),
|
'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0),
|
||||||
|
'NOTIFY_CONCURRENT_IPV6_CIDR': (str, 'Monitoring', '/64'),
|
||||||
'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2),
|
'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2),
|
||||||
'NOTIFY_NEW_DEVICE_INITIAL_ONLY': (int, 'Monitoring', 1),
|
'NOTIFY_NEW_DEVICE_INITIAL_ONLY': (int, 'Monitoring', 1),
|
||||||
'NOTIFY_SERVER_CONNECTION_THRESHOLD': (int, 'Monitoring', 60),
|
'NOTIFY_SERVER_CONNECTION_THRESHOLD': (int, 'Monitoring', 60),
|
||||||
|
|
|
@ -33,6 +33,7 @@ from functools import reduce, wraps
|
||||||
import hashlib
|
import hashlib
|
||||||
import imghdr
|
import imghdr
|
||||||
from future.moves.itertools import islice, zip_longest
|
from future.moves.itertools import islice, zip_longest
|
||||||
|
from ipaddress import ip_address, ip_network, IPv4Address
|
||||||
import ipwhois
|
import ipwhois
|
||||||
import ipwhois.exceptions
|
import ipwhois.exceptions
|
||||||
import ipwhois.utils
|
import ipwhois.utils
|
||||||
|
@ -1777,3 +1778,18 @@ def check_watched(media_type, view_offset, duration, marker_credits_first=None,
|
||||||
|
|
||||||
def pms_name():
|
def pms_name():
|
||||||
return plexpy.CONFIG.PMS_NAME_OVERRIDE or plexpy.CONFIG.PMS_NAME
|
return plexpy.CONFIG.PMS_NAME_OVERRIDE or plexpy.CONFIG.PMS_NAME
|
||||||
|
|
||||||
|
|
||||||
|
def ip_type(ip: str) -> str:
|
||||||
|
try:
|
||||||
|
return "IPv4" if type(ip_address(ip)) is IPv4Address else "IPv6"
|
||||||
|
except ValueError:
|
||||||
|
return "Invalid"
|
||||||
|
|
||||||
|
|
||||||
|
def get_ipv6_network_address(ip: str) -> str:
|
||||||
|
cidr = "/64"
|
||||||
|
cidr_pattern = re.compile(r'^/(1([0-1]\d|2[0-8]))$|^/(\d\d)$|^/[1-9]$')
|
||||||
|
if cidr_pattern.match(plexpy.CONFIG.NOTIFY_CONCURRENT_IPV6_CIDR):
|
||||||
|
cidr = plexpy.CONFIG.NOTIFY_CONCURRENT_IPV6_CIDR
|
||||||
|
return str(ip_network(ip+cidr, strict=False).network_address)
|
||||||
|
|
|
@ -160,6 +160,7 @@ def add_notifier_each(notifier_id=None, notify_action=None, stream_data=None, ti
|
||||||
|
|
||||||
def notify_conditions(notify_action=None, stream_data=None, timeline_data=None, **kwargs):
|
def notify_conditions(notify_action=None, stream_data=None, timeline_data=None, **kwargs):
|
||||||
logger.debug("Tautulli NotificationHandler :: Checking global notification conditions.")
|
logger.debug("Tautulli NotificationHandler :: Checking global notification conditions.")
|
||||||
|
evaluated = False
|
||||||
|
|
||||||
# Activity notifications
|
# Activity notifications
|
||||||
if stream_data:
|
if stream_data:
|
||||||
|
@ -187,7 +188,14 @@ def notify_conditions(notify_action=None, stream_data=None, timeline_data=None,
|
||||||
user_sessions = [s for s in result['sessions'] if s['user_id'] == stream_data['user_id']]
|
user_sessions = [s for s in result['sessions'] if s['user_id'] == stream_data['user_id']]
|
||||||
|
|
||||||
if plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP:
|
if plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP:
|
||||||
evaluated = len(Counter(s['ip_address'] for s in user_sessions)) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD
|
ip_addresses = []
|
||||||
|
for s in user_sessions:
|
||||||
|
if helpers.ip_type(s['ip_address']) == 'IPv6':
|
||||||
|
ip_addresses.append(helpers.get_ipv6_network_address(s['ip_address']))
|
||||||
|
if helpers.ip_type(s['ip_address']) == 'IPv4':
|
||||||
|
ip_addresses.append(s['ip_address'])
|
||||||
|
logger.debug("IP addresses: %s" % ip_addresses)
|
||||||
|
evaluated = len(Counter(ip_addresses)) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD
|
||||||
else:
|
else:
|
||||||
evaluated = len(user_sessions) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD
|
evaluated = len(user_sessions) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue