factor interface-reports.php out
[racktables] / wwwroot / inc / interface-reports.php
CommitLineData
069689de
DO
1<?php
2
3function renderSystemReports ()
4{
5 $tmp = array
6 (
7 array
8 (
9 'title' => 'Dictionary/objects',
10 'type' => 'counters',
11 'func' => 'getDictStats'
12 ),
13 array
14 (
15 'title' => 'Rackspace',
16 'type' => 'counters',
17 'func' => 'getRackspaceStats'
18 ),
19 array
20 (
21 'title' => 'Files',
22 'type' => 'counters',
23 'func' => 'getFileStats'
24 ),
25 array
26 (
27 'title' => 'Tags top list',
28 'type' => 'custom',
29 'func' => 'renderTagStats'
30 ),
31 );
32 renderReports ($tmp);
33}
34
35function renderLocalReports ()
36{
37 global $localreports;
38 renderReports ($localreports);
39}
40
41function renderRackCodeReports ()
42{
43 $tmp = array
44 (
45 array
46 (
47 'title' => 'Stats',
48 'type' => 'counters',
49 'func' => 'getRackCodeStats',
50 'include' => 'code.php',
51 ),
52 array
53 (
54 'title' => 'Warnings',
55 'type' => 'messages',
56 'func' => 'getRackCodeWarnings',
57 'include' => 'code.php',
58 ),
59 );
60 renderReports ($tmp);
61}
62
63function renderIPv4Reports ()
64{
65 $tmp = array
66 (
67 array
68 (
69 'title' => 'Stats',
70 'type' => 'counters',
71 'func' => 'getIPv4Stats'
72 ),
73 );
74 renderReports ($tmp);
75}
76
77function renderIPv6Reports ()
78{
79 $tmp = array
80 (
81 array
82 (
83 'title' => 'Stats',
84 'type' => 'counters',
85 'func' => 'getIPv6Stats'
86 ),
87 );
88 renderReports ($tmp);
89}
90
91function renderPortsReport ()
92{
93 $tmp = array();
94 foreach (getPortIIFOptions() as $iif_id => $iif_name)
95 if (count (getPortIIFStats ($iif_id)))
96 $tmp[] = array
97 (
98 'title' => $iif_name,
99 'type' => 'meters',
100 'func' => 'getPortIIFStats',
101 'args' => $iif_id,
102 );
103 renderReports ($tmp);
104}
105
106function render8021QReport ()
107{
108 if (!count ($domains = getVLANDomainOptions()))
109 {
110 echo '<center><h3>(no VLAN configuration exists)</h3></center>';
111 return;
112 }
113 $vlanstats = array();
114 for ($i = VLAN_MIN_ID; $i <= VLAN_MAX_ID; $i++)
115 $vlanstats[$i] = array();
116 $header = '<tr><th>&nbsp;</th>';
117 foreach ($domains as $domain_id => $domain_name)
118 {
119 foreach (getDomainVLANList ($domain_id) as $vlan_id => $vlan_info)
120 $vlanstats[$vlan_id][$domain_id] = $vlan_info;
121 $header .= '<th>' . mkA ($domain_name, 'vlandomain', $domain_id) . '</th>';
122 }
123 $header .= '</tr>';
124 $output = $available = array();
125 for ($i = VLAN_MIN_ID; $i <= VLAN_MAX_ID; $i++)
126 if (!count ($vlanstats[$i]))
127 $available[] = $i;
128 else
129 $output[$i] = FALSE;
130 foreach (listToRanges ($available) as $span)
131 {
132 if ($span['to'] - $span['from'] < 4)
133 for ($i = $span['from']; $i <= $span['to']; $i++)
134 $output[$i] = FALSE;
135 else
136 {
137 $output[$span['from']] = TRUE;
138 $output[$span['to']] = FALSE;
139 }
140 }
141 ksort ($output, SORT_NUMERIC);
142 $header_delay = 0;
143 startPortlet ('VLAN existence per domain');
144 echo '<table border=1 cellspacing=0 cellpadding=5 align=center class=rackspace>';
145 foreach ($output as $vlan_id => $tbc)
146 {
147 if (--$header_delay <= 0)
148 {
149 echo $header;
150 $header_delay = 25;
151 }
152 echo '<tr class="state_' . (count ($vlanstats[$vlan_id]) ? 'T' : 'F');
153 echo '"><th class=tdright>' . $vlan_id . '</th>';
154 foreach (array_keys ($domains) as $domain_id)
155 {
156 echo '<td class=tdcenter>';
157 if (array_key_exists ($domain_id, $vlanstats[$vlan_id]))
158 echo mkA ('&exist;', 'vlan', "${domain_id}-${vlan_id}");
159 else
160 echo '&nbsp;';
161 echo '</td>';
162 }
163 echo '</tr>';
164 if ($tbc)
165 echo '<tr class="state_A"><th>...</th><td colspan=' . count ($domains) . '>&nbsp;</td></tr>';
166 }
167 echo '</table>';
168 finishPortlet();
169}
170
171function renderReports ($what)
172{
173 if (!count ($what))
174 return;
175 echo "<table align=center>\n";
176 foreach ($what as $item)
177 {
178 if (isset ($item['include']))
179 require_once $item['include'];
180
181 echo "<tr><th colspan=2><h3>${item['title']}</h3></th></tr>\n";
182 switch ($item['type'])
183 {
184 case 'counters':
185 if (array_key_exists ('args', $item))
186 $data = $item['func'] ($item['args']);
187 else
188 $data = $item['func'] ();
189 foreach ($data as $header => $data)
190 echo "<tr><td class=tdright>${header}:</td><td class=tdleft>${data}</td></tr>\n";
191 break;
192 case 'messages':
193 if (array_key_exists ('args', $item))
194 $data = $item['func'] ($item['args']);
195 else
196 $data = $item['func'] ();
197 foreach ($data as $msg)
198 echo "<tr class='msg_${msg['class']}'><td class=tdright>${msg['header']}:</td><td class=tdleft>${msg['text']}</td></tr>\n";
199 break;
200 case 'meters':
201 if (array_key_exists ('args', $item))
202 $data = $item['func'] ($item['args']);
203 else
204 $data = $item['func'] ();
205 foreach ($data as $meter)
206 {
207 echo "<tr><td class=tdright>${meter['title']}:</td><td class=tdcenter>";
208 renderProgressBar ($meter['max'] ? $meter['current'] / $meter['max'] : 0);
209 echo '<br><small>' . ($meter['max'] ? $meter['current'] . '/' . $meter['max'] : '0') . '</small></td></tr>';
210 }
211 break;
212 case 'custom':
213 echo "<tr><td colspan=2>";
214 $item['func'] ();
215 echo "</td></tr>\n";
216 break;
217 default:
218 throw new InvalidArgException ('type', $item['type']);
219 }
220 echo "<tr><td colspan=2><hr></td></tr>\n";
221 }
222 echo "</table>\n";
223}
224
225function renderTagStats ()
226{
227 global $taglist;
228 echo '<table border=1><tr><th>tag</th><th>total</th><th>objects</th><th>IPv4 nets</th><th>IPv6 nets</th>';
229 echo '<th>racks</th><th>IPv4 VS</th><th>IPv4 RS pools</th><th>users</th><th>files</th></tr>';
230 $pagebyrealm = array
231 (
232 'file' => 'files&tab=default',
233 'ipv4net' => 'ipv4space&tab=default',
234 'ipv6net' => 'ipv6space&tab=default',
235 'ipv4vs' => 'ipv4slb&tab=default',
236 'ipv4rspool' => 'ipv4slb&tab=rspools',
237 'object' => 'depot&tab=default',
238 'rack' => 'rackspace&tab=default',
239 'user' => 'userlist&tab=default'
240 );
241 foreach (getTagChart (getConfigVar ('TAGS_TOPLIST_SIZE')) as $taginfo)
242 {
243 echo "<tr><td>${taginfo['tag']}</td><td>" . $taginfo['refcnt']['total'] . "</td>";
244 foreach (array ('object', 'ipv4net', 'ipv6net', 'rack', 'ipv4vs', 'ipv4rspool', 'user', 'file') as $realm)
245 {
246 echo '<td>';
247 if (!isset ($taginfo['refcnt'][$realm]))
248 echo '&nbsp;';
249 else
250 {
251 echo "<a href='index.php?page=" . $pagebyrealm[$realm] . "&cft[]=${taginfo['id']}'>";
252 echo $taginfo['refcnt'][$realm] . '</a>';
253 }
254 echo '</td>';
255 }
256 echo '</tr>';
257 }
258 echo '</table>';
259}
260
261?>