Minggu, 15 April 2018

Monitoring UPS dg Mikrotik

The smart UPS support in the Mikrotik RouterOS

The Mikrotik RouterOS has a supporting module for the APC smart UPS units. The UPS unit can be connected either over serial or USB port with the Mikrotik RouterOS device. The device can be either the Mikrotik RouterBoard or the PC based x86 RouterOS device.
The main reason for this support is support for the router hibernation and safe power on after the power outage. Furthermore, we can monitor the UPS device and make a log of the events. Moreover, we can utilize the observation script and send the alarms to the administration team in specific conditions.
We can turn the Mikrotik device onto a monitoring center, to asses and report on the status of the UPS. That can be very useful when our device is in a remote location. That can be just the branch office or even the wireless hotspot system on some hill. And then there is about 1 metre of the snow and temperature of the -15°C. You cannot just walk there and check what’s going on.

The installation

The UPS support service is an additional package. You can install it either during the installation process on your PC systems or add this package on the RouterBoard and reboot it.
clip_image001[4]
The UPS option will appear in the System menu. You can access it either through the WinBox or the WebFig GUI (System > UPS) or from command line /system ups. The command line interface can be widely used in the monitoring scripts.
clip_image002[4]

Connecting the UPS unit

We can connect the UPS unit either over a special serial cable or over the USB cable supplied with the unit. We cannot use the common cables. If we connect the UPS and the RouterBoard with the wrong cables we can severely damage both units. Bear this in mind.
I want to underline one more piece of information. The UPS unit will send some status information to the Mikrotik device. Not all APC UPS units will report the full status of the device. That means that it can happen that some information will not be available and therefore the Mikrotik device can miss some events and power conditions.
In this test I have one old APC Back-UPS CS500 unit. This device is intended to protect the workstations from short power failures and to enable graceful shutdown or hibernation. This unit had a very dead battery. It will report that battery life is about a half hour. However, if we pull the power cord from the outlet, the UPS unit will turn off immediately. You will see later that this UPS didn’t send the Replace battery signal. And it died completely after this test.
After the successful connection of the signaling cable between the UPS unit and the Mikrotik device, we will open the UPS configuration window. I will show all of this from the WinBox as this is the better view.
clip_image004[4]
Although you can see here the very last screen from the RouterOS version 6.36, you can use any version of the RouterOS that has a UPS package. As I mentioned, this UPS didn’t report certain information. Therefore, I made tests with the RouterOS version from 5.24 up to 6.36 to avoid the possibility that there is some bug in the RouterOS part.
Just click on the Add button and new window will appear. We should indicate the port where the UPS unit is connected. In our example this is the USB port named as usbhid1. We can give the UPS unit any name we want instead of the generic ups1.
clip_image005[4]
We have two more very important options here. The first one is the Off Line Time. This parameter will indicate to the Mikrotik device how long it should work after power failure and when the UPS unit switches to batteries.
As this parameter can vary depending on the UPS model and its condition, we should avoid specifying the time in minutes. If we specify 0 here, that means that the Mikrotik device should hibernate itself when the UPS battery level is at 10%.
The second parameter is the Min Run Time. That parameter is similar to the previous. However, difference is in its meaning; in this case the Mikrotik device will monitor the remaining UPS run-time after the power failure. When the UPS reports an amount of the time equal or less then designated, the Mikrotik device will hibernate.
We can also put 0 here as the value. That has the same meaning as with previous option – hibernate the Mikrotik device when the UPS battery level is at 10%.
When we click on the Apply button, the RouterOS device will begin communication with the UPS unit. Then we will see the UPS information on the tab Model.
clip_image006[4]
All this information is available only for reading. Much more important are information on the Status page.
clip_image007[4]

Accessing the UPS interface from the command line

We can check all this information from the command line interface with the command /system ups monitor. The amount of information varies between models. If any of the status information is not available, then the command will not display that row. We will see later how this looks in our example.
clip_image008[4]
As you can see from this screenshot, we can collect a lot of the information about the current UPS state. We can react to the different events, like the UPS load being higher than a specific percent or an input voltage out of the range. Then we can generate the log events, send the e-mail or SMS or perform any other action.
In the end, all tests performed on a virtual machine. I used the Oracle VirtualBox based virtual machine with the redirected USB device. However, this very cool feature is the theme for some other post. Stay tuned.

Tidak ada komentar:

Posting Komentar