Skip to content

Commit 5e9c0e1

Browse files
David NobleDavid Noble
authored andcommitted
Merge pull request #78 from glennblock/develop
Adding HelloWorldCommand
2 parents ab39725 + aad8d85 commit 5e9c0e1

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

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+
generatehello| 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+
│   └── generatehello.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 GenerateHelloCommand(GeneratingCommand):
23+
count = Option(require=True, validate=validators.Integer())
24+
25+
def generate(self):
26+
for i in range(1, self.count + 1):
27+
text = 'Hello World %d' % i
28+
yield {'_time': time.time(), 'event_no': i, '_raw': text }
29+
30+
dispatch(GenerateHelloCommand, 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+
[generatehello]
29+
filename = generatehello.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_GenerateHelloCommand]
32+
qualname = GenerateHelloCommand
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,19 @@ maintainer = dnoble
5959
usage = public
6060
related = stats
6161
tags = searchcommands_app
62+
63+
[generatehello-command]
64+
syntax = generatehello count=<count>
65+
alias =
66+
shortdesc = Creates a set of 'Hello World' events.
67+
description = This command creates a specified number of dummy events.
68+
comment1 = This example generates 5 events
69+
example1 = | generatehello count=5
70+
category = generating
71+
appears-in = 5.0
72+
maintainer = gblock
73+
usage = public
74+
related = stats
75+
tags = searchcommands_app
76+
77+

0 commit comments

Comments
 (0)