mirror of https://github.com/caronc/apprise
Added Spike.sh support
parent
02058d4fe3
commit
09a50a0ae9
1
KEYWORDS
1
KEYWORDS
|
@ -99,6 +99,7 @@ SMTP2Go
|
|||
SNS
|
||||
SparkPost
|
||||
Splunk
|
||||
Spike
|
||||
Streamlabs
|
||||
Stride
|
||||
Synology Chat
|
||||
|
|
|
@ -124,6 +124,7 @@ The table below identifies the services this tool supports and some example serv
|
|||
| [Slack](https://github.com/caronc/apprise/wiki/Notify_slack) | slack:// | (TCP) 443 | slack://TokenA/TokenB/TokenC/<br />slack://TokenA/TokenB/TokenC/Channel<br />slack://botname@TokenA/TokenB/TokenC/Channel<br />slack://user@TokenA/TokenB/TokenC/Channel1/Channel2/ChannelN
|
||||
| [SMTP2Go](https://github.com/caronc/apprise/wiki/Notify_smtp2go) | smtp2go:// | (TCP) 443 | smtp2go://user@hostname/apikey<br />smtp2go://user@hostname/apikey/email<br />smtp2go://user@hostname/apikey/email1/email2/emailN<br />smtp2go://user@hostname/apikey/?name="From%20User"
|
||||
| [SparkPost](https://github.com/caronc/apprise/wiki/Notify_sparkpost) | sparkpost:// | (TCP) 443 | sparkpost://user@hostname/apikey<br />sparkpost://user@hostname/apikey/email<br />sparkpost://user@hostname/apikey/email1/email2/emailN<br />sparkpost://user@hostname/apikey/?name="From%20User"
|
||||
| [Spike.sh](https://github.com/caronc/apprise/wiki/Notify_spike) | spike:// | (TCP) 443 | spike://Token
|
||||
| [Splunk](https://github.com/caronc/apprise/wiki/Notify_splunk) | splunk:// or victorops:/ | (TCP) 443 | splunk://route_key@apikey<br />splunk://route_key@apikey/entity_id
|
||||
| [Streamlabs](https://github.com/caronc/apprise/wiki/Notify_streamlabs) | strmlabs:// | (TCP) 443 | strmlabs://AccessToken/<br/>strmlabs://AccessToken/?name=name&identifier=identifier&amount=0¤cy=USD
|
||||
| [Synology Chat](https://github.com/caronc/apprise/wiki/Notify_synology_chat) | synology:// or synologys:// | (TCP) 80 or 443 | synology://hostname/token<br />synology://hostname:port/token
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# BSD 2-Clause License
|
||||
#
|
||||
# Apprise - Push Notification Library.
|
||||
# Copyright (c) 2025, Chris Caron <lead2gold@gmail.com>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# Details at:
|
||||
# https://www.spike.sh/docs/alerts/send-alerts-to-spike/
|
||||
|
||||
import re
|
||||
import requests
|
||||
import json
|
||||
|
||||
from ..utils.parse import validate_regex
|
||||
from ..url import PrivacyMode
|
||||
from .base import NotifyBase
|
||||
from ..locale import gettext_lazy as _
|
||||
from ..common import NotifyType
|
||||
|
||||
|
||||
class NotifySpike(NotifyBase):
|
||||
"""
|
||||
A wrapper for Spike.sh Notifications
|
||||
"""
|
||||
|
||||
# The default descriptive name associated with the Notification
|
||||
service_name = _('Spike.sh')
|
||||
|
||||
# The services URL
|
||||
service_url = 'https://www.spike.sh/'
|
||||
|
||||
# The default secure protocol
|
||||
secure_protocol = 'spike'
|
||||
|
||||
# A URL that takes you to the setup/help of the specific protocol
|
||||
setup_url = 'https://github.com/caronc/apprise/wiki/Notify_spike'
|
||||
|
||||
# URL used to send notifications with
|
||||
notify_url = 'https://api.spike.sh/v1/alerts/'
|
||||
|
||||
templates = (
|
||||
'{schema}://{token}',
|
||||
)
|
||||
|
||||
template_tokens = dict(NotifyBase.template_tokens, **{
|
||||
'token': {
|
||||
'name': _('Integration Key'),
|
||||
'type': 'string',
|
||||
'private': True,
|
||||
'required': True,
|
||||
'regex': (r'^[a-z0-9]{32}$', 'i'),
|
||||
},
|
||||
})
|
||||
|
||||
def __init__(self, token, **kwargs):
|
||||
"""
|
||||
Initialize Spike.sh Object
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.token = validate_regex(
|
||||
token,
|
||||
*self.template_tokens['token']['regex']
|
||||
)
|
||||
if not self.token:
|
||||
msg = 'The Spike.sh integration key ({}) is invalid.'.format(
|
||||
token)
|
||||
self.logger.warning(msg)
|
||||
raise TypeError(msg)
|
||||
|
||||
self.webhook_url = f'{self.notify_url}{self.token}'
|
||||
|
||||
@property
|
||||
def url_identifier(self):
|
||||
"""
|
||||
Returns all of the identifiers that make this URL unique from
|
||||
another simliar one. Targets or end points should never be identified
|
||||
here.
|
||||
"""
|
||||
return (self.secure_protocol, self.token)
|
||||
|
||||
def url(self, privacy=False, *args, **kwargs):
|
||||
"""
|
||||
Returns the URL built dynamically based on specified arguments.
|
||||
"""
|
||||
params = self.url_parameters(privacy=privacy, *args, **kwargs)
|
||||
return '{schema}://{key}/?{params}'.format(
|
||||
schema=self.secure_protocol,
|
||||
key=self.pprint(self.token, privacy, mode=PrivacyMode.Secret),
|
||||
params=self.urlencode(params),
|
||||
)
|
||||
|
||||
def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
|
||||
"""
|
||||
Send Spike.sh Notification
|
||||
"""
|
||||
self.throttle()
|
||||
|
||||
payload = {
|
||||
'message': title if title else body,
|
||||
'description': body,
|
||||
}
|
||||
|
||||
headers = {
|
||||
'User-Agent': self.app_id,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
self.webhook_url,
|
||||
headers=headers,
|
||||
data=json.dumps(payload),
|
||||
verify=self.verify_certificate,
|
||||
timeout=self.request_timeout,
|
||||
)
|
||||
if response.status_code != requests.codes.ok:
|
||||
self.logger.warning(
|
||||
'Spike.sh notification failed: %d - %s',
|
||||
response.status_code, response.text)
|
||||
return False
|
||||
|
||||
except requests.RequestException as e:
|
||||
self.logger.warning(f'Spike.sh Exception: {e}')
|
||||
return False
|
||||
|
||||
self.logger.info('Spike.sh notification sent successfully.')
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def parse_url(url):
|
||||
"""
|
||||
Parses the URL and returns arguments to re-instantiate the object
|
||||
"""
|
||||
results = NotifyBase.parse_url(url, verify_host=False)
|
||||
if not results:
|
||||
return results
|
||||
|
||||
# Access token
|
||||
if 'token' in results['qsd'] and len(results['qsd']['token']):
|
||||
# Extract the account sid from an argument
|
||||
results['token'] = \
|
||||
NotifySpike.unquote(results['qsd']['token'])
|
||||
else:
|
||||
# Retrieve the token from the host
|
||||
results['token'] = NotifySpike.unquote(results['host'])
|
||||
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def parse_native_url(url):
|
||||
"""
|
||||
Supports reverse-parsing a Spike.sh native URL into an Apprise one
|
||||
"""
|
||||
match = re.match(
|
||||
r'^https://api\.spike\.sh/v1/alerts/([a-z0-9]{32})$', url, re.I)
|
||||
if not match:
|
||||
return None
|
||||
|
||||
return NotifySpike.parse_url(
|
||||
'{schema}://{token}'.format(
|
||||
schema=NotifySpike.secure_protocol,
|
||||
token=match.group(1)))
|
|
@ -49,10 +49,11 @@ NextcloudTalk, Notica, Notifiarr, Notifico, ntfy, Office365, OneSignal,
|
|||
Opsgenie, PagerDuty, PagerTree, ParsePlatform, Plivo, PopcornNotify, Prowl,
|
||||
Pushalot, PushBullet, Pushjet, PushMe, Pushover, PushSafer, Pushy, PushDeer,
|
||||
Revolt, Reddit, Resend, Rocket.Chat, RSyslog, SendGrid, ServerChan, Seven, SFR,
|
||||
Signal, SimplePush, Sinch, Slack, SMPP, SMSEagle, SMS Manager, SMTP2Go, SparkPost,
|
||||
Splunk, Super Toasty, Streamlabs, Stride, Synology Chat, Syslog, Techulus Push,
|
||||
Telegram, Threema Gateway, Twilio, Twitter, Twist, Vapid, VictorOps, Voipms,
|
||||
Vonage, WebPush, WeCom Bot, WhatsApp, Webex Teams, Workflows, WxPusher, XBMC}
|
||||
Signal, SimplePush, Sinch, Slack, SMPP, SMSEagle, SMS Manager, SMTP2Go,
|
||||
SparkPost, Splunk, Spike, Super Toasty, Streamlabs, Stride, Synology Chat,
|
||||
Syslog, Techulus Push, Telegram, Threema Gateway, Twilio, Twitter, Twist, Vapid,
|
||||
VictorOps, Voipms, Vonage, WebPush, WeCom Bot, WhatsApp, Webex Teams,
|
||||
Workflows, WxPusher, XBMC}
|
||||
|
||||
Name: python-%{pypi_name}
|
||||
Version: 1.9.3
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# BSD 2-Clause License
|
||||
#
|
||||
# Apprise - Push Notification Library.
|
||||
# Copyright (c) 2025, Chris Caron <lead2gold@gmail.com>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
import requests
|
||||
from apprise.plugins.spike import NotifySpike
|
||||
from helpers import AppriseURLTester
|
||||
|
||||
import logging
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
apprise_url_tests = (
|
||||
('spike://', {
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('spike://invalid-key', {
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('spike://1234567890abcdef1234567890abcdef', {
|
||||
'instance': NotifySpike,
|
||||
'privacy_url': 'spike://****/',
|
||||
}),
|
||||
('spike://?token=1234567890abcdef1234567890abcdef', {
|
||||
'instance': NotifySpike,
|
||||
'privacy_url': 'spike://****/',
|
||||
}),
|
||||
('https://api.spike.sh/v1/alerts/1234567890abcdef1234567890abcdef', {
|
||||
'instance': NotifySpike,
|
||||
}),
|
||||
('spike://1234567890abcdef1234567890abcdef', {
|
||||
'instance': NotifySpike,
|
||||
'response': False,
|
||||
'requests_response_code': requests.codes.internal_server_error,
|
||||
}),
|
||||
('spike://1234567890abcdef1234567890abcdef', {
|
||||
'instance': NotifySpike,
|
||||
'response': False,
|
||||
'requests_response_code': 999,
|
||||
}),
|
||||
('spike://ffffffffffffffffffffffffffffffff', {
|
||||
'instance': NotifySpike,
|
||||
'test_requests_exceptions': True,
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
def test_plugin_spike_urls():
|
||||
AppriseURLTester(tests=apprise_url_tests).run_all()
|
Loading…
Reference in New Issue