opsdis / aci-exporter

A Cisco ACI Prometheus exporter written in Go
https://www.opsdis.com
GNU General Public License v3.0
47 stars 16 forks source link

Allow overwriting fabric credentials from environment variables #45

Closed thushjandan closed 11 months ago

thushjandan commented 11 months ago

Problem description

Currently, it is only possible to define the connection credentials in the config.yaml file and not over environment variables. Unfortunately, theUnmarshalKey method from viper only reads the values from the configuration file although viper.AutomaticEnv method is called at the beginning.

Solution

Check if username or password are defined as environment variables. The environment variables are composed by the following pattern: ACI_EXPORTER_FABRICS_{fabric name}_{USERNAME or PASSWORD}. The fabric name used in the environment variables must be all upper case and - symbol will be converted to _

Example

fabrics:
  cisco_sandbox:
    username: foo
    password: bar
    apic:
      - https://sandboxapicdc.cisco.com
  profile-fabric-01:
    username: foo
    password: bar
    apic:
      - https://apic1
      - https://apic2
    aci_name: foobar

credentials for fabric cisco_sandbox and profile-fabric-01 can be configured as follows:

# fabric cisco_sandbox
export ACI_EXPORTER_FABRICS_CISCO_SANDBOX_USERNAME=foo 
export ACI_EXPORTER_FABRICS_CISCO_SANDBOX_PASSWORD=bar
# fabric profile-fabric-01
export ACI_EXPORTER_FABRICS_PROFILE_FABRIC_01_USERNAME=foo 
export ACI_EXPORTER_FABRICS_PROFILE_FABRIC_01_PASSWORD=bar
thenodon commented 11 months ago

@thushjandan I will add some more functionality to the use of env variables, so it possible to define everything related to the fabric(s) as environment variables. https://github.com/opsdis/aci-exporter/releases/tag/v0.6.0