FAQFAQ   SearchSearch   RegisterRegister   ProfileProfile   Log inLog in 

Mod to export function in discover.php

 
Post new topic   Reply to topic    CactiUsers.org Forum Index -> General
View previous topic :: View next topic  
Author Message
ptaylor874
New User


Joined: 04 Jan 2008
Posts: 9

PostPosted: Fri Apr 04, 2008 7:59 am    Post subject: Mod to export function in discover.php Reply with quote

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;
}
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    CactiUsers.org Forum Index -> General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Forums Sitemap