As a unix admin, I've played with a lot of systems to keep an eye on my servers to see if they're working correctly. One thing that's particularly irksome is making sure that all the customizations and features of your web servers are in place. For example, making sure that server side includes (ssi) works, but that ssi-exec is forbidden.

The obvious way to handle this is to write a web page that uses some normal ssi and also tries to run an ssi-exec command. Then you write a script that loads that page and checks for successfull ssi output from the normal command and also checks for the correct error message for the forbidden ssi exec.

This is a pain because you have to not only write the test pages but you also have to write the scripts that parse them.

The solution I've eventually reached is to write all my test web pages according to a strict format that not only encodes the tests but also the expected results. Then the scripts that I use to check the page don't have to know anything about the page to determine if the tests passed or failed.

The specific syntax I use for my test web pages isn't really that important, but here's what I use.

Heres an example:

<HTML> <HEAD><TITLE>SSI</TITLE></HEAD> <BODY> <H1>SSI TEST</H1> <H2>Basic SSI</H2> <H3>Foo</H3> <!--#set var="a_var" value="Foo"--> <H3><!--#echo var="a_var"--></H3> <H2>Exec Forbidden</H2> <H3>[an error occurred while processing this directive]</H3> <H3><!--#exec cmd="ls" --></H3> </BODY> </HTML>

I've written a perl module that I use internally that parses this kind of html and creates a handy object containing test results. It's still pretty rough, but it works. I've also written a nagios plugin that uses this module (and WOW does it make my job easier).

SO! My question to you monks is: is there any reason NOT to post this module to CPAN?

Replies are listed 'Best First'.
Re: Module Idea
by leocharre (Priest) on Aug 28, 2006 at 20:31 UTC

    I would personally think the thinng that can go very wrong here is the namespace. it sounds to me that your code solves a very specific problem.

    Perhals it shold be a script instead?
    If you think things here will be re-used.. then yeah.. module.

    How will I, as a developer, interact with your module? Does your program/system basically tell me if ssi-exec is forbidden or not? Then I suggest that this is *one* of a set of utilities or helper functions your module should provide.

    I can't freak out enough about the Namespace. Depending on what your code does. Do a search on CPAN for ssi, what do we get.. Doesn't seem to be anything about stats. You should look for Server Stats or something like that. I would say Apache.. Is SSI only available on Apache? Seems to me that your functinality fits in with App::Info::HTTPD::Apache.. no?

    if that does not do the trick - then write App::Info::HTTPD::Apache::SSI , maybe.

    Would I be able to interact with your code like:

    use App::Info::HTTPD::Apache::SSI qw(status); my $status = status(); print "ssi on? ". $status->{ssi_on}; print "ssi exec on? ". $status->{exec_on};

    What you suggest is interesting. I would love that for suexec etc.. Make the thing real open to what and how it can be asked, and conservative about how it talks back.

      I don't think I made myself quite clear. It's more of a test harness than a set of specific tests. You can use this to test if your php is working correctly, or if your cgi is working correctly, or anything that your web server does. I was using SSI as an example.

      I've written it as a module rather than as a script because I'd like it to be usable in various testing/monitoring systems. I've written a script that uses it for nagios, but I'd like it to be usable for mon, or anything else.

      As a developer, you would:

      1. Write a web page containing the tests (like my SSI example)
      2. Write a script that...
        1. uses LWP::UserAgent or similer (lynx -source ?) to get the html from that page
        2. feeds the html into my $cw = CheckWeb->new($html)
        3. Then use $cw to do something with the results, ala if ( $cw->all_pass ) { ... do something... }

      Does that make sense?

      P.S.

      I'm calling it CheckWeb in my own head for now. I'll ask for help coming up with a real name once I'm closer to releasing it.

Re: Module Idea
by rvosa (Curate) on Aug 26, 2006 at 17:20 UTC
    That's a pretty good idea. The only reason not to put it on CPAN would be if there's something sufficiently like this out there already. I'm not sure if that's the case.
Re: Module Idea
by Anonymous Monk on Aug 30, 2006 at 23:41 UTC
    I'd stay away from using standard HTML tags to be parsed by your script. I'd use
    classes or comments. This would give you more flexibility. If you use
    tags you could use stylesheets to show the tests for any page etc.

      How does that work? I'm confused. I don't really know what you mean by "classes and comments".

      I like using standard HTML because it's easy to write scripts that generate it.