How to Monitor Your Network with LibreNMS and SNMP
LibreNMS is a free and open-source network monitoring system that automatically discovers your network devices using various protocols provides customisable alerting, API access, billing system, and more. You can use it to monitor both small and large networks, as well as devices and services.
One of the features of LibreNMS is its support for SNMP, which stands for Simple Network Management Protocol. SNMP is a standard protocol that allows network devices to exchange information and commands. SNMP can be used to monitor various aspects of a device, such as CPU usage, memory, disk space, temperature, fan speed, etc.
In this blog post, I will show you how to use Docker to install and configure LibreNMS, and how to use SNMP to monitor servers running Linux and Windows. I will also explain why SNMP is widely used in network monitoring and provide some examples of network assets that can be monitored with SNMP.
Using Docker to Install and Configure LibreNMS
Docker is a software platform that allows you to run applications in isolated containers, which are like virtual machines but more lightweight and efficient.
To use Docker to install and configure LibreNMS, you need to have Docker and Docker Compose installed on your host machine. You can follow the official documentation to install them here: https://docs.docker.com/get-docker/ and https://docs.docker.com/compose/install/.
Once you have Docker and Docker Compose installed, you can download the LibreNMS Docker image from the Docker Hub: https://hub.docker.com/r/librenms/librenms/.
You can also clone the GitHub repository that contains the Docker Compose file and other configuration files for LibreNMS: https://github.com/librenms/docker.
To start LibreNMS with Docker Compose, navigate to the directory where you cloned the repository and run the following command:
docker-compose up -d
This will create and start four containers: one for LibreNMS, one for MySQL (the database used by LibreNMS), one for Memcached (the caching system used by LibreNMS), and one for Nginx (the web server used by LibreNMS).
You can check the status of the containers by running:
docker-compose ps
You should see something like this:
Name Command State Ports
----------------------------------------------------------------------------------------------------------------
librenms-docker_librenms_1 /init Up 0.0.0.0:8000->80/tcp, 0.0.0.0:514->514/udp, 0.0.0.0:5140->5140/tcp, 0.0.0.0:161->161/udp
librenms-docker_memcached_1 docker-entrypoint.sh Up 11211/tcp
librenms-docker_mysql_1 docker-entrypoint.sh Up 3306/tcp, 33060/tcp
librenms-docker_nginx_1 /docker-entrypoint.sh Up 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp
You can access the LibreNMS web interface by opening http://yourhostipaddress in your browser. The default username and password are librenms/librenms.
You can also access the LibreNMS command-line interface by running:
docker exec -it librenms-docker_librenms_1 bash
The LibreNMS command-line interface is a tool that allows you to interact with LibreNMS and its components. You can use it to perform various tasks, such as validating the installation, adding devices, running discovery and polling, etc.
You can find more information about the LibreNMS Docker image and its configuration options here: https://github.com/librenms/docker/blob/master/README.md.
Using SNMP to Monitor Servers with LibreNMS
SNMP is a protocol that allows network devices to communicate with each other and with network management systems, such as LibreNMS. SNMP uses a client-server model, where the network devices are the SNMP agents and the network management systems are the SNMP managers.
The SNMP agents collect and store information about their status and configuration in a data structure called the Management Information Base (MIB). The MIB consists of a hierarchy of objects, each identified by a unique name called the Object Identifier (OID).
The SNMP managers can query the SNMP agents for specific information by sending SNMP Get requests, which contain the OIDs of the desired objects. The SNMP agents respond with SNMP Get responses, which contain the values of the requested objects.
The SNMP managers can also set the values of some objects by sending SNMP Set requests, which contain the OIDs and the new values of the desired objects. The SNMP agents respond with SNMP Set responses, which indicate whether the operation was successful or not.
The SNMP managers can also receive unsolicited notifications from the SNMP agents, called SNMP Traps or SNMP Inform requests, which indicate that something has changed or an event has occurred on the device.
To use SNMP to monitor servers with LibreNMS, you need to enable and configure the SNMP service on the servers and add them as devices in LibreNMS.
Enabling and Configuring SNMP on Linux Servers
To enable and configure SNMP on Linux servers, you need to install the SNMP daemon (snmpd) and the SNMP utilities (snmp) packages. You can use the following commands to install them on Debian-based distributions, such as Ubuntu:
sudo apt update
sudo apt install snmpd snmp
You can use the following commands to install them on Red Hat-based distributions, such as CentOS:
sudo yum update
sudo yum install net-snmp net-snmp-utils
After installing the packages, you need to edit the snmpd configuration file, which is usually located at /etc/snmp/snmpd.conf. You can use any text editor to edit the file, such as nano:
sudo nano /etc/snmp/snmpd.conf
The snmpd configuration file contains various directives and options that control the behavior and security of the SNMP service. You can find more information about the snmpd configuration file here: https://net-snmp.sourceforge.io/docs/man/snmpd.conf.html.
One of the most important options is the community string, which is a password that the SNMP managers need to provide to access the SNMP agents. The community string can be either read-only (rocommunity) or read-write (rwcommunity), depending on the level of access you want to grant to the SNMP managers.
By default, the snmpd configuration file contains a read-only community string called public, which allows anyone to access the SNMP agent. This is not secure and should be changed to a more complex and unique community string. For example, you can change the line that says:
rocommunity public default -V systemonly
To something like:
rocommunity mysecretcommunity default -V systemonly
You can also restrict the access to the SNMP agent by specifying the IP address or the network range of the SNMP managers. For example, you can change the line that says:
rocommunity mysecretcommunity default -V systemonly
To something like:
rocommunity mysecretcommunity 192.168.1.0/24 -V systemonly
This will allow only the SNMP managers in the 192.168.1.0/24 network to access the SNMP agent.
You can also specify the OIDs or the MIBs that the SNMP managers can access by using the -V option. For example, you can change the line that says:
rocommunity mysecretcommunity 192.168.1.0/24 -V systemonly
To something like:
rocommunity mysecretcommunity 192.168.1.0/24 -V 1.3.6.1.4.1.2021
This will allow the SNMP managers to access only the UCD-SNMP-MIB, which contains information about the system resources, such as CPU, memory, disk, etc.
You can also enable and configure SNMP traps or inform requests, which are notifications that the SNMP agent sends to the SNMP manager when something changes or an event occurs on the device. To enable and configure SNMP traps or inform requests, you need to add the following lines to the snmpd configuration file:
# Define the SNMP manager that will receive the traps or inform requests
trapsink 192.168.1.100 mysecretcommunity
# Define the OID that will trigger the trap or inform request
# For example, the following line will send a trap or inform request when the load average exceeds 5
monitor -r 60 "Load Average" loadave 5
# Define the OID that will be included in the trap or inform request
# For example, the following line will include the load average in the trap or inform request
extend .1.3.6.1.4.1.2021.10.1.3.1 loadavg /usr/bin/uptime
You can find more information about SNMP traps and inform requests here: https://net-snmp.sourceforge.io/docs/man/snmpd.conf.html#lbAI.
After editing the snmpd configuration file, you need to restart the service snmpd.
Enabling and Configuring SNMP on Windows Servers
To enable and configure SNMP on Windows servers, you need to install the SNMP service and the SNMP tools. You can use the following steps to install them on Windows Server 2019:
- Open the Server Manager and click on Manage > Add Roles and Features.
- On the Before You Begin page, click Next.
- On the Select Installation Type page, select Role-based or feature-based installation and click Next.
- On the Select Destination Server page, select the server where you want to install the SNMP service and tools and click Next.
- On the Select Server Roles page, click Next.
- On the Select Features page, expand SNMP Service and check SNMP Service and SNMP Tools. Click Next.
- On the Confirm Installation Selections page, click Install.
- On the Installation Progress page, wait for the installation to complete and click Close.
After installing the SNMP service and tools, you need to configure the SNMP service. You can use the following steps to configure the SNMP service on Windows Server 2019:
- Open the Services console and locate the SNMP Service. Right-click on it and select Properties.
- On the SNMP Service Properties window, click on the Security tab.
- Under Accepted community names, click on Add.
- On the Add Community Name window, enter a community name and select the permission level (Read Only or Read Write). Click OK
Adding Servers to LibreNMS for Monitoring
Once SNMP is configured on your Linux and Windows servers, you can easily add them to LibreNMS for monitoring. To do this, follow these steps:
- Log in to your LibreNMS web interface.
- Navigate to the ‘Devices’ menu.
- Click on ‘Add Device’.
- Enter the hostname or IP address of the server you wish to monitor.
- Select the SNMP version and enter the community string you configured on the server.
- Click on ‘Add Device’.
LibreNMS will then attempt to connect to the server using SNMP. If successful, it will begin automatically discovering services and metrics available for monitoring.
Conclusion
Monitoring your network’s health and performance is crucial for maintaining system reliability and efficiency. LibreNMS, coupled with SNMP, provides a powerful and user-friendly platform for keeping an eye on your network infrastructure. Whether you’re monitoring Linux or Windows servers, or other network assets, LibreNMS offers a comprehensive set of tools to ensure you’re always in the know about your network’s status. With its automated discovery, customizable alerting, and detailed reporting, LibreNMS stands out as an excellent choice for network administrators seeking a scalable and open-source monitoring solution.
Remember, regular monitoring and maintenance are vital to preventing network issues and ensuring smooth operations. Happy monitoring! 😊