Synology SNMP Monitoring with LibreNMS
Tutorial for installing LibreNMS on Synology NAS via Docker to monitor SNMP enabled network devices
Update
Apr 20, 2021
- Added single quotes ‘ ‘ on example code to help escape generated passwords that might contain “!” or other special characters which will break a docker run command
- Tutorial revisited again due to Theme change
- Archived myLibreNMS app from page 2 into page 3
- Added a more inform-ed SMB/Enterprise deployment on page 3
Jul 23, 2020
Tutorial fully working again 🙂
Credits to Jari Schäfer jarischaefer for pointing me in the right direction. Details @ https://github.com/jarischaefer/docker-librenms/issues/118
- Changelog
- Choosing a different hostname alias other than “db” when linking MariaDB container to LibreNMS container
- SQL database options as per official LibrerNMS documentation
- Synology DSM 6.2.3-25426
- Version 1.65.1 – Sat Jul 11 2020 03:56:16 GMT+0800
Database Schema 2020_06_23_00522_alter_availability_perc_column (170)
Web Server nginx/1.15.8
PHP 7.4.7
Python 3.6.9
MySQL 10.4.12-MariaDB-1:10.4.12+maria~bionic
Laravel 6.18.20
RRDtool 1.7.0
- Version 1.65.1 – Sat Jul 11 2020 03:56:16 GMT+0800
- Ubuntu 18.04.4 LTS (VM)
- Version 1.65.1 – Sat Jul 11 2020 03:56:16 GMT+0800
Database Schema 2020_06_23_00522_alter_availability_perc_column (170)
Web Server nginx/1.15.8
PHP 7.4.7
Python 3.6.9
MySQL 10.5.4-MariaDB-1:10.5.4+maria~focal
Laravel 6.18.20
RRDtool 1.7.0
- Version 1.65.1 – Sat Jul 11 2020 03:56:16 GMT+0800
Step by Step
It can be time-consuming to google the web & forums for a straight-forward answer, especially IT related, where the replies you get either expect you to understand the acronyms/terms and just point you in a “vague” direction
As with all tutorials, I can’t possibly cover all aspects, but one thing for sure, you will learn to “learn”, if possible in layman easy to understand terms and finally give you a stable and working setup/environment example in the end
Some disclaimer: I am not a network/tech specialist. Tutorials written on my website all came from my personal experience, so it will suit the enthusiasts that want to learn more about networking without browsing multiple forums and to learn from practical
Requirements
The whole idea started when I bought the Synology 916+, so I will base the setup on installing in Syno NASes.
- Main Requirement & Setup (This tutorial)
- Synology NAS model able to run the following:
- Package: Docker
- DSM SSH access
- Optional: Other SNMP enabled devices like Routers, Managed Switches, Workstations to list a few
- Synology NAS model able to run the following:
- My Devices
- Synology DS916+
- DSM 6.2.2-24922 Update 2 (as of first writing)
- OSX – MacBook Pro
- Synology DS916+
- What you will touch on
- DSM SSH access
- Terminal/Putty
- Docker
Who is this tutorial for
- Beginners & Enthusiasts
- Next to no experience in Linux but willing to be adventurous
- SMB Owners, Managers, Entrepreneurs who want to understand or DIY deploy their own NMS monitoring for company devices
- Home lab owners
- Linux veterans; why are you here?! 😉
Summary Sections
- This Page – Main Setup
- Install Docker, Enable SSH & SNMP
- SSH into Syno NAS
- MariaDB Setup
- LibreNMS Setup
- Configure LibreNMS
- Add your Synology & Other Devices
- Page 2 – Optional(s) and Troubleshooting
- Optional(s)
- custom.config.php
- Alerts
- Use SVG graphs
- myLibreNMS app via LibreNMS API
- Troubleshooting
- Synology & Docker Network 101
- Updating Containers
- Optional(s)
- Page 3
- Afterword
- Archive
Install Docker, Enable SSH & SNMP
Install Docker
Install the Docker app from DSM Package Center >> Search for “Docker”
This should be pretty straightforward
Enable SSH
Well, if you don’t know how to SSH into your DSM. Let’s begin by enabling SSH option in your Synology
Control Panel (Advanced Mode) >> Terminal & SNMP >>
Check Enable SSH service
port: 22 (default 22, change if you wish accordingly)
Enable SNMP
Click on the SNMP tab
Check Enable SNMP service
Check SNMPv1, SNMPv2c service
Community: enter-something-here
Enter in the Community field a rather difficult but not too complex phrase, which the NMS will ask you for later. The default is “public” on most SNMP devices, and is highly recommended to change it to something unique.
Do not use your frequently used password as it will be seen on the DSM SNMP settings page.
SNMP Device Information
Device Name: fill-in accordingly, usually NAS hostname
Device Location: optional* fill-in accordingly, a vague location will do
Contact: Email optional* useful for sending alerts from NMS, can also be changed in LibreNMS later
SSH into Syno NAS
Skip to next section if you already know this 😉
For Windows Users ; please Google on how to SSH into your NAS (putty )
OSX Users
Open “Terminal” from your Mac and type in the following commands:
ssh [email protected]
If this is your first time, you should see a warning and be asking whether you would like to add the fingerprint, choose Yes by entering ‘yes’
Enter your password and you should be greeted with the following output
Proceed to gain root access by typing
sudo -i
Enter password again and you will have root access. Now… let the fun begin!
Save your commands!!
At this point of time, it is highly recommended to save any/all docker run commands for the following reasons:
- Test run of docker run commands
- Readability, ease of editing and substitute your values
- Docker container/image update **IMPORTANT**
- Docker by itself doesn’t update the image as it’s built that way. You can google and find many answers on this.
- Go to Page 2 for Upgrading steps
Testing Purposes
Beginners
Beginners following this tutorial should just copy/paste the commands that I’ve posted on this page as is to minimise any errors/conflict due to existing configurations, typos or if you are not very fluent in Linux
Get it to work in a testing environment first, then recreate the changes accordingly like passwords, mounts and your own customizations to secure your install further before using it for production (long-term, real-use)
Veterans / Homelabbers
I am currently using a distributed poller whereby my DigitalOcean droplet hosts the main LibreNMS poller and connected via OpenVPN to the local subnet pollers that I am currently monitoring
If you want to take it further by using a reverse proxy like nginx or traefik, this tutorial does not cover that. I don’t intend to put LibreNMS behind a reverse proxy, as it complicates security with public-facing subdomain and configuration. Although recently I started experimenting with nginx… … for now I’m KISSing it 🙂
MariaDB Setup
Prepare MariaDB Docker folders
By default, Synology docker should create a new shared folder for your docker container data. The default should be at /volume1/docker
Navigate to your docker folder
cd /volume1/docker
Next, create MariaDB folder
mkdir mariadb
Install MariaDB container
docker run \ -v /volume1/docker/mariadb:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD='root_password' \ -e TZ=Asia/Singapore \ --name mariadb \ -d \ --restart always \ mariadb:latest \ --innodb_file_per_table=1 \ --lower_case_table_names=0
** Outputs on my screenshots will be different from what was posted as I already have a running LibreNMS container on my Syno NAS
Note: I am using mariadb-test and librenms-test, with port 8669 instead of 8668 for this tutorial **
Details/Explanation
-v /volume1/docker/mariadb:/var/lib/mysql
Save persistent MariaDB database data onto our newly created mariadb folder under /volume1/docker
-e MYSQL_ROOT_PASSWORD='root_password'
Replace SQL root_password with a generated password as we won’t be using this often
-e TZ=Asia/Singapore
Replace timezone settings with your preferred timezone (TZ Timezone List )
--name mariadb
We name the container as “mariadb”. Without this, Docker will randomly pick a name for your container
-d
Run the container in daemon/background
--restart always
Always restart the container. This docker container will restart itself if you were to reboot your Synology NAS. More options @ Docker’s documentation
mariadb:latest \
Use the latest mariadb image
--innodb_file_per_table=1 \ --lower_case_table_names=0
Run MariaDB with options as per official LibreNMS documentation
\
Indicate a newline, which makes it easier to read, you can also docker run commands without the newline, the above command will look like this one-liner without “\”:
docker run -v /volume1/docker/mariadb:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='root_password' -e TZ=Asia/Singapore --name mariadb -d mariadb:latest --innodb_file_per_table=1 --lower_case_table_names=0
Setup MariaDB LibreNMS Database and User
Now that MariaDB has been installed, time to configure the database for use with LibreNMS
Run the following command to log in to the SQL Console
docker exec -it mariadb mysql -u root
If you see a fancy 2002 Error, wait for a few seconds/moments and try the above command again. Or it asks you for a password, run the command below with “-p” option
For Debian/VM users, run with -p
docker exec -it mariadb mysql -u root -p
Next, we will create a LibreNMS user to read/write to the SQL database, enter the following commands to create “librenms” database and also the user
Change ‘libre_password’ to your preferred password
CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci; CREATE USER 'librenms'@'%' IDENTIFIED BY 'libre_password'; CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'libre_password'; GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'%'; FLUSH PRIVILEGES; exit
Now that MariaDB has been configured, issue a restart to the MariaDB container
docker restart mariadb
LibreNMS Setup
Prepare LibreNMS Docker folders
Same deal, just different names 🙂
cd /volume1/docker mkdir librenms cd librenms mkdir logs mkdir rrd touch custom.config.php
We created librenms folder, in it folder logs, rrd and custom.config.php file to be used by LibreNMS for any custom configuration
Generate an App Key
First, as per jarischaefer’s instructions, we will generate an APP_KEY value to be used for our docker run command
Run the following to generate a base64 key
docker run --rm jarischaefer/docker-librenms generate_key
Copy the base64 key somewhere and continue to customizing our LibreNMS container and its variables
Install LibreNMS Container using jarischaefer/docker-librenms
If you’ve followed this tutorial before Jul, 23 2020, breaking change is to NOT use “db” as the hostname alias to link back to MariaDB container. Latest tutorial uses “libredb” as the hostname alias
docker run \ -p 8668:80 \ -e DB_HOST=libredb \ -e DB_NAME=librenms \ -e DB_USER=librenms \ -e DB_PASS='libre_password' \ -e APP_KEY=base64:THE_GENERATED_KEY_ABOVE \ -e BASE_URL=http://YOUR_NAS_IP:8668 \ -e TZ=Asia/Singapore \ --link mariadb:libredb \ -v /volume1/docker/librenms/logs:/opt/librenms/logs \ -v /volume1/docker/librenms/rrd:/opt/librenms/rrd \ -v /volume1/docker/librenms/custom.config.php:/opt/librenms/conf.d/custom.config.php:ro \ --name librenms \ -d \ --restart always \ jarischaefer/docker-librenms:latest
Details/Explanation
-p 8668:80
Expose port 8668 which will be bound to the container’s port 80
You can ignore this for now if you don’t know what that means, head over to Page 2’s Synology & Docker Network 101 Section to understand more
-e DB_X=
DB_X values point to your MariaDB container created above, substitute them with the correct values
-e APP_KEY=base64:THE_GENERATED_KEY_ABOVE
Paste in the generated key from the initial docker run command, includes ‘base64:’
-e BASE_URL=http://YOUR_NAS_IP:8668
Replace YOUR_NAS_IP with your Synology/Server IP address
--link mariadb:libredb
We are assigning a hostname alias of ‘libredb’ to the container named ‘mariadb’ which we have just created above. DB_HOST is set to ‘libredb’
Examples
--link your-existing-container-name:hostname-alias
Configure LibreNMS Database & User Creation
Preparing LibreNMS Database
Now that MariaDB and LibreNMS containers have been set up and ready, let’s instruct LibreNMS container to prepare (more like the ol’ Setup/Install?) the Database for use
Run the following command
docker exec librenms setup_databaseWait for the process to complete, which takes around 1~5mins (SSD~HDD)
Admin User Creation
Run the following command to add an admin to LibreNMS
docker exec librenms create_admin
Login to your LibreNMS by going to the following address in your browser:
http://YOUR_NAS_IP:8668
Log in with:
Username: admin Password: admin
Sweet!
Add your Synology & Other Devices
Synology Device
Proceed to add your Synology NAS to LibreNMS for monitoring
Before we add your Synology device, let’s find its IP when accessing from Docker
Run the following in Synology Terminal/Console (not the Container’s bash)
docker inspect bridge | grep 'Gateway'
Most installs return 172.17.x.x, there are cases which you might have a different subnet like 172.18.x.x
On the menu of LibreNMS, Devices >> Add Device
Substitute your above IP as the Hostname for the Device to add to LibreNMS for monitoring
Hostname: 172.17.0.1 SNMP Version: v2c Community: your-snmp-passphrase-created-above
Congratulations!
You have a working NMS collecting and monitoring your SNMP enabled devices!
Other Devices
Proceed to add other SNMP enabled devices with their IP address as the hostname
Wait for around 5~10mins for it to collect data and it will output your graphs
Ongoing Updates depends on you
Let me know in the comments if this tutorial helped or, especially if it didn’t!
You can reach me either by commenting on this post or by joining my Discord server (link at bottom of page) where notifications are sent straight to my Mobile if you prefer a faster reply timeline
Continue to Page 2
- Page 2 – Optional(s) and Troubleshooting
- Optional(s)
- custom.config.php
- Alerts
- Use SVG graphs
- myLibreNMS app via LibreNMS API
- Troubleshooting
- Synology & Docker Network 101
- Updating Containers
- Optional(s)
If you found this tutorial to be useful, your comments or
are most appreciated!
Stuck and need help/pointers with this tutorial? Comment in the forum powered by Discourse
Just came back ONCE AGAIN to use your Guide, as i’ve been getting a dozen of customer’s on my own consulting company, where i do network, but dont understand databases.
now your Librenms/MariaDB guide just gave me a little something xtra to use when it comes to monitoring.
im not relying on the tool as im a sole beginner on this platform, so im using it and the Dessert when it comes to monitoring customer’s device health
Thank you so much for using this guide.!
once AGAIN im thanking you
Hi Morten! You’re the first in the forums! Welcome and thank you for commenting!
Glad it worked out on your end!
A user on my discord server shared that he’s using Telegraf to monitor his servers etc. If you need more details than relying on SNMP, Telegraf agent should be next on your list (Mine too
) to check out.
It’s a full stack so you will need a collector, database for long term data, and graphs
No sweat man. i just love the fact that you did the guide…
now i just need to “learn” how to upgrade librenms and mariadb when there is a docker upgrade available. :
Im 110% invested in Ubiquiti Unifi and i got a total of 40 customer’s sites… multiple Site-2-Site-VPN and multiple VPN server’s running on those devices all around…
my next step is to get Influx/Grafana installed(might as well install everything i want before diving into the functions of every program) so its ready for use when i got the time.
but Telegraf? hmm i though it was just another NMS program like Librenms? but apparantly its just a collector? So its somekind of an “agent”? collecting data, and then just putting the data into a database? so the data is ready to be pulled/shows by whatever program you wished to use like grafana or something else?
I don’t usually upgrade the MariaDB, it stays the same version for-almost-ever unless a security loophole is present… as for the LibreNMS upgrade, you can refer to my guide page 2 for the upgrade steps.
So far I’ve encountered problems during an upgrade is major versions like a jump from the previous 1.4 to 1.6.
I would recommend going the non-Docker way for LibreNMS for your setup. At least for the main server, the rest of the distributed pollers can be run as a container
Yep, it’s another full stack alternative to Influx/Grafana… I’ve seen these two solutions floating around the homelab scene, but never tried them yet though!! So I’m not sure which works best or preferences for your scenario.
Since you are going the Grafana way, there’s also netdata agent alternative
So many choices
