Nagios - Selenium: check for file content and compares with specified threshold
firstly I hope to write in the correct subforum.
BTW, I need to find some kind of nagios check that can read a value inside a .html file (particularly it's a result of selenium testcase) and compare it with some specified values that will act as a threshold for warning/critical status on nagios.
Out there (nagios-exchange) I found some "log_file" read check or something similar, but I don't think I can re-use that for my aim... Maybe with a bit of bash scripts or so on I can find a solution... but I'm very newbie in bash scripting.. :scratch:
Does anyone had a similar need before?
My goal is to have a selenium check for site performance and compare with a fixed threshold that send me a notification with nagios telling that a particular selenium testcase is slower than expected... (I know it's not so simple to understand and almost impossible but who knows.....)
Thanks in advance...
I don't use Selenium.
I'd say the two I most commonly use are wget or curl. However others exists such as lynx, links, elinks etc...
curl and wget in their simplest form are simply followed by the URL you want to get information from. You can look at man pages for them to get more options (e.g. dump or source options are sometimes helpful when looking for information not gotten by basic web attachment).
Nagios allows you to develop scripts and use those for your checks. The key to such scripts is that they output only a single line of text (i.e. Nagios pukes on multiline output) for status and one of the return codes that Nagios understands which are:
To issue such a return code you just put "exit <return code>" at the point you want to exit AFTER you've issued the output line.
An example for our check of MS Exchange Webmail site is shown below. Note that this one is also a good example of things you can test for when you can't exactly test the page directly.
Thank u MensaWater for the answer.
I think I've forget something on the explanation...
The .html file I was talking above (that is the selenium testcase result) is a "simple" 2 columns table basic html page, with a series of "text - values" in each row and some informations around.
Something like this:
Starting from this, I've to extract ,for example, "50" from this row "Total Time: 50".
This number has to be interpreted by a nagios check that have to be as arguments some threshold like "if from 25 to 75, it's OK, if greater than 90 it's warning, if greater than 120 it's critical".
So, maybe, for the last part, I can use the exit code you show me above (so I'll put these threshold inside the script for comparison), but, how can I extract that "50" and put it F.E. in another text file and then let nagios read this?
Hope to have clarified a bit more than before... :)
You say "the row" but I don't see a SINGLE row with "Total Time: 50". What I do see similar to that is TWO rows:
If all you need is the second line that contains the value you could use tail:
In my case I'll use "cat" instead of "wget" cause .html file is the output format of selenium result, so it's a "fake" webpage... :)
BTW, I'll study a bit more awk later, now my priority is to have it running.
So now, I have the number. I wrote a simple script to compare it with 3 threshold (nagios-style); my last doubt is:
The threshold now are fixed into the script, but AFAIK some other nagios check take advantage of $ARGS$ variables to set warning and critical level to custom values and it's more easy to modify (instead to edit the script I can simply edit these values, save the nagios check and then it grabs these values as the new threshold, leaving the script unmodified).
I'll check better on nagios-plugin documentation, but on a first quick view there was a lot of code to write...
the idea is something like:
"./check_selenium -w 70 -c 85 < file_with_number_found.txt"
Where, of course, -w is the warning threshold and -c is the critical one.
Thanks a lot for your help MensaWater :)
|All times are GMT -5. The time now is 02:50 PM.|