This lab starts an OpenNMS instance in the cloud and two Minions on your machine, using ActiveMQ for communication through Multipass
and Azure
, for learning purposes.
The lab doesn't cover security (in terms of encryption), which is crucial if you ever want to expose AMQ to the Internet. Follow this guide to learn how to do it with LetsEncrypt.
Keep in mind that nothing prevents you from skipping using the cloud provider and do everything with Multipass
(or VirtualBox
, or Hyper-V
, or VMWare
). The reason for using a cloud provider is to prove that OpenNMS can monitor unreachable devices via Minion. Similarly, you could use any other cloud provider instead of Azure. However I won't explain how to port the solution here.
The scripts used through this tutorial use envsubst, make sure to have it installed.
Make sure to log into Azure using az login
prior creating the VM.
If you have a restricted account in Azure, make sure you have the Network Contributor
role and the Virtual Machine Contributor
role associated with your Azure AD account for the resource group on which you would like to create the VM. Of course, Owner
or Contributor
at resource group level are welcome.
Tune the VMs image size accordingly.
Feel free to change the content if needed.
Do not confuse the Azure Location or Region with the Minion Location; they are both unrelated things.
We're going to leverage the Azure DNS services to avoid the need to remember and using Public IP addresses, which helps if you're interested in having HTTPS with valid certificates as explained here.
In Azure, the default public DNS follow the same pattern:
To make the VM for OpenNMS unique, I added the username to the VM name, as you can see in the ONMS_FQDN
environment variable, which translates to:
The above is what we can use to access the VM via SSH and to configure Minions.
This is a necessary step, as every resource in Azure must belong to a resource group and a location.
However, you can omit the following command and use an existing one if you prefer. In that case, make sure to adjust the environment variable RG_NAME
so the subsequent commands will target the correct group.
Create a cloud-init script to deploy OpenNMS in Ubuntu and save it at /tmp/opennms-template.yaml
:
Note the usage of environment variables within the YAML template. We will substitute them before creating the VM.
The above installs the latest OpenJDK 11, the latest PostgreSQL, and the latest OpenNMS Horizon. I added the most basic configuration for PostgreSQL to work with authentication. The embedded ActiveMQ is enabled, as well as Syslogd
.
Create an Ubuntu VM with 2 Cores an 8GB of RAM for OpenNMS (that's what you'd get with Standard_D2s_v3):
Note that I'm assuming the usage of SSH Keys for password-less access. Make sure to have a public key located at ~/.ssh/id_rsa.pub
, or update the az vm create
command.
By default, the above creates a VNet, a default subnet within it, and it associates a public IP address and a public DNS name to the NIC that Azure will create for the VM.
I've chosen password-based access for simplicity but feel free to use SSH-Keys if needed.
Keep in mind that the cloud-init
process starts after the VM is running, meaning you should wait about 5 minutes after the az vm create
is finished to see OpenNMS up and running.
The last two commands expose the WebUI and AMQ ports to the Internet via the auto-generated Azure Security Group for the VM associated with its NIC.
In case there is a problem, SSH into the VM using the public IP and the provided credentials and check /var/log/cloud-init-output.log
to verify the progress and the status of the cloud-init execution.
multipass
After verifying that OpenNMS is up and running, you can proceed to create the Minions.
Create a cloud-init script to deploy Minion in Ubuntu and save it at /tmp/minion-template.yaml
:
Note the usage of environment variables within the YAML template. We will substitute them before creating the VM.
Then, create the runtime template:
Then, start the new Minion via multipass
with one core and 2GB of RAM:
Optionally, create a second Minion in the same location:
In case there is a problem, access the VM (e.x., multipass shell $MINION_ID1
) and check /var/log/cloud-init-output.log
to verify the progress and the status of the cloud-init execution.
As you can see, the location name is Durham
(a.k.a. $MINION_LOCATION
), and you should see the Minions on that location registered in OpenNMS.
SSH into the OpenNMS server and create a requisition with a node in the same network as the Minion VMs, and make sure to associate it with the appropriate location. For instance,
Make sure to replace 192.168.0.40
with the IP of a working server in your network (reachable from the Minion VM), and do not forget to use the same location as defined in $MINION_LOCATION
.
Please keep in mind that Minions are VMs on your machine. 192.168.0.40
is the IP of my machine which is why Minions can reach it (and vice versa), to access an external machine on your network, make sure to define static routes on that machine so it can reach the Minions through your machine (assuming you're running Linux or macOS).
OpenNMS which runs in Azure, and have no access to 192.168.0.40
directly, should be able to collect data and monitor that node through any of the Minions. In fact, you can stop one of them, and OpenNMS would continue monitoring it.
To test asynchronous messages, you can send SNMP traps or Syslog messages to one of the Minions. Usually, you could put a Load Balancer in front of the Minions and use its IP when sending messages from the monitored devices. Alternatively, you could use udpgen for this purpose.
The machine that will be running udpgen
must be part of the OpenNMS inventory. Then, find the IP of the Minion using multipass list
, then execute the following from the machine added as a node above (the examples assumes the IP of the Minion is 192.168.75.16
):
To send SNMP Traps:
To send Syslog Messages:
The C++ version of udpgen
only works on Linux. If you're on MacOS or Windows, you can use the Go version of it.
Note that an event definition is required when using udpgen
to send traps. Here is what you'd need for Eventd
:
The Hawtio UI in OpenNMS can help to visualize the Camel and ActiveMQ internals, to understand what's circulating between OpenNMS and the Minions.
For OpenNMS, Hawtio is available through http://$ONMS_IP:8980/hawtio
(use the ActiveMQ Tab) if the package opennms-webapp-hawtio
was installed (which is the case with the cloud-init
template used). Alternatively, you could use the opennms-activemq:stats
command from the Karaf Shell.
For Minions, Hawtio is available through http://$MINION_IP1:8181/hawtio
and http://$MINION_IP2:8181/hawtio
respectively (use the Camel Tab).
In production, when having multiple Minions per location, it is a good practice to put a Load Balancer in front of them so that the devices can use a single destination for SNMP Traps, Syslog, and Flows.
The following creates a cloud-init template for Ubuntu to start a basic LB using nginx
through multipass
for SNMP Traps (with a listener on port 162) and Syslog Messages (with a listener on port 514). Save the template at /tmp/nginx-template.yaml:
Note the usage of environment variables within the YAML template. We will substitute them before creating the VM.
Then, update the template and create the LB:
Flows are outside the scope of this test as that requires more configuration on Minions and OpenNMS besides having an Elasticsearch cluster up and running with the required plugin in place.
When you're done, make sure to delete the cloud resources.
If you created the resource group for this exercise, you could remove all the resources with the following command:
If you're using an existing resource group that you cannot remove, make sure only to remove all the resources created in this tutorial. All of them should be easily identified as they will contain the username and the VM name as part of the resource name. The easiest way is to use the Azure Portal for this operation. Alternatively,
The reason to have two sets of deletion groups is that, by default, the list contains disks initially, which cannot be removed before the VMs. For this reason, we exclude the disks on the first set, and then we remove the disks.
Then clean the local resources:
Remember to remove the nginx
instance if you decided to use it.