#Docker: Network monitoring with Docker-compose #LibreNMS environment stack

By | May 28, 2017

I started from a great post Monitoring your Ubiquiti home-network with a Docker LibreNMS and SNMP, to make my own network monitor where to gather all the network devices SNMP messages.

Because I like docker compose files to start up all my components and I want to use a separate docker mysql I made the following derived setup.

STEP 1: Create the librenms and database services

I created a librenms directory under which the following docker-compose.yml file is placed:


version: '2.1'
services:
  nms:
     image: jarischaefer/docker-librenms
     ports:
       - "80:80"
     links:
       - mysql:mysql
     environment:
       - DB_HOST=mysql
       - DB_NAME=librenms
       - DB_USER=librenms
       - DB_PASS=librenms
       - PUID=0
       - PGID=101
       - TZ=Europe/Bucharest
       - BASE_URL=/
       - POLLERS=16
     volumes:
       - /volume1/docker/librenms/logs:/opt/librenms/logs
       - /volume1/docker/librenms/rrd:/opt/librenms/rrd
     depends_on:
       - mysql
     stdin_open: true
     tty: true
  mysql:
       image:
         mysql
       environment:
         - MYSQL_ROOT_PASSWORD=librenms
         - MYSQL_DATABASE=librenms
         - MYSQL_USER=librenms
         - MYSQL_PASSWORD=librenms

The yml file defines a mysql database and links a librenms container to it.
Librenms will be accesible on port 80 exported on localhost.

STEP 2: Start the environment

Change directory to the librenms directory containing the docker-compose.yml file and execute:


# docker-compose up

Checking with “docker ps” we can see the started containers:


[root@nas2 ~]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                                     NAMES
a67b218a5e08        jarischaefer/docker-librenms   "/sbin/my_init"          12 minutes ago      Up 12 minutes       80/tcp, 443/tcp, 0.0.0.0:80->80/tcp   librenms_nms_1
7c1cd0512bba        mysql                          "docker-entrypoint..."   12 minutes ago      Up 12 minutes       3306/tcp                                  librenms_mysql_1

STEP 3: Initialize librenms

Create the librenms tables:


[root@nas2 ~]# docker exec librenms_nms_1 sh -c "cd /opt/librenms && php /opt/librenms/build-base.php"
-- Updating database schema
000 -> 001 ... done (0 errors).
001 -> 002 ... done (0 errors).
002 -> 003 ... done (0 errors).
003 -> 004 ... done (0 errors).
...
181 -> 182 ... done (0 errors).
-- Done

Create an initial admin user:


[root@nas2 ~]# docker exec librenms_nms_1 php /opt/librenms/adduser.php admin admin 10 george@voina.org
User admin added successfully

STEP 4: Open librenms ports in the firewall

So on RedHat/CentOS/Fedora that uses firewalld do the following.

Find the active zones.


[root@nas2 ~]# firewall-cmd --get-active-zones
FedoraServer
  interfaces: bond0

Then open the ports and esp protocol in the active zone.


# firewall-cmd --zone=FedoraServer --add-port=80/tcp --permanent
success
# firewall-cmd --reload 
success


STEP 5: Force librenms autodiscovery

To trigger autodiscovery of all supported devices run the following:


# docker exec -it librenms_nms_1 /opt/librenms/snmp-scan.php -r 192.168.2.0/24

You can also add devices by hand from Add

STEP 6: Enjoy monitoring your devices
Make sure to set SNMP agents in devices that have one. Printers by default send snmp info so they will be found by the scan.
For the HP switches and EdgeRouter devices I had to set the snmp agents to point to the LibreNMS server.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.