Category: Mason


I’ve been using Sybase’s Workspace 1.7 for developing and maintaining a myriad of maintenance scripts, web pages, and other interesting things.  I ran into an interesting issue that is worthwhile to take note:
In most of the 3rd party plugins, the .components directory properly shows up in their perspectives.  For example, the EPIC plugin shows the .components directory in the project with no problems.
The EPIC Perl module's perspective shows the

None of Sybase’s eclipse plugins show the .components directory.  I believe this is based on the assumption that since Workspace only runs on windows, that dot directories are rare or nonexistent.  This is a minor bug but one that people should be aware of in case you think that Workspace ate your directory;-)
Any of the Sybase plugin Perspectives don't include the .components directory.

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)

View full article »

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!

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.

View full article »

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. :(