add the roadmap .dia file for 2019Q2
[racktables-contribs] / wattage_consumption.php
1 <?php
2
3 //-----------------------------------------------------------------------------------
4 // Wattage Consumption - written by curtisb
5 //
6 // Updated for Racktables-0.20.4 by Mark Wilkinson
7 // bonus of Rack Wattage portlet in Rack Page if portlet patch applied (bugs.racktables.org ID 691)
8 //
9 //
10 // Usage - Create attribute 'Wattage consumption' and map to Servers, Chassis, etc
11 // Set power values for servers,etc.
12 // View Report page (or Rack page)
13 //
14 $tab['reports']['watts_per_row'] = 'Enviromental Totals';
15 $tabhandler['reports']['watts_per_row'] = 'getWattsPerRow';
16 if ( function_exists('registerPortletHandler') )
17 registerPortletHandler( 'rack', 'default', 'left', 'Wattage Consumption', 'renderPortletWattConsumption');
18
19 function getWattsPerRow ()
20 {
21 // assertions
22 // find the needed attributes
23
24 global $nextorder;
25
26 // Was this function called with a specific row_id?
27 if (isset ($_REQUEST['row_id']))
28 {
29 assertStringArg ('row_id');
30 $row_toshow = $_REQUEST['row_id'];
31 }
32 else
33 $row_toshow = -1;
34
35 //from renderRackspace(), interface.php:151
36 $found_racks = array();
37 $rows = array();
38 $cellfilter = getCellFilter();
39 $rackCount = 0;
40 $order = 'odd';
41 // get rackspace information
42 foreach (getAllRows() as $row_id => $rowInfo)
43 {
44 $rackList = filterCellList (listCells ('rack', $row_id), $cellfilter['expression']);
45 $found_racks = array_merge ($found_racks, $rackList);
46 $rows[] = array
47 (
48 'location_id' => $rowInfo['location_id'],
49 'location_name' => $rowInfo['location_name'],
50 'row_id' => $row_id,
51 'row_name' => $rowInfo['name'],
52 'racks' => $rackList
53 );
54 $rackCount += count ($rackList);
55 }
56
57 // Main layout starts.
58 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
59
60 // Left portlet with list of rows.
61 echo "<tr><td class=pcleft width='50%'>";
62 startPortlet ('Rack Rows (' . count ($rows) . ')');
63 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
64 foreach ($rows as $row)
65 {
66 $row_id = $row['row_id'];
67 $row_name = $row['row_name'];
68 $row_location = $row['location_name'];
69 $rackList = $row['racks'];
70
71 echo "<tr class=row_${order}><td width='20%'></td><td class=tdleft>";
72 if (! count ($rackList))
73 echo "${row_location} - ${row_name} (empty row)";
74 else
75 echo "<a href='" . makeHref (array ('page' => 'reports', 'tab' => 'watts_per_row', 'row_id' => $row_id)) . "'>${row_location} - ${row_name}</a>";
76 echo "<td><tr>\n";
77 $order = $nextorder[$order];
78 }
79
80 echo "</td></tr>\n";
81 echo "</table><br>\n";
82 finishPortlet();
83
84 echo "</td><td class=pcright>";
85
86 // Right Portlet: Draw the racks in the selected row
87 if ($row_toshow > -1)
88 {
89 $rowInfo = getRowInfo ($row_toshow);
90 $cellfilter = getCellFilter();
91 $rackList = filterCellList (listCells ('rack', $row_toshow), $cellfilter['expression']);
92
93 $rackwidth = getRackImageWidth() * getConfigVar ('ROW_SCALE');
94 // Maximum number of racks per row is proportionally less, but at least 1.
95 $maxPerRow = max (floor (getConfigVar ('RACKS_PER_ROW') / getConfigVar ('ROW_SCALE')), 1);
96 $rackListIdx = 0;
97 $rowTotalWattage = 0;
98 $order = 'odd';
99 startPortlet ('Racks within ' . $rowInfo['name'] . ' (' . count($rackList) . ')' );
100 echo "<table border=0 cellspacing=5 align='center'><tr>";
101 foreach ($rackList as $rack)
102 {
103 $rackTotalWattage = 0;
104 // see renderRack(), interface.php:311
105 $rackData = spotEntity ('rack', $rack['id']);
106 amplifyCell ($rackData);
107 $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
108 foreach ($rackData['mountedObjects'] as $object)
109 {
110 $objectData = spotEntity ('object', $object);
111 amplifyCell ($objectData);
112 foreach (getAttrValues ($objectData['id']) as $record)
113 if ($record['name'] == 'Wattage consumption')
114 $rackTotalWattage += $record['value'];
115 }
116 if ($rackListIdx % $maxPerRow == 0)
117 echo $rackListIdx > 0 ? '</tr><tr>' : '<tr>';
118 echo "<td align=center class=row_${order}><a href='" . makeHref (array( 'page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
119
120 echo "<img border=0 width=${rackwidth} height=" . (getRackImageHeight ($rack['height']) * getConfigVar ('ROW_SCALE'));
121 echo " title='${rack['height']} units'";
122 echo "src='?module=image&img=minirack&rack_id=${rack['id']}'>";
123 echo "<br>${rack['name']} ($rackTotalWattage)</a></td>";
124 $order = $nextorder[$order];
125 $rackListIdx++;
126 $rowTotalWattage += $rackTotalWattage;
127 }
128
129 echo "</tr><tr><td align=center colspan=";
130 print (count ($rackList));
131 echo "><br><b>The row total for attribute Wattage consuption is: $rowTotalWattage</b></td>\n";
132
133 echo "</tr></table>\n";
134 finishPortlet();
135 }
136 echo "</td></tr></table>";
137 }
138
139 function renderPortletWattConsumption ($info)
140 {
141 $rackTotalWattage = 0;
142 $rackData = spotEntity ('rack', $info['id']);
143 amplifyCell ($rackData);
144 $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
145 foreach ($rackData['mountedObjects'] as $object)
146 {
147 $objectData = spotEntity ('object', $object);
148 amplifyCell ($objectData);
149 foreach (getAttrValues ($objectData['id']) as $record)
150 if ($record['name'] == 'Wattage consumption')
151 $rackTotalWattage += $record['value'];
152 }
153 startPortlet ('Wattage Consumption' );
154 echo "<table border=0 cellspacing=5 align='center'><tr>";
155 echo "<td>The total for attribute Wattage consuption is: <b>$rackTotalWattage</b></td>\n";
156 echo "</tr></table>\n";
157 finishPortlet();
158 }