Here is a NEW battery failed probe for APC UPSs. Kudos go to gsandul for the function and probe template. It has helped me a whole bunch.
Your request... "if OID value = null, do nothing. If oid value = 1, send alert BUILDING_POWER. If OID value = 2, send alert BATTERY_POWER."
I built this probe to alert on "False" and when value does not equal 1 since when value=1 everything is fine... I have not built a probe that handles another state like you requested (sorry) and I have spend a lot of time on this already.
Lets start with a function, (right click functions, open separately)
Create a new function, (click + on the function window)
Give the function a name which can be called from a probe...
Name: upsbat
Description: Returns false or the value in 1.3.6.1.4.1.318.1.1.1.2.2.4.0
Code: if(array_size(oid_column("1.3.6.1.4.1.318.1.1.1.2.2.4" ,10 ,29)), oid_raw("1.3.6.1.4.1.318.1.1.1.2.2.4.0", 10, 29) ,"False")
The above function will grab all the values in the oid_column, find the specific one that has the value that we are interested in. If it is non zero it will return the value in the oid_raw form. If it is zero it will return false. Now we should be able to do all the rest of the work on the error line of the probe.
Notice I am using oid_raw in the function. APC UPS returns a text string "noBatteryNeedsRelplacing(1)" when the battery is fine. We need the value "1" for the if statement to work. I used oid_raw since it seems to only return numerical values.
Now it is time to create a probe. Same as above, click probes, click plus...
Notice below on the available line I am calling the function "upsbat()<> "False"" to see if there is a value or if it is "False".
The great thing about this function/probe combo is the notification error message.
The notification has both "UPS on battery" if the value is not equal to 1 and "Cant read UPS" if the OID is not available, otherwise the probe is up and the device up.
Name: ups_bat_test
Type: Function
Agent: default
Available: upsbat()<> "False"
Error: if(upsbat()<>"False", if(upsbat() = 1, "", "Warning: UPS Battery failed"), "Warning cant read Battery")
Note: I didn't put a value to graph. There is no reason to graph the value 1. ALTHOUGH you will have to go manually turn off history (individually (on the history tab) on each device that you put the probe on) if you don't want to see a graph at all. The default is to graph and not putting a value there gives you a graph of 0. Also keep in mind that values are not graphed if the
Error line of the probe is "true".
The probe "Error" line goes true if anything other than "" is returned.
Also note the function of this oid on an APC UPS is for if the battery fails and not for if the ups is on building power like your ups. [edit: I added the correct message to the error line for APC since the rest of the probe is correct for APC.]
I will build all my new probes based on the above model since it can tell the difference between when the value is not available and the value is within an error threshold... It is also much more predictable when using auto discover.
batfunc.PNG
batprobe.PNG
And as gsandul pointed out you can really customize the notification to your hearts content. I am just using the default notification for this in the global settings. You won't need the ping probe since you can tell if this probe is down or if the ups is on battery. You might have 4 or 5 more probes on your UPS if you like, one for battery capacity, temperature, voltage in... these are good to graph
HTH,
Lebowski
[EDIT Awe crap The "Error" line was completely wrong. I wrote the post before/as I built the probe and took screen shots of the working probe but failed to finish proof reading before I had to leave.]
You do not have the required permissions to view the files attached to this post.