Code: Select all
--- cli/host_update_template.php_orig 2010-01-21 11:49:19.000000000 +0100
+++ cli/host_update_template.php 2010-01-21 11:49:49.000000000 +0100
@@ -51,6 +51,7 @@
$debug = FALSE;
$template = "";
$hostid = "";
+$change = FALSE;
foreach($parms as $parameter) {
@list($arg, $value) = @explode("=", $parameter);
@@ -65,6 +66,9 @@
case "--list-host-templates":
displayHostTemplates(getHostTemplates());
exit(0);
+ case "-c":
+ $change = TRUE;
+ break;
case "-d":
$debug = TRUE;
break;
@@ -109,6 +113,11 @@
/* verify that the host template is accurate */
if (db_fetch_cell("SELECT id FROM host_template WHERE id=$template") > 0) {
+
+ if ($change) {
+ print "Changing host template for host ".$host_id." to ".$template."\n";
+ db_execute("update host set host_template_id='$template' where id = '$host_id'");
+ }
$hosts = db_fetch_assoc("SELECT * FROM host $sql_where");
if (sizeof($hosts)) {
@@ -150,10 +159,11 @@
/* display_help - displays the usage of the function */
function display_help () {
print "Cacti Retemplate Host Script 1.0, Copyright 2004-2009 - The Cacti Group\n";
- print "usage: host_update_template.php -host-id=[host-id|All] [--host-template=[ID]] [-d] [-h] [--help] [-v] [--version]\n\n";
+ print "usage: host_update_template.php --host-id=[host-id|All] [--host-template=[ID]] [-c] [-d] [-h] [--help] [-v] [--version]\n\n";
print "--host-id=host_id - The host_id to have templates reapplied 'all' to do all hosts\n";
print "--host-template=ID - Which Host Template to Refresh\n\n";
print "Optional:\n";
+ print "-c - As well change the Host Template\n";
print "-d - Display verbose output during execution\n";
print "-v --version - Display this help message\n";
print "-h --help - Display this help message\n";