Skip to content

Commit 23bc5fd

Browse files
committed
Merge branch 'feature/extras' into develop
2 parents d4ff81e + 3316486 commit 23bc5fd

16 files changed

+852
-242
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
`count`, `offset`, `search`, `sort_dir`, `sort_key` and `sort_mode`. Note
1212
that `Inputs` and `Jobs` are not pageable collections and only support basic
1313
enumeration and iteration.
14-
* Improvements to unit tests
14+
* Support for event types:
15+
- Added Service.event_types + units
16+
- Added examples/event_types.py
17+
* Support for fired alerts:
18+
- Added Service.fired_alerts + units
19+
- Added examples/fired_alerts.py
20+
* Support for saved searches:
21+
- Added Service.saved_searches + units
22+
- Added examples/saved_searches.py
1523

1624
### Breaking changes
1725

examples/event_types.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2011-2012 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+
"""A command line utility that lists Splunk event types."""
18+
19+
import sys
20+
21+
from splunklib.client import connect
22+
23+
from utils import parse
24+
25+
def main():
26+
opts = parse(sys.argv[1:], {}, ".splunkrc")
27+
service = connect(**opts.kwargs)
28+
29+
for item in service.event_types:
30+
print "%s" % item.name
31+
print '='*len(item.name)
32+
content = item.content
33+
for key in sorted(content.keys()):
34+
value = content[key]
35+
print "%s: %s" % (key, value)
36+
print
37+
38+
if __name__ == "__main__":
39+
main()
40+
41+

examples/fired_alerts.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2011-2012 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+
"""A command line utility that prints out fired alerts."""
18+
19+
import sys
20+
21+
from splunklib.client import connect
22+
23+
from utils import parse
24+
25+
def main():
26+
opts = parse(sys.argv[1:], {}, ".splunkrc")
27+
service = connect(**opts.kwargs)
28+
29+
for group in service.fired_alerts:
30+
header = "%s (count: %d)" % (group.name, group.count)
31+
print "%s" % header
32+
print '='*len(header)
33+
alerts = group.alerts
34+
for alert in alerts.list():
35+
content = alert.content
36+
for key in sorted(content.keys()):
37+
value = content[key]
38+
print "%s: %s" % (key, value)
39+
print
40+
41+
if __name__ == "__main__":
42+
main()
43+
44+

examples/index.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
disable [<index>]+
3030
enable [<index>]+
3131
list [<index>]*
32-
reload [<index>]+
3332
update <index> [options]
3433
3534
Examples:
@@ -119,17 +118,13 @@ def run(self, argv):
119118
'disable': self.disable,
120119
'enable': self.enable,
121120
'list': self.list,
122-
'reload': self.reload,
123121
'update': self.update,
124122
}
125123
handler = handlers.get(command, None)
126124
if handler is None:
127125
error("Unrecognized command: %s" % command, 2)
128126
handler(argv[1:])
129127

130-
def reload(self, argv):
131-
self.foreach(argv, lambda index: index.reload())
132-
133128
def foreach(self, argv, func):
134129
"""Apply the function to each index named in the argument vector."""
135130
opts = cmdline(argv)

examples/inputs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ def main():
2727
service = connect(**opts.kwargs)
2828

2929
for item in service.inputs:
30-
print "%s (%s)" % (item.name, item.kind)
30+
header = "%s (%s)" % (item.name, item.kind)
31+
print header
32+
print '='*len(header)
3133
content = item.content
3234
for key in sorted(content.keys()):
3335
value = content[key]
34-
print " %s: %s" % (key, value)
36+
print "%s: %s" % (key, value)
37+
print
3538

3639
if __name__ == "__main__":
3740
main()

examples/saved_searches.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2011-2012 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+
"""A command line utility that lists saved searches."""
18+
19+
import sys
20+
21+
from splunklib.client import connect
22+
23+
from utils import parse
24+
25+
def main():
26+
opts = parse(sys.argv[1:], {}, ".splunkrc")
27+
service = connect(**opts.kwargs)
28+
29+
for saved_search in service.saved_searches:
30+
header = saved_search.name
31+
print header
32+
print '='*len(header)
33+
content = saved_search.content
34+
for key in sorted(content.keys()):
35+
value = content[key]
36+
print "%s: %s" % (key, value)
37+
history = saved_search.history()
38+
if len(history) > 0:
39+
print "history:"
40+
for job in history:
41+
print " %s" % job.name
42+
print
43+
44+
if __name__ == "__main__":
45+
main()
46+
47+

splunklib/binding.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ def __init__(self, response):
298298
def __str__(self):
299299
return self.read()
300300

301+
def close(self):
302+
self._response.close()
303+
301304
def read(self, size = None):
302305
return self._response.read(size)
303306

0 commit comments

Comments
 (0)