Skip to content

Commit 7e78c6e

Browse files
committed
Adding HellWorldCommand
1 parent d176ee5 commit 7e78c6e

5 files changed

Lines changed: 59 additions & 14 deletions

File tree

‎examples/searchcommands_app/README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
splunk-sdk-python search_commands_app example
22
=============================================
33

4-
This app provides three examples of custom search commands; one of each of the
5-
base types:
4+
This app provides several examples of custom search commands which illustrate each of the base types:
65

76
Command | Type | Description
87
:------------ |:-----------|:----------------------------------------------------
8+
helloworld | Generating | Generates a specified number of 'Hello World' events
99
simulate | Generating | Generates a sequence of events drawn from a csv file using repeated random sampling with replacement
1010
sum | Reporting | Adds all the numbers in a set of fields.
1111
countmatches | Streaming | Counts the number of non-overlapping matches to a regular expression in a set of fields.
@@ -18,7 +18,8 @@ The app is tested on Splunk 5 and 6. Here is its manifest:
1818
│ │ └── searchcommands ....... splunklib.searchcommands module
1919
│ ├── simulate.py .............. SimulateCommand implementation
2020
│ ├── sum.py ................... SumCommand implementation
21-
│   └── countmatches.py .......... CountMatchesCommand implementation
21+
│   ├── countmatches.py .......... CountMatchesCommand implementation
22+
│   └── hellowowrld.py ........... HelloWorldCommand implementation
2223
├── default
2324
│ ├── data
2425
│ │   └── ui
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2011-2014 Splunk, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
import sys, time
18+
from splunklib.searchcommands import \
19+
dispatch, GeneratingCommand, Configuration, Option, validators
20+
21+
@Configuration()
22+
class HelloWorldCommand(GeneratingCommand):
23+
count = Option(require=True, validate=validators.Integer())
24+
25+
def generate(self):
26+
for i in range(0, self.count):
27+
text = 'Hello World %d' % i
28+
yield {'_time': time.time(), 'text': text, '_raw': text }
29+
30+
dispatch(HelloWorldCommand, sys.argv, sys.stdin, sys.stdout, __name__)

‎examples/searchcommands_app/default/commands.conf‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ supports_rawargs = true
2424

2525
outputheader = true
2626
requires_srinfo = true
27+
28+
[helloworld]
29+
filename = helloworld.py
30+
supports_getinfo = true
31+
supports_rawargs = true
32+
33+
outputheader = true
34+
requires_srinfo = true

‎examples/searchcommands_app/default/logging.conf‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# [Configuration file format](http://goo.gl/K6edZ8)
55
#
66
[loggers]
7-
keys = root, CountMatchesCommand, SimulateCommand, SumCommand
7+
keys = root, CountMatchesCommand, SimulateCommand, SumCommand, HelloWorldCommand
88

99
[logger_root]
1010
level = WARNING ; Default: WARNING
@@ -28,6 +28,12 @@ level = NOTSET ; Default: WARNING
2828
handlers = file ; Default: stderr
2929
propagate = 0 ; Default: 1
3030

31+
[logger_HelloWorldCommand]
32+
qualname = HelloWorldCommand
33+
level = NOTSET ; Default: WARNING
34+
handlers = file ; Default: stderr
35+
propagate = 0 ; Default: 1
36+
3137
[handlers]
3238
# See [logging.handlers](http://goo.gl/9aoOx)
3339
keys=file, stderr

‎examples/searchcommands_app/default/searchbnf.conf‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ usage = public
4444
related = inputcsv
4545
tags = searchcommands_app
4646

47-
[sum-command]
48-
syntax = sum total=<field> <field-list>
47+
[helloworld-command]
48+
syntax = helloworld count=<count>
4949
alias =
50-
shortdesc = Computes the sum of a set of fields.
51-
description = The total produced is sum(sum(fieldname, 1, n), 1, N) where n = \
52-
number of fields, N = number of records.
53-
comment1 = This example computes the total linecount in the first 200 records \
54-
in the _internal index.
55-
example1 = index = _internal | head 200 | sum total=lines linecount
56-
category = reporting
50+
shortdesc = Creates a set of 'Hello World' events
51+
description = This command creates a specified number of dummy events
52+
comment1 = This example generates 5 events
53+
example1 = | helloworld count=5
54+
category = generating
5755
appears-in = 5.0
58-
maintainer = dnoble
56+
maintainer = gblock
5957
usage = public
6058
related = stats
6159
tags = searchcommands_app
60+
61+

0 commit comments

Comments
 (0)