Skip to content

Commit

Permalink
Merge pull request #10 from tcheronneau/dev
Browse files Browse the repository at this point in the history
New plex integration
  • Loading branch information
tcheronneau authored Nov 12, 2024
2 parents 40cb36d + 4e7224e commit 252f022
Show file tree
Hide file tree
Showing 17 changed files with 1,132 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Set env
run: |
RELEASE_VERSION=$(echo ${GITHUB_REF##*/})
RELEASE_VERSION=$(echo ${GITHUB_REF##/})
echo "DOCKER_TAG=$(echo ${RELEASE_VERSION#v})" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
*local*
*home*
result
.envrc
.direnv/*
37 changes: 19 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chrono = "0.4.34"
clap = "4.5.1"
clap-verbosity-flag = "2.2.0"
figment = { version = "0.10.14", features = ["toml", "env"] }
futures = "0.3.31"
ipgeolocate = "0.3.6"
json = "0.12.4"
lazy_static = "1.4.0"
Expand Down
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ RUN cargo install --path .
FROM debian:trixie-slim
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
ENV TZ="Europe/Paris"
ENV USER="homers"

COPY --from=builder /usr/local/cargo/bin/homers /usr/local/bin
COPY config.toml /app/config.toml
COPY entrypoint.sh /app/entrypoint.sh
RUN apt-get update && \
apt-get install -y sqlite3 ca-certificates
USER 1005
apt-get install -y sqlite3 ca-certificates && \
cp "/usr/share/zoneinfo/${TZ}" /etc/localtime && \
echo "${TZ}" > /etc/timezone
USER root
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["homers", "--config", "config.toml"]
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This project has the purposed to be a replacement for [Varken](https://github.com/Boerderij/Varken).
Since InfluxDB is not a good option for me, I decided to use prometheus and to build an exporter.

It's not ready yet, but some features are already there.
The project is still in early stage and a lot can still change.

![image](https://github.com/user-attachments/assets/9a0c2fb0-52f3-439d-b590-9c6698994d10)

Expand All @@ -20,7 +20,7 @@ You can either use configuration file or environment variables.
Each config key has a correspondent environment variable.
Example: `config.toml`:
```toml
[server]
[http]
port=8000
address="0.0.0.0"
[sonarr.main]
Expand All @@ -44,6 +44,18 @@ api_key=""
address="http://localhost:5055"
api_key=""
requests=200

[plex.main]
address="http://localhost:32400"
token=""

```

Example: `environement`:
```bash
HOMERS_HTTP_ADDRESS: "0.0.0.0"
HOMERS_SONARR_MAIN_ADDRESS: "http://localhost:8989"
HOMERS_SONARR_MAIN_APIKEY: ""
```

For overseerr you can customize the number of requests you want to pull. Default is 20.
Expand All @@ -61,7 +73,7 @@ Then you can run `cargo build --release`.

Alternatively you can also use nix.
To build the project using nix, you can run `nix build .#`.
And for the docker image :
And for the docker image (not used anymore for the current build):
```
nix build .#docker
docker load < ./result
Expand All @@ -71,20 +83,21 @@ docker load < ./result
## Advancement

So far it's not doing much.
[X] Retrieve Sonarr today's calendar
[X] Retrieve Tautulli activity
[X] Retrieve Tautulli library information
[X] Retrieve Overseerr requests
[X] Retrieve missing episodes from sonarr
[ ] Retrieve watch information from tautulli
[ ] Connect to ombi (I'm not using it but if required could do)
[ ] Other
[X] Retrieve Sonarr today's calendar
[X] Retrieve Tautulli activity
[X] Retrieve Tautulli library information
[X] Retrieve Overseerr requests
[X] Retrieve missing episodes from sonarr
[X] Retrieve watch information from tautulli
[ ] Retrieve watch information from plex (in progress available in dev tag)
[ ] Retrieve watch information from jellyfin
[ ] Connect to ombi (I'm not using it but if required could do)
[ ] Other

## Roadmap

The point is to at least support what Varken was doing.
There will also be a Grafana dashboard.
Grafana dashboard is now live at [Grafana](https://grafana.com/grafana/dashboards/20744).
Grafana dashboard example can be found at [Grafana](https://grafana.com/grafana/dashboards/20744).


## Acknowledgments
Expand Down
29 changes: 29 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://taskfile.dev

version: '3'

vars:
DOCKER_TAG: latest

tasks:
build:
cmds:
- cmd: docker build -t mcth/homers:{{.DOCKER_TAG}} .
push:
cmds:
- cmd: docker push mcth/homers:{{.DOCKER_TAG}}
build_alpha:
cmds:
- task: build
vars:
DOCKER_TAG: alpha
- task: push
vars:
DOCKER_TAG: alpha
build_multi_arch:
cmds:
- cmd: docker buildx build --platform linux/amd64,linux/arm64 -t mcth/homers:{{.DOCKER_TAG}} .
default:
cmds:
- task: build
- task: push
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#

if [[ -z "${UID}" ]]; then
echo "UID is not set. Using default UID 1005."
UID="1005"
fi
if [[ -z "${TZ}" ]]; then
echo "TZ is not set. Using default timezone 'UTC'."
TZ="UTC"
fi
cp "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
groupadd -g 1005 homers
useradd -u 1005 -g 1005 -s /bin/bash -m homers

runuser --user homers -- "$@"
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::collections::HashMap;
use std::path::PathBuf;

use crate::providers::overseerr::Overseerr;
use crate::providers::plex::Plex;
use crate::providers::radarr::Radarr;
use crate::providers::sonarr::Sonarr;
use crate::providers::tautulli::Tautulli;
Expand All @@ -20,6 +21,7 @@ pub struct Config {
pub sonarr: Option<HashMap<String, Sonarr>>,
pub radarr: Option<HashMap<String, Radarr>>,
pub overseerr: Option<Overseerr>,
pub plex: Option<HashMap<String, Plex>>,
pub http: rocket::Config,
}
impl Default for Config {
Expand All @@ -29,6 +31,7 @@ impl Default for Config {
sonarr: None,
radarr: None,
overseerr: None,
plex: None,
http: rocket::Config::default(),
}
}
Expand All @@ -42,6 +45,8 @@ pub enum Task {
Overseerr(Overseerr),
TautulliSession(Tautulli),
TautulliLibrary(Tautulli),
PlexSession(Plex),
PlexLibrary(Plex),
Default,
}

Expand Down Expand Up @@ -108,5 +113,12 @@ pub fn get_tasks(config: Config) -> anyhow::Result<Vec<Task>> {
)?;
tasks.push(Task::Overseerr(overseerr));
}
if let Some(plex) = config.plex {
for (name, p) in plex {
let client = Plex::new(&name, remove_trailing_slash(&p.address), &p.token)?;
tasks.push(Task::PlexSession(client.clone()));
tasks.push(Task::PlexLibrary(client));
}
}
Ok(tasks)
}
13 changes: 12 additions & 1 deletion src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub async fn configure_rocket(config: Config) -> Rocket<Build> {
.unwrap_or_else(exit_if_handle_fatal)
.unwrap_or_else(exit_if_handle_fatal);
rocket::custom(config.http)
.manage(config.sonarr)
.manage(tasks)
.mount("/", routes![index, metrics])
}
Expand Down Expand Up @@ -97,6 +96,18 @@ async fn process_task(task: Task) -> Result<TaskResult, JoinError> {
let result = overseerr.get_overseerr_requests().await;
Ok(TaskResult::Overseerr(result))
}
Task::PlexSession(plex) => {
let name = &plex.name;
let result = plex.get_current_sessions().await;
let result = HashMap::from([(name.to_string(), result)]);
Ok(TaskResult::PlexSession(result))
}
Task::PlexLibrary(plex) => {
let name = &plex.name;
let result = plex.get_all_library_size().await;
let result = HashMap::from([(name.to_string(), result)]);
Ok(TaskResult::PlexLibrary(result))
}
Task::Default => Ok(TaskResult::Default),
}
}
Expand Down
Loading

0 comments on commit 252f022

Please sign in to comment.