I have an MRTG system (running on Fedora 29) which uses an external bash script to collect some of the data. My problem occurs when the script takes too long to complete and is abnormally terminated by the system. The script exit code is 137, KILL (9) + abnormal (128). I can't trap on this value so MRTG does not receive any output. The log shows errors like, "did not eval into defined data". With no new data to process, MRTG generates graphs with horizontal straight lines, implying that the return values did not change. But that's misleading at best and probably actually wrong.
I'd like MRTG to treat this case as through the script returned zeros. If I could trap on the exit condition, that would be trivial, but that isn't possible. Is there a way to instruct MRTG to treat this case as though the script returned zeros? If not, are there any other suggestions that would accomplish the same thing?
did not eval into defined data
-
- Dreams In Code
- Posts: 7682
- Joined: Wed Feb 11, 2015 12:54 pm
Re: did not eval into defined data
My recommendation would be for you to update your external script to timeout within a period of time, if that timeout is hit, return zero. That should do what you're looking for.
Another example would be something like this (you'll need to see if this works for you):
- Set X to the number of seconds it should at MAX take to return
Another example would be something like this (you'll need to see if this works for you):
- Set X to the number of seconds it should at MAX take to return
Code: Select all
Target[target_name]: `timeout X /path/to/your/script.sh blah blah blah || printf "0\n0\n0\ntarget_name"`
-
- Posts: 6
- Joined: Mon Feb 26, 2018 8:18 pm
Re: did not eval into defined data
Thank you, ssax. Even without the timeout prefix, your suggestion catches the error and outputs the alternate values (all zeros). Unfortunately, the kill outputs "Killed" to standard out first, meaning that the output effectively consists of five lines with the zeros in the wrong places. The form,
seems to delete the extra line. (If output is normal, grep finds the expected four lines and returns 0. If Killed is present, grep finds nothing else so returns 1 and omits Killed.)
Code: Select all
/path/to/your/script.sh blah blah blah | grep -v Killed || printf "0\n0\n0\ntarget_name"`
-
- Dreams In Code
- Posts: 7682
- Joined: Wed Feb 11, 2015 12:54 pm
Re: did not eval into defined data
Does this work?
Code: Select all
/path/to/your/script.sh blah blah blah | grep -v Killed | grep -v grep || printf "0\n0\n0\ntarget_name"`
-
- Posts: 6
- Joined: Mon Feb 26, 2018 8:18 pm
Re: did not eval into defined data
Not needed. There is no "grep" in the output lines, with or without an error.
-
- Dreams In Code
- Posts: 7682
- Joined: Wed Feb 11, 2015 12:54 pm
Re: did not eval into defined data
Are you still having issues or is it working as expected? It kind of sounds like you were just telling me your resolution but I want to make sure.
-
- Posts: 6
- Joined: Mon Feb 26, 2018 8:18 pm
Re: did not eval into defined data
Yes, fixed. Thanks. Was there something I should have selected to mark the answer?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
Re: did not eval into defined data
Nope.dclose wrote:Yes, fixed. Thanks. Was there something I should have selected to mark the answer?
Glad it is resolved, Locking thread