Nagios 2.x Plugin check_mrtgtraf buggy?

affected:

nagios plugins 1.4.3
nagios plugins 1.4.5
nagios plugins 1.4.6 (Feb, 05 – 2007)

I was trying to implement the check_mrtgtraf plugin for nagios.
A test run in bash using the command
./check_mrtgtraf -F /my/mrtg/log/server.log -w "196608,196608" -c "235929,235929"
resulted in the following “error”:
Traffic UNKNOWN – Avg. In = 2.3 KB/s, Avg. Out = 2.3 KB/s ..

In my constellation the result should be “Traffic OK”, because the limit of 0,19 MByte/s (1,5 MBit) has not been reached. On http://archive.netbsd.se I found a hint from Israel Brewster that fixed it:

From: Israel Brewster
Date: 2007-01-26 17:54:06

I’m pretty sure this is a bug. I ran into the same thing, but was able to fix it easily enough in the source code. Looking at the original code for this plugin, you can find the section where it sets the output state, something like:

if (incoming_rate > incoming_critical_threshold
|| outgoing_rate >
outgoing_critical_threshold) {
result = STATE_CRITICAL;
}
else if (incoming_rate > incoming_warning_threshold
|| outgoing_rate >
outgoing_warning_threshold) {
result = STATE_WARNING;
}

This may not be exact, as I have modified the code somewhat, but I think it is pretty close, if not. At any rate, what you’ll notice is that while the result is set to STATE_CRITICAL or STATE_WARNING, depending on the circumstances, it is never set to STATE_OK (as you mentioned in your original message), which means that it remains in its STATE_UNKNOWN default state if the traffic is OK, to fix it, all you need to do is add the two lines:

else
result = STATE_OK;

Immediately following the closing bracket on the code block above, and recompile. At least, that fixed it for me. I have plugins version 1.4.3, I don’t know if this issue has been fixed in a newer version of the plugins or not (current is 1.4.5)

That workaround did it for me, too.
You can download my patched version of the c source right here: check_mrtgtraf.c – fixed version

6 thoughts on “Nagios 2.x Plugin check_mrtgtraf buggy?”

  1. I have been having the same issues with this plugin for the last couple days. I am using plugins 1.4.6 and Israel’s fix helped me out. All I had to do was recompile my plugins and voila problem fixed.

    Thanks for the fix.

  2. Hey,

    I have a problem the same problem as you but I don’t understand how fix it.
    I’m using debian sarge and nagios plugins are in /usr/local/nagios/etc/libexec
    In this folder I can find check_mrtgtraf but I can’t modify it.
    How can I? Please someone could help me?
    Thanks

  3. Ok sorry for the precedent post, I put your files into the nagios-plugin folder, make ./configure, make & make install but it still doesn’t works.
    I don’t understand anymore :/

  4. Did you try to run the new compiled binary in shell?

    I mean, go to your nagios-plugins source folder, run ./configure ; make
    and try this new binary with ./check_mrtgtraf –your-options directly …

    If it works, you can replace your old file from /usr/local/nagios/etc/libexec
    with the new one ..

  5. I notice in the output, the performance data has “in=” for both the incoming and outgoing rates.
    looks to be around line 200

    fperfdata(“in”, adjusted_incoming_rate, incoming_speed_rating,
    (int)incoming_warning_threshold, incoming_warning_threshold,
    (int)incoming_critical_threshold, incoming_critical_threshold,
    TRUE, 0, FALSE, 0),
    fperfdata(“in”, adjusted_outgoing_rate, outgoing_speed_rating,
    (int)outgoing_warning_threshold, outgoing_warning_threshold,
    (int)outgoing_critical_threshold, outgoing_critical_threshold,
    TRUE, 0, FALSE, 0));

    The second fperfdata should have “in” changed to “out”

Comments are closed.