Hi everyone.
I wrote a (very) small php script to import xml template file from command line. I need this kind of CLI tools to automatize an installation process, with custom templates I wrote for Cacti with data polled by Nagios.
Just unzip the file in your cacti/site/ folder.
usage : add_template.php your_template.xml
windows user may want to call the script with something like
php add_template.php your_template.xml
There is no verification to the template file used, or if the import succeeded : you should use a correct template xml file !
have fun
Adding template from command line
Moderators: Developers, Moderators
Adding template from command line
- Attachments
-
- add_template_0.8.7.zip
- add_template.php for Cacti 0.8.7
- (665 Bytes) Downloaded 1446 times
-
- add_template.zip
- add_template.php for Cacti 0.8.6
- (633 Bytes) Downloaded 1462 times
Last edited by Exo7 on Mon Sep 22, 2008 5:49 pm, edited 2 times in total.
-
- Posts: 5
- Joined: Wed Mar 29, 2006 3:28 am
problem with 0.8.7a:
# /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Extension '/usr/share/cacti/add_template.php' not present.
# php /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Warning: include_once(./include/config.php): failed to open stream: No such file or directory in /usr/share/cacti/add_template.php on line 11
Warning: include_once(): Failed opening './include/config.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/add_template.php on line 11
Warning: include_once(./lib/import.php): failed to open stream: No such file or directory in /usr/share/cacti/add_template.php on line 12
Warning: include_once(): Failed opening './lib/import.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/add_template.php on line 12
Fatal error: Call to undefined function import_xml_data() in /usr/share/cacti/add_template.php on line 33
after correct include:
include_once("/usr/share/cacti/include/config.php");
include_once("/usr/share/cacti/lib/import.php");
]# php /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Warning: Missing argument 2 for import_xml_data(), called in /usr/share/cacti/add_template.php on line 33 and defined in /usr/share/cacti/lib/import.php on line 25
Warning: include_once(/xml.php): failed to open stream: No such file or directory in /usr/share/cacti/lib/import.php on line 28
Warning: include_once(): Failed opening '/xml.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/lib/import.php on line 28
Fatal error: Call to undefined function xml2array() in /usr/share/cacti/lib/import.php on line 32
# /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Extension '/usr/share/cacti/add_template.php' not present.
# php /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Warning: include_once(./include/config.php): failed to open stream: No such file or directory in /usr/share/cacti/add_template.php on line 11
Warning: include_once(): Failed opening './include/config.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/add_template.php on line 11
Warning: include_once(./lib/import.php): failed to open stream: No such file or directory in /usr/share/cacti/add_template.php on line 12
Warning: include_once(): Failed opening './lib/import.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/add_template.php on line 12
Fatal error: Call to undefined function import_xml_data() in /usr/share/cacti/add_template.php on line 33
after correct include:
include_once("/usr/share/cacti/include/config.php");
include_once("/usr/share/cacti/lib/import.php");
]# php /usr/share/cacti/add_template.php /usr/share/cacti/resource/script_queries/graph_active_ssh_conns.xml
Warning: Missing argument 2 for import_xml_data(), called in /usr/share/cacti/add_template.php on line 33 and defined in /usr/share/cacti/lib/import.php on line 25
Warning: include_once(/xml.php): failed to open stream: No such file or directory in /usr/share/cacti/lib/import.php on line 28
Warning: include_once(): Failed opening '/xml.php' for inclusion (include_path='.:/usr/share/pear') in /usr/share/cacti/lib/import.php on line 28
Fatal error: Call to undefined function xml2array() in /usr/share/cacti/lib/import.php on line 32
the import_xml_data function in lib/import.php takes an extra argument in 0.8.7, allowing you to ignore custom rra definition, which is a very good thing.
replace line 33 with
replace line 33 with
Code: Select all
$info_array = import_xml_data($xml_data,false);
- rony
- Developer/Forum Admin
- Posts: 6022
- Joined: Mon Nov 17, 2003 6:35 pm
- Location: Michigan, USA
- Contact:
Yes, VERY GOOD THING!Exo7 wrote:the import_xml_data function in lib/import.php takes an extra argument in 0.8.7, allowing you to ignore custom rra definition, which is a very good thing.
replace line 33 withCode: Select all
$info_array = import_xml_data($xml_data,false);
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
using 0.8.7.a i get still the errors even if i corrected the 33 string
nagios:/srv/www/htdocs/cacti # ./templates_add.php sql.xml
PHP Warning: include_once(/xml.php): failed to open stream: No such file or directory in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Warning: include_once(): Failed opening '/xml.php' for inclusion (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Fatal error: Call to undefined function xml2array() in /srv/www/htdocs/cacti/lib/import.php on line 32
nagios:/srv/www/htdocs/cacti #
nagios:/srv/www/htdocs/cacti # ./templates_add.php sql.xml
PHP Warning: include_once(/xml.php): failed to open stream: No such file or directory in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Warning: include_once(): Failed opening '/xml.php' for inclusion (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Fatal error: Call to undefined function xml2array() in /srv/www/htdocs/cacti/lib/import.php on line 32
nagios:/srv/www/htdocs/cacti #
alens wrote:using 0.8.7.a i get still the errors even if i corrected the 33 string
nagios:/srv/www/htdocs/cacti # ./templates_add.php sql.xml
PHP Warning: include_once(/xml.php): failed to open stream: No such file or directory in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Warning: include_once(): Failed opening '/xml.php' for inclusion (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/htdocs/cacti/lib/import.php on line 28
PHP Fatal error: Call to undefined function xml2array() in /srv/www/htdocs/cacti/lib/import.php on line 32
nagios:/srv/www/htdocs/cacti #
The main configuration file in cacti 0.8.7 changed from config.php to global.php.
Changing line 28 in the script solve the issue. I'll post an updated version including the other needed change.
Who is online
Users browsing this forum: No registered users and 4 guests