本文整理汇总了Python中utils.flare.Flare类的典型用法代码示例。如果您正苦于以下问题:Python Flare类的具体用法?Python Flare怎么用?Python Flare使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Flare类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uri_password
def test_uri_password(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
_, password_found = f._strip_password(os.path.join(get_mocked_temp(), mock_cfgs['uri_password']))
self.assertEqual(
password_found,
" - this file contains a password in a uri which has been removed in the version collected"
)
示例2: windows_flare
def windows_flare():
case_id, ok = QInputDialog.getInteger(
None, "Flare",
"Your logs and configuration files are going to be collected and "
"sent to Datadog Support. Please enter your ticket number if you have one:",
value=0, min=0
)
if not ok:
info_popup("Flare cancelled")
return
case_id = int(case_id) if case_id != 0 else None
f = Flare(case_id=case_id)
f.collect()
email, ok = QInputDialog.getText(
None, "Your email",
"Logs and configuration files have been collected."
" Please enter your email address:"
)
if not ok:
info_popup("Flare cancelled. You can still use {0}".format(f.tar_path))
return
try:
case_id = f.upload(email=str(email))
info_popup("Your logs were successfully uploaded. For future reference,"
" your internal case id is {0}".format(case_id))
except Exception, e:
warning_popup('The upload failed. Please send the following file by email'
' to support: {0}\n\n{1}'.format(f.tar_path, str(e)))
示例3: test_endpoint
def test_endpoint(self, mock_config, mock_temp, mock_stfrtime):
f = Flare()
f._ask_for_email = lambda: None
try:
f.upload(confirmation=False)
raise Exception('Should fail before')
except Exception, e:
self.assertEqual(str(e), "Your request is incorrect: Invalid inputs: 'API key unknown'")
示例4: test_uri_password
def test_uri_password(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
_, credentials_log = f._strip_credentials(
os.path.join(get_mocked_temp(), mock_cfgs['uri_password']),
f.CHECK_CREDENTIALS
)
self.assertEqual(
credentials_log,
" - this file contains a credential (password in a uri) which has been removed in the collected version"
)
示例5: test_uri_verify_ssl_default
def test_uri_verify_ssl_default(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
request_options = {}
f.set_ssl_validation(request_options)
expected_verify = None
if Platform.is_windows():
expected_verify = os.path.realpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.pardir, os.pardir,
'datadog-cert.pem'
))
self.assertEquals(request_options.get('verify'), expected_verify)
示例6: test_whitespace_proxy_user_pass_regex
def test_whitespace_proxy_user_pass_regex(self, mock_config, mock_tempdir, mock_strftime, mock_os_remove):
f = Flare()
file_path, _ = f._strip_credentials(
os.path.join(get_mocked_temp(), 'whitespace_proxy.conf'),
f.MAIN_CREDENTIALS
)
with open(file_path) as f:
contents = f.read()
self.assertEqual(
contents,
"proxy_user: ********\n"
"proxy_password: ********\n"
)
示例7: test_api_keys_regex
def test_api_keys_regex(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
file_path, _ = f._strip_credentials(
os.path.join(get_mocked_temp(), 'apikeys.conf'),
f.MAIN_CREDENTIALS
)
with open(file_path) as f:
contents = f.read()
self.assertEqual(
contents,
"""api_key: *************************aaaaa
other_api_keys: **************************bbbbb, **************************ccccc, **************************dddd
"""
)
示例8: test_upload_with_case
def test_upload_with_case(self, mock_config, mock_tempdir, mock_stfrtime, mock_version, mock_requests):
f = Flare(case_id=1337)
assert not mock_requests.called
f.upload(confirmation=False)
assert mock_requests.called
args, kwargs = mock_requests.call_args_list[0]
self.assertEqual(
args,
('https://6-6-6-flare.agent.datadoghq.com/support/flare/1337?api_key=APIKEY',)
)
self.assertEqual(
kwargs['files']['flare_file'].name,
os.path.join(get_mocked_temp(), "datadog-agent-1.tar.bz2")
)
self.assertEqual(kwargs['data']['case_id'], 1337)
self.assertEqual(kwargs['data']['email'], '')
assert kwargs['data']['hostname']
示例9: test_upload_no_case
def test_upload_no_case(self, mock_config, mock_tempdir, mock_stfrtime, mock_version, mock_requests):
f = Flare()
f._ask_for_email = lambda: '[email protected]'
assert not mock_requests.called
f.upload()
assert mock_requests.called
args, kwargs = mock_requests.call_args_list[0]
self.assertEqual(
args,
('https://6-6-6-flare.agent.datadoghq.com/support/flare?api_key=APIKEY',)
)
self.assertEqual(
kwargs['files']['flare_file'].name,
os.path.join(get_mocked_temp(), "datadog-agent-1.tar.bz2")
)
self.assertEqual(kwargs['data']['case_id'], None)
self.assertEqual(kwargs['data']['email'], '[email protected]')
assert kwargs['data']['hostname']
示例10: test_upload_with_case_proxy
def test_upload_with_case_proxy(self, mock_config, mock_tempdir, mock_stfrtime, mock_version, mock_requests):
f = Flare(case_id=1337)
f._ask_for_email = lambda: '[email protected]'
assert not mock_requests.called
f.upload()
assert mock_requests.called
args, kwargs = mock_requests.call_args_list[0]
self.assertEqual(
args,
('https://6-6-6-flare.agent.datadoghq.com/support/flare/1337?api_key=APIKEY',)
)
self.assertEqual(
kwargs['files']['flare_file'].name,
os.path.join(get_mocked_temp(), "datadog-agent-1.tar.bz2")
)
self.assertEqual(kwargs['data']['case_id'], 1337)
self.assertEqual(kwargs['data']['email'], '[email protected]')
assert kwargs['data']['hostname']
assert kwargs['proxies']['https'] == 'http://proxy_user:[email protected]:3128'
assert not kwargs['verify']
示例11: test_endpoint
def test_endpoint(self, mock_config, mock_temp, mock_stfrtime):
f = Flare()
f._ask_for_email = lambda: None
f._open_tarfile()
f._tar.close()
with self.assertRaises(Exception) as cm:
f.upload()
self.assertEqual(str(cm.exception), "Your request is incorrect: Invalid inputs: 'API key unknown'")
示例12: test_endpoint
def test_endpoint(self, mock_config, mock_temp, mock_stfrtime):
if os.environ['FLARE_BROKEN']:
raise unittest.case.SkipTest('Flare broken, acknowledged')
f = Flare()
f._ask_for_email = lambda: None
f._open_tarfile()
f._tar.close()
with self.assertRaises(Exception) as cm:
f.upload()
self.assertEqual(str(cm.exception), "Your request is incorrect: Invalid inputs: 'API key unknown'")
示例13: main
#.........这里部分代码省略.........
log.info('Restart daemon')
agent.restart()
elif 'status' == command:
agent.status()
elif 'info' == command:
return Agent.info(verbose=options.verbose)
elif 'foreground' == command:
logging.info('Running in foreground')
if autorestart:
# Set-up the supervisor callbacks and fork it.
logging.info('Running Agent with auto-restart ON')
def child_func():
agent.start(foreground=True)
def parent_func():
agent.start_event = False
AgentSupervisor.start(parent_func, child_func)
else:
# Run in the standard foreground.
agent.start(foreground=True)
elif 'check' == command:
if len(args) < 2:
sys.stderr.write(
"Usage: %s check <check_name> [check_rate]\n"
"Add check_rate as last argument to compute rates\n"
% sys.argv[0]
)
return 1
check_name = args[1]
try:
import checks.collector
# Try the old-style check first
print getattr(checks.collector, check_name)(log).check(agentConfig)
except Exception:
# If not an old-style check, try checks.d
checks = load_check_directory(agentConfig, hostname)
for check in checks['initialized_checks']:
if check.name == check_name:
if in_developer_mode:
check.run = AgentProfiler.wrap_profiling(check.run)
cs = Collector.run_single_check(check, verbose=True)
print CollectorStatus.render_check_status(cs)
if len(args) == 3 and args[2] == 'check_rate':
print "Running 2nd iteration to capture rate metrics"
time.sleep(1)
cs = Collector.run_single_check(check, verbose=True)
print CollectorStatus.render_check_status(cs)
check.stop()
elif 'configcheck' == command or 'configtest' == command:
configcheck()
elif 'jmx' == command:
if len(args) < 2 or args[1] not in JMX_LIST_COMMANDS.keys():
print "#" * 80
print "JMX tool to be used to help configuring your JMX checks."
print "See http://docs.datadoghq.com/integrations/java/ for more information"
print "#" * 80
print "\n"
print "You have to specify one of the following commands:"
for command, desc in JMX_LIST_COMMANDS.iteritems():
print " - %s [OPTIONAL: LIST OF CHECKS]: %s" % (command, desc)
print "Example: sudo /etc/init.d/datadog-agent jmx list_matching_attributes tomcat jmx solr"
print "\n"
else:
jmx_command = args[1]
checks_list = args[2:]
confd_directory = get_confd_path(get_os())
jmx_process = JMXFetch(confd_directory, agentConfig)
jmx_process.configure()
should_run = jmx_process.should_run()
if should_run:
jmx_process.run(jmx_command, checks_list, reporter="console")
else:
print "Couldn't find any valid JMX configuration in your conf.d directory: %s" % confd_directory
print "Have you enabled any JMX check ?"
print "If you think it's not normal please get in touch with Datadog Support"
elif 'flare' == command:
Flare.check_user_rights()
case_id = int(args[1]) if len(args) > 1 else None
f = Flare(True, case_id)
f.collect()
try:
f.upload()
except Exception, e:
print 'The upload failed:\n{0}'.format(str(e))
示例14: main
#.........这里部分代码省略.........
command = args[0]
if command not in COMMANDS:
sys.stderr.write("Unknown command: %s\n" % command)
return 3
# TODO: actually kill the start/stop/restart/status command for 5.11
if command in ['start', 'stop', 'restart', 'status'] and not in_developer_mode:
logging.error('Please use supervisor to manage the agent')
return 1
if command in COMMANDS_AGENT:
agent = Agent(PidFile(PID_NAME, PID_DIR).get_path(), autorestart, in_developer_mode=in_developer_mode)
if 'start' == command:
log.info('Start daemon')
agent.start()
elif 'stop' == command:
log.info('Stop daemon')
agent.stop()
elif 'restart' == command:
log.info('Restart daemon')
agent.restart()
elif 'status' == command:
agent.status()
elif 'info' == command:
return Agent.info(verbose=options.verbose)
elif 'foreground' == command:
log.info('Agent version %s' % get_version())
if autorestart:
# Set-up the supervisor callbacks and fork it.
logging.info('Running Agent with auto-restart ON')
def child_func():
agent.start(foreground=True)
def parent_func():
agent.start_event = False
AgentSupervisor.start(parent_func, child_func)
else:
# Run in the standard foreground.
agent.start(foreground=True)
elif 'check' == command:
if len(args) < 2:
sys.stderr.write(
"Usage: %s check <check_name> [check_rate]\n"
"Add check_rate as last argument to compute rates\n"
% sys.argv[0]
)
return 1
check_name = args[1]
try:
import checks.collector
# Try the old-style check first
print getattr(checks.collector, check_name)(log).check(agentConfig)
except Exception:
# If not an old-style check, try checks.d
checks = load_check_directory(agentConfig, hostname)
for check in checks['initialized_checks']:
if check.name == check_name:
if in_developer_mode:
check.run = AgentProfiler.wrap_profiling(check.run)
cs = Collector.run_single_check(check, verbose=True)
print CollectorStatus.render_check_status(cs)
if len(args) == 3 and args[2] == 'check_rate':
print "Running 2nd iteration to capture rate metrics"
time.sleep(1)
cs = Collector.run_single_check(check, verbose=True)
print CollectorStatus.render_check_status(cs)
check.stop()
elif 'configcheck' == command or 'configtest' == command:
configcheck()
sd_configcheck(agentConfig)
elif 'jmx' == command:
jmx_command(args[1:], agentConfig)
elif 'flare' == command:
Flare.check_user_rights()
case_id = int(args[1]) if len(args) > 1 else None
f = Flare(True, case_id)
f.collect()
try:
f.upload()
except Exception as e:
print 'The upload failed:\n{0}'.format(str(e))
return 0
示例15: test_uri_no_verify_ssl
def test_uri_no_verify_ssl(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
request_options = {}
f.set_ssl_validation(request_options)
self.assertFalse(request_options['verify'])