Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.coverage
.coverage.*
.python-version
.vscode
__stdout__
docs/_build
build/
Expand All @@ -24,7 +25,7 @@ tests/searchcommands/data/app/app.log
splunk_sdk.egg-info/
dist/
examples/searchcommands_app/package/default/commands.conf
examples/searchcommands_app/package/bin/packages
examples/searchcommands_app/package/lib/splunklib
tests/searchcommands/apps/app_with_logging_configuration/*.log
*.observed
venv/
8 changes: 4 additions & 4 deletions examples/searchcommands_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ The app is tested on Splunk 5 and 6. Here is its manifest:

```
├── bin
│ ├── splunklib
│ │ └── searchcommands ....... splunklib.searchcommands module
│   ├── countmatches.py .......... CountMatchesCommand implementation
│ ├── generatetext.py .......... GenerateTextCommand implementation
│ ├── pypygeneratetext.py ...... Executes generatetext.py with PyPy
│ ├── simulate.py .............. SimulateCommand implementation
│ ├── sum.py ................... SumCommand implementation
│   └──
│ └── sum.py ................... SumCommand implementation
├── lib
| └── splunklib
│ └── searchcommands ....... splunklib.searchcommands module
├── default
│ ├── data
│ │   └── ui
Expand Down
4 changes: 3 additions & 1 deletion examples/searchcommands_app/package/bin/countmatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app
import os,sys

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators
import sys
from splunklib import six


Expand Down
6 changes: 3 additions & 3 deletions examples/searchcommands_app/package/bin/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app
import os,sys

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, EventingCommand, Configuration, Option
from splunklib.searchcommands.validators import Code

import sys


@Configuration()
class FilterCommand(EventingCommand):
""" Filters, augments, and updates records on the events stream.
Expand Down
8 changes: 5 additions & 3 deletions examples/searchcommands_app/package/bin/generatehello.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app
import os,sys
import time

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import sys
import time
from six.moves import range
from splunklib.six.moves import range


@Configuration()
Expand Down
6 changes: 4 additions & 2 deletions examples/searchcommands_app/package/bin/generatetext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app
import os,sys
import time

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import sys
import time
from splunklib import six
from splunklib.six.moves import range

Expand Down
7 changes: 4 additions & 3 deletions examples/searchcommands_app/package/bin/pypygeneratetext.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app

from splunklib.searchcommands import app_root, execute
import sys
from os import environ, path

import sys
splunkhome = environ['SPLUNK_HOME']
sys.path.append(path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import app_root, execute

pypy_argv = ['pypy', path.join(app_root, 'bin', 'generatetext.py')] + sys.argv[1:]
pypy_environ = dict(environ)
Expand Down
8 changes: 5 additions & 3 deletions examples/searchcommands_app/package/bin/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app

from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import random
import csv
import sys
import os,sys
import time

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators


@Configuration()
class SimulateCommand(GeneratingCommand):
Expand Down
4 changes: 3 additions & 1 deletion examples/searchcommands_app/package/bin/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import app
import os,sys

splunkhome = os.environ['SPLUNK_HOME']
sys.path.append(os.path.join(splunkhome, 'etc', 'apps', 'searchcommands_app', 'lib'))
from splunklib.searchcommands import dispatch, ReportingCommand, Configuration, Option, validators
import sys


@Configuration(requires_preop=True)
Expand Down
13 changes: 6 additions & 7 deletions examples/searchcommands_app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def install_packages(app_root, distribution):
if not requires:
return

target = os.path.join(app_root, 'bin', 'packages')
target = os.path.join(app_root, 'lib', 'packages')

if not os.path.isdir(target):
os.mkdir(target)
Expand Down Expand Up @@ -323,7 +323,7 @@ def run(self):
message = 'Cannot create a link at "{}" because a file by that name already exists.'.format(target)
raise SystemError(message)

packages = os.path.join(self.app_source, 'bin', 'packages')
packages = os.path.join(self.app_source, 'lib')

if not os.path.isdir(packages):
os.mkdir(packages)
Expand Down Expand Up @@ -454,13 +454,12 @@ def run(self):
'Topic :: System :: Logging',
'Topic :: System :: Monitoring'],
packages=[
'bin.packages.splunklib', 'bin.packages.splunklib.searchcommands'
'lib.splunklib', 'lib.splunklib.searchcommands'
],
package_dir={
'bin': os.path.join('package', 'bin'),
'bin.packages': os.path.join('package', 'bin', 'packages'),
'bin.packages.splunklib': os.path.join('..', '..', 'splunklib'),
'bin.packages.splunklib.searchcommands': os.path.join('..', '..', 'splunklib', 'searchcommands')
'lib': os.path.join('package', 'lib'),
'lib.splunklib': os.path.join('..', '..', 'splunklib'),
'lib.splunklib.searchcommands': os.path.join('..', '..', 'splunklib', 'searchcommands')
},
package_data={
'bin': [
Expand Down
6 changes: 4 additions & 2 deletions tests/searchcommands/test_searchcommands_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import csv
import io
import os
import sys

try:
from tests.searchcommands import project_root
Expand Down Expand Up @@ -156,7 +157,6 @@ def setUp(self):
TestCase.setUp(self)

def test_countmatches_as_unit(self):

expected, output, errors, exit_status = self._run_command('countmatches', action='getinfo', protocol=1)
self.assertEqual(0, exit_status, msg=six.text_type(errors))
self.assertEqual('', errors)
Expand Down Expand Up @@ -415,7 +415,9 @@ def _run_command(self, name, action=None, phase=None, protocol=2):
break
ofile.write(b)
with io.open(uncompressed_file, 'rb') as ifile:
process = Popen(recording.get_args(command), stdin=ifile, stderr=PIPE, stdout=PIPE)
env = os.environ.copy()
env['PYTHONPATH'] = ":".join(sys.path)
process = Popen(recording.get_args(command), stdin=ifile, stderr=PIPE, stdout=PIPE, env=env)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding

env['PYTHONPATH'] = ":".join(sys.path)

I think you want os.pathsep here so that it's ":" for unix and ";" for Windows.
https://docs.python.org/2/library/os.html#os.pathsep

output, errors = process.communicate()
with io.open(recording.output_file, 'rb') as ifile:
expected = ifile.read()
Expand Down