Skip to content

Commit 770d490

Browse files
Merge pull request #6 from splunk/develop
Merge develop with master
2 parents d330f83 + 877581d commit 770d490

File tree

16 files changed

+413
-0
lines changed

16 files changed

+413
-0
lines changed

src/eventing_app/bin/eventingcsc.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
#
4+
# Copyright 2011-2015 Splunk, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
7+
# not use this file except in compliance with the License. You may obtain
8+
# a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
18+
import os,sys
19+
20+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
21+
from splunklib.searchcommands import dispatch, EventingCommand, Configuration, Option, validators
22+
23+
24+
@Configuration()
25+
class EventingCSC(EventingCommand):
26+
"""
27+
The eventingcsc command filters records from the events stream returning only those for which the status is same
28+
as search query.
29+
30+
Example:
31+
32+
``index="_internal" | head 4000 | eventingcsc status=200``
33+
34+
Returns records having status 200 as mentioned in search query.
35+
"""
36+
37+
status = Option(
38+
doc='''**Syntax:** **status=***<value>*
39+
**Description:** record having same status value will be returned.''',
40+
require=True)
41+
42+
def transform(self, records):
43+
for record in records:
44+
if str(self.status) == record["status"]:
45+
yield record
46+
47+
48+
dispatch(EventingCSC, sys.argv, sys.stdin, sys.stdout, __name__)

src/eventing_app/default/app.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Splunk app configuration file
3+
#
4+
5+
[install]
6+
is_configured = 0
7+
8+
[ui]
9+
is_visible = 1
10+
label = Eventing App
11+
12+
[launcher]
13+
description = Eventing custom search commands example
14+
version = 1.0.0
15+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[eventingapp]
2+
filename = eventingcsc.py
3+
chunked = true
4+
python.version = python3
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Application-level permissions
3+
4+
[]
5+
access = read : [ * ], write : [ admin, power ]
6+
7+
### EVENT TYPES
8+
9+
[eventtypes]
10+
export = system
11+
12+
13+
### PROPS
14+
15+
[props]
16+
export = system
17+
18+
19+
### TRANSFORMS
20+
21+
[transforms]
22+
export = system
23+
24+
25+
### LOOKUPS
26+
27+
[lookups]
28+
export = system
29+
30+
31+
### VIEWSTATES: even normal users should be able to create shared viewstates
32+
33+
[viewstates]
34+
access = read : [ * ], write : [ * ]
35+
export = system
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
#
4+
# Copyright © 2011-2015 Splunk, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
7+
# not use this file except in compliance with the License. You may obtain
8+
# a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
18+
import os, sys
19+
import time
20+
21+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
22+
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
23+
24+
25+
@Configuration()
26+
class GeneratingCSC(GeneratingCommand):
27+
"""
28+
The generatingcsc command generates a specific number of records.
29+
30+
Example:
31+
32+
``| generatingcsc count=4``
33+
34+
Returns a 4 records having text 'Test Event'.
35+
"""
36+
37+
count = Option(require=True, validate=validators.Integer(0))
38+
39+
def generate(self):
40+
self.logger.debug("Generating %s events" % self.count)
41+
for i in range(1, self.count + 1):
42+
text = f'Test Event {i}'
43+
yield {'_time': time.time(), 'event_no': i, '_raw': text}
44+
45+
46+
dispatch(GeneratingCSC, sys.argv, sys.stdin, sys.stdout, __name__)

src/generating_app/default/app.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Splunk app configuration file
3+
#
4+
5+
[install]
6+
is_configured = 0
7+
8+
[ui]
9+
is_visible = 1
10+
label = Generating App
11+
12+
[launcher]
13+
description = Generating custom search commands example
14+
version = 1.0.0
15+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[generatingapp]
2+
filename = generatingcsc.py
3+
chunked = true
4+
python.version = python3
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Application-level permissions
3+
4+
[]
5+
access = read : [ * ], write : [ admin, power ]
6+
7+
### EVENT TYPES
8+
9+
[eventtypes]
10+
export = system
11+
12+
13+
### PROPS
14+
15+
[props]
16+
export = system
17+
18+
19+
### TRANSFORMS
20+
21+
[transforms]
22+
export = system
23+
24+
25+
### LOOKUPS
26+
27+
[lookups]
28+
export = system
29+
30+
31+
### VIEWSTATES: even normal users should be able to create shared viewstates
32+
33+
[viewstates]
34+
access = read : [ * ], write : [ * ]
35+
export = system

src/reporting_app/bin/reportingcsc.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
#
4+
# Copyright 2011-2015 Splunk, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
7+
# not use this file except in compliance with the License. You may obtain
8+
# a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
18+
import os,sys
19+
20+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
21+
from splunklib.searchcommands import dispatch, ReportingCommand, Configuration, Option, validators
22+
23+
24+
@Configuration(requires_preop=True)
25+
class ReportingCSC(ReportingCommand):
26+
"""
27+
The reportingcsc command returns a count of students having higher total marks than cutoff marks.
28+
29+
Example:
30+
31+
``| makeresults count=10 | eval math=random()%100, eng=random()%100, cs=random()%100 | reportingcsc cutoff=150
32+
math eng cs``
33+
34+
returns a count of students out of 10 having a higher total marks than cutoff.
35+
"""
36+
37+
cutoff = Option(require=True, validate=validators.Integer(0))
38+
39+
@Configuration()
40+
def map(self, records):
41+
"""returns a total marks of a students"""
42+
# list of subjects
43+
fieldnames = self.fieldnames
44+
for record in records:
45+
# store a total marks of a single student
46+
total = 0.0
47+
for fieldname in fieldnames:
48+
total += float(record[fieldname])
49+
yield {"totalMarks": total}
50+
51+
def reduce(self, records):
52+
"""returns a students count having a higher total marks than cutoff"""
53+
pass_student_cnt = 0
54+
for record in records:
55+
value = float(record["totalMarks"])
56+
if value >= float(self.cutoff):
57+
pass_student_cnt += 1
58+
yield {"student having total marks greater than cutoff ": pass_student_cnt}
59+
60+
61+
dispatch(ReportingCSC, sys.argv, sys.stdin, sys.stdout, __name__)

src/reporting_app/default/app.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Splunk app configuration file
3+
#
4+
5+
[install]
6+
is_configured = 0
7+
8+
[ui]
9+
is_visible = 1
10+
label = Reporting App
11+
12+
[launcher]
13+
description = Reporting custom search commands example
14+
version = 1.0.0
15+

0 commit comments

Comments
 (0)