#! /usr/local/bin/perl-w # A perl program to do read the notifAlarmTable use FileHandle; use IPC::Open2; use Symbol; # use Tk; use Sybase::CTlib; use Time::Local; use strict; my $dbAlarm=new Sybase::CTlib 'harmless','harmless','OPSYB1',''; $dbAlarm->ct_sql("use TomTest"); # # WARNING! UNTESTED CODE FOLLOWS!!! # # # Build the SQL statement. This statement will pull together # a list of all Topics, with their most current alarm start # ('WARNING') and alarm stop ('OK NOW'). # # The parsing of the SQL statement is left as an exercise for the # reader... # my $sql = "select q1.Topic, q2.DateTime, q3.DateTime from ( select Topic from notifAlarmEntry group by Topic ) q1 ( select Topic, Category, max(DateTime) from notifAlarmEntry where Category = 'WARNING' group by Topic, Category ) q2 ( select Topic, Category, max(DateTime) from notifAlarmEntry where Category = 'OK NOW' group by Topic, Category ) q3 where q1.Topic *= q2.Topic and q1.Topic *= q3.Topic order by nAE.Topic"; # # get an array containing all the records returned from # the SQL statement # my( @records ) = $dbAlarm->ct_sql( $sql ); # # look thru each retrieved record # foreach my $record ( @records ) { # # Put all the fields from the array entry into their own fields. # # Not really needed, but it's easier to understand what you # are doing if things have meaningful names. # # Note: I'm handling each field individually, but if you know # what the field separator is, then you can do the # following: # # my( $topic, # $alarm_start, # $alarm_stop ) = split( /X/o, $record ); # # (where X is the field separator). Since I don't know # Sybase::CTlib all that well (ok, at all), I just did the # simple thing. # my $topic = $record->[0]; my $alarm_start = $record->[1]; my $alarm_stop = $record->[2]; # if the 'ok now' date is from before the 'warning' date, # reset the 'ok now' date (since it isn't the message # associated with this warning) if ( $alarm_stop < $alarm_start ) { $alarm_stop = ""; } print "$topic $alarm_start $alarm_stop\n"; }