Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Mon Jun 17, 2019 10:49 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Adding template from command line
PostPosted: Tue Aug 09, 2005 5:32 am 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
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:
File comment: add_template.php for Cacti 0.8.7
add_template_0.8.7.zip [665 Bytes]
Downloaded 1315 times
File comment: add_template.php for Cacti 0.8.6
add_template.zip [633 Bytes]
Downloaded 1357 times


Last edited by Exo7 on Mon Sep 22, 2008 5:49 pm, edited 2 times in total.
Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 16, 2007 7:19 pm 
Offline

Joined: Wed Mar 29, 2006 3:28 am
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 4:28 pm 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
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:
$info_array = import_xml_data($xml_data,false);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 5:00 pm 
Offline
Developer/Forum Admin
User avatar

Joined: Mon Nov 17, 2003 6:35 pm
Posts: 6016
Location: Michigan, USA
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:
$info_array = import_xml_data($xml_data,false);


Yes, VERY GOOD THING! :o

_________________
Tony Roman
Experience is what causes a person to make new mistakes instead of old ones.
There are only 3 way to complete a project: Good, Fast or Cheap, pick two.
With age comes wisdom, what you choose to do with it determines whether or not you are wise.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 9:06 am 
Offline

Joined: Wed May 21, 2008 9:28 am
Posts: 3
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 #


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 5:34 pm 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 11:04 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22376
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group