|
1 | 1 | import re
|
2 | 2 | import urllib.request
|
3 |
| -import urllib.error |
4 | 3 |
|
5 | 4 | from splunk_add_on_ucc_framework.const import SPLUNK_COMMANDS
|
6 | 5 |
|
7 | 6 |
|
8 | 7 | def test_command_list_up_to_date():
|
9 |
| - url = "https://docs.splunk.com/Documentation/Splunk/latest/SearchReference" |
10 |
| - try: |
11 |
| - with urllib.request.urlopen(url) as resp: |
12 |
| - content = resp.read().decode() |
13 |
| - except urllib.error.HTTPError: |
14 |
| - # passing an imitation of browser header to make this a request from web browser |
15 |
| - headers = { |
16 |
| - "User-Agent": ( |
17 |
| - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
18 |
| - "AppleWebKit/537.36 (KHTML, like Gecko) " |
19 |
| - "Chrome/115.0.0.0 Safari/537.36" |
20 |
| - ) |
21 |
| - } |
22 |
| - |
23 |
| - req = urllib.request.Request(url, headers=headers) |
24 |
| - |
25 |
| - with urllib.request.urlopen(req) as resp: |
26 |
| - content = resp.read().decode() |
27 |
| - |
28 |
| - match = re.search(r"Search\s+Commands.+?<ul.+?>(.+?)</ul>", content, re.S) |
29 |
| - if match: |
30 |
| - search_commands_ul = match.group(1) |
31 |
| - search_commands = re.findall( |
32 |
| - r"<li[^>]*>.*?<a[^>]*>\s*([^\s<]+)\s+?</a>", search_commands_ul, re.S |
| 8 | + url = "https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/10.0/search-commands" |
| 9 | + # passing an imitation of browser header to make this a request from web browser |
| 10 | + headers = { |
| 11 | + "User-Agent": ( |
| 12 | + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
| 13 | + "AppleWebKit/537.36 (KHTML, like Gecko) " |
| 14 | + "Chrome/115.0.0.0 Safari/537.36" |
33 | 15 | )
|
34 |
| - else: |
35 |
| - search_commands_ul = None |
36 |
| - search_commands = [] |
| 16 | + } |
| 17 | + |
| 18 | + req = urllib.request.Request(url, headers=headers) |
| 19 | + |
| 20 | + with urllib.request.urlopen(req) as resp: |
| 21 | + content = resp.read().decode() |
| 22 | + |
| 23 | + search_commands = re.findall( |
| 24 | + r'splunk-enterprise/search/spl-search-reference/[^/]+/search-commands/([^"&]+)', |
| 25 | + content, |
| 26 | + ) |
| 27 | + assert search_commands, "No search commands found on the Splunk documentation page" |
37 | 28 |
|
38 | 29 | # These are the search commands for the serviceNow add-on. They are not present by default in Splunk instance
|
39 | 30 | not_global_commands = [
|
40 | 31 | "snowincidentstream",
|
41 | 32 | "snoweventstream",
|
42 | 33 | "snowincident",
|
43 | 34 | "snowevent",
|
| 35 | + "3rd-party-custom-commands", |
| 36 | + "awssnsalert", |
44 | 37 | ]
|
45 | 38 | for command in not_global_commands:
|
46 | 39 | search_commands.remove(command)
|
|
0 commit comments