- additional functions for displaying the pcu.
[monitor.git] / www / printbadpcus.php
1 <?php 
2
3 function plc_site_link($site_name) 
4
5         return "https://www.planet-lab.org/db/sites/index.php?site_pattern=" .  $site_name;
6 }
7
8 function pcu_link($pcu) 
9
10         return "https://www.planet-lab.org/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') 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 'soltesz.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
199 //array_multisort($protocols, SORT_ASC, SORT_STRING, $pculist);
200 ?>
201
202 <title>PLC PCU Info</title>
203 <html>
204 <body>
205
206 Total PCUs : <?= $total ?>
207 <table border=1>
208                 <tr>
209                         <th>Count</th>
210                         <th><?= get_category_link("pcu_id", "PCU ID") ?></th>
211                         <th><?= get_category_link("login_base", "Site") ?></th>
212                         <th><?= get_category_link("hostname", "PCU Name") ?></th>
213                         <th><?= get_category_link("complete_entry", "Incomplete Fields") ?></th>
214                         <th><?= get_category_link("dnsmatch", "DNS Status") ?></th>
215                         <th><?= get_category_link("portstatus", "Port Status") ?></th>
216                         <th><?= get_category_link("reboot", "Dry Run Results") ?></th>
217                         <th><?= get_category_link("model", "Model") ?></th>
218                         <th><?= get_category_link("node_ids", "Nodes") ?></th>
219                 </tr>
220 <?php $count = 0; ?>
221 <?php $reachable_nodes = 0; ?>
222 <?php foreach ( $pculist as $pcu ): ?>
223                 <tr>
224                         <td><?= $count ?></td>
225                         <td id='id<?= $pcu['pcu_id'] ?>'><a href='<?= pcu_link($pcu) ?>'><?= $pcu['pcu_id'] ?></a></td>
226                         <td><a href='<?= plc_site_link(pcu_site($pcu)) ?>'><?= pcu_site($pcu) ?></a></td>
227                         <td><?= pcu_name($pcu) ?></td>
228                         <td><?= pcu_entry($pcu) ?></td>
229                         <td bgcolor='<?= DNS_to_color($pcu['dnsmatch']) ?>'><?= $pcu['dnsmatch'] ?></td>
230                         <td><?= format_ports($pcu) ?></td>
231                         <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= reboot_to_str($pcu['reboot']) ?></td>
232                         <td nowrap><?= $pcu['model'] ?></td>
233                         <td><?= count( $pcu['node_ids'] ) ?></td>
234                 </tr>
235
236 <?php if ( $pcu['reboot'] == "0" ) $reachable_nodes+=count($pcu['node_ids']); ?>
237 <?php $count += 1; ?>
238 <?php endforeach; ?>
239 </table>
240
241 <b>Reachable Nodes:</b> <?= $reachable_nodes ?>
242
243 </body>
244 </html>