Skip to content

Commit

Permalink
Added testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed May 16, 2024
1 parent 5690d30 commit f621621
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 6 deletions.
2 changes: 2 additions & 0 deletions KEYWORDS
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ SMS Manager
SMTP2Go
SNS
SparkPost
Splunk
Streamlabs
Stride
Synology Chat
Expand All @@ -100,6 +101,7 @@ Threema Gateway
Twilio
Twist
Twitter
VictorOps
Voipms
Vonage
Webex
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ The table below identifies the services this tool supports and some example serv
| [SimplePush](https://github.com/caronc/apprise/wiki/Notify_simplepush) | spush:// | (TCP) 443 | spush://apikey<br />spush://salt:password@apikey<br />spush://apikey?event=Apprise
| [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://route_key@apikey<br />splunk://route_key@apikey/entity_id
| [Spunk](https://github.com/caronc/apprise/wiki/Notify_splunk) | splunk:// or victorops:/ | (TCP) 443 | splunk://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"
| [Streamlabs](https://github.com/caronc/apprise/wiki/Notify_streamlabs) | strmlabs:// | (TCP) 443 | strmlabs://AccessToken/<br/>strmlabs://AccessToken/?name=name&identifier=identifier&amount=0&currency=USD
| [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"
| [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
| [Syslog](https://github.com/caronc/apprise/wiki/Notify_syslog) | syslog:// | n/a | syslog://<br />syslog://Facility
| [Telegram](https://github.com/caronc/apprise/wiki/Notify_telegram) | tgram:// | (TCP) 443 | tgram://bottoken/ChatID<br />tgram://bottoken/ChatID1/ChatID2/ChatIDN
Expand Down
19 changes: 17 additions & 2 deletions apprise/plugins/splunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ class SplunkAction:
# Use mapping (specify :key=arg to over-ride)
MAP = 'map'

# Creates a timeline event but does not trigger an incident
INFO = 'info'

# Triggers a warning (possibly causing incident) in all cases
WARNING = 'warning'

# Triggers an incident in all cases
CRITICAL = 'critical'

# Acknowldege entity_id provided in all cases
ACKNOWLEDGE = 'acknowledge'
ACKNOWLEDGE = 'acknowledgement'

# Recovery entity_id provided in all cases
RECOVERY = 'recovery'
Expand All @@ -71,6 +74,7 @@ class SplunkAction:
# Define our Splunk Actions
SPLUNK_ACTIONS = (
SplunkAction.MAP,
SplunkAction.INFO,
SplunkAction.ACKNOWLEDGE,
SplunkAction.WARNING,
SplunkAction.RECOVERY,
Expand Down Expand Up @@ -118,7 +122,7 @@ class NotifySplunk(NotifyBase):
service_name = _('Splunk On-Call')

# The services URL
service_url = 'https://www.splunk.com/'
service_url = 'https://www.splunk.com/en_us/products/on-call.html'

# The default secure protocol
secure_protocol = ('splunk', 'victorops')
Expand Down Expand Up @@ -186,6 +190,9 @@ class NotifySplunk(NotifyBase):
'routing_key': {
'alias_of': 'routing_key',
},
'route': {
'alias_of': 'routing_key',
},
'entity_id': {
'alias_of': 'entity_id',
},
Expand Down Expand Up @@ -294,6 +301,10 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
# Always Acknowledge
message_type = SplunkMessageType.ACKNOWLEDGEMENT

elif self.action == SplunkAction.INFO:
# Creates a timeline event but does not trigger an incident
message_type = SplunkMessageType.INFO

elif self.action == SplunkAction.CRITICAL:
# Always create Incident
message_type = SplunkMessageType.CRITICAL
Expand Down Expand Up @@ -432,6 +443,10 @@ def parse_url(url):
results['routing_key'] = \
NotifySplunk.unquote(results['qsd']['routing_key'])

elif 'route' in results['qsd'] and len(results['qsd']['route']):
results['routing_key'] = \
NotifySplunk.unquote(results['qsd']['route'])

else:
results['routing_key'] = NotifySplunk.unquote(results['user'])

Expand Down
7 changes: 4 additions & 3 deletions packaging/redhat/python-apprise.spec
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ NextcloudTalk, Notica, Notifiarr, Notifico, ntfy, Office365, OneSignal,
Opsgenie, PagerDuty, PagerTree, ParsePlatform, PopcornNotify, Prowl, Pushalot,
PushBullet, Pushjet, PushMe, Pushover, PushSafer, Pushy, PushDeer, Revolt,
Reddit, Rocket.Chat, RSyslog, SendGrid, ServerChan, Signal, SimplePush, Sinch,
Slack, SMSEagle, SMS Manager, SMTP2Go, SparkPost, Super Toasty, Streamlabs,
Stride, Synology Chat, Syslog, Techulus Push, Telegram, Threema Gateway, Twilio,
Twitter, Twist, XBMC, Voipms, Vonage, WeCom Bot, WhatsApp, Webex Teams}
Slack, SMSEagle, SMS Manager, SMTP2Go, SparkPost, Splunk, Super Toasty,
Streamlabs, Stride, Synology Chat, Syslog, Techulus Push, Telegram, Threema
Gateway, Twilio, Twitter, Twist, XBMC, VictorOps, Voipms, Vonage, WeCom Bot,
WhatsApp, Webex Teams}

Name: python-%{pypi_name}
Version: 1.8.0
Expand Down
152 changes: 152 additions & 0 deletions test/test_plugin_splunk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# -*- coding: utf-8 -*-
# BSD 2-Clause License
#
# Apprise - Push Notification Library.
# Copyright (c) 2024, Chris Caron <[email protected]>
#
# 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.splunk import NotifySplunk
from helpers import AppriseURLTester

# Disable logging for a cleaner testing output
import logging
logging.disable(logging.CRITICAL)

# Our Testing URLs
apprise_url_tests = (
('splunk://', {
'instance': TypeError,
}),
('splunk://:@/', {
'instance': TypeError,
}),
('splunk://routekey@%badapi%', {
'instance': TypeError,
}),
('splunk://abc123', {
# No route key provided
'instance': TypeError,
}),
('splunk://%badroute%@apikey', {
'instance': TypeError,
}),
('splunk://?apikey=abc123&routing_key=db', {
# We're good
'instance': NotifySplunk,
}),
('splunk://?apikey=abc123&route=db', {
# We're good
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=recovery', {
# Always Recovery Alias
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=resolve', {
# Always Recovery Alias
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=r', {
# Always Recovery (short form)
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=acknowledgement', {
# Always Acknowledgement
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=ack', {
# Always Acknowledgement (short form)
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=critical', {
# Always Critical
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=crit', {
# Always Critical (short form)
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=warning', {
# Always Warning
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=warn', {
# Always Warning (short form)
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=info', {
# Always INFO
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=i', {
# Always INFO (short form)
'instance': NotifySplunk,
}),
('splunk://db@apikey?action=invalid', {
# Invalid Action
'instance': TypeError,
}),
('splunk://db@apikey?:warning=critical', {
# Map warnings to CRITICAL
'instance': NotifySplunk,
}),
('splunk://db@apikey?:invalid=critical', {
# A bad Apprise Notification Type was provided
'instance': TypeError,
}),
('splunk://db@apikey?:warning=invalid', {
# A bad Splunk Notification Type was provided
'instance': TypeError,
}),
('splunk://db@apikey', {
'instance': NotifySplunk,
# force a failure
'response': False,
'requests_response_code': requests.codes.internal_server_error,
}),
('splunk://db@apikey', {
'instance': NotifySplunk,
# throw a bizzare code forcing us to fail to look it up
'response': False,
'requests_response_code': 999,
}),
('splunk://db@token', {
'instance': NotifySplunk,
# Throws a series of connection and transfer exceptions when this flag
# is set and tests that we gracfully handle them
'test_requests_exceptions': True,
}),
)


def test_plugin_splunk_urls():
"""
NotifySplunk() Apprise URLs
"""

# Run our general tests
AppriseURLTester(tests=apprise_url_tests).run_all()

0 comments on commit f621621

Please sign in to comment.