How to use The Dude for monitoring UPS conected to MikroTik

Hello,
after long time looking over forums and testing I have finally found solution how to monitor my APC UPSs which are connected to MikroTik servers by serial/usb cable.

Since there is not possible to use standard SNMP OID (mikrotiks snmp currently do not include values from UPS) you need to use The Dude functions and create own functions/probes.

For that I have used ros_command() function which is possible to use to send command and get an answer from RouterOS server. Please note that you need configure your The Dude to connect to server which monitoring your UPS - so you need to tape an username/password to device configuration. Also be sure that your UPS is named “ups1” (in other way, you need to rename that in fallowing functions).

After that you can use fallowing functions:

ups_status() (returns 1 if UPS is online, 0 if is offline)

if (string_substring(ros_command("/system ups monitor ups1 once"),string_find(ros_command("/system ups monitor ups1 once"),"on-line")+9,3), "1", "0")

ups_battery_charge() (returns an number in %)

round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"battery-charge")+16,
3)
)

ups_temperature() (returns an number in °C)

round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"temperature")+13,
2)
)

You will also need to define some function which returns 1 if an UPS is pressent, 0 if is not. I have make fallowing code for that purpose (but is not so nice, so I would like to make an better one in future).

ups_available()

if (string_size(ros_command("/system ups monitor ups1 once")) > 40, "1", "0")

By this examples you can make your own probes/changes of an official functions to have full monitoring of your UPS. I have made one more function, where I preparing an UPS info and than I have modified original device_performance() function. Both of that is bellow:

ups_info()

concatenate(
if(ups_available() > 0, concatenate("ups: ", round(ups_battery_charge()), "% "), ""),
if(ups_available() > 0, concatenate("temp: ", round(ups_temperature()), "C "), "")
)

device_performance() (modification of original function - will add UPS info when is an ups present)

concatenate(
if(
string_size(cpu_mem_disk()) > 0,

concatenate(cpu_mem_disk(), "
"),

""
)
,
if(
string_size(ups_info()) > 0,

concatenate(ups_info(), "
"),

""
)
)

The last ting is make an probe which will give you info, when your UPS is On-Line or is Off-Line and will show you an graph of battery charge. Here is my example:

ups status - Probe
type: Function
Agent: Default
Available: ups_available()
Errror: if(ups_status(), “”, “Off-line”)
Value: ups_battery_charge()
Unit: %
Rate: none

That is all of my examples. Until RouterOS will give us full SNMP OID UPS status, can be this usefull.

All of this is just an example. Be sure that you make an backup of your The Dude configuration. Also I am pretty sure that my solution is not just only working one - but works.

Any suggestions to improve welcome!
Regards
Pelish

This can be very useful for this:
http://tandem.ck.ua/ups_mtm-eng.php

Did not work for me with ROS5.2 so I post my modifications. I use two probes, one for battery charge and the other for line voltage.

Functions:
ups_available

array_size(ros_command("/system ups monitor ups1 once"))

ups_status

if (string_substring(ros_command("/system ups monitor ups1 once"),string_find(ros_command("/system ups monitor ups1 once"),"on-line")+9,3), "1", "0")

ups_battery_charge

round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"battery-charge")+16,
3)
)

ups_line_voltage

round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"line-voltage")+13,
4)
)

Probes:
Name: ups-status
Type: Function
Agent: server
Available: ups_available()
Error: if(ups_status(), “”, “down”)
Value: ups_battery_charge()


Name: ups-linevoltage
Type: Functions
Agent: server
Available: ups_available()
Error: if(ups_status(), “”, “down”)
Value: ups_line_voltage()



Regards,
Christian Rodler
ENSINCA NETWORKS

Did you tried SNMP UPS OID wich is provided since 5.x? I think that this is out of date… Just one thing still missing - Replace batery probe.

Hmm,
I have RB450G and X86, with 5.4 and APc-UPS on serial line and I do not get any information about for example line voltage with snmp.
I get UPS model and version but nothing else.

May be I do anything wrong??

Download UPS MIB from somewhere and you will see which OID use and how…

Download UPS MIB from somewhere and you will see which OID use and how…

snmpwalk …|grep 1.3.6.1.2.1.33
.1.3.6.1.2.1.33.1.1.2.0 = STRING: "Smart-UPS SC420 "
.1.3.6.1.2.1.33.1.1.3.0 = STRING: “725.1.I”
.1.3.6.1.2.1.33.1.2.1.0 = INTEGER: 2 #battery status
.1.3.6.1.2.1.33.1.2.3.0 = INTEGER: 8340 #minutes remaining
.1.3.6.1.2.1.33.1.2.5.0 = INTEGER: 1377 #battery voltage
.1.3.6.1.2.1.33.1.2.7.0 = INTEGER: 0 #temperatue

I can not get any information about ups input and ups output like input/output voltage.

I mean something like this:
Pantallazo-47.png

Sorry than… it is true that SNMP UPS OID includes only few informations… hopefully will Mikrotik deveopers add others too. For example Baterry replace is really necessar.

So good job that you have updated my old work :wink: