From f0fa670ac59e314f89d78fc497cec334f37eefcf Mon Sep 17 00:00:00 2001 From: Charles N Wyble Date: Mon, 21 Apr 2025 16:23:34 -0400 Subject: [PATCH] first cut of librenms package --- .../CloudronManifest.json | 52 ++++++ Techops/netmon.knownelement.com/Dockerfile | 77 +++++++++ .../LibrenmsBuildNotes.md | 158 ++++++++++++++++++ Techops/netmon.knownelement.com/config.php | 88 ++++++++++ .../docker-compose.yml | 1 - .../netmon.knownelement.com/input-files/info | 1 - Techops/netmon.knownelement.com/nginx.conf | 39 +++++ .../netmon.knownelement.com/output-files/info | 1 - Techops/netmon.knownelement.com/start.sh | 126 ++++++++++++++ .../netmon.knownelement.com/supervisord.conf | 41 +++++ .../netmon.knownelement.com/vendor-files/info | 1 - 11 files changed, 581 insertions(+), 4 deletions(-) create mode 100644 Techops/netmon.knownelement.com/CloudronManifest.json create mode 100644 Techops/netmon.knownelement.com/Dockerfile create mode 100644 Techops/netmon.knownelement.com/LibrenmsBuildNotes.md create mode 100644 Techops/netmon.knownelement.com/config.php delete mode 100644 Techops/netmon.knownelement.com/docker-compose.yml delete mode 100644 Techops/netmon.knownelement.com/input-files/info create mode 100644 Techops/netmon.knownelement.com/nginx.conf delete mode 100644 Techops/netmon.knownelement.com/output-files/info create mode 100644 Techops/netmon.knownelement.com/start.sh create mode 100644 Techops/netmon.knownelement.com/supervisord.conf delete mode 100644 Techops/netmon.knownelement.com/vendor-files/info diff --git a/Techops/netmon.knownelement.com/CloudronManifest.json b/Techops/netmon.knownelement.com/CloudronManifest.json new file mode 100644 index 0000000..89deee4 --- /dev/null +++ b/Techops/netmon.knownelement.com/CloudronManifest.json @@ -0,0 +1,52 @@ +{ + "id": "org.librenms.cloudronapp", + "title": "LibreNMS", + "author": "LibreNMS Team", + "description": "LibreNMS is a fully featured network monitoring system that provides a wealth of features and device support.", + "version": "24.4.0", + "tagline": "Open Source Network Monitoring", + "healthCheckPath": "/login", + "httpPort": 8000, + "addons": { + "localstorage": {}, + "mysql": { + "memoryLimit": 134217728 + }, + "redis": {} + }, + "manifestVersion": 2, + "website": "https://www.librenms.org/", + "documentation": "https://docs.librenms.org/", + "icon": "file://logo.png", + "memoryLimit": 734003200, + "minBoxVersion": "7.0.0", + "tags": [ + "monitoring", + "network", + "snmp", + "graphs", + "alerts" + ], + "postInstallMessage": "LibreNMS has been installed successfully!\n\nDefault login:\nUsername: admin\nPassword: admin\n\nPlease change your password after the first login.", + "forceSSL": true, + "installationProgress": true, + "tcpPorts": { + "SNMP": { + "port": 161, + "description": "SNMP port for device monitoring" + } + }, + "optionalSso": true, + "sso": [ + { + "name": "oidc", + "configurePath": "/auth/oidc/login", + "logoutPath": "/logout" + }, + { + "name": "ldap", + "configurePath": "/auth/ldap/login", + "logoutPath": "/logout" + } + ] +} \ No newline at end of file diff --git a/Techops/netmon.knownelement.com/Dockerfile b/Techops/netmon.knownelement.com/Dockerfile new file mode 100644 index 0000000..0240424 --- /dev/null +++ b/Techops/netmon.knownelement.com/Dockerfile @@ -0,0 +1,77 @@ +FROM cloudron/base:4.2.0 + +# Install required packages +RUN apt-get update && apt-get install -y \ + acl \ + composer \ + fping \ + git \ + graphviz \ + imagemagick \ + mariadb-client \ + mtr-tiny \ + nginx \ + nmap \ + php8.2-cli \ + php8.2-curl \ + php8.2-fpm \ + php8.2-gd \ + php8.2-gmp \ + php8.2-mbstring \ + php8.2-mysql \ + php8.2-snmp \ + php8.2-xml \ + php8.2-zip \ + python3 \ + python3-pip \ + python3-pymysql \ + python3-redis \ + python3-dotenv \ + python3-systemd \ + rrdtool \ + snmp \ + snmp-mibs-downloader \ + unzip \ + whois \ + supervisor \ + && rm -rf /var/lib/apt/lists/* + +# Download MIBs +RUN download-mibs + +# Clone LibreNMS repository +WORKDIR /app/code +RUN git clone --depth 1 https://github.com/librenms/librenms.git . + +# Install PHP dependencies +RUN composer install --no-dev --no-interaction + +# Install Python dependencies +RUN pip3 install -r requirements.txt + +# Create initial data directory structure +RUN mkdir -p /tmp/data/rrd \ + /tmp/data/logs \ + /tmp/data/config \ + /tmp/data/plugins \ + /app/data/rrd \ + /app/data/logs \ + /app/data/config \ + /app/data/plugins + +# Copy configuration files +COPY nginx.conf /etc/nginx/sites-available/librenms +RUN ln -sf /etc/nginx/sites-available/librenms /etc/nginx/sites-enabled/default +COPY supervisord.conf /etc/supervisor/conf.d/librenms.conf +COPY start.sh /app/code/ +COPY config.php /tmp/data/config/ + +# Set permissions +RUN chmod +x /app/code/start.sh \ + && chown -R cloudron:cloudron /app/code \ + && chown -R cloudron:cloudron /tmp/data \ + && chown -R cloudron:cloudron /app/data + +WORKDIR /app/code + +CMD ["/app/code/start.sh"] \ No newline at end of file diff --git a/Techops/netmon.knownelement.com/LibrenmsBuildNotes.md b/Techops/netmon.knownelement.com/LibrenmsBuildNotes.md new file mode 100644 index 0000000..de77a83 --- /dev/null +++ b/Techops/netmon.knownelement.com/LibrenmsBuildNotes.md @@ -0,0 +1,158 @@ +# LibreNMS for Cloudron - Build Notes + +This document provides instructions for building, testing, and deploying the LibreNMS package to your Cloudron instance. + +## Package Contents + +The LibreNMS Cloudron package includes: + +- **CloudronManifest.json**: The main configuration file for the Cloudron application +- **Dockerfile**: Sets up the container with all required dependencies +- **start.sh**: The entry point script that initializes and configures LibreNMS +- **nginx.conf**: Web server configuration for LibreNMS +- **supervisord.conf**: Process management for multiple services +- **config.php**: Default LibreNMS configuration + +## Building the Package + +1. Create a new directory for the package: + ```bash + mkdir librenms-cloudron + cd librenms-cloudron + ``` + +2. Copy all files into this directory: + - CloudronManifest.json + - Dockerfile + - start.sh + - nginx.conf + - supervisord.conf + - config.php + +3. Download the LibreNMS logo: + ```bash + curl -o logo.png https://raw.githubusercontent.com/librenms/librenms/master/html/images/librenms_logo_light.svg + ``` + +4. Ensure proper file permissions: + ```bash + chmod +x start.sh + ``` + +5. Build the Cloudron package: + ```bash + cloudron build + ``` + +## Testing the Package + +1. Install the app on your Cloudron for testing: + ```bash + cloudron install —app librenms + ``` + +2. Access the LibreNMS web interface at the URL provided by Cloudron. + +3. Log in with the default credentials: + - Username: `admin` + - Password: `admin` + +4. Verify functionality by: + - Adding a test device + - Checking discovery and polling + - Configuring alerts + - Testing authentication (especially if using Cloudron SSO) + +## Deploying to Production + +1. Update the CloudronManifest.json with appropriate values: + - Update `version` if needed + - Adjust `memoryLimit` based on your production needs + - Update `contactEmail` with your support email + +2. Rebuild the package: + ```bash + cloudron build + ``` + +3. Install on your production Cloudron: + ```bash + cloudron install —app librenms + ``` + +## Authentication Configuration + +### OIDC Authentication (Recommended) + +The package automatically configures OIDC authentication when Cloudron SSO is enabled. This provides: + +- Single sign-on with your Cloudron users +- Automatic user provisioning +- Group-based access control + +### LDAP Authentication + +If OIDC is not enabled, the package can use Cloudron’s LDAP server. This is configured automatically by the start.sh script. + +### Manual Authentication + +If neither OIDC nor LDAP is used, the package defaults to MySQL authentication with a local admin user. + +## Data Persistence + +The following data is stored in persistent volumes: + +- **/app/data/rrd**: RRD files for graphing +- **/app/data/logs**: LibreNMS logs +- **/app/data/config**: Configuration files +- **/app/data/plugins**: Custom plugins + +## Troubleshooting + +If you encounter issues: + +1. Check the logs: + ```bash + cloudron logs -f librenms + ``` + +2. Verify database connection: + ```bash + cloudron exec —app librenms — mysql -h “$CLOUDRON_MYSQL_HOST” -P “$CLOUDRON_MYSQL_PORT” -u “$CLOUDRON_MYSQL_USERNAME” -p”$CLOUDRON_MYSQL_PASSWORD” -e “SHOW TABLES” “$CLOUDRON_MYSQL_DATABASE” + ``` + +3. Check file permissions: + ```bash + cloudron exec —app librenms — ls -la /app/data + ``` + +4. Restart the application: + ```bash + cloudron restart —app librenms + ``` + +## Upgrading + +To upgrade LibreNMS: + +1. Update the git clone command in the Dockerfile to use the latest version tag +2. Update the version in CloudronManifest.json +3. Rebuild and upgrade the package: + ```bash + cloudron build + cloudron update —app librenms + ``` + +## Security Considerations + +- The default admin password should be changed immediately after installation +- Consider using Cloudron SSO to leverage your existing authentication system +- SNMP port 161 is exposed for device monitoring - ensure proper network security + +## Resource Usage + +LibreNMS resource requirements depend on the number of monitored devices: + +- For <100 devices: Default memory limit (734MB) should be sufficient +- For 100-500 devices: Consider increasing memory limit to 1GB or more +- For >500 devices: Consider distributed polling with multiple instances \ No newline at end of file diff --git a/Techops/netmon.knownelement.com/config.php b/Techops/netmon.knownelement.com/config.php new file mode 100644 index 0000000..8c17356 --- /dev/null +++ b/Techops/netmon.knownelement.com/config.php @@ -0,0 +1,88 @@ + 'mysql'|'auth_mechanism' => 'socialite'|g" /app/data/config/config.php + + # Add OIDC configuration + cat >> /app/data/config/config.php << EOF +\$config['auth_socialite_oidc']['enabled'] = true; +\$config['auth_socialite_oidc']['client_id'] = '${CLOUDRON_OIDC_CLIENT_ID}'; +\$config['auth_socialite_oidc']['client_secret'] = '${CLOUDRON_OIDC_CLIENT_SECRET}'; +\$config['auth_socialite_oidc']['authorize_url'] = '${CLOUDRON_OIDC_ISSUER}/auth'; +\$config['auth_socialite_oidc']['token_url'] = '${CLOUDRON_OIDC_ISSUER}/token'; +\$config['auth_socialite_oidc']['userinfo_url'] = '${CLOUDRON_OIDC_ISSUER}/userinfo'; +\$config['auth_socialite_oidc']['scope'] = 'openid email profile groups'; +\$config['auth_socialite_oidc']['redirect'] = 'https://${CLOUDRON_APP_DOMAIN}/auth/oidc/callback'; +EOF +fi + +# Set up LDAP authentication if enabled and OIDC is not enabled +if [[ -z "${CLOUDRON_OIDC_IDENTIFIER:-}" && -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then + echo "Configuring LDAP authentication..." + sed -i "s|'auth_mechanism' => 'mysql'|'auth_mechanism' => 'ldap'|g" /app/data/config/config.php + + # Add LDAP configuration + cat >> /app/data/config/config.php << EOF +\$config['auth_ldap_server'] = '${CLOUDRON_LDAP_SERVER}'; +\$config['auth_ldap_port'] = ${CLOUDRON_LDAP_PORT}; +\$config['auth_ldap_version'] = 3; +\$config['auth_ldap_starttls'] = true; +\$config['auth_ldap_prefix'] = '${CLOUDRON_LDAP_BIND_DN%%,*}'; +\$config['auth_ldap_suffix'] = ',${CLOUDRON_LDAP_BIND_DN#*,}'; +\$config['auth_ldap_group'] = '${CLOUDRON_LDAP_USERS_GROUP_DN}'; +\$config['auth_ldap_groupbase'] = '${CLOUDRON_LDAP_GROUPS_BASE_DN}'; +\$config['auth_ldap_groups']['admin']['level'] = 10; +\$config['auth_ldap_groups']['admin']['group'] = '${CLOUDRON_LDAP_ADMINS_GROUP_DN}'; +EOF +fi + +# Fix permissions +chown -R cloudron:cloudron /app/data + +# Initialize database if needed +echo "Checking database..." +if ! mysql -h "${CLOUDRON_MYSQL_HOST}" -P "${CLOUDRON_MYSQL_PORT}" -u "${CLOUDRON_MYSQL_USERNAME}" -p"${CLOUDRON_MYSQL_PASSWORD}" -e "USE ${CLOUDRON_MYSQL_DATABASE}" 2>/dev/null; then + echo "Setting up database schema..." + cd /app/code + php build-base.php +fi + +# Apply database updates if needed +cd /app/code +php includes/sql-schema/update.php + +# Create admin user on first run if authentication is MySQL +if [[ ! -n "${CLOUDRON_OIDC_IDENTIFIER:-}" && ! -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then + if ! mysql -h "${CLOUDRON_MYSQL_HOST}" -P "${CLOUDRON_MYSQL_PORT}" -u "${CLOUDRON_MYSQL_USERNAME}" -p"${CLOUDRON_MYSQL_PASSWORD}" -e "SELECT username FROM users WHERE username='admin'" ${CLOUDRON_MYSQL_DATABASE} 2>/dev/null | grep -q admin; then + echo "Creating admin user..." + php adduser.php admin admin 10 admin@localhost + fi +fi + +# Link config file +ln -sf /app/data/config/config.php /app/code/config.php + +# Setup cron jobs +echo "Setting up cron jobs..." +cat > /etc/cron.d/librenms << EOF +# Run a complete discovery of all devices once every 6 hours +33 */6 * * * cloudron cd /app/code/ && php discovery.php -h all >> /app/data/logs/discovery-all.log 2>&1 +# Run a complete poll of all devices once every 5 minutes +*/5 * * * * cloudron cd /app/code/ && php poller.php -h all >> /app/data/logs/poll-all.log 2>&1 +# Run hourly maintenance tasks +15 * * * * cloudron cd /app/code/ && php daily.php >> /app/data/logs/daily.log 2>&1 +# Run daily maintenance tasks +15 0 * * * cloudron cd /app/code/ && php daily.sh >> /app/data/logs/daily.log 2>&1 +# Check services +*/5 * * * * cloudron cd /app/code/ && php check-services.php >> /app/data/logs/check-services.log 2>&1 +# Process alerts +*/5 * * * * cloudron cd /app/code/ && php alerts.php >> /app/data/logs/alerts.log 2>&1 +# Poll billing +*/5 * * * * cloudron cd /app/code/ && php poll-billing.php >> /app/data/logs/poll-billing.log 2>&1 +# Generate billing data +01 * * * * cloudron cd /app/code/ && php billing-calculate.php >> /app/data/logs/billing-calculate.log 2>&1 +# Update device groups +*/5 * * * * cloudron cd /app/code/ && php update-device-groups.php >> /app/data/logs/update-device-groups.log 2>&1 +EOF + +# Start supervisord to manage all processes +echo "Starting supervisord..." +exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/Techops/netmon.knownelement.com/supervisord.conf b/Techops/netmon.knownelement.com/supervisord.conf new file mode 100644 index 0000000..444ec18 --- /dev/null +++ b/Techops/netmon.knownelement.com/supervisord.conf @@ -0,0 +1,41 @@ +[program:nginx] +command=nginx -g "daemon off;" +autostart=true +autorestart=true +priority=10 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:php-fpm] +command=/usr/sbin/php-fpm8.2 --nodaemonize +autostart=true +autorestart=true +priority=5 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:cron] +command=cron -f +autostart=true +autorestart=true +priority=15 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:dispatcher-service] +command=/usr/bin/python3 /app/code/dispatcher.py +directory=/app/code +user=cloudron +autostart=true +autorestart=true +priority=20 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 \ No newline at end of file diff --git a/Techops/netmon.knownelement.com/vendor-files/info b/Techops/netmon.knownelement.com/vendor-files/info deleted file mode 100644 index 110d921..0000000 --- a/Techops/netmon.knownelement.com/vendor-files/info +++ /dev/null @@ -1 +0,0 @@ -This directory contains files from the vendor unmodified. They serve as a base for the input-files sibling directory