bluecmd / fortigate_exporter

Prometheus exporter for Fortigate firewalls
GNU General Public License v3.0
232 stars 72 forks source link

Failed to read API authentication map file: open fortigate-key.yaml: no such file or directory #271

Closed azte closed 8 months ago

azte commented 8 months ago

Hi all, I've been trying to get this running without luck. Any help is really appreciated. I'm using this command as per the documentation.

sudo docker run -p 9710:9710 -v /var/docks/forti_exporter/fortigate-key.yaml:/config/fortigate-key.yaml quay.io/bluecmd/fortigate_exporter:master -insecure

My fortigate-key.yaml. file (with the correct structure as mentioned and API key) is located at /var/docks/forti_exporter

I'm getting this error: 2024/01/10 05:22:43 Failed to read API authentication map file: open fortigate-key.yaml: no such file or directory

I tried different paths, check for typos, permissions, newly created yaml files but I'm getting the same message over and over. I got it running fine directly in a different environment without using containers. So I think that's the part I'm doing wrong somewhere. Any ideas of what I could be missing?

azte commented 8 months ago

Hi I got some additional help but I couldn't get it running using any of the default examples provided. I was getting the same error over and over again. I had to recreate the image and pass the the key yaml file using COPY directly in the Dockerfile.

Dockerfile looks something like this.

FROM golang:1.18 as builder

WORKDIR /build

COPY . . RUN go get -v -t -d ./... RUN make build

FROM scratch WORKDIR /opt/fortigate_exporter

COPY --from=builder /build/target/fortigate-exporter . COPY --from=builder /etc/ssl/certs/ca-certificates.crt . ENV SSL_CERT_DIR=/opt/fortigate_exporter

COPY fortigate-key.yaml .

EXPOSE 9710 ENTRYPOINT ["./fortigate-exporter"] CMD ["-auth-file", "/opt/fortigate_exporter/fortigate-key.yaml", "-insecure"]

DockerCompose file:

version: '3'

services: prometheus_fortigate_exporter: image: forti_exporter_custom container_name: forti_container_exporter ports:

Now it's running as expected. I'm posting this here in case anyone else encounters a similar issue. Thanks, great project!

bluecmd commented 8 months ago

If you put in -insecure you override all other default arguments which is why the configuration file cannot be found.

Either way, building your own container with the correct CAs in is the best way to do things - but I do but recommend adding secrets into Docker layers.

Anyway, this seems to be resolved.