[racktables-users] Re: Feature Request?
- From: "Aaron Dummer" <aaron@xxxxxxxxxxx>
- To: racktables-users@xxxxxxxxxxxxx
- Date: Sat, 30 Aug 2008 21:53:58 -0700
>> I could be missing this feature all together, but I would like to be
>> able to generate a report of my stuff. For example, right now I
>> would like to get a report of all the servers and save that somewhere
>> for another user. Would it be possible to exports reports and/or
>> data?
> The last (0.16.2) release provides an easy way to add own extensions.
> Basically, you have to keep your code in local.php file and then just
> keep it the "inc" directory of the extracted tree. Even more,
> I've seen an early version of "show my servers" addon by Aaron. He may
> find it appropriate publishing it, so I can save on explaining how it
> works.
Hey Jason,
Attached is the custom Server report that you might find useful. As Denis explained, place the file in your "inc" directory and you will see a new "Local" tab appear in the Reports section of RackTables. The query uses several sub-selects but I found this necessary to do it right.
Please send your feedback and any improvements back to the list!
--
Aaron Dummer
aaron@xxxxxxxxxxx<?php
// Credits:
// Report back-end created by Denis Ovsienko <http://www.racktables.org/>
// Query created, interface adjusted by Aaron Dummer <aaron@xxxxxxxxxxx>
$localreports[] = array
(
'title' => 'My Servers',
'type' => 'custom',
'func' => 'getMyServers'
);
function getMyServers ()
{
// Returns details of all objects whose type is 4 (Server).
// Since an object may exist in multiple racks, the Rack & Row details are
those of the first one only.
// TODO: Make report sortable by column, make it prettier with CSS.
$query = 'SELECT RackObject.id AS object_id,
RackObject.name,
RackObject.asset_no,
RackObject.barcode,
RackObject.has_problems,
(SELECT d.dict_value
FROM AttributeValue a
LEFT JOIN Dictionary d ON a.uint_value = d.dict_key
WHERE a.object_id = RackObject.id
AND a.attr_id = 2) AS hw_type,
(SELECT d.dict_value
FROM AttributeValue a
LEFT JOIN Dictionary d ON a.uint_value = d.dict_key
WHERE a.object_id = RackObject.id
AND a.attr_id = 4) AS sw_type,
(SELECT row_id
FROM Rack
WHERE id = (SELECT DISTINCT(rack_id)
FROM RackSpace
WHERE object_id = RackObject.id
ORDER BY rack_id LIMIT 1)) AS row_id,
(SELECT d.dict_value
FROM Dictionary d
WHERE d.chapter_no = 3
AND d.dict_key = (SELECT row_id
FROM Rack
WHERE id = (SELECT DISTINCT(rack_id)
FROM RackSpace
WHERE object_id =
RackObject.id
ORDER BY rack_id LIMIT
1))) AS row_name,
(SELECT DISTINCT(rack_id)
FROM RackSpace
WHERE object_id = RackObject.id
ORDER BY rack_id LIMIT 1) AS rack_id,
(SELECT name
FROM Rack
WHERE id = (SELECT DISTINCT(rack_id)
FROM RackSpace
WHERE object_id = RackObject.id
ORDER BY rack_id LIMIT 1)) AS rack_name
FROM RackObject
WHERE objtype_id = 4
ORDER BY name';
$result = useSelectBlade ($query, __FUNCTION__);
echo "<style type='text/css'>\n";
echo "tr.has_problems {\n";
echo "background-color: #ffa0a0;\n";
echo "}\n";
echo "</style>\n";
echo "<table border=1><tr valign=top>";
echo "<th align=left>Name</th>";
echo "<th align=left>Asset Tag</th>";
echo "<th align=left>Barcode</th>";
echo "<th align=left>Problems?</th>";
echo "<th align=left>Hardware</th>";
echo "<th align=left>Software</th>";
echo "<th align=left>Row</th>";
echo "<th align=left>Rack</th></tr>";
while ($row = $result->fetch (PDO::FETCH_ASSOC))
{
// make the row red if server has problems
if ($row['has_problems'] == 'yes')
echo "<tr class=has_problems>";
else
echo "<tr>";
printf("<td><a href='?page=object&object_id=%s'>%s</a></td>",
$row['object_id'], $row['name']);
printf("<td>%s</td>", $row['asset_no']);
printf("<td>%s</td>", $row['barcode']);
printf("<td>%s</td>", $row['has_problems']);
printf("<td>%s</td>", parseWikiLink ($row['hw_type'], 'a', TRUE));
printf("<td>%s</td>", parseWikiLink ($row['sw_type'], 'a', TRUE));
printf("<td><a href='?page=row&row_id=%s'>%s</a></td>", $row['row_id'],
$row['row_name']);
printf("<td><a href='?page=rack&rack_id=%s'>%s</a></td>",
$row['rack_id'], $row['rack_name']);
echo "</tr>\n";
}
echo "</table>\n";
}
?>
Other related posts:
- » [racktables-users] Feature Request?
- » [racktables-users] Re: Feature Request?
- » [racktables-users] Re: Feature Request?
- » [racktables-users] Re: Feature Request?
- » [racktables-users] Re: Feature Request?
> The last (0.16.2) release provides an easy way to add own extensions.
> Basically, you have to keep your code in local.php file and then just
> keep it the "inc" directory of the extracted tree. Even more,
> I've seen an early version of "show my servers" addon by Aaron. He may
> find it appropriate publishing it, so I can save on explaining how it
> works.