本文整理汇总了Python中splunklib.binding.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.")
示例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.")
示例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)
示例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)
示例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.")
示例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)
示例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()
示例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))
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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()