本文整理汇总了Python中splunklib.binding.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_login_fails_without_cookie_or_token
def test_login_fails_without_cookie_or_token(self):
opts = {"host": self.opts.kwargs["host"], "port": self.opts.kwargs["port"]}
try:
binding.connect(**opts)
self.fail()
except AuthenticationError as ae:
self.assertEqual(str(ae), "Login failed.")
开发者ID:malmoore,项目名称:splunk-sdk-python,代码行数:7,代码来源:test_binding.py
示例2: test_login_fails_without_cookie_or_token
def test_login_fails_without_cookie_or_token(self):
opts = {
'host': self.opts.kwargs['host'],
'port': self.opts.kwargs['port']
}
try:
binding.connect(**opts)
self.fail()
except AuthenticationError as ae:
self.assertEqual(ae.message, "Login failed.")
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:10,代码来源:test_binding.py
示例3: main
def main():
""" main entry """
options = parse(sys.argv[1:], CLIRULES, ".splunkrc")
if options.kwargs['omode'] not in OUTPUT_MODES:
print "output mode must be one of %s, found %s" % (OUTPUT_MODES,
options.kwargs['omode'])
sys.exit(1)
service = connect(**options.kwargs)
if path.exists(options.kwargs['output']):
if options.kwargs['recover'] == False:
error("Export file exists, and recover option nor specified")
else:
options.kwargs['end'] = recover(options)
options.kwargs['fixtail'] = True
openmode = "a"
else:
openmode = "w"
options.kwargs['fixtail'] = False
try:
options.kwargs['fd'] = open(options.kwargs['output'], openmode)
except IOError:
print "Failed to open output file %s w/ mode %s" % \
(options.kwargs['output'], openmode)
sys.exit(1)
export(options, service)
开发者ID:chiehwen,项目名称:splunk-sdk-python,代码行数:30,代码来源:export.py
示例4: test_unicode_connect
def test_unicode_connect(self):
opts = self.opts.kwargs.copy()
opts['host'] = unicode(opts['host'])
context = binding.connect(**opts)
# Just check to make sure the service is alive
response = context.get("/services")
self.assertEqual(response.status, 200)
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:7,代码来源:test_binding.py
示例5: test_login_fails_with_bad_cookie
def test_login_fails_with_bad_cookie(self):
new_context = binding.connect(**{"cookie": "bad=cookie"})
# We should get an error if using a bad cookie
try:
new_context.get("apps/local")
self.fail()
except AuthenticationError as ae:
self.assertEqual(ae.message, "Request failed: Session is not logged in.")
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:8,代码来源:test_binding.py
示例6: test_list
def test_list(self):
context = binding.connect(**self.opts.kwargs)
response = context.get(PATH_USERS)
self.assertEqual(response.status, 200)
response = context.get(PATH_USERS + "/_new")
self.assertEqual(response.status, 200)
开发者ID:archankr,项目名称:splunk-sdk-python,代码行数:8,代码来源:test_binding.py
示例7: test_connect
def test_connect(self):
context = binding.connect(**self.opts.kwargs)
# Just check to make sure the service is alive
response = context.get("/services")
self.assertEqual(response.status, 200)
# Make sure we can open a socket to the service
context.connect().close()
开发者ID:archankr,项目名称:splunk-sdk-python,代码行数:9,代码来源:test_binding.py
示例8: test_handlers
def test_handlers(self):
paths = ["/services", "authentication/users", "search/jobs"]
handlers = [binding.handler(), urllib2_handler] # default handler
for handler in handlers:
logging.debug("Connecting with handler %s", handler)
context = binding.connect(handler=handler, **self.opts.kwargs)
for path in paths:
body = context.get(path).body.read()
self.assertTrue(isatom(body))
开发者ID:Jaykul,项目名称:splunk-sdk-python,代码行数:9,代码来源:test_binding.py
示例9: main
def main(argv):
opts = parse(argv, {}, ".splunkrc")
context = connect(**opts.kwargs)
service = Service(context)
assert service.apps().status == 200
assert service.indexes().status == 200
assert service.info().status == 200
assert service.settings().status == 200
assert service.search("search 404").status == 200
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:9,代码来源:binding1.py
示例10: setUp
def setUp(self):
self.opts = testlib.parse([], {}, ".splunkrc")
self.context = binding.connect(**self.opts.kwargs)
# Skip these tests if running below Splunk 6.2, cookie-auth didn't exist before
import splunklib.client as client
service = client.Service(**self.opts.kwargs)
splver = service.splunk_version
if splver[:2] < (6, 2):
self.skipTest("Skipping cookie-auth tests, running in %d.%d.%d, this feature was added in 6.2+" % splver)
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:10,代码来源:test_binding.py
示例11: setUp
def setUp(self):
self.opts = testlib.parse([], {}, ".splunkrc")
opts = self.opts.kwargs.copy()
opts["basic"] = True
opts["username"] = self.opts.kwargs["username"]
opts["password"] = self.opts.kwargs["password"]
self.context = binding.connect(**opts)
import splunklib.client as client
service = client.Service(**opts)
开发者ID:larrys,项目名称:splunk-sdk-python,代码行数:10,代码来源:test_binding.py
示例12: main
def main(argv):
""" main entry """
usage = 'usage: %prog --help for options'
opts = utils.parse(argv, RULES, ".splunkrc", usage=usage)
context = binding.connect(**opts.kwargs)
operation = None
# splunk.binding.debug = True # for verbose information (helpful for debugging)
# Extract from command line and build into variable args
kwargs = {}
for key in RULES.keys():
if opts.kwargs.has_key(key):
if key == "operation":
operation = opts.kwargs[key]
else:
kwargs[key] = urllib.quote(opts.kwargs[key])
# no operation? if name present, default to list, otherwise list-all
if not operation:
if kwargs.has_key('name'):
operation = 'list'
else:
operation = 'list-all'
# pre-sanitize
if (operation != "list" and operation != "create"
and operation != "delete"
and operation != "list-all"):
print "operation %s not one of list-all, list, create, delete" % operation
sys.exit(0)
if not kwargs.has_key('name') and operation != "list-all":
print "operation requires a name"
sys.exit(0)
# remove arg 'name' from passing through to operation builder, except on create
if operation != "create" and operation != "list-all":
name = kwargs['name']
kwargs.pop('name')
# perform operation on saved search created with args from cli
if operation == "list-all":
result = context.get("saved/searches", **kwargs)
elif operation == "list":
result = context.get("saved/searches/%s" % name, **kwargs)
elif operation == "create":
result = context.post("saved/searches", **kwargs)
else:
result = context.delete("saved/searches/%s" % name, **kwargs)
print "HTTP STATUS: %d" % result.status
xml_data = result.body.read()
sys.stdout.write(xml_data)
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:54,代码来源:saved_search.py
示例13: test_logout
def test_logout(self):
context = binding.connect(**self.opts.kwargs)
response = context.get("/services")
self.assertEqual(response.status, 200)
context.logout()
try:
context.get("/services")
self.fail()
except HTTPError, e:
self.assertEqual(e.status, 401)
开发者ID:archankr,项目名称:splunk-sdk-python,代码行数:12,代码来源:test_binding.py
示例14: test_create
def test_create(self):
context = binding.connect(**self.opts.kwargs)
username = "sdk-test-user"
password = "changeme"
roles = "power"
try:
response = context.delete(PATH_USERS + username)
self.assertEqual(response.status, 200)
except HTTPError, e:
self.assertEqual(e.status, 400) # User doesnt exist
开发者ID:archankr,项目名称:splunk-sdk-python,代码行数:12,代码来源:test_binding.py
示例15: test_connect_with_preexisting_token_sans_user_and_pass
def test_connect_with_preexisting_token_sans_user_and_pass(self):
token = self.context.token
opts = self.opts.kwargs.copy()
del opts["username"]
del opts["password"]
opts["token"] = token
newContext = binding.connect(**opts)
response = newContext.get("/services")
self.assertEqual(response.status, 200)
socket = newContext.connect()
socket.write("POST %s HTTP/1.1\r\n" % self.context._abspath("some/path/to/post/to"))
socket.write("Host: %s:%s\r\n" % (self.context.host, self.context.port))
socket.write("Accept-Encoding: identity\r\n")
socket.write("Authorization: %s\r\n" % self.context.token)
socket.write("X-Splunk-Input-Mode: Streaming\r\n")
socket.write("\r\n")
socket.close()
开发者ID:Jaykul,项目名称:splunk-sdk-python,代码行数:19,代码来源:test_binding.py
示例16: test_login_with_multiple_cookies
def test_login_with_multiple_cookies(self):
bad_cookie = 'bad=cookie'
new_context = binding.connect(**{"cookie": bad_cookie})
# We should get an error if using a bad cookie
try:
new_context.get("apps/local")
self.fail()
except AuthenticationError as ae:
self.assertEqual(ae.message, "Request failed: Session is not logged in.")
# Bring in a valid cookie now
for key, value in self.context.get_cookies().items():
new_context.get_cookies()[key] = value
self.assertEqual(len(new_context.get_cookies()), 2)
self.assertTrue('bad' in new_context.get_cookies().keys())
self.assertTrue('cookie' in new_context.get_cookies().values())
for k, v in self.context.get_cookies().items():
self.assertEqual(new_context.get_cookies()[k], v)
self.assertEqual(new_context.get("apps/local").status, 200)
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:21,代码来源:test_binding.py
示例17: setUp
def setUp(self):
logging.info("%s", self.__class__.__name__)
self.opts = testlib.parse([], {}, ".splunkrc")
self.context = binding.connect(**self.opts.kwargs)
logging.debug("Connected to splunkd.")
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:5,代码来源:test_binding.py
示例18: test_context_with_system_sharing
def test_context_with_system_sharing(self):
context = binding.connect(
owner="me", app="MyApp", sharing="system", **self.kwargs)
path = context._abspath("foo")
self.assertTrue(isinstance(path, UrlEncoded))
self.assertEqual(path, "/servicesNS/nobody/system/foo")
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:6,代码来源:test_binding.py
示例19: test_context_with_both
def test_context_with_both(self):
context = binding.connect(owner="me", app="MyApp", **self.kwargs)
path = context._abspath("foo")
self.assertTrue(isinstance(path, UrlEncoded))
self.assertEqual(path, "/servicesNS/me/MyApp/foo")
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:5,代码来源:test_binding.py
示例20: test_context_defaults
def test_context_defaults(self):
context = binding.connect(**self.kwargs)
path = context._abspath("foo")
self.assertTrue(isinstance(path, UrlEncoded))
self.assertEqual(path, "/services/foo")
开发者ID:huit,项目名称:splunk-sdk-python,代码行数:5,代码来源:test_binding.py
注:本文中的splunklib.binding.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论