- additional functions for displaying the pcu.
[monitor.git] / www / printbadpcus.php
index fb86fa3..c2d8daa 100644 (file)
@@ -1,11 +1,24 @@
 <?php 
 
+function plc_site_link($site_name) 
+{ 
+       return "https://www.planet-lab.org/db/sites/index.php?site_pattern=" .  $site_name;
+}
 
 function pcu_link($pcu) 
 { 
        return "https://www.planet-lab.org/db/sites/pcu.php?id=" . $pcu['pcu_id']; 
 }
 
+function pcu_site($pcu)
+{
+       if ( array_key_exists('plcsite', $pcu) ):
+               return $pcu['plcsite']['login_base'];
+       else: 
+               return "none";
+       endif;
+}
+
 function pcu_name($pcu)
 {
        if ( $pcu['hostname'] != NULL and $pcu['hostname'] != "" ):
@@ -28,7 +41,7 @@ function format_ports($pcu)
        $str = "";
        #print print_r(is_array($pcu)) . "<BR>";
        #print print_r(array_key_exists('portstatus', $pcu)) . "<BR>";
-       if ( is_array($pcu) && array_key_exists('portstatus', $pcu) )
+       if ( is_array($pcu) && array_key_exists('portstatus', $pcu) && count(array_keys($pcu['portstatus'])) > 0 )
        {
                $portstat = $pcu['portstatus'];
 
@@ -83,6 +96,19 @@ function DNS_to_color($dns)
        }
        return 'white';
 }
+function reboot_to_str($reboot)
+{
+       $ret = $reboot;
+       switch ($reboot)
+       {
+               case "0":
+                       $ret = "OK";
+                       break;
+               default:
+                       break;
+       }
+       return $ret;
+}
 
 function reboot_to_color($reboot)
 {
@@ -147,22 +173,16 @@ foreach ( $findbadpcus as $pcu_id )
 $total = count($pculist);
 
 
-## Sort the pculist
-
-#$pcu_ids = array_map('get_pcuid', $pculist);
-#array_multisort($pcu_ids, SORT_ASC, SORT_NUMERIC, $pculist);
-
-#$dns_ids = array_map('get_dns', $pculist);
-#array_multisort($dns_ids, SORT_ASC, SORT_STRING, $pculist);
 
-#$dry_ids = array_map('get_dryrun', $pculist);
-#array_multisort($dry_ids, SORT_ASC, SORT_STRING, $pculist);
 if ( $_GET['category'] ) 
 {
        $category = $_GET['category'];
        if ( $category == "node_ids" )
        {
                $newfunc = create_function('$pcu', 'return count($pcu[\'' . $category . '\']);');
+       } else if ( $category == "login_base" )
+       {
+               $newfunc = create_function('$pcu', 'return $pcu[\'plcsite\'][\'' . $category . '\'];');
        } else {
                $newfunc = create_function('$pcu', 'return $pcu[\'' . $category . '\'];');
        }
@@ -175,13 +195,6 @@ if ( $_GET['category'] )
        }
 }
 
-if ( $_GET['auth'] )
-{
-       $auth = True;
-} else {
-       $auth = False;
-}
-
 
 //array_multisort($protocols, SORT_ASC, SORT_STRING, $pculist);
 ?>
@@ -195,40 +208,37 @@ Total PCUs : <?= $total ?>
                <tr>
                        <th>Count</th>
                        <th><?= get_category_link("pcu_id", "PCU ID") ?></th>
-                       <th><?= get_category_link("hostname", "Hostname") ?></th>
+                       <th><?= get_category_link("login_base", "Site") ?></th>
+                       <th><?= get_category_link("hostname", "PCU Name") ?></th>
                        <th><?= get_category_link("complete_entry", "Incomplete Fields") ?></th>
                        <th><?= get_category_link("dnsmatch", "DNS Status") ?></th>
                        <th><?= get_category_link("portstatus", "Port Status") ?></th>
                        <th><?= get_category_link("reboot", "Dry Run Results") ?></th>
                        <th><?= get_category_link("model", "Model") ?></th>
                        <th><?= get_category_link("node_ids", "Nodes") ?></th>
-                       <?php if ( $auth ): ?>
-                               <th>Username</th>
-                               <th>Password</th>
-                               <th>Notes</th>
-                       <?php endif; ?>
                </tr>
 <?php $count = 0; ?>
+<?php $reachable_nodes = 0; ?>
 <?php foreach ( $pculist as $pcu ): ?>
                <tr>
                        <td><?= $count ?></td>
                        <td id='id<?= $pcu['pcu_id'] ?>'><a href='<?= pcu_link($pcu) ?>'><?= $pcu['pcu_id'] ?></a></td>
+                       <td><a href='<?= plc_site_link(pcu_site($pcu)) ?>'><?= pcu_site($pcu) ?></a></td>
                        <td><?= pcu_name($pcu) ?></td>
                        <td><?= pcu_entry($pcu) ?></td>
                        <td bgcolor='<?= DNS_to_color($pcu['dnsmatch']) ?>'><?= $pcu['dnsmatch'] ?></td>
                        <td><?= format_ports($pcu) ?></td>
-                       <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= $pcu['reboot'] ?></td>
+                       <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= reboot_to_str($pcu['reboot']) ?></td>
                        <td nowrap><?= $pcu['model'] ?></td>
                        <td><?= count( $pcu['node_ids'] ) ?></td>
-                       <?php if ( $auth ): ?>
-                               <td><?= ( $pcu['username'] ? $pcu['username'] : "&nbsp;" ) ?></td>
-                               <td><?= $pcu['password'] ?></td>
-                               <td><?= $pcu['notes'] ?></td>
-                       <?php endif; ?>
                </tr>
+
+<?php if ( $pcu['reboot'] == "0" ) $reachable_nodes+=count($pcu['node_ids']); ?>
 <?php $count += 1; ?>
 <?php endforeach; ?>
 </table>
 
+<b>Reachable Nodes:</b> <?= $reachable_nodes ?>
+
 </body>
 </html>