How to use The Dude for monitoring UPS conected to MikroTik
Posted: Wed May 19, 2010 3:06 pm
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)
ups_battery_charge() (returns an number in %)
ups_temperature() (returns an number in °C)
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()
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()
device_performance() (modification of original function - will add UPS info when is an ups present)
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
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)
Code: Select all
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")
Code: Select all
round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"battery-charge")+16,
3)
)
Code: Select all
round(
string_substring(ros_command("/system ups monitor ups1 once"),
string_find(
ros_command("/system ups monitor ups1 once"),"temperature")+13,
2)
)
ups_available()
Code: Select all
if (string_size(ros_command("/system ups monitor ups1 once")) > 40, "1", "0")
ups_info()
Code: Select all
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)
Code: Select all
concatenate(
if(
string_size(cpu_mem_disk()) > 0,
concatenate(cpu_mem_disk(), "
"),
""
)
,
if(
string_size(ups_info()) > 0,
concatenate(ups_info(), "
"),
""
)
)
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