Python datadog.initialize() Examples

The following are 17 code examples of datadog.initialize(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module datadog , or try the search function .
Example #1
Source File: remind.py    From integrations-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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}') 
Example #2
Source File: datadog_service.py    From spinnaker-monitoring with Apache License 2.0 6 votes vote down vote up
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 
Example #3
Source File: ddlogmsg.py    From SML-Cogs with MIT License 5 votes vote down vote up
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']) 
Example #4
Source File: datadog.py    From crane with MIT License 5 votes vote down vote up
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") 
Example #5
Source File: datadog.py    From code-coverage with Mozilla Public License 2.0 5 votes vote down vote up
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 
Example #6
Source File: csvmod.py    From Miscellany with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #7
Source File: merge_screenboards.py    From Miscellany with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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']) 
Example #8
Source File: merge_screenboards.py    From Miscellany with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def initialize(cls):
		# Init method for keys

		options = {
			'api_key': '****',
			'app_key': '****'
		}
		initialize(**options) 
Example #9
Source File: ddlog.py    From SML-Cogs with MIT License 5 votes vote down vote up
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']) 
Example #10
Source File: metrics_datadog.py    From isitfit with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        datadog.initialize()
        self.set_ndays(90) # default is 90 days
        self.print_configured = True
        self.map_aws_dd = None 
Example #11
Source File: dogpush.py    From DogPush with Apache License 2.0 5 votes vote down vote up
def main():
    datadog.initialize(**CONFIG['datadog'])
    args.command(args) 
Example #12
Source File: metrics.py    From bucket-antivirus-function with Apache License 2.0 5 votes vote down vote up
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]) 
Example #13
Source File: downtime.py    From commcare-cloud with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #14
Source File: datadog.py    From calebj-cogs with GNU General Public License v3.0 5 votes vote down vote up
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']) 
Example #15
Source File: issue10.py    From isitfit with Apache License 2.0 5 votes vote down vote up
def datadog_api():
    import datadog
    datadog.initialize()
    return datadog.api 
Example #16
Source File: test_metricsDatadog_datadogApiWrap_functional.py    From isitfit with Apache License 2.0 5 votes vote down vote up
def datadog_api():
    import datadog
    datadog.initialize()
    return datadog.api 
Example #17
Source File: datadog_callback.py    From ansible-datadog-callback with MIT License 4 votes vote down vote up
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',
            )