boot manager log upload revival (formerly known as alpina-logs)
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 17 Nov 2008 14:03:04 +0000 (14:03 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 17 Nov 2008 14:03:04 +0000 (14:03 +0000)
boot/upload-bmlog.php [new file with mode: 0755]
nodeconfig.spec

diff --git a/boot/upload-bmlog.php b/boot/upload-bmlog.php
new file mode 100755 (executable)
index 0000000..4584111
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+
+  // Thierry Parmentelat -- INRIA
+  // first draft for a revival of former (3.x?) alpina-logs in 5.0
+
+  // this needs be created with proper permissions at package install time
+$logdir="/var/log/bm";
+$limit_bytes=16*1024;
+
+function mkdir_if_needed ($dirname) {
+  if (is_dir ($dirname))
+    return;
+  mkdir ($dirname) or die ("Cannot create dir " . $dirname);
+}
+  
+// Get admin API handle
+require_once 'plc_api.php';
+global $adm;
+
+// find the node that these longs should belong to by looking for a node_id
+// with an ip the same as the http requestor ip
+$ip = $_SERVER['REMOTE_ADDR'];
+
+$hostname="unknown";
+// locate hostname from DB based on this IP
+$interfaces=$adm->GetInterfaces(array("ip"=>$ip));
+if (! empty($interfaces) ) {
+  $interface=$interfaces[0];
+  $node_id=$interface['node_id'];
+  $nodes=$adm->GetNodes($node_id,array("hostname"));
+  if (!empty($nodes)) {
+    $hostname=$nodes[0]['hostname'];
+  }
+ }
+
+// store the actual data in /var/log/bm/raw/2008-11-31-20-02-onelab01.inria.fr-138.96.250.141.txt
+
+$rawdir=$logdir . "/raw";
+$date=strftime("%Y-%m-%d-%H-%M");
+$log_name=$rawdir . "/" . $date . "-" . $hostname . "-" . $ip . ".txt";
+$month=strftime("%Y-%m");
+$time=strftime("%d-%H-%M");
+
+mkdir_if_needed ($rawdir);
+
+////////////////////////////////////////
+
+$log=fopen($log_name,"w") or die ("Cannot open logfile "+$log_name);
+
+$uploaded_name= $_FILES['log']['tmp_name'];
+$uploaded_size=filesize($uploaded_name);
+
+fprintf ($log, "BootManager log created on: %s-%s\n",$month,$time);
+fprintf( $log, "From IP: %s\n",$ip);
+fprintf( $log, "hostname: %s\n",$hostname);
+fprintf ( $log, "uploaded file: %s (%d bytes)\n",$uploaded_name,$uploaded_size);
+if ( $uploaded_size >= $limit_bytes) {
+  fprintf ( $log, "contents truncated to %d bytes\n",$limit_bytes);
+  $truncated=TRUE;
+  $uploaded_size=$limit_bytes;
+ }
+
+fprintf( $log, "-----------------\n\n" );
+$uploaded = fopen($uploaded_name,'r');
+$contents = fread($uploaded, $uploaded_size);
+fclose($uploaded);
+fwrite($log,$contents);
+if ($truncated)
+  fwrite ($log, " ..<truncated>..\n");
+fclose($log);
+
+////////////////////////////////////////
+
+// create symlinks for easy browsing
+
+// /var/log/bm/per-month/2008-11/onelab1.inria.fr/31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-month";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $month;
+mkdir_if_needed ($linkdir);
+$linkdir = $linkdir . "/" . $hostname;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $time ;
+symlink ($log_name,$link);
+
+# /var/log/bm/per-hostname/onelab1.inria.fr/2008-11-31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-hostname";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $hostname;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $month . "-" . $time ;
+symlink ($log_name,$link);
+
+# /var/log/bm/per-ip/138.96.250.141/2008-11-31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-ip";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $ip;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $month . "-" . $time ;
+symlink ($log_name,$link);
+
+?>
index a6bcd07..3978bbe 100644 (file)
@@ -27,6 +27,8 @@ URL: %(echo %{url} | cut -d ' ' -f 2)
 # We use set everywhere
 Requires: php >= 5.0
 Requires: PLCAPI >= 5.0
+# need the apache user at install-time
+Requires: httpd 
 
 %description
 
@@ -82,6 +84,11 @@ install -D -m 644 ./yum/%{distroname}/yum.conf                    $RPM_BUILD_ROOT/var/www/htm
 # expose the (fcdistro-dependant) stock.repo as                                    https://<plc>/yum/stock.repo
 install -D -m 644 ./yum/%{distroname}/yum.myplc.d/stock.repo $RPM_BUILD_ROOT/var/www/html/yum/stock.repo
 
+# the boot manager upload area
+mkdir -p /var/log/bm
+chown apache:apache /var/log/bm
+chmod 700 /var/log/bm
+
 popd
 
 %clean