4

I'm trying to use the datadog api but the initialize method keeps giving the error 'INFO No agent or invalid configuration file found'.

The datadog agent is running:

(PYTHON) daphnepaparis@Daphnes-MBP-2 ~ $ /usr/local/bin/datadog-agent status Datadog Agent (supervisor) is running all child processes

And the configuration file permissions look alright:

(PYTHON) daphnepaparis@Daphnes-MBP-2 ~ $ ls -l ~/.datadog-agent/datadog.conf lrwxr-xr-x 1 daphnepaparis staff 35 Mar 22 12:58 /Users/daphnepaparis/.datadog-agent/datadog.conf -> /opt/datadog-agent/etc/datadog.conf

Original commands I'm running:

In [1]: from datadog import initialize, api

In [2]: options = {'api_key': '***'}

In [3]: initialize(**options)

2017-03-22 13:24:20 INFO No agent or invalid configuration file found

Anyone able to help?

Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
Daph
  • 43
  • 1
  • 6

1 Answers1

5

So from that log line, it appears as though this try is excepting in the library's hostname.py. So either...

  • (A) The hostname line is where it's excepting, and (weirdly) the library requires that a hostname option be set in your datadog.conf file. Maybe worth setting a hostname there if you haven't already. Or,

  • (B) The get_config() line is where it's excepting, and so the library isn't able to correctly identify the configuration file location (or access it, possibly related to permissions). Based on the directory structure in your question, I think you're working on an OSX / mac environment, which means the library will be using the function _mac_config_path() in config.py to try to identify the configuration path, which from this line in the function would make it seem as though the library were looking for the configuration file in ~/.datadog-agent/agent/datadog.conf instead of the appropriate ~/.datadog-agent/datadog.conf. Which might be a legitimate bug...

So if I were you, and if all this seemed right, I'd try adding a hostname in the datadog.conf to see if that helped, and if it didn't, then I'd try making a ~/.datadog-agent/agent/ directory and copying your datadog.conf file there as well, just to see if that got things working.

This answer assumes you are working in an OSX / mac environment, and will likely not be correct otherwise.

If either (A) or (B) are the case, then that's a problem with the library and should be updated--it would be kind of you to open an issue on the library itself to bring this up so the Datadog team that supports that library can be made aware. I suspect not many people end up this library in OSX / mac environments to begin with, so that could explain all this.

stephenlechner
  • 1,836
  • 11
  • 11
  • 2
    hey Stephen thanks for your help! the issue was B, once I created the agent directory and copied the conf over everything worked fine. I'll bring it up to the Datadog team. thanks again. – Daph Jul 06 '17 at 21:03
  • I received this error while running my code in google cloud function and there I believe, I can not apply any of the fix mentioned above. Is there something I am missing? – JD-V Feb 10 '20 at 09:53
  • oooh, not really sure how you'd call on that library from a cloud function, but you can probably reach out to Datadog support to get some guidance on that. – stephenlechner Feb 11 '20 at 14:53
  • For anybody looking… I’m on macOS Catalina (10.15.7) and running the Agent locally on my Mac. It reported an invalid API key ("datadog API key ending with PIKEY”) despite it being populated correctly (I double and triple checked). It turned out I needed to explicitly provide the hostname in the datadog.yaml file. – Pawel Krakowiak Jan 22 '21 at 11:03