tlkamp / litter-exporter

A Prometheus exporter for the Litter Robot 3 Connect
MIT License
7 stars 0 forks source link

More flexibility in configuration #17

Closed Starttoaster closed 2 years ago

Starttoaster commented 2 years ago

It would be a nice-to-have for setting these values with either a yaml config, or environment variables.

The yaml config would be nice for Kubernetes deployments, as you could mount a k8s Secret object in the container.

Environment variables are a bit of a lower hanging fruit. But would be nice to have as it's a pattern for configuring behavior inside containers that people are accustomed to.

I could help with this if you're interested. I'll probably have already forked this repo and done it for my own use.

tlkamp commented 2 years ago

Referring to these?

https://github.com/tlkamp/litter-exporter/blob/main/main.go#L12-L22

I think that would be pretty easy to implement. I would be happy to do the implementation, but I'll also accept contributions :)

Starttoaster commented 2 years ago

Yup! Referring to those. Either way is fine with me, if you would like to write it, I won't argue.

I'm actually trying to debug a different issue I'm having anyway. On the call to the login() function in tlkamp/litter-api, I'm getting the error time="2022-07-20T00:39:38Z" level=error msg="failed to parse token claims" error="token contains an invalid number of segments" so perhaps something regarding the JWT token returned from the litter robot API was altered. (Understanding that this convo is better suited for a different Issue, and if you'd like, I could open one up for it. Otherwise I'm fine with getting to the bottom of it too.)

tlkamp commented 2 years ago

I think you are likely having an auth configuration issue as everything is working fine for me.

Starttoaster commented 2 years ago

I think you are likely having an auth configuration issue as everything is working fine for me.

You're right. After a bit of digging, I found I actually needed the -client-id and -client-secret flags, and I used the values I found on a random google search result lol: https://raw.githubusercontent.com/dcmeglio/hubitat-litterrobot/master/smartapps/natekspencer/litter-robot-manager.src/litter-robot-manager.groovy

Not sure if that was expected... but the README implies the exporter should start without those flags... hence the confusion :smile:

edit: Though I'm seeing now that if I were to read the content of the docs directory, it also says as much. (The example on the readme is just a bit misleading I guess.)

tlkamp commented 2 years ago

The architecture of the Litter Robot API appears to be an AWS API Gateway fronting a Python Lambda function, and the API Gateway seems to require the various tokens. The only way to obtain them has been to reverse engineer the mobile phone apps since the API isn't exactly public or documented, but the values mentioned in the example do work: https://github.com/tlkamp/litter-exporter/blob/main/doc/examples/docker-compose.yml

I can set them as defaults in the CLI.

Starttoaster commented 2 years ago

The values in that docker-compose file do get this working for me. I don't currently have any litter robot related metrics showing up on the exporter, just the default ones that the prometheus library self-reports. But for now I'm assuming that's just because I got my Litter Robot last night and my cats haven't used it yet :joy:

tlkamp commented 2 years ago

Possible! You should see some configuration related information at the very least. You can always cycle it manually to force it though :)

tlkamp commented 2 years ago

@Starttoaster I have a PR open for environment variable support now. Please have a look and confirm this is what you imagined.

Also note the breaking changes.

tlkamp commented 2 years ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: