Suggestion for Discovery Export

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Moderators, Developers

Post Reply
Author
Message
Vertigo
Posts: 16
Joined: Thu Jul 07, 2005 5:14 pm
Location: Melb, Australia
Contact:

Suggestion for Discovery Export

#1 Post by Vertigo » Tue Jul 03, 2012 4:11 am

Just tried the export function and noticed it doesn't enclose the fields it exports in quotes, which creates an issue when opening in Excel as fields get shifted if they contain a comma.

Have just changed my discover.php as per the below patch to enclose the fields in quotes which Excel recognises.
Would be handy if this was included in the mainline code either as an option or by default.

Code: Select all

--- /discover.php	Thu Dec 22 08:27:32 2011
+++ /discover (2).php	Tue Jul 03 18:58:07 2012
@@ -156,17 +156,17 @@
 		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";
+		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;
 }
Cheers,
Karl

Post Reply