Author Topic: Web Interface for Scheduler Inquiry  (Read 8760 times)

CKilgore

  • Professional
  • ***
  • Posts: 20
Web Interface for Scheduler Inquiry
« on: February 10, 2010, 09:57:24 AM »
Here are three scripts that put together a web interface (inquiry only) for the Prelude Scheduler.

UniBasic program to parse scheduler file
Code: [Select]
*  SCHED.STATUS
*  Scheduler Status
*  10/21/2009
*  Chris Kilgore | ckilgore@brake.com
*  Brake Supply Co., Inc.
*
*  Notes: Provides a '!~' seperated dump of scheduled jobs
*         Shows scheduled frequency, last and next runtime
*         Indicates currently running jobs
*         Indicates distribution method
   
   PROG.NAME = "SCHED.STATUS"
   ERMSG = ""
   OPEN "SCHEDULER" TO F.SCHED ELSE STOP
   OPEN "CONTROL" TO F.CONTROL ELSE STOP

   READ SCHED.REC FROM F.CONTROL,"001!SCHEDULE" ELSE SCHED.REC = ""   
   COUNTER = DCOUNT(SCHED.REC<1>,@VM)

   COLOR = 1

   FOR Y = 1 TO COUNTER
      SCHED.ID = "001!":SCHED.REC<1,Y>
      READ SCHED FROM F.SCHED,SCHED.ID THEN
     
         RUNNING.ID = SCHED.ID:"!Running"
         READ RUN.REC FROM F.SCHED,RUNNING.ID ELSE RUN.REC = ""

         PRE = ""
         POST = ""
         FREQ = ""
         RECUR = ""
         RUN.FLAG = ""
         RUN.START =""
         
         IF RUN.REC # "" THEN
            RUN.FLAG = "Y"
            RUN.START = RUN.REC<1>
         END
     

     
         PRINTER.NAME = SCHED<31,8>
         PRINTER.STAT = SCHED<31,9>
         SCHED.ID = SCHED.REC<1,Y>
         SLASH.COMMAND = SCHED.REC<2,Y>
         ITEM.NOTES = SCHED.REC<16,Y>
         LAST.RUN.DATE = SCHED.REC<6,Y>
         LAST.RUN.TIME = SCHED.REC<7,Y>
         NEXT.RUN.DATE = SCHED.REC<4,Y>
         NEXT.RUN.TIME = SCHED.REC<5,Y>
         IS.DONE = SCHED.REC<14,Y>

         
         RECUR = SCHED<33,7>
         FREQ = "Run Once"
         
         
         **Determine Schedule
         IF RECUR = "D" THEN
            FREQ = "DLY: "
            IF SCHED<33,8> # "" THEN
               FREQ := "Every ":SCHED<33,8>:" Day(s)"
            END
            IF SCHED<33,9> # "" THEN
               FREQ := "Every ":(SCHED<33,9>/60):" Minutes"
            END
            IF SCHED<33,10> = "Y" THEN
               FREQ := "Every Weekday"
            END
         END
         
         IF RECUR = "W" THEN
            FREQ = "WKLY: "
           
            IF SCHED<33,11> = "Y" THEN
               FREQ := "S"
            END ELSE
               FREQ := "-"
            END
            IF SCHED<33,12> = "Y" THEN
               FREQ := "M"
            END ELSE
               FREQ := "-"
            END
            IF SCHED<33,13> = "Y" THEN
               FREQ := "T"
            END ELSE
               FREQ := "-"
            END
            IF SCHED<33,14> = "Y" THEN
               FREQ := "W"
            END ELSE
               FREQ := "-"
            END
            IF SCHED<33,15> = "Y" THEN
               FREQ := "T"
            END ELSE
               FREQ := "-"
            END
            IF SCHED<33,16> = "Y" THEN
               FREQ := "F"
            END ELSE
               FREQ := "-"
            END                                   
            IF SCHED<33,17> = "Y" THEN
               FREQ := "S"
            END ELSE
               FREQ := "-"
            END
           
            IF SCHED<33,18> # "" THEN
               FREQ := " Every ":SCHED<33,18>:" Week(s)"
            END
         END
         
         IF RECUR = "M" THEN
            FREQ = "MLY: "
            IF SCHED<33,19> # "" THEN
               FREQ := "On day ":SCHED<33,19>
            END
            IF SCHED<33,20> # "" THEN
               FREQ := " every ":SCHED<33,20>:" month(s)"
            END
         
            IF SCHED<33,21> # "" THEN
               FREQ = "MLY: See Scheduler"
            END
         END
             
         
         **Argument String
         ARGS = SCHED<30>
         SWAP @VM WITH "&nbsp;|&nbsp;" IN ARGS
         
         OUTPUT.TYPE = SCHED<36,1>
         IF OUTPUT.TYPE="E" THEN
            PRINTER.NAME = SCHED<36,4>    ;  *EMAIL TO ADDRESS
            PRINTER.STAT = SCHED<36,3>    ;  *EMAIL FROM ADDRESS
            SWAP ";" WITH "<BR>" IN PRINTER.NAME
            SWAP "," WITH "<BR>" IN PRINTER.NAME
           
            PRE := "<FONT COLOR='BLUE'>"
            POST := "</FONT>"
         END
         
         IF PRINTER.NAME="EMAIL" THEN
            PRE := "<FONT COLOR='BLUE'>"
            POST := "</FONT>"
         END           

         IF PRINTER.NAME="DAILY" THEN
            PRE := "<B><FONT COLOR='GREEN'>"
            POST := "</B></FONT>"
         END           
         
         IF PRINTER.NAME="ATTACH" THEN
            PRE := "<B><FONT COLOR='RED'>"
            POST := "</B></FONT>"
         END 
         
         IF IS.DONE = "1" THEN
            PRE := "<s>"
            POST := "</s>"
         END
         
         IF RUN.FLAG = "Y" THEN
            PRE = "<B><FONT COLOR='ORANGE'>"
            POST = "</FONT></B>"
         END

         
         PRINT PRE:OUTPUT.TYPE:"-":SCHED.ID:POST:"!~":
         PRINT PRE:SLASH.COMMAND:POST:"!~":
         PRINT PRE:PRINTER.NAME:POST:"!~":
         PRINT PRE:PRINTER.STAT:POST:"!~":
         IF RUN.FLAG = "Y" THEN
            PRINT PRE:"Running":POST:"!~":
            PRINT PRE:RUN.START:POST:"!~":
         END ELSE
            PRINT PRE:OCONV(LAST.RUN.DATE,'D2/'):POST:"!~":
            PRINT PRE:OCONV(LAST.RUN.TIME,'MTH'):POST:"!~":
         END
         PRINT PRE:OCONV(NEXT.RUN.DATE,'D2/'):POST:"!~":
         PRINT PRE:OCONV(NEXT.RUN.TIME,'MTH'):POST:"!~":
         PRINT PRE:ITEM.NOTES:POST:"!~":
         PRINT PRE:FREQ:POST:"!~":
         PRINT PRE:ARGS:POST:"!~":     
         PRINT PRE:OUTPUT.TYPE:"-":SCHED.ID:POST:"!~":
         
         IF COLOR = 1 THEN
            COLOR = 0
            PRINT " bgcolor=#FFFFFF":"!~"
         END ELSE
            COLOR = 1
            PRINT " bgcolor=#DDDDDD":"!~"
         END
         
         PRINT   
      END   
   NEXT Y

   STOP

/var/www/cgi-bin/ script to parse output
Code: [Select]
#!/bin/bash
export TERM=vt100
echo Content-type: text/html
echo ""

SCHED.STATUS()
{
    printf "<h2>Scheduler Status<h2>"
    printf "<h4>"
    printf "<font color='blue'>BLUE</font>=Emailed | "
    printf "<font color='green'>GREEN</font>=Daily Report | "
    printf "<font color='orange'>ORANGE</font>=Running | "
    printf "<s>STRIKEOUT</s> =Done"
    printf "</h4>"
    printf "<table cellpadding=\"2\" cellspacing=\"0\" border=\"1\">"
    echo "<tr>"
    echo "<td><b>ID</b>"
    echo "<td><b>Command</b>"
    echo "<td><b>Printer/To</b>"
    echo "<td><b>Stationary/From</b>"
    echo "<td><b>Last Run Date</b>"
    echo "<td><b>Last Run Time</b>"
    echo "<td><b>Next Run Date</b>"
    echo "<td><b>Next Run Time</b>"
    echo "<td><b>Notes</b>"
    echo "<td><b>Frequency</b>"
    echo "<td><b>Arguments</b>"
    echo "<td><b>ID</b>"

    /usr/local/bin/ud SCHED.STATUS |
      awk -F"!~" '
        BEGIN{}
{print "<tr"$13">"
print "<td>"$1
print "<td>"$2
print "<td>"$3
print "<td>"$4
print "<td>"$5
print "<td>"$6
print "<td>"$7
print "<td>"$8
print "<td>"$9
print "<td>"$10
print "<td>"$11
print "<td>"$12}'

  printf "</table>"   
  return
}
 

printf "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""
printf "\"http://www.w3.org/TR/html4/loose.dtd\">"
printf "<html>"
printf "<head>"
printf "<title>"
printf "Scheduler Status"
printf "</title>"
printf "</head>"
printf "<body>"
printf "<pre>"

SCHED.STATUS

printf "</pre>"
printf "</body>"
printf "</html>"

exit 0

/usr/local/bin script called by cgi-bin script to call unibasic program
Code: [Select]
#!/bin/bash

#
# A little script to execute UniBasic programs
#

PROG="$*"
UDDIR="/ud/<<ACCOUNT>>"
UDT="/usr/udthome/bin/udt"
TMP="/tmp/ud.tmp$RANDOM"

cd $UDDIR
echo "$PROG" |
    $UDT > "$TMP" 
    NOLINES=`cat $TMP | wc -l`
    KEEP=$(($NOLINES-7))
    tail -$KEEP "$TMP" |
    grep -v -x ":" |
    grep -v "^$"

rm -f $TMP
exit 0
Chris Kilgore
Brake Supply Co., Inc.
Prelude ADS Version 20.2

CKilgore

  • Professional
  • ***
  • Posts: 20
Re: Web Interface for Scheduler Inquiry
« Reply #1 on: February 10, 2010, 10:11:12 AM »
If you have any questions as to how this works, feel free to email me at ckilgore@brake.com
Chris Kilgore
Brake Supply Co., Inc.
Prelude ADS Version 20.2

precisonline

  • President
  • Administrator
  • Rock Star
  • *****
  • Posts: 1612
    • Precision Solutions
Re: Web Interface for Scheduler Inquiry
« Reply #2 on: February 10, 2010, 10:29:52 AM »
Wow!  thanks for sharing!
-Kevin
Accidents "happen"; success, however, is planned and executed.

slestak

  • Uber-Pro
  • ****
  • Posts: 77
Re: Web Interface for Scheduler Inquiry
« Reply #3 on: February 10, 2010, 12:11:49 PM »
Nice script Chris.  You should post this to Pick Wiki.

Something I ran into out of the gate was to be careful which tail and grep are being used.  I have aix standards in their place and gnu tools at /opt/freeware/bin.

slestak

  • Uber-Pro
  • ****
  • Posts: 77
Re: Web Interface for Scheduler Inquiry
« Reply #4 on: February 10, 2010, 01:01:22 PM »
I am probably going to try to call this via Rex's u2pipe.

slestak

  • Uber-Pro
  • ****
  • Posts: 77
Re: Web Interface for Scheduler Inquiry
« Reply #5 on: February 12, 2010, 12:56:44 PM »
I have mine working as a cherrypy app getting data from unidata through u2pipe.  I want to template the html and then I;ll post it somewhere.

CKilgore

  • Professional
  • ***
  • Posts: 20
Re: Web Interface for Scheduler Inquiry
« Reply #6 on: February 12, 2010, 01:13:25 PM »
I'm interested in seeing what other people develop to accomplish this.  The scripts that I used really mix form and function.  I would have preferred to use XML and leave all the color coding on the php side.
Chris Kilgore
Brake Supply Co., Inc.
Prelude ADS Version 20.2

precisonline

  • President
  • Administrator
  • Rock Star
  • *****
  • Posts: 1612
    • Precision Solutions
Re: Web Interface for Scheduler Inquiry
« Reply #7 on: February 12, 2010, 03:37:04 PM »
Why XML and not JSON?  Just wondering, as JSON can do what XML can and for a smaller footprint.
-Kevin
Accidents "happen"; success, however, is planned and executed.

CKilgore

  • Professional
  • ***
  • Posts: 20
Re: Web Interface for Scheduler Inquiry
« Reply #8 on: February 19, 2010, 01:51:56 PM »
In the unibasic program, a job that has aborted is indicated by a '-1' in attribute 14 of the CONTROL record.
Chris Kilgore
Brake Supply Co., Inc.
Prelude ADS Version 20.2