ptaylor874 New User
Joined: 04 Jan 2008 Posts: 9
|
Posted: Fri Apr 04, 2008 7:59 am Post subject: Mod to export function in discover.php |
|
|
When performing a discovery I found that multi-line results have commas separating the lines. This means that when you bring the file into a spreadsheet like Excel, the data rows don't all line up properly.
To fix this, I made a very minor modification to the routine that exports in discover.php. The change involves surrounding the data with quote characters so that the commas are treated as part of the data. The below code segment is that entire code block.
The result of this is a .csv file that is more compatible with spreadsheet software.
| Code: |
if (isset($_POST['button_export_x'])) {
$sql = "SELECT * FROM plugin_discover_hosts $where order by hash";
$result = db_fetch_assoc($sql);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=discovery_results.csv");
print "Host,IP,Community Name,SNMP Name,Location,Contact,Description,OS,Uptime,SNMP,Status\n";
foreach ($result as $host) {
if ($host['sysUptime'] != 0) {
$days = intval($host['sysUptime']/8640000);
$hours = intval(($host['sysUptime'] - ($days * 8640000)) / 360000);
$uptime = $days . ' days ' . $hours . ' hours';
} else {
$uptime = '';
}
foreach($host as $h=>$r) {
$host['$h'] = str_replace(',','',$r);
}
print '"' . $host['hostname'] . '",';
print '"' . $host['ip'] . '",';
print '"' . $host['community'] . '",';
print '"' . $host['sysName'] . '",';
print '"' . $host['sysLocation'] . '",';
print '"' . $host['sysContact'] . '",';
print '"' . $host['sysDescr'] . '",';
print '"' . $host['os'] . '",';
print '"' . $uptime . '",';
print '"' . $host['snmp'] . '",';
print '"' . $host['up'] . '"' . "\n";
}
exit;
}
|
|
|