# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: LibreNMS
spec:
    description: A fully featured network monitoring system that provides a wealth of features and device support.
    coverImage: https://www.librenms.org/img/librenms.png
    icon: https://www.librenms.org/favicon.ico
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: LibreNMS Domain
          description: The domain for accessing your LibreNMS application.
        - key: SMTP_HOST
          type: STRING
          name: SMTP Host
          description: SMTP server hostname for email notifications (optional).
        - key: SMTP_USER
          type: STRING
          name: SMTP Username
          description: SMTP username for email authentication (optional).
        - key: SMTP_PASSWORD
          type: STRING
          name: SMTP Password
          description: SMTP password for email authentication (optional).
        - key: SMTP_FROM
          type: STRING
          name: SMTP From Address
          description: From email address for notifications (optional).
    tags:
        - Network Monitoring
        - SNMP
        - Infrastructure
        - Monitoring
        - PHP
    readme: |-
        # LibreNMS

        A fully featured network monitoring system that provides a wealth of features and device support.

        LibreNMS is an autodiscovering PHP/MySQL-based network monitoring system which includes support for a wide range of network hardware and operating systems including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP and many more.

        ## Features

        - **Auto-discovery**: Automatically discover network devices and their interfaces
        - **Device Support**: Support for thousands of device types from major vendors
        - **SNMP Monitoring**: Comprehensive SNMP v1/v2c/v3 support
        - **Alerting**: Flexible alerting system with multiple notification methods
        - **Graphing**: Beautiful graphs and charts for network metrics
        - **API**: RESTful API for integration with other systems
        - **Multi-user**: Role-based access control for team environments
        - **Mobile Ready**: Responsive web interface works on all devices
        - **Plugin System**: Extensible with applications and plugins

        ## Architecture

        This template deploys a complete LibreNMS stack including:

        - **LibreNMS Web Interface**: Main application server
        - **Dispatcher**: Background job processing service
        - **Syslog**: System log collection service (port 514)
        - **SNMP Trap**: SNMP trap receiver service (port 162)
        - **MariaDB**: Database backend
        - **Redis**: Cache and session storage
        - **MSMTP**: Email delivery service

        ## Environment Variables

        After deployment, the following environment variables are available:

        - `MARIADB_HOST`: The hostname of your MariaDB database
        - `MARIADB_PORT`: The port of your MariaDB database
        - `MARIADB_DATABASE`: The database name for LibreNMS
        - `MARIADB_USERNAME`: The username for database access
        - `MARIADB_PASSWORD`: The password for database access
        - `REDIS_HOST`: The hostname of your Redis instance
        - `REDIS_PORT`: The port of your Redis instance

        ## Getting Started

        1. **Initial Access**: After deployment, visit your LibreNMS domain to complete setup
        2. **Admin Account**: Create your first administrator account during initial setup
        3. **Network Discovery**: Configure network ranges for auto-discovery
        4. **Device Addition**: Start adding devices manually or via auto-discovery
        5. **Configure Alerting**: Set up alert rules and notification methods
        6. **Customize Dashboards**: Create custom dashboards and views

        ## Configuration

        - **SNMP Community**: Default community string is `librenmsdocker`
        - **Performance**: Optimized with Redis caching and background processing
        - **Security**: Runs with appropriate user permissions and network capabilities
        - **Monitoring Ports**: Syslog (514) and SNMP Trap (162) services available

        ## Email Configuration

        Email notifications can be configured using the provided SMTP variables:
        - Configure SMTP_HOST, SMTP_USER, SMTP_PASSWORD for your email provider
        - Set SMTP_FROM to your desired sender address
        - Email settings can also be configured through the web interface

        ## Documentation

        For detailed configuration and usage information, visit the [official LibreNMS documentation](https://docs.librenms.org/).
    services:
        - name: mariadb
          icon: https://cdn.zeabur.com/mariadb.svg
          template: PREBUILT
          spec:
            id: mariadb
            source:
                image: mariadb:10
            ports:
                - id: database
                  port: 3306
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/mysql
            instructions:
                - title: Command to connect to your MariaDB
                  content: mariadb --host ${PORT_FORWARDED_HOSTNAME} --port=${DATABASE_PORT_FORWARDED_PORT} --user=${MARIADB_USERNAME} --password=${MARIADB_PASSWORD} --database=${MARIADB_DATABASE}
                - title: MariaDB username
                  content: ${MARIADB_USERNAME}
                - title: MariaDB password
                  content: ${MARIADB_PASSWORD}
                - title: MariaDB database
                  content: ${MARIADB_DATABASE}
                - title: MariaDB host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: MariaDB port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                MARIADB_DATABASE:
                    default: librenms
                    expose: true
                MARIADB_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                MARIADB_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                MARIADB_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                MARIADB_ROOT_PASSWORD:
                    default: ${PASSWORD}
                MARIADB_USERNAME:
                    default: root
                    expose: true
            configs:
                - path: /etc/mysql/conf.d/99-librenms.cnf
                  template: |
                    [mysqld]
                    innodb_file_per_table=1
                    lower_case_table_names=0
                    character-set-server=utf8mb4
                    collation-server=utf8mb4_unicode_ci
                  permission: null
                  envsubst: null
            healthCheck:
                type: TCP
                port: database
        - name: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            id: redis
            source:
                image: redis:7.2-alpine
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: librenms-data
                  dir: /data
            instructions:
                - title: Command to connect to your Redis
                  content: redis-cli -h ${PORT_FORWARDED_HOSTNAME} -p ${DATABASE_PORT_FORWARDED_PORT}
                - title: Redis host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: Redis port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                LIBRENMS_REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                TZ:
                    default: UTC
        - name: msmtpd
          icon: https://www.debian.org/logos/openlogo-nd.svg
          template: PREBUILT
          spec:
            id: msmtpd
            source:
                image: crazymax/msmtpd:latest
            env:
                SMTP_AUTH:
                    default: "on"
                SMTP_FROM:
                    default: ${SMTP_FROM}
                SMTP_HOST:
                    default: ${SMTP_HOST}
                SMTP_PASSWORD:
                    default: ${SMTP_PASSWORD}
                SMTP_PORT:
                    default: "587"
                SMTP_STARTTLS:
                    default: "on"
                SMTP_TLS:
                    default: "on"
                SMTP_TLS_CHECKCERT:
                    default: "on"
                SMTP_USER:
                    default: ${SMTP_USER}
        - name: librenms
          icon: https://www.librenms.org/favicon.ico
          template: PREBUILT
          spec:
            id: librenms
            source:
                image: librenms/librenms:latest
            ports:
                - id: web
                  port: 8000
                  type: HTTP
            volumes:
                - id: librenms-data
                  dir: /data
            instructions:
                - title: LibreNMS Admin URL
                  content: https://${ZEABUR_WEB_DOMAIN}
                - title: Default SNMP Community
                  content: librenmsdocker
                - title: Database Connection
                  content: mysql://${MARIADB_USERNAME}:${MARIADB_PASSWORD}@${MARIADB_HOST}:${MARIADB_PORT}/${MARIADB_DATABASE}
            env:
                CACHE_DRIVER:
                    default: redis
                DB_HOST:
                    default: ${MARIADB_HOST}
                DB_NAME:
                    default: ${MARIADB_DATABASE}
                DB_PASSWORD:
                    default: ${MARIADB_PASSWORD}
                DB_TIMEOUT:
                    default: "60"
                DB_USER:
                    default: ${MARIADB_USERNAME}
                LIBRENMS_SNMP_COMMUNITY:
                    default: librenmsdocker
                LIBRENMS_WEATHERMAP:
                    default: "false"
                LIBRENMS_WEATHERMAP_SCHEDULE:
                    default: '*/5 * * * *'
                LOG_IP_VAR:
                    default: remote_addr
                MAX_INPUT_VARS:
                    default: "1000"
                MEMORY_LIMIT:
                    default: 256M
                OPCACHE_MEM_SIZE:
                    default: "128"
                PGID:
                    default: "1000"
                PUID:
                    default: "1000"
                REAL_IP_FROM:
                    default: 0.0.0.0/32
                REAL_IP_HEADER:
                    default: X-Forwarded-For
                REDIS_HOST:
                    default: ${LIBRENMS_REDIS_HOST}
                SESSION_DRIVER:
                    default: redis
                TZ:
                    default: UTC
                UPLOAD_MAX_SIZE:
                    default: 16M
            healthCheck:
                type: HTTP
                port: web
                http:
                    path: /
          domainKey: PUBLIC_DOMAIN
        - name: dispatcher
          icon: https://www.librenms.org/favicon.ico
          template: PREBUILT
          spec:
            id: dispatcher
            source:
                image: librenms/librenms:latest
                command:
                    - sh
                    - -c
                    - sleep 60 && /init
            volumes:
                - id: librenms-data
                  dir: /data
            env:
                DB_HOST:
                    default: ${MARIADB_HOST}
                DB_NAME:
                    default: ${MARIADB_DATABASE}
                DB_PASSWORD:
                    default: ${MARIADB_PASSWORD}
                DB_TIMEOUT:
                    default: "60"
                DB_USER:
                    default: ${MARIADB_USERNAME}
                DISPATCHER_NODE_ID:
                    default: dispatcher1
                PGID:
                    default: "1000"
                PUID:
                    default: "1000"
                REDIS_HOST:
                    default: ${LIBRENMS_REDIS_HOST}
                SIDECAR_DISPATCHER:
                    default: "1"
                TZ:
                    default: UTC
        - name: syslogng
          icon: https://www.librenms.org/favicon.ico
          template: PREBUILT
          spec:
            id: syslogng
            source:
                image: librenms/librenms:latest
                command:
                    - sh
                    - -c
                    - sleep 90 && /init
            ports:
                - id: syslogtcp
                  port: 514
                  type: TCP
                - id: syslogudp
                  port: 514
                  type: UDP
            volumes:
                - id: librenms-data
                  dir: /data
            env:
                DB_HOST:
                    default: ${MARIADB_HOST}
                DB_NAME:
                    default: ${MARIADB_DATABASE}
                DB_PASSWORD:
                    default: ${MARIADB_PASSWORD}
                DB_TIMEOUT:
                    default: "60"
                DB_USER:
                    default: ${MARIADB_USERNAME}
                PGID:
                    default: "1000"
                PUID:
                    default: "1000"
                REDIS_HOST:
                    default: ${LIBRENMS_REDIS_HOST}
                SIDECAR_SYSLOGNG:
                    default: "1"
                TZ:
                    default: UTC
        - name: snmptrapd
          icon: https://www.librenms.org/favicon.ico
          template: PREBUILT
          spec:
            id: snmptrapd
            source:
                image: librenms/librenms:latest
                command:
                    - sh
                    - -c
                    - sleep 120 && /init
            ports:
                - id: snmptraptcp
                  port: 162
                  type: TCP
                - id: snmptrapudp
                  port: 162
                  type: UDP
            volumes:
                - id: librenms-data
                  dir: /data
            env:
                DB_HOST:
                    default: ${MARIADB_HOST}
                DB_NAME:
                    default: ${MARIADB_DATABASE}
                DB_PASSWORD:
                    default: ${MARIADB_PASSWORD}
                DB_TIMEOUT:
                    default: "60"
                DB_USER:
                    default: ${MARIADB_USERNAME}
                PGID:
                    default: "1000"
                PUID:
                    default: "1000"
                REDIS_HOST:
                    default: ${LIBRENMS_REDIS_HOST}
                SIDECAR_SNMPTRAPD:
                    default: "1"
                TZ:
                    default: UTC
