www interface and support libraries for some of monitor's data. Specifically:
[monitor.git] / www / printbadpcus.php
1 <?php 
2
3
4 function pcu_link($pcu) 
5
6         return "https://www.planet-lab.org/db/sites/pcu.php?id=" . $pcu['pcu_id']; 
7 }
8
9 function pcu_name($pcu)
10 {
11         if ( $pcu['hostname'] != NULL and $pcu['hostname'] != "" ):
12                 return $pcu['hostname'];
13         else: 
14                 return $pcu['ip'];
15         endif;
16 }
17 function pcu_entry($pcu)
18 {
19         if ( count($pcu['complete_entry']) > 0 ) {
20                 return join("<BR>", $pcu['complete_entry']);
21         } else {
22                 return "&nbsp;";
23         }
24 }
25
26 function format_ports($pcu)
27 {
28         $str = "";
29         #print print_r(is_array($pcu)) . "<BR>";
30         #print print_r(array_key_exists('portstatus', $pcu)) . "<BR>";
31         if ( is_array($pcu) && array_key_exists('portstatus', $pcu) )
32         {
33                 $portstat = $pcu['portstatus'];
34
35                 #foreach ( array('22', '23', '80', '443') $portstat as $port => $state)
36                 foreach ( array('22', '23', '80', '443') as $port)
37                 {
38                         $state = $portstat[$port];
39                         switch ($state)
40                         {
41                                 case "open":
42                                         $color = "lightgreen";
43                                         break;
44                                 case "filtered":
45                                         $color = "gold";
46                                         break;
47                                 case "closed":
48                                         $color = "indianred";
49                                         break;
50                                 default:
51                                         $color = "white";
52                                         break;
53                         }
54                         $str .= "<span style='background-color: $color'>$port</span>&nbsp;"; 
55                         #  . ":&nbsp;" . $state . "<br>";
56                 }
57         } else {
58         #       print print_r(is_array($pcu)) . "<BR>";
59         #       print print_r(array_key_exists('portstatus', $pcu)) . "<BR>";
60                 #echo "<pre>";
61                 #print_r($pcu['portstatus']);
62                 #echo "</pre>";
63         }
64         if ( $str == "" )
65         {
66                 $str = "Closed/Filtered";
67         }
68         return $str;
69 }
70 function DNS_to_color($dns)
71 {
72         switch ($dns)
73         {
74                 case "DNS-OK":
75                         return 'lightgreen';
76                 case "NOHOSTNAME":
77                         return 'white';
78                 case "DNS-MISMATCH":
79                         return 'gold';
80                 case "NO-DNS-OR-IP":
81                 case "DNS-NOENTRY":
82                         return 'indianred';
83         }
84         return 'white';
85 }
86
87 function reboot_to_color($reboot)
88 {
89         switch ($reboot)
90         {
91                 case "0":
92                         return "darkseagreen";
93                         break;
94                 case "NetDown":
95                         return "lightgrey";
96                         break;
97                 case "Not_Run":
98                         return "lightgrey";
99                         break;
100                 case "Unsupported_PCU":
101                         return "indianred";
102                         break;
103                 default:
104                         if ( strpos($reboot, "error") >= 0)
105                         {
106                                 return "indianred";
107                         } else {
108                                 return 'white';
109                         }
110                         break;
111         }
112         return "white";
113 }
114
115 function get_pcuid($pcu) { return $pcu['pcu_id']; }
116 function get_dns($pcu) { return $pcu['dnsmatch']; }
117 function get_dryrun($pcu) { return $pcu['reboot']; }
118 function get_model($pcu) { return $pcu['model']; }
119 function get_category_link($category,$header) 
120
121         return "<a href='printbadpcus.php?category=$category'>$header</a>"; 
122 }
123
124 include 'soltesz.php';
125 $p = new Pickle();
126 $findbad = $p->load("findbadpcus");
127 $findbadpcus = array_keys($findbad['nodes']);
128
129 $pculist = array();
130 $c = 0;
131 foreach ( $findbadpcus as $pcu_id )
132 {
133         if ( is_array($findbad['nodes'][$pcu_id]) ) 
134         {
135                 #if ( in_array('values', $findbad['nodes'][$pcu]) )
136                 #{
137                 #       echo $pcu . " true<BR>";
138                 #} else{
139                 #       echo $pcu . " false<br>";
140                 #}
141                 if ( array_key_exists('values', $findbad['nodes'][$pcu_id]) )
142                 {
143                         $pculist[] = $findbad['nodes'][$pcu_id]['values'];
144                 }
145         }
146 }
147 $total = count($pculist);
148
149
150 ## Sort the pculist
151
152 #$pcu_ids = array_map('get_pcuid', $pculist);
153 #array_multisort($pcu_ids, SORT_ASC, SORT_NUMERIC, $pculist);
154
155 #$dns_ids = array_map('get_dns', $pculist);
156 #array_multisort($dns_ids, SORT_ASC, SORT_STRING, $pculist);
157
158 #$dry_ids = array_map('get_dryrun', $pculist);
159 #array_multisort($dry_ids, SORT_ASC, SORT_STRING, $pculist);
160 if ( $_GET['category'] ) 
161 {
162         $category = $_GET['category'];
163         if ( $category == "node_ids" )
164         {
165                 $newfunc = create_function('$pcu', 'return count($pcu[\'' . $category . '\']);');
166         } else {
167                 $newfunc = create_function('$pcu', 'return $pcu[\'' . $category . '\'];');
168         }
169         if ( $newfunc != "" )
170         {
171                 $fields = array_map($newfunc, $pculist);
172                 array_multisort($fields, SORT_ASC, SORT_STRING, $pculist);
173         } else {
174                 echo "ERROR create_function == null<BR>";
175         }
176 }
177
178 if ( $_GET['auth'] )
179 {
180         $auth = True;
181 } else {
182         $auth = False;
183 }
184
185
186 //array_multisort($protocols, SORT_ASC, SORT_STRING, $pculist);
187 ?>
188
189 <title>PLC PCU Info</title>
190 <html>
191 <body>
192
193 Total PCUs : <?= $total ?>
194 <table border=1>
195                 <tr>
196                         <th>Count</th>
197                         <th><?= get_category_link("pcu_id", "PCU ID") ?></th>
198                         <th><?= get_category_link("hostname", "Hostname") ?></th>
199                         <th><?= get_category_link("complete_entry", "Incomplete Fields") ?></th>
200                         <th><?= get_category_link("dnsmatch", "DNS Status") ?></th>
201                         <th><?= get_category_link("portstatus", "Port Status") ?></th>
202                         <th><?= get_category_link("reboot", "Dry Run Results") ?></th>
203                         <th><?= get_category_link("model", "Model") ?></th>
204                         <th><?= get_category_link("node_ids", "Nodes") ?></th>
205                         <?php if ( $auth ): ?>
206                                 <th>Username</th>
207                                 <th>Password</th>
208                                 <th>Notes</th>
209                         <?php endif; ?>
210                 </tr>
211 <?php $count = 0; ?>
212 <?php foreach ( $pculist as $pcu ): ?>
213                 <tr>
214                         <td><?= $count ?></td>
215                         <td id='id<?= $pcu['pcu_id'] ?>'><a href='<?= pcu_link($pcu) ?>'><?= $pcu['pcu_id'] ?></a></td>
216                         <td><?= pcu_name($pcu) ?></td>
217                         <td><?= pcu_entry($pcu) ?></td>
218                         <td bgcolor='<?= DNS_to_color($pcu['dnsmatch']) ?>'><?= $pcu['dnsmatch'] ?></td>
219                         <td><?= format_ports($pcu) ?></td>
220                         <td bgcolor='<?= reboot_to_color($pcu['reboot']) ?>'><?= $pcu['reboot'] ?></td>
221                         <td nowrap><?= $pcu['model'] ?></td>
222                         <td><?= count( $pcu['node_ids'] ) ?></td>
223                         <?php if ( $auth ): ?>
224                                 <td><?= ( $pcu['username'] ? $pcu['username'] : "&nbsp;" ) ?></td>
225                                 <td><?= $pcu['password'] ?></td>
226                                 <td><?= $pcu['notes'] ?></td>
227                         <?php endif; ?>
228                 </tr>
229 <?php $count += 1; ?>
230 <?php endforeach; ?>
231 </table>
232
233 </body>
234 </html>