SOURCES: cacti-add_template.php - rewrite script to handle multiple file im...
glen
glen at pld-linux.org
Sun Oct 5 14:19:33 CEST 2008
Author: glen Date: Sun Oct 5 12:19:33 2008 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- rewrite script to handle multiple file imports
- proper exit codes and error handling
---- Files affected:
SOURCES:
cacti-add_template.php (1.1 -> 1.2)
---- Diffs:
================================================================
Index: SOURCES/cacti-add_template.php
diff -u SOURCES/cacti-add_template.php:1.1 SOURCES/cacti-add_template.php:1.2
--- SOURCES/cacti-add_template.php:1.1 Sun Oct 5 14:11:57 2008
+++ SOURCES/cacti-add_template.php Sun Oct 5 14:19:27 2008
@@ -11,25 +11,23 @@
include_once("/usr/share/cacti/lib/import.php");
// check if we have good number of argument
-if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?')))
-{
- echo "usage : $argv[0] file.xml\n";
- echo "this script will import file.xml template into cacti\n";
- return 0;
+if ($argc < 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
+ echo "Usage: $argv[0] FILE.xml [FILE.xml]\n";
+ echo "This script will import FILE.xml template into cacti\n";
+ exit(0);
}
+array_shift($argv);
-// open the .xml file
-$xml_file = $argv[1];
-$fp = fopen($xml_file, "r");
-if ($fp == FALSE)
-{
- echo "cannot open $xml_file, exiting\n";
- return -1;
-}
-$xml_data = fread($fp,filesize($xml_file));
+foreach ($argv as $xml_file) {
+ $xml_data = file_get_contents($xml_file);
+ if ($xml_data === false) {
+ echo "ERROR: cannot open $xml_file, exiting\n";
+ exit(1);
+ }
-// import data into cacti. $info_array will contain debugging info.
-$info_array = import_xml_data($xml_data,false);
+ // import data into cacti. $info_array will contain debugging info.
+ echo "cacti-add_template: importing $xml_file\n";
+ $info_array = import_xml_data($xml_data, false);
+}
-return 0;
-?>
+exit(0);
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/cacti-add_template.php?r1=1.1&r2=1.2&f=u
More information about the pld-cvs-commit
mailing list