Skip to content

Commit 77f9030

Browse files
author
Itay Neeman
committed
Check in custom search commands v2
1 parent 7d937bc commit 77f9030

198 files changed

Lines changed: 113259 additions & 1380 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Commands.conf.spec.xlsx

5.98 KB
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname "$0")/bash-prologue" ${BASH_SOURCE[0]} 'help,clean,debug-client:' 'hcd:' $* || exit $?
4+
5+
###########
6+
# Arguments
7+
###########
8+
9+
eval set -- $args
10+
11+
while [[ $1 != '--' ]]
12+
do
13+
case $1 in
14+
-h|--help)
15+
usage; # does not return
16+
shift 1
17+
;;
18+
-c|--clean)
19+
declare -r clean="clean"
20+
shift 1
21+
;;
22+
-d|--debug-client)
23+
[[ -f "$d" ]] || error 1 "Debug client '$2' does not exist."
24+
declare -r debugClient="--debug-client '$2'"
25+
shift 2
26+
;;
27+
esac
28+
done
29+
30+
[[ -z ${clean:- } ]] || rm -rf "${scriptRoot}/build"
31+
"${scriptRoot}/setup.py" build --build-number="$(git log -1 --pretty=format:%ct)" ${debugClient:-}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[CmdletBinding()]
2+
param(
3+
[parameter(Mandatory=$false)]
4+
[switch]
5+
$Clean,
6+
[parameter(Mandatory=$false)]
7+
[switch]
8+
$DebugBuild
9+
)
10+
11+
$buildNumber = git log -1 --pretty=format:%ct
12+
13+
$debugClient = if ($DebugBuild) {
14+
"--debug-client=`"C:\Program Files (x86)\JetBrains\PyCharm\debug-eggs\pycharm-debug.egg`""
15+
}
16+
else {
17+
""
18+
}
19+
20+
if ($Clean) {
21+
Get-Item -ErrorAction SilentlyContinue "$PSScriptRoot\build", "${env:SPLUNK_HOME}\etc\apps\chunked_searchcommands" | Remove-Item -ErrorAction Stop -Force -Recurse
22+
}
23+
24+
$ErrorActionPreference = "Continue" ;# Because PowerShell assumes a command has failed if there's any output to stderr even if the command's exit code is zero
25+
26+
python "${PSScriptRoot}\setup.py" build --build-number="${buildNumber}" $debugClient
27+
28+
if ($LASTEXITCODE -ne 0) {
29+
"Exit code = $LASTEXITCODE"
30+
return
31+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname "$0")/bash-prologue" ${BASH_SOURCE[0]} 'help,clean,debug-client:' 'hcd:' $* || exit $?
4+
5+
###########
6+
# Arguments
7+
###########
8+
9+
eval set -- $args
10+
11+
while [[ $1 != '--' ]]
12+
do
13+
case $1 in
14+
-h|--help)
15+
usage; # does not return
16+
shift 1
17+
;;
18+
-c|--clean)
19+
declare -r clean="clean"
20+
shift 1
21+
;;
22+
-d|--debug-client)
23+
[[ -f "$d" ]] || error 1 "Debug client '$2' does not exist."
24+
declare -r debugClient="--debug-client '$2'"
25+
shift 2
26+
;;
27+
esac
28+
done
29+
30+
# TODO: Answer this: We like "splunk restart -f" because it's fast, but what's the right thing to do for customers?
31+
# TODO: Do the right thing when SPLUNK_HOME is undefined
32+
# TODO: Parameterize version number
33+
34+
declare -r appName="$(basename '${scriptRoot}')"
35+
declare -r buildNumber=$(git log -1 --pretty=format:%ct)
36+
37+
[[ -z ${clean:-} ]] || rm -rf "$scriptRoot/build" "${SPLUNK_HOME}/etc/apps/${appName}"
38+
"${scriptRoot}/setup.py" build --build-number="$buildNumber" ${debugClient:-}
39+
splunk start ;# Because the splunk daemon might not be running
40+
splunk install app "${scriptRoot}\build\${appName}-1.0.0-${buildNumber}.tar.gz" -auth admin:changeme -update 1
41+
splunk restart -f ;# Because a restart is usually required after installing an application
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[CmdletBinding()]
2+
param(
3+
[parameter(Mandatory=$false)]
4+
[switch]
5+
$Clean,
6+
[ValidateScript(ScriptBlock={Test-Path $_})]
7+
[parameter(Mandatory=$false)]
8+
[string]
9+
$DebugClient
10+
)
11+
12+
# TODO: Answer this: We like "splunk restart -f" because it's fast, but what's the right thing to do for customers?
13+
# TODO: Do the right thing when SPLUNK_HOME is undefined
14+
# TODO: Parameterize version number
15+
16+
$appName = Split-Path -Leaf $PSScriptRoot
17+
$buildNumber = git log -1 --pretty=format:%ct
18+
19+
$debugClient = if ($DebugClient -ne $null) {
20+
"--debug-client=`"$DebugClient`""
21+
}
22+
else {
23+
""
24+
}
25+
26+
if ($Clean) {
27+
Get-Item -ErrorAction SilentlyContinue "$PSScriptRoot\build", "${env:SPLUNK_HOME}\etc\apps\${appName}" | Remove-Item -ErrorAction Stop -Force -Recurse
28+
}
29+
30+
$ErrorActionPreference = "Continue" ;# Because PowerShell assumes a command has failed if there's any output to stderr even if the command's exit code is zero
31+
32+
python "${PSScriptRoot}\setup.py" build --build-number="${buildNumber}" $debugClient
33+
34+
if ($LASTEXITCODE -ne 0) {
35+
"Exit code = $LASTEXITCODE"
36+
return
37+
}
38+
39+
splunk start ;# Because the splunk daemon might not be running
40+
41+
if ($LASTEXITCODE -ne 0) {
42+
"Exit code = $LASTEXITCODE"
43+
return
44+
}
45+
46+
splunk install app "${PSScriptRoot}\build\${appName}-1.0.0-${buildNumber}.tar.gz" -auth admin:changeme -update 1
47+
48+
if ($LASTEXITCODE -ne 0) {
49+
"Exit code = $LASTEXITCODE"
50+
return
51+
}
52+
53+
splunk restart -f ;# Because a restart is usually required after installing an application
54+
55+
if ($LASTEXITCODE -ne 0) {
56+
"Exit code = $LASTEXITCODE"
57+
return
58+
}

examples/searchcommands_app/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ splunk-sdk-python searchcommands_app example
33

44
This app provides several examples of custom search commands which illustrate each of the base types:
55

6-
Command | Type | Description
7-
:------------ |:-----------|:----------------------------------------------------
8-
generatehello| Generating | Generates a specified number of 'Hello World' events
9-
simulate | Generating | Generates a sequence of events drawn from a csv file using repeated random sampling with replacement
10-
sum | Reporting | Adds all the numbers in a set of fields.
11-
countmatches | Streaming | Counts the number of non-overlapping matches to a regular expression in a set of fields.
12-
6+
Command | Type | Description
7+
:---------------- |:-----------|:-------------------------------------------------------------------------------------------
8+
countmatches | Streaming | Counts the number of non-overlapping matches to a regular expression in a set of fields.
9+
generatetext | Generating | Generates a specified number of events containing a specified text string.
10+
pypygeneratetext | | Executes generatetext with PyPy
11+
simulate | Generating | Generates a sequence of events drawn from a csv file using repeated random sampling with replacement
12+
sum | Reporting | Adds all the numbers in a set of fields.
13+
1314
The app is tested on Splunk 5 and 6. Here is its manifest:
1415

1516
```
1617
├── bin
1718
│ ├── splunklib
1819
│ │ └── searchcommands ....... splunklib.searchcommands module
20+
│   ├── countmatches.py .......... CountMatchesCommand implementation
21+
│ ├── generatetext.py .......... GenerateTextCommand implementation
22+
│ ├── pypygeneratetext.py ...... Executes generatetext.py with PyPy
1923
│ ├── simulate.py .............. SimulateCommand implementation
2024
│ ├── sum.py ................... SumCommand implementation
21-
│   ├── countmatches.py .......... CountMatchesCommand implementation
22-
│   └── generatehello.py ........... HelloWorldCommand implementation
25+
│   └──
2326
├── default
2427
│ ├── data
2528
│ │   └── ui
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname "$0")/bash-prologue" ${BASH_SOURCE[0]} 'help,clean,debug-client:' 'hcd:' $* || exit $?
4+
5+
if [[ $1 == scpv1-1.3 ]]; then
6+
rm -f "${SPLUNK_HOME}/etc/apps/searchcommands_app"
7+
cd "${SPLUNK_HOME}/etc/apps"
8+
ln -s ~/Workspace/splunk-sdks/splunk-sdk-python.master/examples/searchcommands_app
9+
elif [[ $1 == scpv1-1.5 ]]; then
10+
"${scriptRoot}/setup.py" link --scp-version 1
11+
elif [[ $1 == scpv2-1.5 ]]; then
12+
"${scriptRoot}/setup.py" link --scp-version 2
13+
else
14+
error 1 "Unrecognized argument: $1"
15+
fi
16+
17+
splunk restart -f

examples/searchcommands_app/Test-Performance

Whitespace-only changes.
43.8 KB
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
###########
2+
# Variables
3+
###########
4+
5+
declare -r scriptRoot="$(cd "$(dirname "$1")" && pwd)"
6+
declare -r scriptName="$(basename "$1")"
7+
declare -r scriptLongOptions="$2"
8+
declare -r scriptOptions="$3"
9+
10+
shift 3
11+
12+
###########
13+
# Functions
14+
###########
15+
16+
function usage {
17+
18+
man "${scriptName}"
19+
exit 0
20+
}
21+
22+
function error {
23+
echo "${scriptName} error: $2" 1>&2
24+
exit $1
25+
}
26+
27+
###########
28+
# Constants
29+
###########
30+
31+
# useful for printing text to console...
32+
33+
declare -r b="$(tput bold)" ; # bold
34+
declare -r n="$(tput sgr0)" ; # normal
35+
declare -r u="$(tput smul)" ; # underline
36+
declare -r u_="$(tput rmul)" ; # underline off (neither $n nor $b defeat $u)
37+
38+
###########
39+
# Arguments
40+
###########
41+
42+
declare args=$(getopt --name "$scriptName" --options "$scriptOptions" --longoptions "$scriptLongOptions" -- $* || exit 1)
43+
set -o errexit -o nounset

0 commit comments

Comments
 (0)