ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/moderator/runStatusOnDemand.pl  view on Meta::CPAN

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use vars qw($PROGNAME);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$PROGNAME       = "runStatusOnDemand.pl";
my $prgtext     = "Run status Collector/Display on demand for the '$APPLICATION'";
my $version     = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; # must be all on one line or MakeMaker will get confused.

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use CGI;
use DBI;
use Shell;
use Date::Calc qw(Delta_Days);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# URL Access Parameters
my $cgi = new CGI;
my $pagedir    = (defined $cgi->param('pagedir'))   ? $cgi->param('pagedir')   : '<NIHIL>';   $pagedir =~ s/\+/ /g;
my $pageset    = (defined $cgi->param('pageset'))   ? $cgi->param('pageset')   : 'moderator'; $pageset =~ s/\+/ /g;
my $debug      = (defined $cgi->param('debug'))     ? $cgi->param('debug')     : 'F';
my $status     = (defined $cgi->param('status'))    ? $cgi->param('status')    : '<NIHIL>';   $status  =~ s/\+/ /g;
my $action     = (defined $cgi->param('action'))    ? $cgi->param('action')    : '<NIHIL>';
my $Cpid       = (defined $cgi->param('pid'))       ? $cgi->param('pid')       : -1;
my $Cppid      = (defined $cgi->param('ppid'))      ? $cgi->param('ppid')      : -1;
my $Ccommand   = (defined $cgi->param('command'))   ? $cgi->param('command')   : '<NIHIL>';

my $command    = '';

my $FORMATPSA  = "<tr><td class=\"%s\">%s %s %s %s %s %s %s %s</td><td class=\"%s\">%s</td></tr>\n";
my $FORMATPS   = "<tr><td colspan=\"2\" class=\"%s\">%s %s %s %s %s %s %s %s</td>\n";

my (%daemonProcessTableCmndline, %daemonProcessTablePctmem, %daemonProcessTableSize, %daemonProcessTableTtydev, %daemonProcessTableStart, %daemonProcessTableState) = ();

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $htmlTitle = $APPLICATION;

# User Session and Access Control
my ($sessionID, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $iconQuery, $iconTable, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, $userType, undef, undef, undef, $subTitle) = user_session_and_access_control (1, 'modera...

# Serialize the URL Access Parameters into a string
my $urlAccessParameters = "pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&status=$status";

# Debug information
print "<pre>pagedir     : $pagedir<br>pageset     : $pageset<br>debug       : $debug<br>status      : $status<br>action      : $action<br>pid         : $Cpid<br>ppid        : $Cppid<br>command     : $Ccommand<br>URL ...     : $urlAccessParameters</pr...

my $urlWithAccessParameters = $ENV{SCRIPT_NAME} . "?pagedir=$pagedir&amp;pageset=$pageset&amp;debug=$debug&amp;CGISESSID=$sessionID&amp;status=$status";

unless ( defined $errorUserAccessControl ) {
  # 'Moderator' = 2, 'Administrator' = 4 & 'Server Administrator' = 8
  if ($userType >= 4) {
    ($iconAdd, $iconDelete, $iconDetails, $iconEdit) = (1, 1, 1, 1);
  } else {
    ($iconAdd, $iconDelete, $iconDetails, $iconEdit) = (0, 0, 0, 0);
  }

  my $typeStatusSelect = create_combobox_from_keys_and_values_pairs ('collector=>Collectors|display=>Displays|importDataThroughCatalog=>Import Data Through Catalog', 'K', 0, $status, 'status', 'none', '-Select-', '', '', $debug);

  # HTML  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  my $onload = ($status ne '<NIHIL>') ? "ONLOAD=\"if (document.images) document.Progress.src='".$IMAGESURL."/spacer.gif';\"" : '';
  print_header (*STDOUT, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, $onload, 'F', '', $sessionID);

  print <<EndOfHtml;
  <BR>
  <form action="$ENV{SCRIPT_NAME}" name="params">
    <input type="hidden" name="pagedir"   value="$pagedir">
    <input type="hidden" name="pageset"   value="$pageset">
    <input type="hidden" name="CGISESSID" value="$sessionID">
    <input type="hidden" name="debug"     value="$debug">
    <table border=0>
	  <tr align="left"><td>Status:</td><td>$typeStatusSelect</td></tr>
      <tr align="left"><td align="right"><br><input type="submit" value="Launch"></td><td><br><input type="reset" value="Reset"></td></tr>
    </table>
  </form>
  <HR>
EndOfHtml

  if ($action eq 'kill') {
    doRequestedActions ($htmlTitle, "$Ccommand $Cpid", "$Ccommand $Cpid", "Process(es) killed.", "Process(es) not killed.", $debug);
  } elsif ($action =~ /^(?:start|stop|reload|restart)$/) {
    doRequestedActions ($htmlTitle, "script $Ccommand $action", "script $Ccommand $action", "$Ccommand ${action}ed.", "$Ccommand not ${action}ed.", $debug);
  } elsif ($action eq 'remove') {
    doRequestedActions ($htmlTitle, "remove $Ccommand", "remove $Ccommand", "$Ccommand removed.", "$Ccommand not removed.", $debug);
  } elsif ($status ne '<NIHIL>') {
    my $binMasterOrSlave = '<NIHIL>';

    if (-s "$APPLICATIONPATH/master/asnmtap-$status.sh") {
      $binMasterOrSlave = 'master';
    } elsif (-s "$APPLICATIONPATH/slave/asnmtap-$status.sh") {
      $binMasterOrSlave = 'slave';
    } elsif (-s "$APPLICATIONPATH/bin/asnmtap-$status.sh") {
      $binMasterOrSlave = 'bin';
    }

    if ($binMasterOrSlave ne '<NIHIL>') {
      my ($capture_array, $daemonCaptureHeader, $daemonCaptureStatus, $daemonCaptureParent);
      my (%daemonCaptureArrayName, %daemonCaptureArrayPid, %daemonCaptureArrayParent) = ();
      my (%daemonProcessTableParent, %daemonProcessTableChild, %daemonProcessTableSubChild) = ();

      $command = "asnmtap-$status.sh status";
      print "<P class=\"RunStatusOnDemandHtmlTitle\">$htmlTitle: <font class=\"RunStatusOnDemandCommand\">$APPLICATIONPATH/$binMasterOrSlave/$command</font></P><IMG SRC=\"".$IMAGESURL."/gears.gif\" HSPACE=\"0\" VSPACE=\"0\" BORDER=\"0\" NAME=\"Progre...

      my $_ppid = 1;

      if (-e '/usr/bin/zonename') { # Solaris 10 root into an non global zone where pid != 1 & pid == ppid 
        my $zonename = `/usr/bin/zonename`;

        if ( $zonename ne 'global' ) {
          $_ppid = `ps -e -o 'pid ppid zone fname' | grep zsched | awk '{print \$1}'`;
        }
      }

      my @capture_array = `cd $APPLICATIONPATH/$binMasterOrSlave; $PERLCOMMAND $command 2>&1`;

      use Proc::ProcessTable;
      my $tProcessTable = new Proc::ProcessTable;



( run in 1.478 second using v1.01-cache-2.11-cpan-2398b32b56e )