Community discussions

MikroTik App
 
pelish
just joined
Topic Author
Posts: 20
Joined: Sun Dec 14, 2008 7:58 pm

How to use The Dude for monitoring UPS conected to MikroTik

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)
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
 
User avatar
matrot2
Frequent Visitor
Frequent Visitor
Posts: 79
Joined: Thu Jun 25, 2009 12:34 pm

Re: How to use The Dude for monitoring UPS conected to Mikro

Tue May 25, 2010 7:27 pm

This can be very useful for this:
http://tandem.ck.ua/ups_mtm-eng.php
 
crodler
just joined
Posts: 17
Joined: Sun Jun 19, 2011 12:03 am

Re: How to use The Dude for monitoring UPS conected to Mikro

Sun Jun 19, 2011 12:19 am

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
 
pelish
just joined
Topic Author
Posts: 20
Joined: Sun Dec 14, 2008 7:58 pm

Re: How to use The Dude for monitoring UPS conected to Mikro

Mon Jun 20, 2011 3:15 pm

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.
 
crodler
just joined
Posts: 17
Joined: Sun Jun 19, 2011 12:03 am

Re: How to use The Dude for monitoring UPS conected to Mikro

Tue Jun 21, 2011 8:36 pm

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??
 
pelish
just joined
Topic Author
Posts: 20
Joined: Sun Dec 14, 2008 7:58 pm

Re: How to use The Dude for monitoring UPS conected to Mikro

Wed Jun 22, 2011 10:40 am

Download UPS MIB from somewhere and you will see which OID use and how...
 
crodler
just joined
Posts: 17
Joined: Sun Jun 19, 2011 12:03 am

Re: How to use The Dude for monitoring UPS conected to Mikro

Thu Jun 23, 2011 11:49 am

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.
 
crodler
just joined
Posts: 17
Joined: Sun Jun 19, 2011 12:03 am

Re: How to use The Dude for monitoring UPS conected to Mikro

Thu Jun 23, 2011 12:14 pm

I mean something like this:
You do not have the required permissions to view the files attached to this post.
 
pelish
just joined
Topic Author
Posts: 20
Joined: Sun Dec 14, 2008 7:58 pm

Re: How to use The Dude for monitoring UPS conected to Mikro

Thu Jun 23, 2011 1:11 pm

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 ;)

Who is online

Users browsing this forum: No registered users and 25 guests