### async fn start(&self) -> anyhow::Result<()> Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Starts the main event processing loop which polls the database, checks event conditions, processes files, and manages event dispatching and retries. ```APIDOC ## async fn start(&self) -> anyhow::Result<()> ### Description Main event processing loop. Runs continuously until an error occurs. It handles polling the database for pending events, validating processing conditions, checking file integrity, sending requests to targets, and managing retries with exponential backoff. ### Usage ```rust let handle = manager.start(); tokio::select! { res = handle => { res?; } } ``` ``` -------------------------------- ### Pre-initialize Database Backend Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Required setup step before creating a connection pool. ```rust AnyConnection::pre_init("sqlite://autopulse.db")?; let pool = get_pool("sqlite://autopulse.db")?; ``` -------------------------------- ### Initialize PulseManager Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Example of constructing the PulseManager using settings and a database pool. ```rust let settings = Settings::get_settings(None)?; let pool = get_pool(&settings.app.database_url)?; let manager = PulseManager::new(settings.settings, pool); ``` -------------------------------- ### Initialize Connection Pool Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Example of creating a connection pool and acquiring a connection for migration. ```rust let pool = get_pool("sqlite://autopulse.db")?; let mut conn = get_conn(&pool)?; conn.migrate()?; ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md A sample YAML configuration file demonstrating the app settings structure. ```yaml app: hostname: 0.0.0.0 port: 2875 database_url: sqlite://autopulse.db log_level: info api_logging: false base_path: "" secure_cookies: false trusted_proxies: [] ``` -------------------------------- ### Configure Authentication via YAML Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Example YAML configuration for setting authentication credentials. ```yaml auth: username: admin password: secure-password-here ``` -------------------------------- ### GET / Version Response Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Returns the current application version. ```json { "autopulse": "v2.0.0" } ``` -------------------------------- ### Manual Trigger cURL Example Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Example command to trigger a manual scan using cURL with authentication. ```bash curl -u admin:password \ 'http://localhost:2875/triggers/manual?path=/media/Show/S01E01.mkv&hash=abc123def456' ``` -------------------------------- ### Project Setup and Execution Source: https://github.com/dan-online/autopulse/blob/main/README.md Commands to clone the repository, create a basic configuration file, and run the application with different dependency configurations. ```bash # clone the repo $ git clone https://github.com/dan-online/autopulse.git $ cd autopulse # basic easy config $ cat < config.toml [app] database_url = "sqlite://data/test.sqlite" log_level = "trace" EOF # easy start using vendored/bundled dependencies $ cargo run --features vendored # or if you have the dependencies installed (libql-dev, libsqlite3-dev) $ cargo run # or if you only have one of the dependencies installed $ cargo run --no-default-features --features sqlite # for sqlite $ cargo run --no-default-features --features postgres # for postgres ``` -------------------------------- ### GET / Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Returns the current version of the application. ```APIDOC ## GET / ### Description Returns the current version of the application. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **autopulse** (string) - The current version of the application. #### Response Example { "autopulse": "v2.0.0" } ``` -------------------------------- ### Configure Global Options via YAML Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Example YAML configuration for setting global service options. ```yaml opts: check_path: false max_retries: 5 default_timer_wait: 60 cleanup_days: 10 log_file: /var/log/autopulse.log log_file_rollover: daily log_file_max_files: 30 webhook_retries: 3 webhook_timeout: 10 webhook_interval: 10 ``` -------------------------------- ### GET /list Response and Requests Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Retrieves a paginated list of scan events with optional filtering and sorting, and provides examples for common query patterns. ```json { "items": [ { "id": "550e8400-e29b-41d4-a716-446655440000", "event_source": "my_sonarr", "file_path": "/tvshows/Breaking Bad/Season 1/s01e01.mkv", "process_status": "complete", "found_status": "found", "created_at": "2024-01-15T10:30:00", "updated_at": "2024-01-15T10:30:05" } ], "total": 1250, "page": 1, "pages": 63, "limit": 20 } ``` ```bash # Get pending events, page 2 curl -u admin:password 'http://localhost:2875/list?status=pending&page=2' # Search for episodes with "Breaking" in path, sorted by creation time (ascending) curl -u admin:password 'http://localhost:2875/list?search=Breaking&sort=-created_at' # Get failed events curl -u admin:password 'http://localhost:2875/list?status=failed&limit=50' ``` -------------------------------- ### Access re-exported crates Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Examples showing how to define and import re-exported dependencies. ```rust pub extern crate regex; pub extern crate tracing_appender; ``` ```rust use autopulse_utils::regex::Regex; use autopulse_utils::tracing_appender::non_blocking; ``` -------------------------------- ### async fn start_webhooks(&self) -> anyhow::Result<()> Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Starts the webhook delivery loop which subscribes to the event bus, batches events, and handles delivery to configured webhooks with retry logic. ```APIDOC ## async fn start_webhooks(&self) -> anyhow::Result<()> ### Description Webhook delivery loop. Runs continuously and batches webhook deliveries based on configured intervals. ### Configuration - **opts.webhook_retries**: Retry attempts - **opts.webhook_timeout**: HTTP timeout in seconds - **opts.webhook_interval**: Batch interval in seconds ### Usage ```rust let handle = manager.start_webhooks(); tokio::select! { res = handle => { res?; } } ``` ``` -------------------------------- ### async fn start_notify(&self) -> anyhow::Result<()> Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Starts the file system monitoring loop for notify triggers, applying filters and debouncing events. ```APIDOC ## async fn start_notify(&self) -> anyhow::Result<()> ### Description File system monitoring loop for notify triggers. Subscribes to file system events, applies path filters, and creates scan events. ### Configuration - **Trigger-specific**: recursive, paths, filter - **Global**: opts.default_timer_wait ### Usage ```rust let handle = manager.start_notify(); tokio::select! { res = handle => { res?; } } ``` ``` -------------------------------- ### Define Webhook Integrations Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/webhooks.md Example configuration for Discord, Matrix, and generic JSON webhook endpoints. ```yaml webhooks: discord_notifications: type: discord url: https://discord.com/api/webhooks/123456789/abcdefghijklmnopqrstuvwxyz mentions: - targets: [here] on: [failed] - targets: - role: "moderators" on: [hash_mismatch] matrix_notifications: type: hookshot url: https://matrix.example.com/_matrix/hookshot/webhook/hook-token generic_json: type: json url: https://monitoring.example.com/api/events/autopulse ``` -------------------------------- ### Environment Variable Configuration Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Examples of setting configuration via environment variables using the AUTOPULSE__SECTION__KEY format. ```bash AUTOPULSE__APP__PORT=3000 AUTOPULSE__AUTH__PASSWORD=secret AUTOPULSE__OPTS__MAX_RETRIES=10 AUTOPULSE__TARGETS__PLEX__TOKEN=xxxxx AUTOPULSE__AUTH__PASSWORD__FILE=/run/secrets/password ``` -------------------------------- ### GET /api/config-template Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Retrieves configuration templates. ```APIDOC ## GET /api/config-template ### Description Retrieves available configuration templates. Requires Basic Auth. ### Method GET ### Endpoint /api/config-template ``` -------------------------------- ### GET /stats Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Retrieves system statistics. ```APIDOC ## GET /stats ### Description Returns current system statistics. ### Method GET ### Endpoint /stats ``` -------------------------------- ### Path Filter Example Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Demonstrates filtering paths under /media while excluding specific subdirectories and file extensions. ```yaml filter: include: - "^/media/" # Only process paths under /media exclude: - "/temp/" # But skip anything under /temp - "\\.sample\\." # And skip sample files ``` -------------------------------- ### Wait Timer Example Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Configures a 5-minute wait period before processing for a specific trigger. ```yaml triggers: my_sonarr: timer: wait: 300 ``` -------------------------------- ### GET /list Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Lists all events. ```APIDOC ## GET /list ### Description Retrieves a list of events. Requires Basic Auth. ### Method GET ### Endpoint /list ``` -------------------------------- ### Install Autopulse on Unraid via CLI Source: https://github.com/dan-online/autopulse/blob/main/README.md Commands to create the private application directory and download the Unraid template file. ```bash mkdir -p /boot/config/plugins/community.applications/private/autopulse wget -O /boot/config/plugins/community.applications/private/autopulse/autopulse.xml \ https://raw.githubusercontent.com/dan-online/autopulse/main/unraid/autopulse.xml ``` -------------------------------- ### Start Notify Monitoring Loop Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Integrate the file system monitoring loop into a Tokio select block for notify triggers. ```rust let handle = manager.start_notify(); tokio::select! { res = handle => { res?; } // ... other tasks } ``` -------------------------------- ### Apply path rewrites in Rust Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Examples of using the Rewrite struct to transform paths. ```rust let rewrite = Rewrite::single("^/downloads", "/media"); let result = rewrite.rewrite_path("/downloads/show/ep.mkv".to_string()); assert_eq!(result, "/media/show/ep.mkv"); ``` ```rust let rewrite = Rewrite::multiple(vec![ ("^/downloads", "/media"), ("tmp_", ""), ]); let result = rewrite.rewrite_path("/downloads/tmp_episode.mkv".to_string()); assert_eq!(result, "/media/episode.mkv"); ``` -------------------------------- ### Configure Autopulse via YAML Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Example configuration file demonstrating the required structure for application settings, triggers, targets, and webhooks. ```yaml app: hostname: 0.0.0.0 port: 2875 database_url: sqlite://autopulse.db auth: username: admin password: secure-password opts: check_path: true max_retries: 5 default_timer_wait: 60 triggers: my_sonarr: type: sonarr rewrite: from: /downloads/tv to: /tvshows my_manual: type: manual targets: my_plex: type: plex url: http://plex:32400 token: xxxxx webhooks: my_discord: type: discord url: https://discord.com/api/webhooks/123456/abcdef anchors: - /mnt/media - /mnt/anchor_file ``` -------------------------------- ### Start Autopulse via Command Line Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Commands to launch the service using either the default local configuration or an explicit file path. ```bash # Use config from current directory autopulse # Use explicit config file autopulse --config /etc/autopulse/config.toml ``` -------------------------------- ### GET / Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/README.md Root endpoint for the service. This endpoint does not require authentication. ```APIDOC ## GET / ### Description Root endpoint for the service. ### Method GET ### Endpoint / ### Authentication No authentication required. ``` -------------------------------- ### Start Service Manager Event Loop Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Integrate the main event processing loop into a Tokio select block. ```rust let handle = manager.start(); tokio::select! { res = handle => { res?; } // ... other tasks } ``` -------------------------------- ### Check Attempts Timer Example Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Configures the system to verify file existence 3 times at 10-second intervals before processing. ```yaml triggers: my_sonarr: timer: check_attempts: 3 wait: 10 ``` -------------------------------- ### Configure Plex Target Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/targets.md Provides a configuration example for a Plex Media Server target, including the optional metadata refresh setting. ```yaml targets: my_plex: type: plex url: http://plex.example.com:32400 token: your-plex-token rewrite: from: /media to: /plex-mount refresh_metadata: true ``` ```yaml targets: my_plex: type: plex url: http://192.168.1.100:32400 token: abcdef1234567890 ``` -------------------------------- ### Configure Autopulse Authorization Source: https://github.com/dan-online/autopulse/blob/main/README.md Example YAML configuration for setting API credentials. ```yaml auth: username: terry password: yoghurt ``` -------------------------------- ### Authenticate with Curl Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Examples of using curl to authenticate with the API using basic auth or base64 headers. ```bash curl -u 'admin:password' http://localhost:2875/list # or curl -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' http://localhost:2875/list ``` -------------------------------- ### Configure Discord webhook Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/webhooks.md Example configuration for a Discord webhook including specific mention rules for different event types. ```yaml webhooks: my_discord: type: discord url: https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz mentions: - targets: [here] on: [failed, hash_mismatch] - targets: [everyone] on: [failed] - targets: - role: "1234567890" on: [hash_mismatch] - targets: - user: "9876543210" on: [completed] ``` -------------------------------- ### Start Webhook Delivery Loop Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Integrate the webhook delivery loop into a Tokio select block to handle batched deliveries. ```rust let handle = manager.start_webhooks(); tokio::select! { res = handle => { res?; } // ... other tasks } ``` -------------------------------- ### Get Statistics Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Retrieve system statistics, optionally piped to jq for formatted output. ```bash curl 'http://localhost:2875/stats' | jq ``` -------------------------------- ### Manage WorkerGuard lifecycle Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Examples for maintaining the WorkerGuard to ensure logs are flushed and closed correctly. ```rust let guard = setup_logs(...)?; // Guard is alive drop(guard); // Logs flushed and closed ``` ```rust let _guard = setup_logs(...)?; // _guard is dropped when function returns ``` -------------------------------- ### GET /triggers/manual Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Initiates a scan request for a specific file path using query parameters. ```APIDOC ## GET /triggers/manual ### Description Initiates a scan request for a specific file path using query parameters. ### Method GET ### Endpoint /triggers/manual ### Parameters #### Query Parameters - **path** (string) - Required - File path to process - **hash** (string) - Optional - SHA256 hash for verification ### Request Example curl -u admin:password 'http://localhost:2875/triggers/manual?path=/media/Show/S01E01.mkv&hash=abc123def456' ``` -------------------------------- ### Get Event Details Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Fetch specific event information by providing the unique event UUID. ```bash curl -u 'admin:password' \ 'http://localhost:2875/status/550e8400-e29b-41d4-a716-446655440000' ``` -------------------------------- ### Manual Trigger Configuration Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Example configuration for the manual trigger type, which allows path rewriting and target exclusion. ```yaml triggers: manual: type: manual rewrite: from: "^/downloads" to: /media timer: wait: 30 excludes: ["some_target"] ``` -------------------------------- ### GET /list Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Returns a paginated list of scan events with optional filtering and sorting. ```APIDOC ## GET /list ### Description Returns paginated list of scan events. ### Method GET ### Endpoint /list ### Parameters #### Query Parameters - **status** (string) - Optional - Filter by status: pending, complete, retry, failed - **page** (integer) - Optional - Page number (1-indexed) - **limit** (integer) - Optional - Items per page (max 100) - **sort** (string) - Optional - Sort field: id, file_path, process_status, event_source, created_at, updated_at - **search** (string) - Optional - Partial path match (case-insensitive) ### Response #### Success Response (200) - **items** (array) - List of scan events - **total** (integer) - Total count of events - **page** (integer) - Current page number - **pages** (integer) - Total number of pages - **limit** (integer) - Items per page #### Response Example { "items": [ { "id": "550e8400-e29b-41d4-a716-446655440000", "event_source": "my_sonarr", "file_path": "/tvshows/Breaking Bad/Season 1/s01e01.mkv", "process_status": "complete", "found_status": "found", "created_at": "2024-01-15T10:30:00", "updated_at": "2024-01-15T10:30:05" } ], "total": 1250, "page": 1, "pages": 63, "limit": 20 } ``` -------------------------------- ### GET /list Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/README.md Retrieves the list of current processing tasks. Requires HTTP Basic Authentication. ```APIDOC ## GET /list ### Description Retrieves the list of current processing tasks. ### Method GET ### Endpoint /list ### Authentication Requires HTTP Basic Authentication (e.g., -u 'username:password' or Authorization header). ``` -------------------------------- ### setup_logs Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Initializes the tracing logging system for the application. ```APIDOC ## setup_logs ### Description Initializes the tracing logging system. Returns a WorkerGuard if file logging is enabled, which must be kept alive for the duration of the application. ### Signature `pub fn setup_logs(level: &LogLevel, log_file: &Option, rollover: &Rotation, max_files: usize, api_logging: bool) -> anyhow::Result>` ### Parameters - **level** (LogLevel) - Required - Minimum log level to emit. - **log_file** (Option) - Required - Optional file path for file logging (None = stderr only). - **rollover** (Rotation) - Required - Log file rotation strategy. - **max_files** (usize) - Required - Number of rotated files to keep. - **api_logging** (bool) - Required - Enable HTTP request/response logging. ### Returns - **WorkerGuard** (Option) - Guard object if file logging is enabled. ### Example ```rust let _guard = setup_logs( &LogLevel::Info, &Some(PathBuf::from("/var/log/autopulse.log")), &Rotation::DAILY, 30, false, )?; ``` ``` -------------------------------- ### GET /api/config-template Source: https://github.com/dan-online/autopulse/blob/main/README.md Retrieves configuration templates dynamically based on provided database, trigger, and target types. ```APIDOC ## GET /api/config-template ### Description Returns configuration templates for external applications to generate configurations programmatically. ### Method GET ### Endpoint /api/config-template ### Parameters #### Query Parameters - **database** (string) - Optional - Database type (e.g., sqlite, postgres). - **triggers** (string) - Optional - Comma-separated trigger types (e.g., manual, sonarr, radarr). - **targets** (string) - Optional - Comma-separated target types (e.g., plex, jellyfin, emby). - **output** (string) - Optional - Output format (json, toml). ``` -------------------------------- ### GET /api/config-template Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Retrieves configuration templates based on specified database, trigger, target, and output format parameters. ```APIDOC ## GET /api/config-template ### Description Returns configuration templates for generating config files programmatically. ### Method GET ### Endpoint /api/config-template ### Parameters #### Query Parameters - **database** (string) - Required - Database type: sqlite, postgres - **triggers** (string) - Required - Comma-separated trigger types: manual, sonarr, radarr, lidarr, readarr, notify, autoscan, sportarr - **targets** (string) - Required - Comma-separated target types: plex, jellyfin, emby, command, sonarr, radarr, tdarr, fileflows, audiobookshelf, autopulse - **output** (string) - Required - Output format: json, toml ### Response #### Success Response (200) - **body** (string) - Configuration template in the requested format (JSON or TOML) ``` -------------------------------- ### Manual Trigger GET Request Format Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md The URL structure for triggering a manual scan via GET request. ```http GET /triggers/manual?path=/path/to/file&hash=sha256hash ``` -------------------------------- ### Environment Variable Overrides Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Examples of overriding configuration values using environment variables with the AUTOPULSE__ prefix. ```text AUTOPULSE__APP__HOSTNAME=127.0.0.1 AUTOPULSE__AUTH__PASSWORD__FILE=/run/secrets/autopulse_password AUTOPULSE__APP__PORT=3000 ``` -------------------------------- ### GET /triggers/{name} Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Submits a file for processing via a manual trigger using query parameters. ```APIDOC ## GET /triggers/{name} ### Description Used for manual triggers and testing. Parameters are passed as query string. ### Method GET ### Endpoint /triggers/{name} ### Parameters #### Path Parameters - **name** (string) - Required - Trigger name from configuration (e.g., `my_sonarr`, `manual`) #### Query Parameters - **path** (string) - Required - File path to process - **hash** (string) - Optional - SHA256 hash of the file (for verification) ### Response #### Success Response (201) - **id** (string) - Unique identifier for the event - **event_source** (string) - The trigger name used - **file_path** (string) - The path of the file processed - **process_status** (string) - Current status of the process - **found_status** (string) - Status of file discovery - **created_at** (string) - Timestamp of creation - **updated_at** (string) - Timestamp of last update #### Response Example { "id": "550e8400-e29b-41d4-a716-446655440000", "event_source": "manual", "file_path": "/media/tv/show.mkv", "process_status": "pending", "found_status": "not_found", "created_at": "2024-01-15T10:30:00", "updated_at": "2024-01-15T10:30:00" } ``` -------------------------------- ### Create an Event via API Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Trigger events manually using either GET query parameters or a POST request with a JSON body. ```bash # Using GET query parameters curl -u 'admin:password' \ 'http://localhost:2875/triggers/manual?path=/media/show/ep.mkv' # Using POST with JSON curl -u 'admin:password' -X POST \ 'http://localhost:2875/triggers/manual' \ -d '{"path": "/media/show/ep.mkv", "hash": "abc123..."}' ``` -------------------------------- ### Manual Trigger GET Request Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Executes a manual trigger using query parameters for file path and optional hash verification. ```bash curl -u 'admin:password' 'http://localhost:2875/triggers/manual?path=/media/tv/show.mkv&hash=abc123...' ``` -------------------------------- ### GET /status/{id} Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Retrieves details for a specific event. ```APIDOC ## GET /status/{id} ### Description Returns detailed information for a specific event by ID. Requires Basic Auth. ### Method GET ### Endpoint /status/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the event. ``` -------------------------------- ### get_timestamp() Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Gets the current UTC timestamp with naive datetime. ```APIDOC ## get_timestamp() ### Description Gets the current UTC timestamp with naive datetime (no timezone). ### Signature `pub fn get_timestamp() -> chrono::NaiveDateTime` ### Returns - **chrono::NaiveDateTime** - Current time in UTC ``` -------------------------------- ### Configure Multi-Source and Multi-Target Workflow Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/README.md Demonstrates path rewriting for multiple media sources and distribution to several media server targets. ```yaml triggers: sonarr: type: sonarr rewrite: { from: "^/downloads", to: /tvshows } radarr: type: radarr rewrite: { from: "^/downloads", to: /movies } targets: plex: type: plex url: http://plex:32400 token: TOKEN jellyfin: type: jellyfin url: http://jellyfin:8096 token: TOKEN emby: type: emby url: http://emby:8096 token: TOKEN ``` -------------------------------- ### GET /stats Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/README.md Retrieves system statistics. This endpoint does not require authentication. ```APIDOC ## GET /stats ### Description Retrieves system statistics. ### Method GET ### Endpoint /stats ### Authentication No authentication required. ``` -------------------------------- ### Configure Database Backend at Build Time Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Uses Cargo features to specify which database backends are included in the final binary. ```bash # Build with SQLite only cargo build --no-default-features --features sqlite # Build with PostgreSQL only cargo build --no-default-features --features postgres # Build with both (default) cargo build --features sqlite,postgres ``` -------------------------------- ### Configure PostgreSQL Database Backend Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Set the database URL for a PostgreSQL instance. ```bash AUTOPULSE__APP__DATABASE_URL=postgres://user:pass@localhost:5432/autopulse ``` -------------------------------- ### Get event by ID Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Retrieves a single event record by its unique identifier. ```rust let event = manager.get_event(&"550e8400-e29b-41d4-a716-446655440000".to_string())?; if let Some(ev) = event { println!("Event: {}", ev.file_path); } ``` -------------------------------- ### GET /list Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Retrieves a list of events with support for pagination, filtering, and sorting. ```APIDOC ## GET /list ### Description Retrieves a list of events. ### Method GET ### Endpoint /list ### Parameters #### Query Parameters - **limit** (integer) - Optional - Number of events to return. - **page** (integer) - Optional - Page number for pagination. - **status** (string) - Optional - Filter events by status. - **search** (string) - Optional - Search events by path. - **sort** (string) - Optional - Sort order (e.g., -created_at). ``` -------------------------------- ### Retrieve Configuration Template via cURL Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Use this command to fetch a configuration template with specified database, trigger, target, and output format parameters. Requires Basic Authentication. ```bash curl -u admin:password \ 'http://localhost:2875/api/config-template?database=sqlite&triggers=sonarr,radarr&targets=plex,jellyfin&output=json' ``` -------------------------------- ### Get UTC Timestamp Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Retrieves the current UTC time as a NaiveDateTime object. ```rust pub fn get_timestamp() -> chrono::NaiveDateTime ``` ```rust let now = get_timestamp(); println!("Current timestamp: {}", now); ``` -------------------------------- ### GET /status/{id} Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Retrieves a specific scan event by its unique identifier. ```APIDOC ## GET /status/{id} ### Description Retrieves a scan event by ID. ### Method GET ### Endpoint /status/{id} ### Parameters #### Path Parameters - **id** (string) - Required - UUID of the scan event ### Response #### Success Response (200) - **id** (string) - UUID of the scan event - **event_source** (string) - Source of the event - **event_timestamp** (string) - Timestamp of the event - **file_path** (string) - Path to the file - **file_hash** (string) - Hash of the file - **process_status** (string) - Current status of processing - **found_status** (string) - Status of the file discovery - **failed_times** (integer) - Number of failed attempts - **next_retry_at** (string/null) - Timestamp for next retry - **targets_hit** (string) - Targets processed - **found_at** (string) - Timestamp when found - **processed_at** (string) - Timestamp when processed - **created_at** (string) - Creation timestamp - **updated_at** (string) - Last update timestamp - **can_process** (string) - Earliest time processing can occur #### Response Example { "id": "550e8400-e29b-41d4-a716-446655440000", "event_source": "my_sonarr", "event_timestamp": "2024-01-15T10:30:00", "file_path": "/tvshows/Breaking Bad/Season 1/s01e01.mkv", "file_hash": "abc123def456...", "process_status": "complete", "found_status": "found", "failed_times": 0, "next_retry_at": null, "targets_hit": "my_plex", "found_at": "2024-01-15T10:30:02", "processed_at": "2024-01-15T10:30:05", "created_at": "2024-01-15T10:30:00", "updated_at": "2024-01-15T10:30:05", "can_process": "2024-01-15T10:30:00" } ``` -------------------------------- ### Get event statistics Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Retrieves summary statistics for events using the manager service. ```rust use autopulse_service::manager::Stats; let stats = manager.get_stats()?; println!( "Total: {}, Processed: {}, Failed: {}, Retrying: {}, Pending: {}", stats.total, stats.processed, stats.failed, stats.retrying, stats.pending ); ``` -------------------------------- ### Configure SQLite Database Backend Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Set the database URL for SQLite, including support for in-memory databases for testing. ```bash AUTOPULSE__APP__DATABASE_URL=sqlite://autopulse.db # Or in-memory for testing AUTOPULSE__APP__DATABASE_URL=sqlite://:memory: ``` -------------------------------- ### Configure Multi-Target Sync with Webhooks Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Demonstrates routing a single trigger to multiple media targets and configuring Discord webhooks for failure notifications. ```yaml triggers: sonarr: type: sonarr rewrite: from: "^/downloads" to: /media targets: plex: type: plex url: http://plex:32400 token: plex-token jellyfin: type: jellyfin url: http://jellyfin:8096 token: jellyfin-token emby: type: emby url: http://emby:8096 token: emby-token webhooks: discord: type: discord url: https://discord.com/api/webhooks/123456/abcdef mentions: - targets: [here] on: [failed] ``` -------------------------------- ### GET /library/sections/{section_id}/refresh Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/service-manager.md Triggers a library refresh for a specific section in Plex. ```APIDOC ## GET /library/sections/{section_id}/refresh ### Description Triggers a library refresh for a specific section in Plex. ### Method GET ### Endpoint http://plex:32400/library/sections/{section_id}/refresh ### Parameters #### Path Parameters - **section_id** (string) - Required - The ID of the library section to refresh. ``` -------------------------------- ### Settings Module Interface Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Core methods for loading and managing application settings. ```rust impl Settings { pub fn get_settings(optional_config_file: Option) -> anyhow::Result pub fn resolved_config_path(cwd: &Path) -> Option pub fn searched_paths(cwd: &Path) -> Vec pub fn normalize(&mut self) -> anyhow::Result<()> pub fn log_summary(&self) } ``` -------------------------------- ### Deploy Autopulse with Docker Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Run the service containerized with environment variables for configuration overrides and volume mounts for persistence. ```bash docker run -d \ -e AUTOPULSE__APP__DATABASE_URL=sqlite:///autopulse/autopulse.db \ -e AUTOPULSE__AUTH__USERNAME=admin \ -e AUTOPULSE__AUTH__PASSWORD=secure-password \ -v /path/to/config.yaml:/app/config.yaml \ ghcr.io/dan-online/autopulse:latest ``` -------------------------------- ### Run Database Migrations Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Execute pending migrations on an established connection. ```rust let mut conn = get_conn(&pool)?; conn.migrate()?; ``` -------------------------------- ### Performance Tuning for Low-End Hardware Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Configuration settings to reduce resource consumption on constrained hardware. ```yaml app: log_level: warn opts: max_retries: 3 cleanup_days: 3 ``` -------------------------------- ### GET /stats Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Retrieves aggregated service statistics including processing counts and database performance. ```APIDOC ## GET /stats ### Description Retrieves aggregated service statistics. ### Method GET ### Endpoint /stats ### Response #### Success Response (200) - **total** (integer) - Total events - **processed** (integer) - Total processed events - **retrying** (integer) - Events currently retrying - **failed** (integer) - Total failed events - **pending** (integer) - Total pending events - **db_response_time_ms** (integer) - Database query response time in milliseconds #### Response Example { "total": 1250, "processed": 1200, "retrying": 30, "failed": 20, "pending": 0, "db_response_time_ms": 5 } ``` -------------------------------- ### Accessing Configuration Template API Source: https://github.com/dan-online/autopulse/blob/main/README.md Retrieve configuration templates dynamically using the API. ```bash # Get basic templates $ curl -u "admin:password" "http://localhost:2875/api/config-template" # Get templates with specific types $ curl -u "admin:password" "http://localhost:2875/api/config-template?database=postgres&triggers=sonarr,radarr&targets=plex,jellyfin&output=json" ``` -------------------------------- ### Configure Radarr to Jellyfin with Path Mapping Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Sets up a Radarr trigger and a Jellyfin target, including specific path rewriting for the Jellyfin library. ```yaml triggers: radarr: type: radarr rewrite: from: "^/downloads" to: /movies targets: jellyfin: type: jellyfin url: http://jellyfin:8096 token: xxxxx rewrite: from: "^/movies" to: /jellyfin-library ``` -------------------------------- ### GET /stats Response Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Returns aggregated service statistics, including database response time. ```json { "total": 1250, "processed": 1200, "retrying": 30, "failed": 20, "pending": 0, "db_response_time_ms": 5 } ``` -------------------------------- ### Initialize Logging System Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Configures the tracing logging system with rotation strategies and log levels. The returned WorkerGuard must be kept alive for the duration of the application if file logging is enabled. ```rust pub fn setup_logs( level: &LogLevel, log_file: &Option, rollover: &Rotation, max_files: usize, api_logging: bool, ) -> anyhow::Result> pub enum LogLevel { Trace, Debug, Info, Warn, Error, } pub enum Rotation { NEVER, HOURLY, DAILY, MINUTELY, } ``` ```rust let _guard = setup_logs( &LogLevel::Info, &Some(PathBuf::from("/var/log/autopulse.log")), &Rotation::DAILY, 30, false, )?; // Guard is kept alive for the lifetime of the application ``` -------------------------------- ### Configure Timer Settings Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Defines the delay and check parameters for file processing. ```yaml timer: wait: 300 # Seconds to wait before processing max_wait: 3600 # Optional: maximum wait time check_attempts: 0 # Optional: number of checks before processing ``` -------------------------------- ### Configure PostgreSQL database connection Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/settings.md Use connection strings to specify PostgreSQL database credentials and host information. ```text postgres://username:password@localhost:5432/autopulse postgresql://username:password@localhost:5432/autopulse ``` -------------------------------- ### GET /status/{id} Response Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Returns detailed information for a specific scan event identified by its UUID. ```json { "id": "550e8400-e29b-41d4-a716-446655440000", "event_source": "my_sonarr", "event_timestamp": "2024-01-15T10:30:00", "file_path": "/tvshows/Breaking Bad/Season 1/s01e01.mkv", "file_hash": "abc123def456...", "process_status": "complete", "found_status": "found", "failed_times": 0, "next_retry_at": null, "targets_hit": "my_plex", "found_at": "2024-01-15T10:30:02", "processed_at": "2024-01-15T10:30:05", "created_at": "2024-01-15T10:30:00", "updated_at": "2024-01-15T10:30:05", "can_process": "2024-01-15T10:30:00" } ``` -------------------------------- ### Configure Notify Trigger Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/triggers.md Sets up a cross-platform file system monitor with recursive path watching, rewriting, and filtering. ```yaml triggers: my_notify: type: notify paths: - /watch/downloads - /watch/media recursive: true # default: true rewrite: from: "^/watch" to: /media timer: wait: 30 filter: exclude: - "\\.tmp$" - "\\.part$" ``` -------------------------------- ### GET /triggers/manual Source: https://github.com/dan-online/autopulse/blob/main/README.md Triggers a manual scan for a specific file path and hash. This is useful for testing or immediate processing. ```APIDOC ## GET /triggers/manual ### Description Triggers a manual scan for a specific file path and hash. ### Method GET ### Endpoint /triggers/manual ### Parameters #### Query Parameters - **path** (string) - Required - The file path to scan. - **hash** (string) - Required - The hash associated with the file. ``` -------------------------------- ### Define Auth Settings Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/types.md Authentication credentials and helper methods for credential validation. ```rust pub struct Auth { pub username: String, pub password: String, } impl Auth { pub fn is_default_credentials(&self) -> bool } ``` -------------------------------- ### Define App Settings Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/types.md Configuration for application-level settings such as networking and database connectivity. ```rust pub struct App { pub hostname: String, pub port: u16, pub database_url: String, pub log_level: LogLevel, pub api_logging: bool, pub base_path: String, pub secure_cookies: bool, pub trusted_proxies: Vec, } ``` -------------------------------- ### Configure path rewrites in YAML Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Configuration formats for defining single or multiple sequential path rewrites. ```yaml rewrite: from: "^/downloads" to: /media ``` ```yaml rewrite: - from: "^/downloads" to: /media - from: "tmp_" to: "" ``` -------------------------------- ### Run Autopulse with Docker CLI Source: https://github.com/dan-online/autopulse/blob/main/README.md Commands to initialize a Docker network and run Autopulse containers with either Postgres or SQLite database configurations. ```bash # create a network $ docker network create autopulse # postgres database $ docker run -d --net autopulse --name postgres -e POSTGRES_PASSWORD=autopulse -e POSTGRES_DB=autopulse postgres $ docker run -d --net autopulse -e AUTOPULSE__APP__DATABASE_URL=postgres://postgres:autopulse@postgresql/autopulse --name autopulse ghcr.io/dan-online/autopulse # sqlite database $ docker run -d --net autopulse -e AUTOPULSE__APP__DATABASE_URL=sqlite://database.db --name autopulse ghcr.io/dan-online/autopulse # or in-memory $ docker run -d --net autopulse -e AUTOPULSE__APP__DATABASE_URL=sqlite://:memory: --name autopulse ghcr.io/dan-online/autopulse ``` -------------------------------- ### Convert bytes to human-readable string Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Function signature and usage examples for converting byte counts into formatted size strings. ```rust pub fn sify(value: usize) -> String ``` ```rust assert_eq!(sify(1024), "1.0 KB"); assert_eq!(sify(1_000_000), "976.6 KB"); assert_eq!(sify(1_000_000_000), "953.7 MB"); ``` -------------------------------- ### Define Minimal Configuration Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md A basic YAML configuration structure defining application settings, authentication, triggers, and targets. ```yaml app: database_url: sqlite://autopulse.db port: 2875 auth: username: admin password: password triggers: manual: type: manual targets: my_plex: type: plex url: http://plex:32400 token: your-token-here ``` -------------------------------- ### Construct Full URL Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/utilities.md Combines a base URL and a path component. Returns an error if the resulting URL format is invalid. ```rust pub fn get_url(base_url: &str, path: &str) -> anyhow::Result ``` ```rust let url = get_url("http://plex:32400", "/library/sections")?; assert_eq!(url, "http://plex:32400/library/sections"); ``` -------------------------------- ### Configure Autopulse Environment Variables Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/quick-start.md Defines server, authentication, and global options via environment variables. Supports loading sensitive values from files using the __FILE suffix. ```bash # Server configuration AUTOPULSE__APP__HOSTNAME=0.0.0.0 AUTOPULSE__APP__PORT=2875 AUTOPULSE__APP__DATABASE_URL=sqlite://autopulse.db AUTOPULSE__APP__LOG_LEVEL=info # Authentication AUTOPULSE__AUTH__USERNAME=admin AUTOPULSE__AUTH__PASSWORD=password # Global options AUTOPULSE__OPTS__CHECK_PATH=false AUTOPULSE__OPTS__MAX_RETRIES=5 AUTOPULSE__OPTS__DEFAULT_TIMER_WAIT=60 AUTOPULSE__OPTS__CLEANUP_DAYS=10 # Secrets from files AUTOPULSE__AUTH__PASSWORD__FILE=/run/secrets/autopulse_password AUTOPULSE__TARGETS__MY_PLEX__TOKEN__FILE=/run/secrets/plex_token ``` -------------------------------- ### POST /login Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/INDEX.md Performs UI login. ```APIDOC ## POST /login ### Description Authenticates the user for the UI. Requires Basic Auth. ### Method POST ### Endpoint /login ``` -------------------------------- ### POST /login Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/endpoints.md Authenticates a user and establishes a session via a cookie. ```APIDOC ## POST /login ### Description Authenticates a user and creates a session. Used by the web UI to establish cookie-based sessions. ### Method POST ### Endpoint /login ### Response #### Success Response (200) - **status** (string) - Status of the login request #### Response Example { "status": "ok" } ``` -------------------------------- ### Database Module Interface Definitions Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/database.md Core definitions for database types, connection pooling, and connection methods. ```rust pub enum DatabaseType { Sqlite, Postgres, } impl DatabaseType { pub fn default_url(&self) -> String } pub fn get_pool(database_url: &str) -> anyhow::Result pub fn get_conn(pool: &DbPool) -> anyhow::Result pub fn close_pool(pool: &DbPool) pub struct AnyConnection { /* ... */ } impl AnyConnection { pub fn pre_init(database_url: &str) -> anyhow::Result<()> pub fn migrate(&mut self) -> anyhow::Result<()> pub fn upsert_pending( &mut self, event: &NewScanEvent, now: NaiveDateTime, ) -> anyhow::Result } ``` -------------------------------- ### Configure Jellyfin Target Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/targets.md Defines a Jellyfin media server target with path rewriting and metadata refresh settings. ```yaml targets: my_jellyfin: type: jellyfin url: http://jellyfin.example.com:8096 token: your-jellyfin-token rewrite: from: /media to: /jellyfin-mount metadata_refresh_mode: FullRefresh ``` -------------------------------- ### Configure generic webhook Source: https://github.com/dan-online/autopulse/blob/main/_autodocs/webhooks.md Basic structure for defining a webhook in the configuration file. ```yaml webhooks: my_webhook: type: # Webhook type (required) url: # Webhook URL (required) # ... type-specific fields ```