Check_http to look for special symbols??

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Check_http to look for special symbols??

Postby mmartin » Fri Jul 15, 2011 2:03 pm

Hey All,

So I have been using the check_http plugin for quite a while now, but I ran into a problem.

The search string I am looking for contains a copyright (c) symbol which is &copy.
When I look at the webpage the searched string is all on one line which looks something like this:
"Copyright © The Company Name & Blah, Inc."

But when I view the source code for the page I can see it looks like this:
Code: Select all
<div class="smalltext" align="center">
   Copyright &copy;

   The Company Name &amp; Blah, Inc. *All prices are subject to publisher revision
   &nbsp;
</div>


By the source it looks like line breaks are in there or something, but I can't get it to work. I tried just copying the code exactly as it is and placing it in parenthesis but I get a config error if I try to do that.

So does anyone know how to solve this is it possible to use a file with the string in it?? If its not possible I guess I'll resort to regex.


Thanks in advance,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mguthrie » Sat Jul 16, 2011 12:04 pm

Can you post the full command-line test of what you've got so far?
mguthrie
 
Posts: 4384
Joined: Mon Jun 14, 2010 10:21 am

Re: Check_http to look for special symbols??

Postby mmartin » Sat Jul 16, 2011 12:19 pm

Sure, I'm sending this from my phone right now. Bit I'll post it when I get to my computer.

Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mmartin » Mon Jul 18, 2011 8:24 am

Here is the full command as it looks in "commands.cfg":

Code: Select all
# 'check_homepage' command definition
define command{
        command_name    check_homepage
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u /music/welcome.jsp -c 15 -s "Copyright &copy;"
        }



The searched string that shows in their now, DOES work but I can't seem to get the rest of that string to work correctly?
Any thoughts about how it should look? Or how to arrange the source of the string?

I would like it to find everything in this html code below from "Copyright" to "Inc.": (not sure why the source for that one line are spread across 2 lines?)
Code: Select all
<div class="smalltext" align="center">
   Copyright &copy;

   The Company Name &amp; Blah, Inc. *All prices are subject to publisher revision
   &nbsp;
</div>




Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mguthrie » Mon Jul 18, 2011 9:16 am

Both the ';' and the '&' characters can potentially be interpreted by the shell, just for kicks can you try wrapper the string in single quotes instead of double? Single quotes will not do any interpretation.
mguthrie
 
Posts: 4384
Joined: Mon Jun 14, 2010 10:21 am

Re: Check_http to look for special symbols??

Postby mmartin » Mon Jul 18, 2011 1:03 pm

Here is the modified output of what you asked:
Code: Select all
# ./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r 'Copyright &copy;'
HTTP OK: HTTP/1.1 200 OK - 89797 bytes in 0.011 second response time |time=0.010934s;;15.000000;0.000000 size=89797B;;;0

# ./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r 'Copyright &copy; \s'
HTTP OK: HTTP/1.1 200 OK - 89797 bytes in 0.013 second response time |time=0.013103s;;15.000000;0.000000 size=89797B;;;0


I also found another option the "-l" which "Allows regex to span newline (must precede -r or -R)", but I can't figure out the correct syntax to span the newline?
Because from my understanding the check_http command searches through the page source code of the specified address. And the source for the part I want is this (notice the 'tabs' at start of each line and blank line in between the 2):
The part that I want to match is from "Copyright" to "Inc."
Code: Select all
<div class="smalltext" align="center">
   Copyright &copy;

   The Company Name &amp; Blah, Inc *All prices are subject to publisher revision
   &nbsp;
</div>



Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mmartin » Mon Jul 18, 2011 1:15 pm

Ok, so I think I just made a BIG leap forward. I got the following to give me an HTTP OK:

Code: Select all
# ./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r '\t[Copyright][&copy;]\n[The][Company][Name]'
HTTP OK: HTTP/1.1 200 OK - 90153 bytes in 0.013 second response time |time=0.013431s;;15.000000;0.000000 size=90153B;;;0


Now that that works I tried adding [&amp;] to the end of the one above and I get a CRITICAL Back???
Code: Select all
# ./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r '\t[Copyright][&copy;]\n[The][Company][Name][&amp;]'
HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 90153 bytes in 0.011 second response time |time=0.011387s;;15.000000;0.000000 size=90153B;;;0


Any ideas?


Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mmartin » Mon Jul 18, 2011 3:26 pm

Hey mguthrie,

Sorry about posting soo many time in a row before you come back with a reply. But I thought it be best to keep updated where I am at so you don't answer something that I already am passed.

I downloaded this module for Perl called Perl::PrefSuf, you might already know what it is.
But if you don't its a Perl Module that simply takes a string of words you give it and builds a REGEX for that exact string of words.

So I made a little test script and copied the string I wanted to find exactly as it is in the code, and pasted it into the script. Below the script is the regular expression that it generated:
**The Comapny Name is actually "J.W. Pepper & Son, Inc."

PreSuf Script:
Code: Select all
#!/usr/bin/env perl

use strict;
use warnings;

use Regex::PreSuf;

# Put in the words you want to match here
my @words = qw( Copyright &copy;

   J.W. Pepper &amp; Son, Inc. );

my $re = presuf( @words );
print "$re\n";


REGEX Generated From Script Output:
Code: Select all
(?:Copyright|Inc\.|J\.W\.|Pepper|Son\,|\&(?:amp|copy)\;)


Then I tried using that REGEX it gave me exactly as it is and put it into the command, and get a bash error. Output below:
Code: Select all
./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r (?:Copyright|Inc\.|J\.W\.|Pepper|Son\,|\&(?:amp|copy)\;)
-bash: syntax error near unexpected token `('


So I then removed the "( )" parenthesis and added ' ' single-quotes. Output below:
Code: Select all
./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r '?:Copyright|Inc\.|J\.W\.|Pepper|Son\,|\&(?:amp|copy)\;'
Could Not Compile Regular Expression: Invalid preceding regular expressioncheck_http: Could not parse arguments


Finally I kept the single-quotes but this time removed both of the "?:" (question-marks and colons). Output below:
Code: Select all
./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r 'Copyright|Inc\.|J\.W\.|Pepper|Son\,|\&(amp|copy)\;'
HTTP OK: HTTP/1.1 200 OK - 90097 bytes in 0.015 second response time |time=0.015230s;;15.000000;0.000000 size=90097B;;;0


So I guess I'm wondering if this worked correctly? Because I tried a REGEX in the Nagios command and in the middle of the string to match I added a word that is not on the page and it still came back with an "HTTP OK"? Let me know what your thoughts are... Thanks again.


Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Check_http to look for special symbols??

Postby mguthrie » Mon Jul 18, 2011 9:39 pm

Most regular expressions I've done need to start and end with a '/'. However, based on the nightmare that I find REGEX's to be, I try to use literal strings whenever possible ; )


Code: Select all
./check_http -H 192.168.4.100 -u /sheet-music/welcome.jsp -c 15 -l -r '/(?:Copyright|Inc\.|J\.W\.|Pepper|Son\,|\&(?:amp|copy)\;)/'


Otherwise, a literal string search of a single line might be easier. Do you need the multi-line expression, or will a single line suffice?
mguthrie
 
Posts: 4384
Joined: Mon Jun 14, 2010 10:21 am

Re: Check_http to look for special symbols??

Postby mmartin » Tue Jul 19, 2011 8:25 am

From what the source code of the page looks like, the line being searched for appears on 2 lines.
But on the actual page view it appears on one line, so I'm not exactly sure if I need the multi-line part.
But I'm pretty sure that it worked with and without the "-l" for multi-linespan.

Also, you are right I usually put my regexs between "/ /" too, but for some reason I get an error every time I tried using the backslashes.

Thanks,
Matt
mmartin
 
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Next

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 19 guests