From 056a4517fea66332e7e367633d3ba30641ab41fd Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:25:13 +0200 Subject: [PATCH 01/17] SIGNL4 Plugin Added SIGNL4 plugin added. --- apprise/plugins/signl4.py | 320 ++++++++++++++++++++++++++++++++++++ tests/test_plugin_signl4.py | 163 ++++++++++++++++++ 2 files changed, 483 insertions(+) create mode 100644 apprise/plugins/signl4.py create mode 100644 tests/test_plugin_signl4.py diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py new file mode 100644 index 00000000..cc3047ee --- /dev/null +++ b/apprise/plugins/signl4.py @@ -0,0 +1,320 @@ +# -*- coding: utf-8 -*- +# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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. + +# API Refererence: +# - https://docs.signl4.com/integrations/webhook/webhook.html +# + +import requests +from json import dumps + +from .base import NotifyBase +from ..url import PrivacyMode +from ..common import NotifyType +from ..utils.parse import validate_regex +from ..locale import gettext_lazy as _ + +class NotifySIGNL4(NotifyBase): + """ + A wrapper for SIGNL4 Notifications + """ + + # The default descriptive name associated with the Notification + service_name = "SIGNL4" + + # The services URL + service_url = "https://connect.signl4.com/webhook/" + + # Secure Protocol + secure_protocol = "signl4" + + # A URL that takes you to the setup/help of the specific protocol + setup_url = "https://github.com/caronc/apprise/wiki/Notify_signl4" + + # Our event action type + event_action = "trigger" + + # Define object templates + templates = ( + "{schema}://{secret}", + ) + + # Define our template tokens + template_tokens = dict(NotifyBase.template_tokens, **{ + # SIGNL4 team or integration secret + "secret": { + "name": _("Secret"), + "type": "string", + "private": True, + "required": True + }, + }) + + # Define our template arguments + template_args = dict(NotifyBase.template_args, **{ + "service": { + "name": _("service"), + "type": "string", + }, + "location": { + "name": _("location"), + "type": "string", + }, + "alerting_scenario": { + "name": _("alerting_scenario"), + "type": "string", + }, + "filtering": { + "name": _("filtering"), + "type": "bool", + }, + "external_id": { + "name": _("external_id"), + "type": "string", + }, + "status": { + "name": _("status"), + "type": "string", + }, + }) + + def __init__(self, secret, service=None, location=None, alerting_scenario=None, + filtering=None, external_id=None, status=None, **kwargs): + """ + Initialize SIGNL4 Object + """ + super().__init__(**kwargs) + + # SIGNL4 team or integration secret + self.secret = validate_regex(secret) + if not self.secret: + msg = "An invalid SIGNL4 team or integration secret " \ + "({}) was specified.".format(secret) + self.logger.warning(msg) + raise TypeError(msg) + + # A service option for notifications + self.service = service + + # A location option for notifications + self.location = location + + # A alerting_scenario option for notifications + self.alerting_scenario = alerting_scenario + + # A filtering option for notifications + self.filtering = bool(filtering) + + # A external_id option for notifications + self.external_id = external_id + + # A location option for notifications + self.status = status + + return + + def send(self, body, title="", notify_type=NotifyType.INFO, **kwargs): + """ + Send our SIGNL4 Notification + """ + + # Prepare our headers + headers = { + "Content-Type": "application/json", + } + + # Prepare our persistent_notification.create payload + payload = { + "title": title if title else self.app_desc, + "body": body, + "X-S4-SourceSystem": "Apprise", + } + + if self.service: + payload["X-S4-Service"] = self.service + + if self.alerting_scenario: + payload["X-S4-AlertingScenario"] = self.alerting_scenario + + if self.location: + payload["X-S4-Location"] = self.location + + if self.filtering: + payload["X-S4-Filtering"] = self.filtering + + if self.external_id: + payload["X-S4-ExternalID"] = self.external_id + + if self.status: + payload["X-S4-Status"] = self.status + + # Prepare our URL + notify_url = self.service_url + self.secret + + self.logger.debug("SIGNL4 POST URL: %s (cert_verify=%r)" % ( + notify_url, self.verify_certificate, + )) + self.logger.debug("SIGNL4 Payload: %s" % str(payload)) + + # Always call throttle before any remote server i/o is made + self.throttle() + + try: + r = requests.post( + notify_url, + data=dumps(payload), + headers=headers, + verify=self.verify_certificate, + timeout=self.request_timeout, + ) + if r.status_code not in ( + requests.codes.ok, requests.codes.created, + requests.codes.accepted): + # We had a problem + status_str = \ + NotifySIGNL4.http_response_code_lookup( + r.status_code) + + self.logger.warning( + "Failed to send SIGNL4 notification: " + "{}{}error={}.".format( + status_str, + ", " if status_str else "", + r.status_code)) + + self.logger.debug("Response Details:\r\n{}".format(r.content)) + + # Return; we're done + return False + + else: + self.logger.info("Sent SIGNL4 notification.") + + except requests.RequestException as e: + self.logger.warning( + "A Connection error occurred sending SIGNL4 " + "notification to %s." % self.host) + self.logger.debug("Socket Exception: %s" % str(e)) + + # Return; we're done + return False + + return True + + @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.secret, + ) + + def url(self, privacy=False, *args, **kwargs): + """ + Returns the URL built dynamically based on specified arguments. + """ + + # Define any URL parameters + params = { + "region": "none", + } + + if self.service is not None: + params["service"] = self.service + + if self.location is not None: + params["location"] = self.location + + if self.alerting_scenario is not None: + params["alerting_scenario"] = self.alerting_scenario + + if self.filtering is not None: + params["filtering"] = self.filtering + + if self.external_id is not None: + params["external_id"] = self.external_id + + if self.status is not None: + params["status"] = self.status + + # Extend our parameters + params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) + + url = "{schema}://{secret}/" + + return url.format( + schema=self.secure_protocol, + # never encode hostname since we're expecting it to be a valid one + secret=self.pprint( + self.secret, privacy, mode=PrivacyMode.Secret, safe=""), + params=NotifySIGNL4.urlencode(params), + ) + + @staticmethod + def parse_url(url): + """ + Parses the URL and returns enough arguments that can allow + us to re-instantiate this object. + """ + + results = NotifyBase.parse_url(url, verify_host=False) + if not results: + # We're done early as we couldn"t load the results + return results + + # The "secret" makes it easier to use yaml configuration + if "secret" in results["qsd"] and \ + len(results["qsd"]["secret"]): + results["secret"] = \ + NotifySIGNL4.unquote(results["qsd"]["secret"]) + else: + results["secret"] = \ + NotifySIGNL4.unquote(results["host"]) + + if "service" in results["qsd"] and len(results["qsd"]["service"]): + results["service"] = NotifySIGNL4.unquote(results["qsd"]["service"]) + + if "location" in results["qsd"] and len(results["qsd"]["location"]): + results["location"] = NotifySIGNL4.unquote(results["qsd"]["location"]) + + if "alerting_scenario" in results["qsd"] and len(results["qsd"]["alerting_scenario"]): + results["alerting_scenario"] = NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) + + if "filtering" in results["qsd"] and len(results["qsd"]["filtering"]): + results["filtering"] = NotifySIGNL4.unquote(results["qsd"]["filtering"]) + + if "external_id" in results["qsd"] and len(results["qsd"]["external_id"]): + results["external_id"] = NotifySIGNL4.unquote(results["qsd"]["external_id"]) + + if "status" in results["qsd"] and len(results["qsd"]["status"]): + results["status"] = NotifySIGNL4.unquote(results["qsd"]["status"]) + + return results diff --git a/tests/test_plugin_signl4.py b/tests/test_plugin_signl4.py new file mode 100644 index 00000000..676f549a --- /dev/null +++ b/tests/test_plugin_signl4.py @@ -0,0 +1,163 @@ +# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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.# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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. + +from json import dumps + +# Disable logging for a cleaner testing output +import logging +from unittest import mock + +from helpers import AppriseURLTester +import requests + +import apprise +from apprise.plugins.signl4 import ( + NotifySIGNL4, + NotifyType, +) + +logging.disable(logging.CRITICAL) + +SIGNL4_GOOD_RESPONSE = dumps({ + "eventId": "2516485120936941747_76d5cf30-27d2-4529-84ed-f31a8f2c72b1", +}) + +# Our Testing URLs +apprise_url_tests = ( + ( + "signl4://", + { + # We failed to identify any valid authentication + "instance": TypeError, + }, + ), + ( + "signl4://:@/", + { + # We failed to identify any valid authentication + "instance": TypeError, + }, + ), + ( + "signl4://%20%20/", + { + # invalid secret specified + "instance": TypeError, + }, + ), + ( + "signl4://secret/", + { + # No targets specified; this is allowed + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?service=IoT", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?location=40.6413111,-73.7781391", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?alerting_scenario=singl4_ack", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?filtering=False", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?external_id=ar1234&status=new", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), +) + +def test_plugin_signl4_urls(): + """NotifySIGNL4() Apprise URLs.""" + + # Run our general tests + AppriseURLTester(tests=apprise_url_tests).run_all() From fd3c1fa5997d75552732f8d39ceb5878a90a2e4d Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:49:34 +0200 Subject: [PATCH 02/17] Update pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index bca515f9..18f3a576 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -143,6 +143,7 @@ keywords = [ "Seven", "SFR", "Signal", + "SIGNL4", "SimplePush", "Sinch", "Slack", From 47e432be2006b750db06e9a3253362a3f2ea6701 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:54:54 +0200 Subject: [PATCH 03/17] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d6a96523..91f5aab2 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ The table below identifies the services this tool supports and some example serv | [SendGrid](https://github.com/caronc/apprise/wiki/Notify_sendgrid) | sendgrid:// | (TCP) 443 | sendgrid://APIToken:FromEmail/
sendgrid://APIToken:FromEmail/ToEmail
sendgrid://APIToken:FromEmail/ToEmail1/ToEmail2/ToEmailN/ | [ServerChan](https://github.com/caronc/apprise/wiki/Notify_serverchan) | schan:// | (TCP) 443 | schan://sendkey/ | [Signal API](https://github.com/caronc/apprise/wiki/Notify_signal) | signal:// or signals:// | (TCP) 80 or 443 | signal://hostname:port/FromPhoneNo
signal://hostname:port/FromPhoneNo/ToPhoneNo
signal://hostname:port/FromPhoneNo/ToPhoneNo1/ToPhoneNo2/ToPhoneNoN/ +| [SIGNL4](https://github.com/caronc/apprise/wiki/Notify_signl4) | signl4:// | (TCP) 80 or 443 | sign4l://secret | [SimplePush](https://github.com/caronc/apprise/wiki/Notify_simplepush) | spush:// | (TCP) 443 | spush://apikey
spush://salt:password@apikey
spush://apikey?event=Apprise | [Slack](https://github.com/caronc/apprise/wiki/Notify_slack) | slack:// | (TCP) 443 | slack://TokenA/TokenB/TokenC/
slack://TokenA/TokenB/TokenC/Channel
slack://botname@TokenA/TokenB/TokenC/Channel
slack://user@TokenA/TokenB/TokenC/Channel1/Channel2/ChannelN | [SMTP2Go](https://github.com/caronc/apprise/wiki/Notify_smtp2go) | smtp2go:// | (TCP) 443 | smtp2go://user@hostname/apikey
smtp2go://user@hostname/apikey/email
smtp2go://user@hostname/apikey/email1/email2/emailN
smtp2go://user@hostname/apikey/?name="From%20User" From 52767796b784c1e8d5702e5dc73c218b90b2474e Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:56:54 +0200 Subject: [PATCH 04/17] Update python-apprise.spec --- packaging/redhat/python-apprise.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/redhat/python-apprise.spec b/packaging/redhat/python-apprise.spec index 68b628db..253ad8d6 100644 --- a/packaging/redhat/python-apprise.spec +++ b/packaging/redhat/python-apprise.spec @@ -69,7 +69,7 @@ notification services. It supports sending alerts to platforms such as: \ `ParsePlatform`, `Plivo`, `PopcornNotify`, `Prowl`, `Pushalot`, \ `PushBullet`, `Pushjet`, `PushMe`, `Pushover`, `Pushplus`, `PushSafer`, \ `Pushy`, `PushDeer`, `QQ Push`, `Revolt`, `Reddit`, `Resend`, `Rocket.Chat`, \ -`RSyslog`, `SendGrid`, `ServerChan`, `Seven`, `SFR`, `Signal`, \ +`RSyslog`, `SendGrid`, `ServerChan`, `Seven`, `SFR`, `Signal`, `SIGNL4`, \ `SimplePush`, `Sinch`, `Slack`, `SMPP`, `SMSEagle`, `SMS Manager`, \ `SMTP2Go`, `SparkPost`, `Splunk`, `Spike`, `Spug Push`, `Super Toasty`, \ `Streamlabs`, `Stride`, `Synology Chat`, `Syslog`, `Techulus Push`, \ From fd69c2897e79ec15a0763105e8bc28e22ed1901a Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 15:15:08 +0200 Subject: [PATCH 05/17] Update signl4.py --- apprise/plugins/signl4.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index cc3047ee..738eebe5 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -32,7 +32,6 @@ import requests from json import dumps - from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType @@ -103,8 +102,9 @@ class NotifySIGNL4(NotifyBase): }, }) - def __init__(self, secret, service=None, location=None, alerting_scenario=None, - filtering=None, external_id=None, status=None, **kwargs): + def __init__(self, secret, service=None, location=None, + alerting_scenario=None, filtering=None, + external_id=None, status=None, **kwargs): """ Initialize SIGNL4 Object """ @@ -176,10 +176,9 @@ class NotifySIGNL4(NotifyBase): # Prepare our URL notify_url = self.service_url + self.secret - self.logger.debug("SIGNL4 POST URL: %s (cert_verify=%r)" % ( - notify_url, self.verify_certificate, - )) - self.logger.debug("SIGNL4 Payload: %s" % str(payload)) + self.logger.debug("SIGNL4 POST URL: {notify_url} \ + (cert_verify={self.verify_certificate}") + self.logger.debug("SIGNL4 Payload: {payload}") # Always call throttle before any remote server i/o is made self.throttle() @@ -218,8 +217,8 @@ class NotifySIGNL4(NotifyBase): except requests.RequestException as e: self.logger.warning( "A Connection error occurred sending SIGNL4 " - "notification to %s." % self.host) - self.logger.debug("Socket Exception: %s" % str(e)) + "notification to {self.host}.") + self.logger.debug("Socket Exception: " + str(e)) # Return; we're done return False @@ -300,21 +299,29 @@ class NotifySIGNL4(NotifyBase): NotifySIGNL4.unquote(results["host"]) if "service" in results["qsd"] and len(results["qsd"]["service"]): - results["service"] = NotifySIGNL4.unquote(results["qsd"]["service"]) - - if "location" in results["qsd"] and len(results["qsd"]["location"]): - results["location"] = NotifySIGNL4.unquote(results["qsd"]["location"]) + results["service"] = \ + NotifySIGNL4.unquote(results["qsd"]["service"]) - if "alerting_scenario" in results["qsd"] and len(results["qsd"]["alerting_scenario"]): - results["alerting_scenario"] = NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) + if "location" in results["qsd"] and len(results["qsd"]["location"]): + results["location"] = \ + NotifySIGNL4.unquote(results["qsd"]["location"]) + + if "alerting_scenario" in results["qsd"] and \ + len(results["qsd"]["alerting_scenario"]): + results["alerting_scenario"] = \ + NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) if "filtering" in results["qsd"] and len(results["qsd"]["filtering"]): - results["filtering"] = NotifySIGNL4.unquote(results["qsd"]["filtering"]) + results["filtering"] = \ + NotifySIGNL4.unquote(results["qsd"]["filtering"]) - if "external_id" in results["qsd"] and len(results["qsd"]["external_id"]): - results["external_id"] = NotifySIGNL4.unquote(results["qsd"]["external_id"]) + if "external_id" in results["qsd"] and \ + len(results["qsd"]["external_id"]): + results["external_id"] = \ + NotifySIGNL4.unquote(results["qsd"]["external_id"]) if "status" in results["qsd"] and len(results["qsd"]["status"]): - results["status"] = NotifySIGNL4.unquote(results["qsd"]["status"]) + results["status"] = \ + NotifySIGNL4.unquote(results["qsd"]["status"]) return results From 56445293caaafc9b2c2ce5d354a21cd2d2624702 Mon Sep 17 00:00:00 2001 From: Ron Date: Wed, 30 Jul 2025 12:47:48 +0200 Subject: [PATCH 06/17] Update signl4.py --- apprise/plugins/signl4.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index 738eebe5..1e8350bd 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -102,9 +102,15 @@ class NotifySIGNL4(NotifyBase): }, }) - def __init__(self, secret, service=None, location=None, - alerting_scenario=None, filtering=None, - external_id=None, status=None, **kwargs): + def __init__(self, + secret, + service=None, + location=None, + alerting_scenario=None, + filtering=None, + external_id=None, + status=None, + **kwargs): """ Initialize SIGNL4 Object """ @@ -242,9 +248,7 @@ class NotifySIGNL4(NotifyBase): """ # Define any URL parameters - params = { - "region": "none", - } + params = {} if self.service is not None: params["service"] = self.service @@ -267,7 +271,7 @@ class NotifySIGNL4(NotifyBase): # Extend our parameters params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) - url = "{schema}://{secret}/" + url = "{schema}://{secret}" return url.format( schema=self.secure_protocol, From 54fc72cc3048a115731895eb9f4062684e3386f5 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:25:13 +0200 Subject: [PATCH 07/17] SIGNL4 Plugin Added SIGNL4 plugin added. --- apprise/plugins/signl4.py | 320 ++++++++++++++++++++++++++++++++++++ tests/test_plugin_signl4.py | 163 ++++++++++++++++++ 2 files changed, 483 insertions(+) create mode 100644 apprise/plugins/signl4.py create mode 100644 tests/test_plugin_signl4.py diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py new file mode 100644 index 00000000..cc3047ee --- /dev/null +++ b/apprise/plugins/signl4.py @@ -0,0 +1,320 @@ +# -*- coding: utf-8 -*- +# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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. + +# API Refererence: +# - https://docs.signl4.com/integrations/webhook/webhook.html +# + +import requests +from json import dumps + +from .base import NotifyBase +from ..url import PrivacyMode +from ..common import NotifyType +from ..utils.parse import validate_regex +from ..locale import gettext_lazy as _ + +class NotifySIGNL4(NotifyBase): + """ + A wrapper for SIGNL4 Notifications + """ + + # The default descriptive name associated with the Notification + service_name = "SIGNL4" + + # The services URL + service_url = "https://connect.signl4.com/webhook/" + + # Secure Protocol + secure_protocol = "signl4" + + # A URL that takes you to the setup/help of the specific protocol + setup_url = "https://github.com/caronc/apprise/wiki/Notify_signl4" + + # Our event action type + event_action = "trigger" + + # Define object templates + templates = ( + "{schema}://{secret}", + ) + + # Define our template tokens + template_tokens = dict(NotifyBase.template_tokens, **{ + # SIGNL4 team or integration secret + "secret": { + "name": _("Secret"), + "type": "string", + "private": True, + "required": True + }, + }) + + # Define our template arguments + template_args = dict(NotifyBase.template_args, **{ + "service": { + "name": _("service"), + "type": "string", + }, + "location": { + "name": _("location"), + "type": "string", + }, + "alerting_scenario": { + "name": _("alerting_scenario"), + "type": "string", + }, + "filtering": { + "name": _("filtering"), + "type": "bool", + }, + "external_id": { + "name": _("external_id"), + "type": "string", + }, + "status": { + "name": _("status"), + "type": "string", + }, + }) + + def __init__(self, secret, service=None, location=None, alerting_scenario=None, + filtering=None, external_id=None, status=None, **kwargs): + """ + Initialize SIGNL4 Object + """ + super().__init__(**kwargs) + + # SIGNL4 team or integration secret + self.secret = validate_regex(secret) + if not self.secret: + msg = "An invalid SIGNL4 team or integration secret " \ + "({}) was specified.".format(secret) + self.logger.warning(msg) + raise TypeError(msg) + + # A service option for notifications + self.service = service + + # A location option for notifications + self.location = location + + # A alerting_scenario option for notifications + self.alerting_scenario = alerting_scenario + + # A filtering option for notifications + self.filtering = bool(filtering) + + # A external_id option for notifications + self.external_id = external_id + + # A location option for notifications + self.status = status + + return + + def send(self, body, title="", notify_type=NotifyType.INFO, **kwargs): + """ + Send our SIGNL4 Notification + """ + + # Prepare our headers + headers = { + "Content-Type": "application/json", + } + + # Prepare our persistent_notification.create payload + payload = { + "title": title if title else self.app_desc, + "body": body, + "X-S4-SourceSystem": "Apprise", + } + + if self.service: + payload["X-S4-Service"] = self.service + + if self.alerting_scenario: + payload["X-S4-AlertingScenario"] = self.alerting_scenario + + if self.location: + payload["X-S4-Location"] = self.location + + if self.filtering: + payload["X-S4-Filtering"] = self.filtering + + if self.external_id: + payload["X-S4-ExternalID"] = self.external_id + + if self.status: + payload["X-S4-Status"] = self.status + + # Prepare our URL + notify_url = self.service_url + self.secret + + self.logger.debug("SIGNL4 POST URL: %s (cert_verify=%r)" % ( + notify_url, self.verify_certificate, + )) + self.logger.debug("SIGNL4 Payload: %s" % str(payload)) + + # Always call throttle before any remote server i/o is made + self.throttle() + + try: + r = requests.post( + notify_url, + data=dumps(payload), + headers=headers, + verify=self.verify_certificate, + timeout=self.request_timeout, + ) + if r.status_code not in ( + requests.codes.ok, requests.codes.created, + requests.codes.accepted): + # We had a problem + status_str = \ + NotifySIGNL4.http_response_code_lookup( + r.status_code) + + self.logger.warning( + "Failed to send SIGNL4 notification: " + "{}{}error={}.".format( + status_str, + ", " if status_str else "", + r.status_code)) + + self.logger.debug("Response Details:\r\n{}".format(r.content)) + + # Return; we're done + return False + + else: + self.logger.info("Sent SIGNL4 notification.") + + except requests.RequestException as e: + self.logger.warning( + "A Connection error occurred sending SIGNL4 " + "notification to %s." % self.host) + self.logger.debug("Socket Exception: %s" % str(e)) + + # Return; we're done + return False + + return True + + @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.secret, + ) + + def url(self, privacy=False, *args, **kwargs): + """ + Returns the URL built dynamically based on specified arguments. + """ + + # Define any URL parameters + params = { + "region": "none", + } + + if self.service is not None: + params["service"] = self.service + + if self.location is not None: + params["location"] = self.location + + if self.alerting_scenario is not None: + params["alerting_scenario"] = self.alerting_scenario + + if self.filtering is not None: + params["filtering"] = self.filtering + + if self.external_id is not None: + params["external_id"] = self.external_id + + if self.status is not None: + params["status"] = self.status + + # Extend our parameters + params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) + + url = "{schema}://{secret}/" + + return url.format( + schema=self.secure_protocol, + # never encode hostname since we're expecting it to be a valid one + secret=self.pprint( + self.secret, privacy, mode=PrivacyMode.Secret, safe=""), + params=NotifySIGNL4.urlencode(params), + ) + + @staticmethod + def parse_url(url): + """ + Parses the URL and returns enough arguments that can allow + us to re-instantiate this object. + """ + + results = NotifyBase.parse_url(url, verify_host=False) + if not results: + # We're done early as we couldn"t load the results + return results + + # The "secret" makes it easier to use yaml configuration + if "secret" in results["qsd"] and \ + len(results["qsd"]["secret"]): + results["secret"] = \ + NotifySIGNL4.unquote(results["qsd"]["secret"]) + else: + results["secret"] = \ + NotifySIGNL4.unquote(results["host"]) + + if "service" in results["qsd"] and len(results["qsd"]["service"]): + results["service"] = NotifySIGNL4.unquote(results["qsd"]["service"]) + + if "location" in results["qsd"] and len(results["qsd"]["location"]): + results["location"] = NotifySIGNL4.unquote(results["qsd"]["location"]) + + if "alerting_scenario" in results["qsd"] and len(results["qsd"]["alerting_scenario"]): + results["alerting_scenario"] = NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) + + if "filtering" in results["qsd"] and len(results["qsd"]["filtering"]): + results["filtering"] = NotifySIGNL4.unquote(results["qsd"]["filtering"]) + + if "external_id" in results["qsd"] and len(results["qsd"]["external_id"]): + results["external_id"] = NotifySIGNL4.unquote(results["qsd"]["external_id"]) + + if "status" in results["qsd"] and len(results["qsd"]["status"]): + results["status"] = NotifySIGNL4.unquote(results["qsd"]["status"]) + + return results diff --git a/tests/test_plugin_signl4.py b/tests/test_plugin_signl4.py new file mode 100644 index 00000000..676f549a --- /dev/null +++ b/tests/test_plugin_signl4.py @@ -0,0 +1,163 @@ +# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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.# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2025, Chris Caron +# +# 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. + +from json import dumps + +# Disable logging for a cleaner testing output +import logging +from unittest import mock + +from helpers import AppriseURLTester +import requests + +import apprise +from apprise.plugins.signl4 import ( + NotifySIGNL4, + NotifyType, +) + +logging.disable(logging.CRITICAL) + +SIGNL4_GOOD_RESPONSE = dumps({ + "eventId": "2516485120936941747_76d5cf30-27d2-4529-84ed-f31a8f2c72b1", +}) + +# Our Testing URLs +apprise_url_tests = ( + ( + "signl4://", + { + # We failed to identify any valid authentication + "instance": TypeError, + }, + ), + ( + "signl4://:@/", + { + # We failed to identify any valid authentication + "instance": TypeError, + }, + ), + ( + "signl4://%20%20/", + { + # invalid secret specified + "instance": TypeError, + }, + ), + ( + "signl4://secret/", + { + # No targets specified; this is allowed + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?service=IoT", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?location=40.6413111,-73.7781391", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?alerting_scenario=singl4_ack", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?filtering=False", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( + "signl4://secret/?external_id=ar1234&status=new", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), +) + +def test_plugin_signl4_urls(): + """NotifySIGNL4() Apprise URLs.""" + + # Run our general tests + AppriseURLTester(tests=apprise_url_tests).run_all() From f01cd40f9e0bbcebe32d26d29c7ee24bdd242eb5 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:49:34 +0200 Subject: [PATCH 08/17] Update pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index bca515f9..18f3a576 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -143,6 +143,7 @@ keywords = [ "Seven", "SFR", "Signal", + "SIGNL4", "SimplePush", "Sinch", "Slack", From 51a5dcfa19ff255f89e9f588038f2c4d4eeea919 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:54:54 +0200 Subject: [PATCH 09/17] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d6a96523..91f5aab2 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ The table below identifies the services this tool supports and some example serv | [SendGrid](https://github.com/caronc/apprise/wiki/Notify_sendgrid) | sendgrid:// | (TCP) 443 | sendgrid://APIToken:FromEmail/
sendgrid://APIToken:FromEmail/ToEmail
sendgrid://APIToken:FromEmail/ToEmail1/ToEmail2/ToEmailN/ | [ServerChan](https://github.com/caronc/apprise/wiki/Notify_serverchan) | schan:// | (TCP) 443 | schan://sendkey/ | [Signal API](https://github.com/caronc/apprise/wiki/Notify_signal) | signal:// or signals:// | (TCP) 80 or 443 | signal://hostname:port/FromPhoneNo
signal://hostname:port/FromPhoneNo/ToPhoneNo
signal://hostname:port/FromPhoneNo/ToPhoneNo1/ToPhoneNo2/ToPhoneNoN/ +| [SIGNL4](https://github.com/caronc/apprise/wiki/Notify_signl4) | signl4:// | (TCP) 80 or 443 | sign4l://secret | [SimplePush](https://github.com/caronc/apprise/wiki/Notify_simplepush) | spush:// | (TCP) 443 | spush://apikey
spush://salt:password@apikey
spush://apikey?event=Apprise | [Slack](https://github.com/caronc/apprise/wiki/Notify_slack) | slack:// | (TCP) 443 | slack://TokenA/TokenB/TokenC/
slack://TokenA/TokenB/TokenC/Channel
slack://botname@TokenA/TokenB/TokenC/Channel
slack://user@TokenA/TokenB/TokenC/Channel1/Channel2/ChannelN | [SMTP2Go](https://github.com/caronc/apprise/wiki/Notify_smtp2go) | smtp2go:// | (TCP) 443 | smtp2go://user@hostname/apikey
smtp2go://user@hostname/apikey/email
smtp2go://user@hostname/apikey/email1/email2/emailN
smtp2go://user@hostname/apikey/?name="From%20User" From a07a38248022c8438a25bc503b8f142718165906 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 14:56:54 +0200 Subject: [PATCH 10/17] Update python-apprise.spec --- packaging/redhat/python-apprise.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/redhat/python-apprise.spec b/packaging/redhat/python-apprise.spec index 68b628db..253ad8d6 100644 --- a/packaging/redhat/python-apprise.spec +++ b/packaging/redhat/python-apprise.spec @@ -69,7 +69,7 @@ notification services. It supports sending alerts to platforms such as: \ `ParsePlatform`, `Plivo`, `PopcornNotify`, `Prowl`, `Pushalot`, \ `PushBullet`, `Pushjet`, `PushMe`, `Pushover`, `Pushplus`, `PushSafer`, \ `Pushy`, `PushDeer`, `QQ Push`, `Revolt`, `Reddit`, `Resend`, `Rocket.Chat`, \ -`RSyslog`, `SendGrid`, `ServerChan`, `Seven`, `SFR`, `Signal`, \ +`RSyslog`, `SendGrid`, `ServerChan`, `Seven`, `SFR`, `Signal`, `SIGNL4`, \ `SimplePush`, `Sinch`, `Slack`, `SMPP`, `SMSEagle`, `SMS Manager`, \ `SMTP2Go`, `SparkPost`, `Splunk`, `Spike`, `Spug Push`, `Super Toasty`, \ `Streamlabs`, `Stride`, `Synology Chat`, `Syslog`, `Techulus Push`, \ From 71650b141edd4f8beda85d636ed1ce13b54e2bc0 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 29 Jul 2025 15:15:08 +0200 Subject: [PATCH 11/17] Update signl4.py --- apprise/plugins/signl4.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index cc3047ee..738eebe5 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -32,7 +32,6 @@ import requests from json import dumps - from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType @@ -103,8 +102,9 @@ class NotifySIGNL4(NotifyBase): }, }) - def __init__(self, secret, service=None, location=None, alerting_scenario=None, - filtering=None, external_id=None, status=None, **kwargs): + def __init__(self, secret, service=None, location=None, + alerting_scenario=None, filtering=None, + external_id=None, status=None, **kwargs): """ Initialize SIGNL4 Object """ @@ -176,10 +176,9 @@ class NotifySIGNL4(NotifyBase): # Prepare our URL notify_url = self.service_url + self.secret - self.logger.debug("SIGNL4 POST URL: %s (cert_verify=%r)" % ( - notify_url, self.verify_certificate, - )) - self.logger.debug("SIGNL4 Payload: %s" % str(payload)) + self.logger.debug("SIGNL4 POST URL: {notify_url} \ + (cert_verify={self.verify_certificate}") + self.logger.debug("SIGNL4 Payload: {payload}") # Always call throttle before any remote server i/o is made self.throttle() @@ -218,8 +217,8 @@ class NotifySIGNL4(NotifyBase): except requests.RequestException as e: self.logger.warning( "A Connection error occurred sending SIGNL4 " - "notification to %s." % self.host) - self.logger.debug("Socket Exception: %s" % str(e)) + "notification to {self.host}.") + self.logger.debug("Socket Exception: " + str(e)) # Return; we're done return False @@ -300,21 +299,29 @@ class NotifySIGNL4(NotifyBase): NotifySIGNL4.unquote(results["host"]) if "service" in results["qsd"] and len(results["qsd"]["service"]): - results["service"] = NotifySIGNL4.unquote(results["qsd"]["service"]) - - if "location" in results["qsd"] and len(results["qsd"]["location"]): - results["location"] = NotifySIGNL4.unquote(results["qsd"]["location"]) + results["service"] = \ + NotifySIGNL4.unquote(results["qsd"]["service"]) - if "alerting_scenario" in results["qsd"] and len(results["qsd"]["alerting_scenario"]): - results["alerting_scenario"] = NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) + if "location" in results["qsd"] and len(results["qsd"]["location"]): + results["location"] = \ + NotifySIGNL4.unquote(results["qsd"]["location"]) + + if "alerting_scenario" in results["qsd"] and \ + len(results["qsd"]["alerting_scenario"]): + results["alerting_scenario"] = \ + NotifySIGNL4.unquote(results["qsd"]["alerting_scenario"]) if "filtering" in results["qsd"] and len(results["qsd"]["filtering"]): - results["filtering"] = NotifySIGNL4.unquote(results["qsd"]["filtering"]) + results["filtering"] = \ + NotifySIGNL4.unquote(results["qsd"]["filtering"]) - if "external_id" in results["qsd"] and len(results["qsd"]["external_id"]): - results["external_id"] = NotifySIGNL4.unquote(results["qsd"]["external_id"]) + if "external_id" in results["qsd"] and \ + len(results["qsd"]["external_id"]): + results["external_id"] = \ + NotifySIGNL4.unquote(results["qsd"]["external_id"]) if "status" in results["qsd"] and len(results["qsd"]["status"]): - results["status"] = NotifySIGNL4.unquote(results["qsd"]["status"]) + results["status"] = \ + NotifySIGNL4.unquote(results["qsd"]["status"]) return results From 777625457f8a4a0049df8fbb12559f6a8bd3952c Mon Sep 17 00:00:00 2001 From: Ron Date: Wed, 30 Jul 2025 12:47:48 +0200 Subject: [PATCH 12/17] Update signl4.py --- apprise/plugins/signl4.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index 738eebe5..1e8350bd 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -102,9 +102,15 @@ class NotifySIGNL4(NotifyBase): }, }) - def __init__(self, secret, service=None, location=None, - alerting_scenario=None, filtering=None, - external_id=None, status=None, **kwargs): + def __init__(self, + secret, + service=None, + location=None, + alerting_scenario=None, + filtering=None, + external_id=None, + status=None, + **kwargs): """ Initialize SIGNL4 Object """ @@ -242,9 +248,7 @@ class NotifySIGNL4(NotifyBase): """ # Define any URL parameters - params = { - "region": "none", - } + params = {} if self.service is not None: params["service"] = self.service @@ -267,7 +271,7 @@ class NotifySIGNL4(NotifyBase): # Extend our parameters params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) - url = "{schema}://{secret}/" + url = "{schema}://{secret}" return url.format( schema=self.secure_protocol, From 2ce79302ca35c8d67ab913899bc1b472dfbb8156 Mon Sep 17 00:00:00 2001 From: Ron Date: Fri, 1 Aug 2025 00:02:25 +0200 Subject: [PATCH 13/17] Fixes --- apprise/plugins/signl4.py | 4 +++- tests/test_plugin_signl4.py | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index 1e8350bd..a03d8805 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -30,8 +30,10 @@ # - https://docs.signl4.com/integrations/webhook/webhook.html # -import requests from json import dumps + +import requests + from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType diff --git a/tests/test_plugin_signl4.py b/tests/test_plugin_signl4.py index 676f549a..24941096 100644 --- a/tests/test_plugin_signl4.py +++ b/tests/test_plugin_signl4.py @@ -54,12 +54,9 @@ from json import dumps # Disable logging for a cleaner testing output import logging -from unittest import mock from helpers import AppriseURLTester -import requests -import apprise from apprise.plugins.signl4 import ( NotifySIGNL4, NotifyType, From 6dc3324dd1b902fd4053c3c661a0c2c5a6230d68 Mon Sep 17 00:00:00 2001 From: Ron Date: Fri, 1 Aug 2025 00:05:18 +0200 Subject: [PATCH 14/17] Fixing --- apprise/plugins/signl4.py | 4 +++- tests/test_plugin_signl4.py | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index 1e8350bd..a03d8805 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -30,8 +30,10 @@ # - https://docs.signl4.com/integrations/webhook/webhook.html # -import requests from json import dumps + +import requests + from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType diff --git a/tests/test_plugin_signl4.py b/tests/test_plugin_signl4.py index 676f549a..24941096 100644 --- a/tests/test_plugin_signl4.py +++ b/tests/test_plugin_signl4.py @@ -54,12 +54,9 @@ from json import dumps # Disable logging for a cleaner testing output import logging -from unittest import mock from helpers import AppriseURLTester -import requests -import apprise from apprise.plugins.signl4 import ( NotifySIGNL4, NotifyType, From e3ce566a57145398d971ae942f3136ab5da36548 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Fri, 1 Aug 2025 15:58:00 -0400 Subject: [PATCH 15/17] updated test coverage + code cleanup --- apprise/plugins/signl4.py | 81 ++++++++++++++++++++++--------------- tests/test_plugin_signl4.py | 65 +++++++++++++++++------------ 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/apprise/plugins/signl4.py b/apprise/plugins/signl4.py index a03d8805..fab1eeeb 100644 --- a/apprise/plugins/signl4.py +++ b/apprise/plugins/signl4.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # BSD 2-Clause License # # Apprise - Push Notification Library. @@ -31,14 +30,16 @@ # from json import dumps +from typing import Any, Optional import requests -from .base import NotifyBase -from ..url import PrivacyMode from ..common import NotifyType -from ..utils.parse import validate_regex from ..locale import gettext_lazy as _ +from ..url import PrivacyMode +from ..utils.parse import parse_bool, validate_regex +from .base import NotifyBase + class NotifySIGNL4(NotifyBase): """ @@ -49,7 +50,7 @@ class NotifySIGNL4(NotifyBase): service_name = "SIGNL4" # The services URL - service_url = "https://connect.signl4.com/webhook/" + service_url = "https://signl4.com/" # Secure Protocol secure_protocol = "signl4" @@ -60,6 +61,9 @@ class NotifySIGNL4(NotifyBase): # Our event action type event_action = "trigger" + # Our default notification URL + notify_url = "https://connect.signl4.com/webhook/{secret}/" + # Define object templates templates = ( "{schema}://{secret}", @@ -79,40 +83,43 @@ class NotifySIGNL4(NotifyBase): # Define our template arguments template_args = dict(NotifyBase.template_args, **{ "service": { - "name": _("service"), + "name": _("Service"), "type": "string", }, "location": { - "name": _("location"), + "name": _("Location"), "type": "string", }, "alerting_scenario": { - "name": _("alerting_scenario"), + "name": _("Alerting Scenario"), "type": "string", }, "filtering": { - "name": _("filtering"), + "name": _("Filtering"), "type": "bool", + "default": False, }, "external_id": { - "name": _("external_id"), + "name": _("External ID"), "type": "string", }, "status": { - "name": _("status"), + "name": _("Status"), "type": "string", }, }) - def __init__(self, - secret, - service=None, - location=None, - alerting_scenario=None, - filtering=None, - external_id=None, - status=None, - **kwargs): + def __init__( + self, + secret: str, + service: Optional[str] = None, + location: Optional[str] = None, + alerting_scenario: Optional[str] = None, + filtering: Optional[bool] = None, + external_id: Optional[str] = None, + status: Optional[str] = None, + **kwargs: Any + ) -> None: """ Initialize SIGNL4 Object """ @@ -136,7 +143,11 @@ class NotifySIGNL4(NotifyBase): self.alerting_scenario = alerting_scenario # A filtering option for notifications - self.filtering = bool(filtering) + self.filtering = ( + self.template_args["filtering"]["default"] + if filtering is None + else bool(filtering) + ) # A external_id option for notifications self.external_id = external_id @@ -160,7 +171,7 @@ class NotifySIGNL4(NotifyBase): payload = { "title": title if title else self.app_desc, "body": body, - "X-S4-SourceSystem": "Apprise", + "X-S4-SourceSystem": self.app_id, } if self.service: @@ -182,11 +193,13 @@ class NotifySIGNL4(NotifyBase): payload["X-S4-Status"] = self.status # Prepare our URL - notify_url = self.service_url + self.secret + notify_url = self.notify_url.format(secret=self.secret) + + self.logger.debug( + "SIGNL4 POST URL: %s (cert_verify=%s)", + notify_url, self.verify_certificate) + self.logger.debug("SIGNL4 Payload: %r", payload) - self.logger.debug("SIGNL4 POST URL: {notify_url} \ - (cert_verify={self.verify_certificate}") - self.logger.debug("SIGNL4 Payload: {payload}") # Always call throttle before any remote server i/o is made self.throttle() @@ -214,7 +227,7 @@ class NotifySIGNL4(NotifyBase): ", " if status_str else "", r.status_code)) - self.logger.debug("Response Details:\r\n{}".format(r.content)) + self.logger.debug("Response Details:\r\n%r", r.content) # Return; we're done return False @@ -225,8 +238,8 @@ class NotifySIGNL4(NotifyBase): except requests.RequestException as e: self.logger.warning( "A Connection error occurred sending SIGNL4 " - "notification to {self.host}.") - self.logger.debug("Socket Exception: " + str(e)) + "notification to %s", self.host) + self.logger.debug("Socket Exception: %s", str(e)) # Return; we're done return False @@ -261,8 +274,9 @@ class NotifySIGNL4(NotifyBase): if self.alerting_scenario is not None: params["alerting_scenario"] = self.alerting_scenario - if self.filtering is not None: - params["filtering"] = self.filtering + if self.filtering != self.template_args["filtering"]["default"]: + # Only add filtering if it is not the default value + params["filtering"] = "yes" if self.filtering else "no" if self.external_id is not None: params["external_id"] = self.external_id @@ -319,7 +333,10 @@ class NotifySIGNL4(NotifyBase): if "filtering" in results["qsd"] and len(results["qsd"]["filtering"]): results["filtering"] = \ - NotifySIGNL4.unquote(results["qsd"]["filtering"]) + parse_bool( + NotifySIGNL4.unquote( + results["qsd"]["filtering"], + NotifySIGNL4.template_args["filtering"]["default"])) if "external_id" in results["qsd"] and \ len(results["qsd"]["external_id"]): diff --git a/tests/test_plugin_signl4.py b/tests/test_plugin_signl4.py index 24941096..a7a35835 100644 --- a/tests/test_plugin_signl4.py +++ b/tests/test_plugin_signl4.py @@ -24,31 +24,6 @@ # 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.# BSD 2-Clause License -# -# Apprise - Push Notification Library. -# Copyright (c) 2025, Chris Caron -# -# 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. from json import dumps @@ -101,6 +76,16 @@ apprise_url_tests = ( "requests_response_text": SIGNL4_GOOD_RESPONSE, }, ), + ( + "signl4://?secret=secret", + { + # No targets specified; this is allowed + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), ( "signl4://secret/?service=IoT", { @@ -111,7 +96,17 @@ apprise_url_tests = ( "requests_response_text": SIGNL4_GOOD_RESPONSE, }, ), - ( + ( + "signl4://secret/?filtering=yes", + { + # European Region + "instance": NotifySIGNL4, + "notify_type": NotifyType.FAILURE, + # Our response expected server response + "requests_response_text": SIGNL4_GOOD_RESPONSE, + }, + ), + ( "signl4://secret/?location=40.6413111,-73.7781391", { # European Region @@ -151,6 +146,24 @@ apprise_url_tests = ( "requests_response_text": SIGNL4_GOOD_RESPONSE, }, ), + ( + "signl4://secret/", + { + "instance": NotifySIGNL4, + # throw a bizzare code forcing us to fail to look it up + "response": False, + "requests_response_code": 999, + }, + ), + ( + "signl4://secret/", + { + "instance": NotifySIGNL4, + # Throws a series of i/o exceptions with this flag + # is set and tests that we gracfully handle them + "test_requests_exceptions": True, + }, + ), ) def test_plugin_signl4_urls():