multiple agents

allow for sending to multiple notification agents.
This commit is contained in:
blacktwin 2018-02-21 15:37:28 -05:00 committed by GitHub
parent dad6341da8
commit fda36098ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,29 +1,28 @@
import psutil import psutil
import requests import requests
import urllib
# Drive letter to check if exists. # Drive letter to check if exists.
drive = 'D:' drive = 'F:'
disk = psutil.disk_partitions() disk = psutil.disk_partitions()
PLEXPY_URL = 'http://localhost:8181/' # Your PlexPy URL PLEXPY_URL = 'http://localhost:8182/' # Your PlexPy URL
PLEXPY_APIKEY = '#####' # Enter your PlexPy API Key PLEXPY_APIKEY = 'xxxxxx' # Enter your PlexPy API Key
AGENT_ID = 10 # The PlexPy notifier agent id found here: https://github.com/drzoidberg33/plexpy/blob/master/plexpy/notifiers.py#L43 AGENT_LST = [10, 11] # The PlexPy notifier agent id found here: https://github.com/drzoidberg33/plexpy/blob/master/plexpy/notifiers.py#L43
NOTIFY_SUBJECT = 'PlexPy' # The notification subject NOTIFY_SUBJECT = 'PlexPy' # The notification subject
NOTIFY_BODY = 'The Plex disk {0} was not found'.format(drive) # The notification body NOTIFY_BODY = 'The Plex disk {0} was not found'.format(drive) # The notification body
disk_check = [True for i in disk if drive in i.mountpoint] disk_check = [True for i in disk if drive in i.mountpoint]
if not disk_check: if not disk_check:
# Send notification to PlexPy using the API # Send the notification through PlexPy
data = {'apikey': PLEXPY_APIKEY, payload = {'apikey': PLEXPY_APIKEY,
'cmd': 'notify', 'cmd': 'notify',
'agent_id': int(AGENT_ID),
'subject': NOTIFY_SUBJECT, 'subject': NOTIFY_SUBJECT,
'body': NOTIFY_BODY} 'body': NOTIFY_BODY}
url = PLEXPY_URL + 'api/v2?' + urllib.urlencode(data) for agent in AGENT_LST:
r = requests.post(url) payload['agent_id'] = agent
requests.post(PLEXPY_URL.rstrip('/') + '/api/v2', params=payload)
else: else:
pass pass