-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from splunk/feature/savedsearch-tests
feat: Adds mechanism to generate tests by parsing savedsearches.conf.
- Loading branch information
Showing
16 changed files
with
298 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
pytest_splunk_addon/standard_lib/addon_parser/savedsearches_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Provides savedsearches.conf parsing mechanism | ||
""" | ||
|
||
class SavedSearchParser(object): | ||
""" | ||
Parses savedsearches.conf and extracts savedsearches | ||
Args: | ||
splunk_app_path (str): Path of the Splunk app | ||
app (splunk_appinspect.App): Object of Splunk app | ||
""" | ||
def __init__(self, splunk_app_path, app): | ||
self.app = app | ||
self.splunk_app_path = splunk_app_path | ||
self._savedsearches = None | ||
|
||
@property | ||
def savedsearches(self): | ||
try: | ||
if not self._savedsearches: | ||
self._savedsearches = self.app.get_config("savedsearches.conf") | ||
return self._savedsearches | ||
except OSError: | ||
return None | ||
|
||
def get_savedsearches(self): | ||
""" | ||
Parse the App configuration files & yield savedsearches | ||
Yields: | ||
generator of list of savedsearches | ||
""" | ||
if not self.savedsearches: | ||
return None | ||
for stanza in self.savedsearches.sects: | ||
savedsearch_sections = self.savedsearches.sects[stanza] | ||
savedsearch_container = { | ||
"stanza" : stanza, | ||
"search" : "index = \"main\"", | ||
"dispatch.earliest_time" : "0", | ||
"dispatch.latest_time" : "now"} | ||
for key in savedsearch_sections.options: | ||
empty_value = ['None','',' '] | ||
if key == "search" and savedsearch_sections.options[key].value not in empty_value: | ||
savedsearch_container[key] = savedsearch_sections.options[key].value | ||
elif key == "dispatch.earliest_time" and savedsearch_sections.options[key].value not in empty_value: | ||
savedsearch_container[key] = savedsearch_sections.options[key].value | ||
elif key == "dispatch.latest_time" and savedsearch_sections.options[key].value not in empty_value: | ||
savedsearch_container[key] = savedsearch_sections.options[key].value | ||
yield savedsearch_container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.