Moved some files around and merged from 1.0 branch:
[monitor.git] / www / printbadpcus.php
1 <?php 
2
3 function plc_site_link($site_name) 
4
5         return "https://" . MONITOR_HOSTNAME . "/db/sites/index.php?site_pattern=" .  $site_name;
6 }
7
8 function pcu_link($pcu) 
9
10         return "https://" . MONITOR_HOSTNAME . "/db/sites/pcu.php?id=" . $pcu['pcu_id']; 
11 }
12
13 function pcu_site($pcu)
14 {
15         if ( array_key_exists('plcsite', $pcu) ):
16                 return $pcu['plcsite']['login_base'];
17         else: 
18                 return "none";
19         endif;
20 }
21
22 function pcu_name($pcu)
23 {
24         if ( $pcu['hostname'] != NULL and $pcu['hostname'] != "" ):
25                 return $pcu['hostname'];
26         else: 
27                 return $pcu['ip'];
28         endif;
29 }
30 function pcu_entry($pcu)
31 {
32         if ( count($pcu['complete_entry']) > 0 ) {
33                 return join("<BR>", $pcu['complete_entry']);
34         } else {
35                 return "&nbsp;";
36         }
37 }
38
39 function format_ports($pcu)
40 {
41         $str = "";
42         #print print_r(is_array($pcu)) . "<BR>";
43         #print print_r(array_key_exists('portstatus', $pcu)) . "<BR>";
44         if ( is_array($pcu) && array_key_exists('portstatus', $pcu) && count(array_keys($pcu['portstatus'])) > 0 )
45         {
46                 $portstat = $pcu['portstatus'];
47
48                 #foreach ( array('22', '23', '80', '443') $portstat as $port => $state)
49                 foreach ( array('22', '23', '80', '443', '9100',  '16992') as $port)
50                 {
51                         $state = $portstat[$port];
52                         switch ($state)
53                         {
54                                 case "open":
55                                         $color = "lightgreen";
56                                         break;
57                                 case "filtered":
58                                         $color = "gold";
59                                         break;
60                                 case "closed":
61                                         $color = "indianred";
62                                         break;
63                                 default:
64                                         $color = "white";
65                                         break;
66                         }
67                         $str .= "<span style='background-color: $color'>$port</span>&nbsp;"; 
68                         #  . ":&nbsp;" . $state . "<br>";
69                 }
70         } else {
71         #       print print_r(is_array($pcu)) . "<BR>";
72         #       print print_r(array_key_exists('portstatus', $pcu)) . "<BR>";
73                 #echo "<pre>";
74                 #print_r($pcu['portstatus']);
75                 #echo "</pre>";
76         }
77         if ( $str == "" )
78         {
79                 $str = "Closed/Filtered";
80         }
81         return $str;
82 }
83 function DNS_to_color($dns)
84 {
85         switch ($dns)
86         {
87                 case "DNS-OK":
88                         return 'lightgreen';
89                 case "NOHOSTNAME":
90                         return 'white';
91                 case "DNS-MISMATCH":
92                         return 'gold';
93                 case "NO-DNS-OR-IP":
94                 case "DNS-NOENTRY":
95                         return 'indianred';
96         }
97         return 'white';
98 }
99 function reboot_to_str($reboot)
100 {
101         $ret = $reboot;
102         switch ($reboot)
103         {
104                 case "0":
105                         $ret = "OK";
106                         break;
107                 default:
108                         break;
109         }
110         return $ret;
111 }
112
113 function reboot_to_color($reboot)
114 {
115         switch ($reboot)
116         {
117                 case "0":
118                         return "darkseagreen";
119                         break;
120                 case "NetDown":
121                         return "lightgrey";
122                         break;
123                 case "Not_Run":
124                         return "lightgrey";
125                         break;
126                 case "Unsupported_PCU":
127                         return "indianred";
128                         break;
129                 default:
130                         if ( strpos($reboot, "error") >= 0)
131                         {
132                                 return "indianred";
133                         } else {
134                                 return 'white';
135                         }
136                         break;
137         }
138         return "white";
139 }
140
141 function get_pcuid($pcu) { return $pcu['pcu_id']; }
142 function get_dns($pcu) { return $pcu['dnsmatch']; }
143 function get_dryrun($pcu) { return $pcu['reboot']; }
144 function get_model($pcu) { return $pcu['model']; }
145 function get_category_link($category,$header) 
146
147         return "<a href='printbadpcus.php?category=$category'>$header</a>"; 
148 }
149
150 include 'database.php';
151 $p = new Pickle();
152 $findbad = $p->load("findbadpcus");
153 $findbadpcus = array_keys($findbad['nodes']);
154
155 $pculist = array();
156 $c = 0;
157 foreach ( $findbadpcus as $pcu_id )
158 {
159         if ( is_array($findbad['nodes'][$pcu_id]) ) 
160         {
161                 #if ( in_array('values', $findbad['nodes'][$pcu]) )
162                 #{
163                 #       echo $pcu . " true<BR>";
164                 #} else{
165                 #       echo $pcu . " false<br>";
166                 #}
167                 if ( array_key_exists('values', $findbad['nodes'][$pcu_id]) )
168                 {
169                         $pculist[] = $findbad['nodes'][$pcu_id]['values'];
170                 }
171         }
172 }
173 $total = count($pculist);
174
175
176
177 if ( $_GET['category'] ) 
178 {
179         $category = $_GET['category'];
180         if ( $category == "node_ids" )
181         {
182                 $newfunc = create_function('$pcu', 'return count($pcu[\'' . $category . '\']);');
183         } else if ( $category == "login_base" )
184         {
185                 $newfunc = create_function('$pcu', 'return $pcu[\'plcsite\'][\'' . $category . '\'];');
186         } else {
187                 $newfunc = create_function('$pcu', 'return $pcu[\'' . $category . '\'];');
188         }
189         if ( $newfunc != "" )
190         {
191                 $fields = array_map($newfunc, $pculist);
192                 array_multisort($fields, SORT_ASC, SORT_STRING, $pculist);
193         } else {
194                 echo "ERROR create_function == null<BR>";
195         }
196 }
197
198 if ( $_REQUEST['id'] )
199 {
200         $id = $_REQUEST['id'];
201 } else{
202         $id = "all";
203 }
204 #print print_r($_SERVER) . "<BR>";
205
206 //array_multisort($protocols, SORT_ASC, SORT_STRING, $pculist);
207 ?>
208
209 <title>PLC PCU Info</title>
210 <html>
211 <body>
212
213 <?php if ( $id == "all" ): ?>
214         Total PCUs : <?= $total ?>
215         <table border=1>
216                         <tr>
217                                 <th>Count</th>
218                                 <th><?= get_category_link("pcu_id", "PCU ID") ?></th>
219                                 <th><?= get_category_link("login_base", "Site") ?></th>
220                                 <th><?= get_category_link("hostname", "PCU Name") ?></th>
221                                 <th><?= get_category_link("complete_entry", "Incomplete Fields") ?></th>
222                                 <th><?= get_category_link("dnsmatch", "DNS Status") ?></th>
223                                 <th><?= get_category_link("portstatus", "Port Status") ?></th>
224                                 <th><?= get_category_link("reboot", "Test Results") ?></th>
225                                 <th><?= get_category_link("model", "Model") ?></th>
226                                 <th><?= get_category_link("node_ids", "Nodes") ?></th>
227                         </tr>
228         <?php $count = 0; ?>
229         <?php $reachable_nodes = 0; ?>
230         <?php foreach ( $pculist as $pcu ): ?>
231                         <tr>
232                                 <td><?= $count ?></td>
233                                 <td id='id<?= $pcu['pcu_id'] ?>'><a href='<?= pcu_link($pcu) ?>'><?= $pcu['pcu_id'] ?></a></td>
234                                 <td><a href='<?= plc_site_link(pcu_site($pcu)) ?>'><?= pcu_site($pcu) ?></a></td>
235                                 <td><?= pcu_name($pcu) ?></td>
236                                 <td><?= pcu_entry($pcu) ?></td>
237                                 <td bgcolor='<?= DNS_to_color($pcu['dnsmatch']) ?>'><?= $pcu['dnsmatch'] ?></td>
238                                 <td><?= format_ports($pcu) ?></td>
239                                 <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= reboot_to_str($pcu['reboot']) ?></td>
240                                 <td nowrap><?= $pcu['model'] ?></td>
241                                 <td><?= count( $pcu['node_ids'] ) ?></td>
242                         </tr>
243
244         <?php if ( $pcu['reboot'] == "0" ) $reachable_nodes+=count($pcu['node_ids']); ?>
245         <?php $count += 1; ?>
246         <?php endforeach; ?>
247         </table>
248         <b>Reachable Nodes:</b> <?= $reachable_nodes ?>
249 <?php else: ?>
250         <table align=center border=1>
251                         <tr>
252                                 <th><?= get_category_link("pcu_id", "PCU ID") ?></th>
253                                 <th><?= get_category_link("login_base", "Site") ?></th>
254                                 <th><?= get_category_link("hostname", "PCU Name") ?></th>
255                                 <th><?= get_category_link("complete_entry", "Incomplete Fields") ?></th>
256                                 <th><?= get_category_link("dnsmatch", "DNS Status") ?></th>
257                                 <th><?= get_category_link("portstatus", "Port Status") ?></th>
258                                 <th><?= get_category_link("reboot", "Test Results") ?></th>
259                                 <th><?= get_category_link("model", "Model") ?></th>
260                                 <th><?= get_category_link("node_ids", "Nodes") ?></th>
261                         </tr>
262         <?php $count = 0; ?>
263         <?php $reachable_nodes = 0; ?>
264         <?php foreach ( $pculist as $pcu ): ?>
265                 <?php if ( $pcu['pcu_id'] == $id ): ?>
266                         <tr>
267                                 <td id='id<?= $pcu['pcu_id'] ?>'><a href='<?= pcu_link($pcu) ?>'><?= $pcu['pcu_id'] ?></a></td>
268                                 <td><a href='<?= plc_site_link(pcu_site($pcu)) ?>'><?= pcu_site($pcu) ?></a></td>
269                                 <td><?= pcu_name($pcu) ?></td>
270                                 <td><?= pcu_entry($pcu) ?></td>
271                                 <td bgcolor='<?= DNS_to_color($pcu['dnsmatch']) ?>'><?= $pcu['dnsmatch'] ?></td>
272                                 <td><?= format_ports($pcu) ?></td>
273                                 <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= reboot_to_str($pcu['reboot']) ?></td>
274                                 <td nowrap><?= $pcu['model'] ?></td>
275                                 <td><?= count( $pcu['node_ids'] ) ?></td>
276                         </tr>
277                 <?php endif; ?>
278         <?php endforeach; ?>
279         </table>
280         <br>
281         <table border=1 align=center>
282                 <tr><th colspan=2>Legend for 'DNS Status'</th></tr>
283
284                 <tr><td bgcolor=lightgreen>DNS-OK</td>
285                         <td>This indicates that the DNS name and registered IP address match.</td>
286                 </tr>
287                 <tr><td bgcolor=lightgrey>DNS-MISMATCH</td>
288                         <td>Sometimes, the registered IP and DNS IP address do not match.  In these cases it is not clear which is correct, 
289                                 so an error is flagged.</td>
290                 </tr>
291                 <tr><td bgcolor=lightgrey>DNS-NOENTRY</td>
292                         <td>While a hostname is provided in the registration, the hostname is not actually registered in DNS.</td>
293                 </tr>
294                 <tr><td bgcolor=white>NOHOSTNAME</td>
295                         <td>While we prefer that a hostname be registered, it is not
296                         strictly required, since simply the IP address, if it is static, is enough to access the PCU.</td>
297                 </tr>
298         <!--/table>
299         <table border=1-->
300                 <tr><th colspan=2>Legend for 'Port Status'</th></tr>
301
302                 <tr><td bgcolor=lightgreen>Open</td>
303                         <td>Green port numbers are believed to be open.</td>
304                 </tr>
305                 <tr><td bgcolor=gold>Filtered</td>
306                         <td>Gold port numbers are believed to be filtered or simply offline.</td>
307                 </tr>
308                 <tr><td bgcolor=indianred>Closed</td>
309                         <td>Finally, red ports appear to be closed.</td>
310                 </tr>
311         <!--/table>
312         <table border=1-->
313                 <tr><th colspan=2>Legend for 'Test Results'</th></tr>
314
315                 <tr><td bgcolor=darkseagreen>OK</td>
316                         <td>The PCU is accessible, and short of actually rebooting the node, everything appears to work.</td>
317                 </tr>
318                 <tr><td bgcolor=lightgrey>NetDown</td>
319                         <td>The PCU is inaccessible from the PlanetLab address block 128.112.139.0/25, or it is simply offline.</td>
320                 </tr>
321                 <tr><td bgcolor=lightgrey>Not_Run</td>
322                         <td>Previous errors, such as DNS or an incomplete configuration prevented the actual test from begin performed.</td>
323                 </tr>
324                 <tr><td bgcolor=indianred>Other Errors</td>
325                         <td>Other errors are reported by the test that are more specific to the block encountered by the script.</td>
326                 </tr>
327         </table>
328 <?php endif; ?>
329
330
331 </body>
332 </html>