|
15 | 15 | """Retrieves a list of installed apps from Splunk by making REST API calls
|
16 | 16 | using Python's httplib module."""
|
17 | 17 |
|
18 |
| -import httplib |
| 18 | +from __future__ import absolute_import |
| 19 | +from __future__ import print_function |
| 20 | +import splunklib.six.moves.http_client |
19 | 21 | import urllib
|
20 | 22 | from xml.etree import ElementTree
|
21 | 23 |
|
|
25 | 27 | PASSWORD = "changeme"
|
26 | 28 |
|
27 | 29 | # Present credentials to Splunk and retrieve the session key
|
28 |
| -connection = httplib.HTTPSConnection(HOST, PORT) |
| 30 | +connection = six.moves.http_client.HTTPSConnection(HOST, PORT) |
29 | 31 | body = urllib.urlencode({'username': USERNAME, 'password': PASSWORD})
|
30 | 32 | headers = {
|
31 | 33 | 'Content-Type': "application/x-www-form-urlencoded",
|
|
40 | 42 | finally:
|
41 | 43 | connection.close()
|
42 | 44 | if response.status != 200:
|
43 |
| - raise Exception, "%d (%s)" % (response.status, response.reason) |
| 45 | + raise Exception("%d (%s)" % (response.status, response.reason)) |
44 | 46 | body = response.read()
|
45 | 47 | sessionKey = ElementTree.XML(body).findtext("./sessionKey")
|
46 | 48 |
|
47 | 49 | # Now make the request to Splunk for list of installed apps
|
48 |
| -connection = httplib.HTTPSConnection(HOST, PORT) |
| 50 | +connection = six.moves.http_client.HTTPSConnection(HOST, PORT) |
49 | 51 | headers = {
|
50 | 52 | 'Content-Length': "0",
|
51 | 53 | 'Host': HOST,
|
|
59 | 61 | finally:
|
60 | 62 | connection.close()
|
61 | 63 | if response.status != 200:
|
62 |
| - raise Exception, "%d (%s)" % (response.status, response.reason) |
| 64 | + raise Exception("%d (%s)" % (response.status, response.reason)) |
63 | 65 |
|
64 | 66 | body = response.read()
|
65 | 67 | data = ElementTree.XML(body)
|
66 | 68 | apps = data.findall("{http://www.w3.org/2005/Atom}entry/{http://www.w3.org/2005/Atom}title")
|
67 | 69 | for app in apps:
|
68 |
| - print app.text |
| 70 | + print(app.text) |
0 commit comments