ASNMTAP
view release on metacpan or search on metacpan
applications/htmlroot/cgi-bin/moderator/runStatusOnDemand.pl view on Meta::CPAN
# 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&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&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;
my $daemonPidStatus = ( ($status eq 'display') ? 'Display' : ( ($status eq 'collector') ? 'Collector' : 'importDataThroughCatalog' ) );
my $prefix = ( ( $status eq 'importDataThroughCatalog' ) ? '' : 'CT-');
my @daemonPidPathFilenames = glob("$PIDPATH/${daemonPidStatus}$prefix". ( $prefix eq '' ? '' : '*' ) ."\.pid");
foreach my $daemonPidPathFilename (@daemonPidPathFilenames) {
my $rvOpen = open(PID, "$daemonPidPathFilename");
if ($rvOpen) {
my $pid;
while (<PID>) { chomp; $pid = $_; }
close(PID);
if ( $prefix eq '' ) {
$daemonPidPathFilename =~ /^$PIDPATH\/(${daemonPidStatus})\.pid*/;
$daemonCaptureArrayName {$1} = -1;
$daemonCaptureArrayPid {$1} = $pid;
} else {
$daemonPidPathFilename =~ /^$PIDPATH\/${daemonPidStatus}${prefix}([\w-]+)\.pid*/;
$daemonCaptureArrayName {$1} = -1;
$daemonCaptureArrayPid {$1} = $pid;
}
}
}
for ($capture_array = 0; $capture_array < @capture_array; $capture_array++) {
my $capture = $capture_array[$capture_array];
chomp ($capture);
$capture =~ s/^\s+//g;
unless ( defined $daemonCaptureStatus ) {
if ($capture =~ /^Status: 'All ASNMTAP (Collectors|Displays|Import Data Through Catalog)' ...$/) {
$daemonCaptureHeader = $capture;
$daemonCaptureStatus = ( ($1 eq 'Displays') ? 'display' : ( ($1 eq 'Collectors') ? 'collector' : 'importDataThroughCatalog' ) );
$daemonCaptureParent = '';
}
} elsif ($capture =~ /^Status: '(?:Collector|Display|Import Data Through Catalog) ASNMTAP ([\w-]+)' is running$/) {
$daemonCaptureParent = $1;
$daemonCaptureArrayName {$1} = 1;
} elsif ($capture =~ /^Status: '(?:Collector|Display|Import Data Through Catalog) ASNMTAP ([\w-]+)' is not running$/) {
$daemonCaptureParent = '';
$daemonCaptureArrayName {$1} = 0;
} elsif ($capture =~ /\.\/$daemonCaptureStatus(?:-test)?\.pl/) {
applications/htmlroot/cgi-bin/moderator/runStatusOnDemand.pl view on Meta::CPAN
listAllProblems ('Parent', 'Running Parents', $daemonPidStatus, $prefix, \%daemonProcessTableParent, '(\.\/[\w-]+.pl)', 'kill', $debug);
listAllProblems ('Child', 'Running Childs', $daemonPidStatus, $prefix, \%daemonProcessTableChild, '^(sh -c cd ' .$PLUGINPATH. '; \.\/[\w-]+.pl)', 'kill', $debug);
listAllProblems ('SubChild', 'Running SubChilds', $daemonPidStatus, $prefix, \%daemonProcessTableSubChild, '^(' .$PERLCOMMAND. ' \.\/[\w-]+.pl)', 'kill', $debug);
} else {
print "<tr><td colspan=\"2\" class=\"RunStatusOnDemandCaptureDebug\">There are no UNKNOWN errors !!!</td></tr>\n";
}
} else {
print "<tr><th colspan=\"2\" class=\"RunStatusOnDemandCaptureHeader\">ERROR regarding 'All ASNMTAP $status'</th></tr>\n";
}
print "<tr><td> </td></tr>\n" if ($capture_array == 0);
print '</table><br>';
} else {
print '<br>No '. ucfirst($status) .' daemons defined.<br>';
}
} else {
print '<br>Select application for immediate launch.<br>';
}
print '<BR>', "\n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
print_legend (*STDOUT);
print '</BODY>', "\n", '</HTML>', "\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub listAllProblems {
my ($classType, $text, $daemonPidStatus, $prefix, $daemonProcessTableHash, $regex, $action, $debug) = @_;
print "<tr><td colspan=\"2\" class=\"RunStatusOnDemandCaptureRunning\">$text</td></tr>\n" if (keys (%$daemonProcessTableHash));
while ( my ($pid, $ppid) = each(%$daemonProcessTableHash) ) {
my $cmndline = (defined $regex and $daemonProcessTableCmndline {$pid} =~ /$regex/) ? $1 . ' ...' : $daemonProcessTableCmndline {$pid};
if ($iconDelete) {
if ($action eq 'remove') {
my $urlAction = "<A HREF=\"$urlWithAccessParameters&pid=<NIHIL>&ppid=<NIHIL>&command=$PIDPATH/${daemonPidStatus}${prefix}${pid}.pid&action=remove\"><IMG SRC=\"$IMAGESURL/$ICONSSYSTEM{pidRemove}\" ALT=\"Remove\" BORDER=0></A>";
print "<tr><td class=\"RunStatusOnDemandCapture$classType\">No running process for pidfile '$PIDPATH/${daemonPidStatus}${prefix}${pid}.pid' found</td><td class=\"RunStatusOnDemandCapture${classType}Action\">$urlAction</td></tr>\n";
} else {
my $urlAction = "<A HREF=\"$urlWithAccessParameters&pid=$pid&ppid=$ppid&command=killall&action=$action\"><IMG SRC=\"$IMAGESURL/$ICONSSYSTEM{pidKill}\" ALT=\"$action\" BORDER=0></A>";
printf($FORMATPSA, "RunStatusOnDemandCapture$classType", $pid, $ppid, $daemonProcessTablePctmem {$pid}, $daemonProcessTableSize {$pid}, $daemonProcessTableTtydev {$pid}, $daemonProcessTableState {$pid}, scalar(localtime($daemonProcessTableSta...
}
} else {
if ($action eq 'remove') {
print "<tr><td colspan=\"2\" class=\"RunStatusOnDemandCapture$classType\">No running process for pidfile '$PIDPATH/${daemonPidStatus}${prefix}${pid}.pid' found</td></tr>\n";
} else {
printf($FORMATPS, "RunStatusOnDemandCapture$classType", $pid, $ppid, $daemonProcessTablePctmem {$pid}, $daemonProcessTableSize {$pid}, $daemonProcessTableTtydev {$pid}, $daemonProcessTableState {$pid}, scalar(localtime($daemonProcessTableStar...
}
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub doRequestedActions {
my ($htmlTitle, $title, $command, $statusOK, $statusNOK, $debug) = @_;
print "<P class=\"RunStatusOnDemandHtmlTitle\">$htmlTitle: <font class=\"RunStatusOnDemandCommand\">$title</font></P><IMG SRC=\"".$IMAGESURL."/gears.gif\" HSPACE=\"0\" VSPACE=\"0\" BORDER=\"0\" NAME=\"Progress\" title=\"Please Wait ...\" alt=\"Plea...
my ($rStatus, $rStdout, $rStderr) = call_system ("$SSHCOMMAND -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=$WWWKEYPATH/.ssh/known_hosts' -i '$WWWKEYPATH/.ssh/ssh' $SSHLOGONNAME\@localhost '$command'", ($debug eq 'T') ? 1 : 0);
$rStderr =~ s/^stdin: is not a tty//;
chomp ($rStderr);
# my $message = ($rStderr) ? $rStderr : (($rStatus) ? $statusOK : $statusNOK);
my $message = ($rStderr) ? $rStderr : $statusOK;
print "<tr><td><pre>Status : '$rStatus'\n\nCommand: '$command'\n\nMessage: $message\n\nSTDOUT : '$rStdout'\n\nSTDERR : '$rStderr'></pre></tr></td></table>\n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( run in 0.532 second using v1.01-cache-2.11-cpan-5a3173703d6 )