Prometheus.yml sync with AD-DHCP

Hello,
Would you know how to automate the prometheus.yml file to dynamically add computers that receive their IP addresses via DHCP from a Windows Active Directory?

Hi,

Usually, Windows AD with DHCP have DNS inside them, so, put your Windows AD IP as the DNS server from your machine.
Then test the dns resolving to the machine that you want to check using the name that inside the AD. And perhaps using the complete name with the domain that used by the AD.
In the prometheus.yml just use that name to query.

Regards,
Fadjar

Hi Fadjar,

Thanks for your answer. However, I managed to complete the task yesterday by creating two scripts:

  • A PowerShell script that collects DHCP data, names the document based on the server name, and exports the CSV to an FTP server every hour using the task scheduler.

  • A bash script that extracts the CSV’s information and fills my prometheus.yml file with the correct indentation if any host isn’t already registered, every hour with cron which looks like this:

  • job_name: 'the document name ’
    static_configs:

    • targets: [‘IP@:9182’]
      labels:
      location: ‘“HostName”’
    • targets: [‘IP@:9182’]
      labels:
      location: “HOSTNAME”
    • targets: [IP@:9182’]
      labels:
      location: “HoStNaMe”
1 Like