本文整理汇总了Python中datadog.initialize方法的典型用法代码示例。如果您正苦于以下问题:Python datadog.initialize方法的具体用法?Python datadog.initialize怎么用?Python datadog.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datadog
的用法示例。
在下文中一共展示了datadog.initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def main():
global DD_API_KEY, REPO, TRELLO_KEY, TRELLO_TOKEN
if len(sys.argv) > 1:
REPO = sys.argv[1]
try:
DD_API_KEY = os.environ['DD_API_KEY']
TRELLO_KEY = os.environ['TRELLO_KEY']
TRELLO_TOKEN = os.environ['TRELLO_TOKEN']
except KeyError as e:
env_var = str(e).replace('KeyError:', '', 1).strip(' "\'')
raise EnvironmentError(f'Missing required environment variable `{env_var}`')
dd.initialize(api_key=DD_API_KEY)
pull_request = get_latest_pr()
if should_create_card(pull_request):
create_trello_card(pull_request)
else:
pr_url = pull_request.get('html_url')
print(f'Not creating a card for Pull Request {pr_url}')
示例2: __init__
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def __init__(self):
datadog.initialize()
self.set_ndays(90) # default is 90 days
self.print_configured = True
self.map_aws_dd = None
示例3: datadog_api
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def datadog_api():
import datadog
datadog.initialize()
return datadog.api
示例4: __init__
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def __init__(self, bot):
self.bot = bot
self.tags = []
self.task = bot.loop.create_task(self.loop_task())
self.settings = dataIO.load_json(JSON)
try:
self.analytics = CogAnalytics(self)
except Exception as error:
self.bot.logger.exception(error)
self.analytics = None
datadog.initialize(statsd_host=self.settings['HOST'])
示例5: initialize_datadog
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def initialize_datadog(environment):
datadog_enabled = environment.public_vars.get('DATADOG_ENABLED', False)
if datadog_enabled:
datadog.initialize(
environment.get_vault_var('secrets.DATADOG_API_KEY'),
environment.get_vault_var('secrets.DATADOG_APP_KEY')
)
return True
示例6: send
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def send(env, bucket, key, status):
if "DATADOG_API_KEY" in os.environ:
datadog.initialize() # by default uses DATADOG_API_KEY
result_metric_name = "unknown"
metric_tags = ["env:%s" % env, "bucket:%s" % bucket, "object:%s" % key]
if status == AV_STATUS_CLEAN:
result_metric_name = "clean"
elif status == AV_STATUS_INFECTED:
result_metric_name = "infected"
datadog.api.Event.create(
title="Infected S3 Object Found",
text="Virus found in s3://%s/%s." % (bucket, key),
tags=metric_tags,
)
scanned_metric = {
"metric": "s3_antivirus.scanned",
"type": "counter",
"points": 1,
"tags": metric_tags,
}
result_metric = {
"metric": "s3_antivirus.%s" % result_metric_name,
"type": "counter",
"points": 1,
"tags": metric_tags,
}
print("Sending metrics to Datadog.")
datadog.api.Metric.send([scanned_metric, result_metric])
示例7: main
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def main():
datadog.initialize(**CONFIG['datadog'])
args.command(args)
示例8: __init__
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def __init__(self, bot):
self.bot = bot
self.tags = []
self.task = bot.loop.create_task(self.loop_task())
self.settings = dataIO.load_json(JSON)
datadog.initialize(statsd_host=self.settings['HOST'])
示例9: initialize
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def initialize(cls):
# Init method for keys
options = {
'api_key': '****',
'app_key': '****'
}
initialize(**options)
示例10: create
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def create(cls, dash_list, config):
# Main method to init, build and perform the API call
cls.initialize()
cls.builder(dash_list, config)
output = api.Screenboard.create(board_title=cls.title,
widgets=cls.dash['widgets'], template_variables=cls.dict_tem_var, width=cls.dash['width'])
print "http://app.datadoghq.com/screen/" + str(output['id'])
示例11: __init__
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def __init__(self, api_key, app_key):
#To strongly suggest that outside objects don't access a property or method
#prefix it with a double underscore, this will perform name mangling on the
#attribute in question.
self.__api_key = api_key
self.__app_key = app_key
myKeys = {
'api_key':self.__api_key,
'app_key':self.__app_key
}
initialize(**myKeys) #call the API's initialize function that unpacks the myKeys dict, and uses those key-value pairs as parameters
#function that takes a JSON object and converts it to a python dictionary
示例12: api
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def api(self):
"""The Datadog API stub for interacting with Datadog."""
if self.__api is None:
datadog.initialize(api_key=self.__arguments['api_key'],
app_key=self.__arguments['app_key'],
host_name=self.__arguments['host'])
self.__api = datadog.api
return self.__api
示例13: get_stats
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def get_stats():
"""
Configure a shared ThreadStats instance for datadog
"""
global __stats
if __stats is not None:
return __stats
app_channel = taskcluster.secrets["APP_CHANNEL"]
if taskcluster.secrets.get("DATADOG_API_KEY"):
datadog.initialize(
api_key=taskcluster.secrets["DATADOG_API_KEY"],
host_name=f"coverage.{app_channel}.moz.tools",
)
else:
logger.info("No datadog credentials")
# Must be instantiated after initialize
# https://datadogpy.readthedocs.io/en/latest/#datadog-threadstats-module
__stats = datadog.ThreadStats(
constant_tags=[config.PROJECT_NAME, f"channel:{app_channel}"]
)
__stats.start(flush_in_thread=True)
return __stats
示例14: __init__
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def __init__(self):
datadog.initialize(api_key=settings["datadog_key"])
self.after_upgrade_success = partial(self.create_event, "success")
self.after_upgrade_failure = partial(self.create_event, "error")
示例15: v2_playbook_on_play_start
# 需要导入模块: import datadog [as 别名]
# 或者: from datadog import initialize [as 别名]
def v2_playbook_on_play_start(self, play):
# On Ansible v2, Ansible doesn't set `self.play` automatically
self.play = play
if self.disabled:
return
# Read config and hostvars
config_path = os.environ.get('ANSIBLE_DATADOG_CALLBACK_CONF_FILE', os.path.join(os.path.dirname(__file__), "datadog_callback.yml"))
api_key, dd_url, dd_site = self._load_conf(config_path)
# If there is no api key defined in config file, try to get it from hostvars
if api_key == '':
hostvars = self.play.get_variable_manager()._hostvars
if not hostvars:
print("No api_key found in the config file ({0}) and hostvars aren't set: disabling Datadog callback plugin".format(config_path))
self.disabled = True
else:
try:
api_key = hostvars['localhost']['datadog_api_key']
if not dd_url:
dd_url = hostvars['localhost'].get('datadog_url')
if not dd_site:
dd_site = hostvars['localhost'].get('datadog_site')
except Exception as e:
print('No "api_key" found in the config file ({0}) and "datadog_api_key" is not set in the hostvars: disabling Datadog callback plugin'.format(config_path))
self.disabled = True
if not dd_url:
if dd_site:
dd_url = "https://api."+ dd_site
else:
dd_url = DEFAULT_DD_URL # default to Datadog US
# Set up API client and send a start event
if not self.disabled:
datadog.initialize(api_key=api_key, api_host=dd_url)
self.send_playbook_event(
'Ansible play "{0}" started in playbook "{1}" by "{2}" against "{3}"'.format(
self.play.name,
self._playbook_name,
getpass.getuser(),
self._inventory_name),
event_type='start',
)