An easy way to view maintenance logs using a browser

ASE, Mason, Perl, Sybase, mod_perl No Comments »

As part of our regular weekend maintenance for our Sybase database servers, we run many scripts, two of which are: update statistics and reorg/reindex.  In the past, if we wanted to show the output (log) of a maintenance script to someone outside of our group, we had to attach the log to an email and email to the person with instructions to open it using "write" or Microsoft Word and not Notepad because of the way unix/linux and windows handle new lines.  I wanted to get away from this painful ordeal by having the webserver find the logs and display them.  Now we just have to give the url to the person once. Cool

As we use Apache with mod_perl and Mason quite heavily, I decided the easiest way to do this is to create a component to obtain the list of the log files I’m interested in.  When I click on one of the files, instead of accessing the file semi-directly using a symbolic link to the file, a dhandle is called instead.  The dhandle catches the reorg/SISDBA1.out request, goes and reads the real file and spits it out.  If the file is an archived log (compressed), then we uncompress the file as we read it.

Adding a new series of log files are easy because the criteria we search for is a prefix in the filename.  Change the prefix in the index.html file, then the new log files are now viewable.  Of course, you will want to either modify the index.html file to handle multiple types of log files or just create another directory (i.e. dbccs) and copy the index.html & dhandler into it.

Adding a CSS template to this would be a simple matter.  In any case, enjoy!

Example: 

Update Statistics Logs

Server Current Log Archived Logs
DBADEV1 update_stats_DBADEV1.out  
SISDBA1 update_stats_SISDBA1.out update_stats_SISDBA1.out.1.gz (Wed Feb 7 09:50:02 2007)

Read the rest of this entry »

Listen to this podcast Listen to this podcast

disappearing alert override table SOLVED!

Mason, Perl, mod_perl No Comments »

At work, I created a web page that would raise alerts depending on various criteria and could be overridden by an entry in a db table.

Server Name Override Start Override End Authorized By Comments
my_server Nov 20 2006 3:24PM CST Dec 4 2006 12:00PM CST RG add space

Well, I solved it!  When you create a subroutine in Mason, it is stored in the HTML::Mason::Commands name space.  The problem is that some of our monitoring web pages would over write the subroutine in the name space.  So, I was looking for the wrong type of override!  Icorrected it by creating a single subroutine call (the subroutines were 99% identical).

I knew this but somehow overlooked it!  argh!

Listen to this podcast Listen to this podcast

Problem with filtered Mason code & db connection

ASE, DBI, Mason, Perl, Sybase, mod_perl No Comments »

Hi,

In chapter 5 (Advanced Features pgs 82,83) of Embedding Perl in HTML with Mason from O’Reilly, the"a simple SQL select expressed in something like a taglib style" example appears to be straight forward.  It is but it doesn’t seem to work too well.

The premise is that the ".components/sql/select" will filter the chunk of html code
    <&| .components/sql/select, query => ‘SELECT name, type FROM sysobjects’ &>
—-> here
        <tr>
            <td>%name</td>
            <td>%type</td>
        </tr>
—–>to here
     </&>

The select returns data correctly but the ".components/sql/select" doesn’t appear to be printing the code hmmmm….  see the very bottom for the answer… I didn’t catch it for awhile but later saw the cause and could have kicked myself.

Read the rest of this entry »

Listen to this podcast Listen to this podcast

Apache 2, mod_perl 2 and security (Apache2::Const)

Apache, Perl, mod_perl No Comments »

Problem:

I want to send a 404 (not found) error back to the browser when any ".*" or "*.mas" or "*handler" files are requested.  The example in the Mason book is for mod_perl v1 and so far, I haven’t been able to find a working example of how to send the 404 return code using Apache2::Const in an apache .conf file.

This wasn’t a small issue because it was a security hole that may have allowed for the viewing of the web page code and/or sensitive information.

Solution (/etc/httpd/conf.d/perl-HTML-Mason.conf):

<FilesMatch "(\.mas|handler)$">
    SetHandler perl-script
    PerlResponseHandler "sub { use Apache2::Const qw(NOT_FOUND); return NOT_FOUND }"
</FilesMatch>

<FilesMatch "^(\.)">
    SetHandler perl-script
    PerlResponseHandler "sub { use Apache2::Const qw(NOT_FOUND); return NOT_FOUND }"
</FilesMatch>

Notice that the Apache2::Const perl module is loaded in the anonymous subroutine and not preloaded.  Apparently mod_perl 2 doesn’t allow for Apache2::Const to be preloaded in the apache config file.

Listen to this podcast Listen to this podcast

Mason, mod_perl and DBI

ASE, DBI, Databases, Mason, Perl, Sybase, mod_perl 1 Comment »

I’m new to Mason and am having trouble printing a simple html table pulling data from a table on a database.  I know this has to do with scope but there has to be an easier way other than putting the entire dbms call (including printing the table) within a perl code section.

One thing I have noticed is the apparent lack of any useful information of using Mason with DBI connections.

This is how you do it if you wanted a single file to connect to the dbms and then spit out the result set:

< %shared>
    my %serverDump;

    my $dbh = DBI->connect("dbi:Sybase:server=mydb", ‘info’, ‘infopwd’, { RaiseError => 1, PrintError => 1 } );
    $dbh->do("use sybase_dba");

    my $query = "select serverName, min(dumpdate) from dbLastBackup group by serverName";

    my $sth = $dbh->prepare($query);
    $sth->execute or die "Error: unable to run query! " . $dbh->errstr;
   
<table Border=1>
  % while (my $row = $sth->fetchrow_arrayref ) {

    <tr>
      <td>< % $row->[0] %></td><td>< % $row->[1] %></td>
    </tr>

  % }
</table>

Note, don’t forget to uncomment "PerlSetVar MasonErrorMode fatal".  For some reason, no errors were being sent to the browser. :(

 

Listen to this podcast Listen to this podcast
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in
Close
E-mail It