Debian Codegraph @

tests/test_plugin_splunk.py

raw
1 # BSD 2-Clause License
2 #
3 # Apprise - Push Notification Library.
4 # Copyright (c) 2026, Chris Caron <[email protected]>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation
14 # and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27
28 # Disable logging for a cleaner testing output
29 import logging
30
31 from helpers import AppriseURLTester
32 import requests
33
34 from apprise.exception import AppriseImproperlyConfigured
35 from apprise.plugins.splunk import NotifySplunk
36
37 logging.disable(logging.CRITICAL)
38
39 # Our Testing URLs
40 apprise_url_tests = (
41 (
42 "splunk://",
43 {
44 "instance": AppriseImproperlyConfigured,
45 },
46 ),
47 (
48 "splunk://:@/",
49 {
50 "instance": AppriseImproperlyConfigured,
51 },
52 ),
53 (
54 "splunk://routekey@%badapi%",
55 {
56 "instance": AppriseImproperlyConfigured,
57 },
58 ),
59 (
60 "splunk://abc123",
61 {
62 # No route key provided
63 "instance": AppriseImproperlyConfigured,
64 },
65 ),
66 (
67 "splunk://%badroute%@apikey",
68 {
69 "instance": AppriseImproperlyConfigured,
70 },
71 ),
72 (
73 "splunk://?apikey=abc123&routing_key=db",
74 {
75 # We're good
76 "instance": NotifySplunk,
77 },
78 ),
79 (
80 "splunk://route@abc123/entity_id",
81 {
82 # We're good
83 "instance": NotifySplunk,
84 },
85 ),
86 (
87 "splunk://route@abc123/?entity_id=my_entity",
88 {
89 # We're good
90 "instance": NotifySplunk,
91 },
92 ),
93 (
94 # An entity_id containing characters that are reserved in a URL
95 # (?, #, %, /) must survive a url() round-trip without being
96 # truncated or corrupted.
97 "splunk://route@abc123/?entity_id=a%3Fb%23c%25d%2Fe",
98 {
99 # We're good
100 "instance": NotifySplunk,
101 # Our privacy url confirms the entity_id was quoted (not
102 # dropped) when the url() was re-assembled
103 "privacy_url": "splunk://[email protected]/a%3Fb%23c%25d/e",
104 },
105 ),
106 # Support legacy URL
107 (
108 (
109 "https://alert.victorops.com/integrations/generic/20131114/"
110 "alert/apikey/routing_key"
111 ),
112 {
113 # We're good
114 "instance": NotifySplunk,
115 },
116 ),
117 # Support legacy URL (with entity id provided)
118 (
119 (
120 "https://alert.victorops.com/integrations/generic/20131114/"
121 "alert/apikey/routing_key/entity_id"
122 ),
123 {
124 # We're good
125 "instance": NotifySplunk,
126 },
127 ),
128 # support victorops:// too!
129 (
130 "victorops://?apikey=abc123&route=db",
131 {
132 # We're good
133 "instance": NotifySplunk,
134 },
135 ),
136 (
137 "splunk://?apikey=abc123&route=db",
138 {
139 # We're good
140 "instance": NotifySplunk,
141 },
142 ),
143 (
144 "splunk://db@apikey?action=recovery",
145 {
146 # Always Recovery Alias
147 "instance": NotifySplunk,
148 },
149 ),
150 (
151 "splunk://db@apikey?action=resolve",
152 {
153 # Always Recovery Alias
154 "instance": NotifySplunk,
155 },
156 ),
157 (
158 "splunk://db@apikey?action=r",
159 {
160 # Always Recovery (short form)
161 "instance": NotifySplunk,
162 },
163 ),
164 (
165 "splunk://db@apikey?action=acknowledgement",
166 {
167 # Always Acknowledgement
168 "instance": NotifySplunk,
169 },
170 ),
171 (
172 "splunk://db@apikey?action=ack",
173 {
174 # Always Acknowledgement (short form)
175 "instance": NotifySplunk,
176 },
177 ),
178 (
179 "splunk://db@apikey?action=critical",
180 {
181 # Always Critical
182 "instance": NotifySplunk,
183 },
184 ),
185 (
186 "splunk://db@apikey?action=crit",
187 {
188 # Always Critical (short form)
189 "instance": NotifySplunk,
190 },
191 ),
192 (
193 "splunk://db@apikey?action=warning",
194 {
195 # Always Warning
196 "instance": NotifySplunk,
197 },
198 ),
199 (
200 "splunk://db@apikey?action=warn",
201 {
202 # Always Warning (short form)
203 "instance": NotifySplunk,
204 },
205 ),
206 (
207 "splunk://db@apikey?action=info",
208 {
209 # Always INFO
210 "instance": NotifySplunk,
211 },
212 ),
213 (
214 "splunk://db@apikey?action=i",
215 {
216 # Always INFO (short form)
217 "instance": NotifySplunk,
218 },
219 ),
220 (
221 "splunk://db@apikey?action=invalid",
222 {
223 # Invalid Action
224 "instance": AppriseImproperlyConfigured,
225 },
226 ),
227 (
228 "splunk://db@apikey?:warning=critical",
229 {
230 # Map warnings to CRITICAL
231 "instance": NotifySplunk,
232 },
233 ),
234 (
235 "splunk://db@apikey?:invalid=critical",
236 {
237 # A bad Apprise Notification Type was provided
238 "instance": AppriseImproperlyConfigured,
239 },
240 ),
241 (
242 "splunk://db@apikey?:warning=invalid",
243 {
244 # A bad Splunk Notification Type was provided
245 "instance": AppriseImproperlyConfigured,
246 },
247 ),
248 (
249 "splunk://db@apikey",
250 {
251 "instance": NotifySplunk,
252 # force a failure
253 "response": False,
254 "requests_response_code": requests.codes.internal_server_error,
255 },
256 ),
257 (
258 "splunk://db@apikey",
259 {
260 "instance": NotifySplunk,
261 # throw a bizarre code forcing us to fail to look it up
262 "response": False,
263 "requests_response_code": 999,
264 },
265 ),
266 (
267 "splunk://db@token",
268 {
269 "instance": NotifySplunk,
270 # Throws a series of i/o exceptions with this flag
271 # is set and tests that we gracefully handle them
272 "test_requests_exceptions": True,
273 },
274 ),
275 )
276
277
278 def test_plugin_splunk_urls():
279 """NotifySplunk() Apprise URLs."""
280
281 # Run our general tests
282 AppriseURLTester(tests=apprise_url_tests).run_all()