Adding template from command line

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Post Reply
Author
Message
Exo7
Cacti User
Posts: 135
Joined: Wed Jul 13, 2005 4:50 pm

Adding template from command line

#1 Post by Exo7 » Tue Aug 09, 2005 5:32 am

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
Attachments
add_template_0.8.7.zip
add_template.php for Cacti 0.8.7
(665 Bytes) Downloaded 1327 times
add_template.zip
add_template.php for Cacti 0.8.6
(633 Bytes) Downloaded 1368 times
Last edited by Exo7 on Mon Sep 22, 2008 5:49 pm, edited 2 times in total.

wolvverine-pld
Posts: 5
Joined: Wed Mar 29, 2006 3:28 am

#2 Post by wolvverine-pld » Sun Dec 16, 2007 7:19 pm

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

Exo7
Cacti User
Posts: 135
Joined: Wed Jul 13, 2005 4:50 pm

#3 Post by Exo7 » Mon Dec 17, 2007 4:28 pm

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

Code: Select all

$info_array = import_xml_data($xml_data,false);

User avatar
rony
Developer/Forum Admin
Posts: 6016
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

#4 Post by rony » Mon Dec 17, 2007 5:00 pm

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 with

Code: Select all

$info_array = import_xml_data($xml_data,false);
Yes, VERY GOOD THING! :o
[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]

alens
Posts: 3
Joined: Wed May 21, 2008 9:28 am

#5 Post by alens » Wed May 28, 2008 9:06 am

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 #

Exo7
Cacti User
Posts: 135
Joined: Wed Jul 13, 2005 4:50 pm

#6 Post by Exo7 » Mon Sep 22, 2008 5:34 pm

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.

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#7 Post by gandalf » Thu Sep 25, 2008 11:04 am

Please refer to cacti SVN code before applying changes.
There have been bug fixes and enhancements. Most of the should work instantaneously on 087* versions of cacti.
Reinhard

Post Reply