示例#1
0
文件: auth.php 项目: MrWnn/cacti
function check_auth_cookie()
{
    if (isset($_COOKIE['cacti_remembers']) && read_config_option('auth_cache_enabled') == 'on') {
        $parts = explode(',', $_COOKIE['cacti_remembers']);
        $user = $parts[0];
        if ($user != '') {
            $user_info = db_fetch_row_prepared('SELECT id, username 
				FROM user_auth 
				WHERE username = ?', array($user));
            if (!empty($user_info)) {
                if (isset($parts[1])) {
                    $nssecret = $parts[1];
                    $secret = hash('sha512', $nssecret, false);
                    $found = db_fetch_cell_prepared('SELECT user_id 
						FROM user_auth_cache 
						WHERE user_id = ? AND token = ?', array($user_info['id'], $secret));
                    if (empty($found)) {
                        return false;
                    } else {
                        set_auth_cookie($user_info);
                        cacti_log("LOGIN: User '" . $user_info['username'] . "' Authenticated via Authentication Cookie", false, 'AUTH');
                        db_execute_prepared('INSERT INTO user_log 
							(username, user_id, result, ip, time) 
							VALUES 
							(?, ?, 2, ?, NOW())', array($user, $user_info['id'], $_SERVER['REMOTE_ADDR']));
                        return $user_info['id'];
                    }
                }
            }
        }
    }
    return false;
}
 public static function log($message)
 {
     if (func_num_args() > 1) {
         $args = func_get_args();
         $message = call_user_func_array('sprintf', $args);
     }
     if (function_exists('debug_log_insert')) {
         cacti_log("DEBUG: " . rtrim($message), true, "WEATHERMAP");
     }
 }
示例#3
0
function sig_handler($signo)
{
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            cacti_log('WARNING: Thold Sub Process terminated by user', FALSE, 'thold');
            exit;
            break;
        default:
            /* ignore all other signals */
    }
}
示例#4
0
function upgrade_to_0_8_8()
{
    /* speed up the joins */
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM `poller_item`"), "Field", "Field");
    if (in_array("host_id", $_columns)) {
        db_install_execute("0.8.8", "ALTER TABLE `poller_item` MODIFY COLUMN `host_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0'");
        cacti_log(__FUNCTION__ . " upgrade table poller_item", false, "UPGRADE");
    }
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `poller_output`"), "Key_name", "Key_name");
    if (in_array("PRIMARY", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `poller_output` DROP PRIMARY KEY");
        cacti_log(__FUNCTION__ . " table poller_output: dropping old PRIMARY KEY", false, "UPGRADE");
    }
    /* now the KEY we want to create is definitively NOT present 
     * MySQL < 5.00.60 requires a different syntax, this was fixed in MySQL 5.00.60, so take care */
    db_install_execute("0.8.8", "ALTER TABLE `poller_output` ADD PRIMARY KEY (`local_data_id`, `rrd_name`, `time`) /*!50060 USING BTREE */");
    cacti_log(__FUNCTION__ . " upgrade table poller_output", false, "UPGRADE");
    /* speed up user management */
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `user_log`"), "Key_name", "Key_name");
    if (!in_array("user_id", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `user_log` ADD KEY `user_id` (`user_id`)");
        cacti_log(__FUNCTION__ . " upgrade table user_log", false, "UPGRADE");
    }
    /* Plugin Architecture
     * be prepared to find those data already present
     * in case of upgrade of a cacti+PIA installation */
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_config` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`directory` varchar(32) \tNOT NULL default '',\n\t\t\t\t`name` \t\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`status`\ttinyint(2) \t\tNOT NULL default 0,\n\t\t\t\t`author`\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`webpage`\tvarchar(255)  \tNOT NULL default '',\n\t\t\t\t`version`\tvarchar(8) \t\tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `status` (`status`),\n\t\t\t\tKEY `directory` (`directory`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Configuration'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_config", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_db_changes` (\n\t\t\t\t`id` \t\tint(10) unsigned NOT NULL auto_increment,\n\t\t\t\t`plugin` \tvarchar(16) \tNOT NULL default '',\n\t\t\t\t`table` \tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`column`\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`method` \tvarchar(16) \tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `plugin` (`plugin`),\n\t\t\t\tKEY `method` (`method`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Database Changes'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_db_changes", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_hooks` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`name` \t\tvarchar(32) \tNOT NULL default '',\n\t\t\t\t`hook` \t\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`file`\t\tvarchar(255) \tNOT NULL default '',\n\t\t\t\t`function` \tvarchar(128) \tNOT NULL default '',\n\t\t\t\t`status`\tint(8) \t\t\tNOT NULL default 0,\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `hook` (`hook`),\n\t\t\t\tKEY `status` (`status`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Hooks'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_hooks", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_realms` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`plugin` \tvarchar(32) \tNOT NULL default '',\n\t\t\t\t`file`\t\ttext\t\t \tNOT NULL,\n\t\t\t\t`display` \tvarchar(64) \tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `plugin` (`plugin`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Realms'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_realms", false, "UPGRADE");
    /* fill initial data into plugin tables
     * be prepared to find those data already present
     * in case of upgrade of a cacti+PIA installation */
    db_install_execute("0.8.8", "REPLACE INTO `plugin_realms` VALUES (1, 'internal', 'plugins.php', 'Plugin Management')");
    db_install_execute("0.8.8", "REPLACE INTO `plugin_hooks` VALUES (1, 'internal', 'config_arrays', '', 'plugin_config_arrays', 1)");
    db_install_execute("0.8.8", "REPLACE INTO `plugin_hooks` VALUES (2, 'internal', 'draw_navigation_text', '', 'plugin_draw_navigation_text', 1)");
    /* allow admin user to access Plugin Management */
    db_install_execute("0.8.8", "REPLACE INTO user_auth_realm VALUES (101,1)");
    /* create index on data_template_data on data_input_id */
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `data_template_data`"), "Key_name", "Key_name");
    if (!in_array("data_input_id", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `data_template_data` ADD KEY `data_input_id` (`data_input_id`)");
        cacti_log(__FUNCTION__ . " upgrade table data_template_data", false, "UPGRADE");
    }
}
示例#5
0
function sig_handler($signo)
{
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            cacti_log('WARNING: DSStats Poller terminated by user', FALSE, 'dsstats');
            /* tell the main poller that we are done */
            db_execute("REPLACE INTO settings (name, value) VALUES ('dsstats_poller_status', 'terminated - end time:" . date('Y-m-d G:i:s') . "')");
            exit;
            break;
        default:
            /* ignore all other signals */
    }
}
示例#6
0
文件: cmd.php 项目: MrWnn/cacti
function sig_handler($signo)
{
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            cacti_log('WARNING: Cacti Poller process terminated by user', true);
            /* record the process as having completed */
            record_cmdphp_done();
            exit;
            break;
        default:
            /* ignore all other signals */
    }
}
示例#7
0
function sig_handler($signo)
{
    global $include_file, $function, $parameters;
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
        case SIGABRT:
        case SIGQUIT:
        case SIGSEGV:
            cacti_log("WARNING: Script Server terminated with signal '{$signo}' in file:'" . basename($include_file) . "', function:'{$function}', params:'{$parameters}'", FALSE, 'PHPSVR');
            exit;
            break;
        default:
            cacti_log("WARNING: Script Server received signal '{$signo}' in file:'{$include_file}', function:'{$function}', params:'{$parameters}'", FALSE, 'PHPSVR');
            break;
    }
}
function warn($string, $notice_only = FALSE)
{
    global $weathermap_map;
    global $weathermap_warncount;
    $message = "";
    if (!$notice_only) {
        $weathermap_warncount++;
        $message .= "WARNING: ";
    }
    $message .= ($weathermap_map == '' ? '' : $weathermap_map . ": ") . rtrim($string);
    // use Cacti's debug log, if we are running from the poller
    if (function_exists('cacti_log') && !function_exists('show_editor_startpage')) {
        cacti_log($message, true, "WEATHERMAP");
    } else {
        $stderr = fopen('php://stderr', 'w');
        fwrite($stderr, $message . "\n");
        fclose($stderr);
    }
}
示例#9
0
function db_connect_real($host,$user,$pass,$db_name,$db_type, $retries = 20) {
	global $cnn_id;

	$i = 1;
	$cnn_id = NewADOConnection($db_type);

	while ($i <= $retries) {
		if ($cnn_id->Connect($host,$user,$pass,$db_name)) {
			return(1);
		}

		$i++;
		usleep(100000);
	}

	cacti_log("ERROR: Cannot connect to MySQL server on '$host'. Please make sure you have specified a valid MySQL   database name in 'include/config.php'.");

	die("<br>Cannot connect to MySQL server on '$host'. Please make sure you have specified a valid MySQL database name in 'include/config.php'.");

	return(0);
}
示例#10
0
function upgrade_to_0_8_7h()
{
    global $config;
    require_once $config["base_path"] . "/lib/poller.php";
    /* speed up the reindexing */
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM host_snmp_cache"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE host_snmp_cache ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `oid`");
        db_install_execute("0.8.7h", "ALTER TABLE host_snmp_cache ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table host_snmp_cache", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM poller_item"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE poller_item ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`");
        db_install_execute("0.8.7h", "ALTER TABLE poller_item ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table poller_item", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM poller_reindex"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE poller_reindex ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`");
        db_install_execute("0.8.7h", "ALTER TABLE poller_reindex ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table poller_reindex", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM host"), "Field", "Field");
    if (!in_array("device_threads", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE host ADD COLUMN device_threads tinyint(2) unsigned NOT NULL DEFAULT '1' AFTER max_oids;");
        cacti_log(__FUNCTION__ . " upgrade table host", false, "UPGRADE");
    }
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM data_template_rrd"), "Key_name", "Key_name");
    if (!in_array("duplicate_dsname_contraint", $_keys)) {
        db_install_execute("0.8.7h", "ALTER TABLE `data_template_rrd` ADD UNIQUE INDEX `duplicate_dsname_contraint` (`local_data_id`, `data_source_name`, `data_template_id`)");
        cacti_log(__FUNCTION__ . " upgrade table data_template_rrd", false, "UPGRADE");
    }
    /* update the reindex cache, as we now introduced more options for "index count changed" */
    $command_string = read_config_option("path_php_binary");
    $extra_args = "-q \"" . $config["base_path"] . "/cli/poller_reindex_hosts.php\" --id=all";
    exec_background($command_string, "{$extra_args}");
    cacti_log(__FUNCTION__ . " running {$command_string} {$extra_args}", false, "UPGRADE");
}
示例#11
0
文件: cmd.php 项目: songchin/Cacti
	if (($using_proc_function == true) && ($script_server_calls > 0)) {
		// close php server process
		fwrite($pipes[0], "quit\r\n");
		fclose($pipes[0]);
		fclose($pipes[1]);
		fclose($pipes[2]);

		$return_value = proc_close($cactiphp);
	}

	if (($print_data_to_stdout) || (read_config_option("log_verbosity") >= POLLER_VERBOSITY_MEDIUM)) {
		/* take time and log performance data */
		list($micro,$seconds) = split(" ", microtime());
		$end = $seconds + $micro;

		cacti_log(sprintf("Time: %01.4f s, " .
			"Theads: N/A, " .
			"Hosts: %s",
			round($end-$start,4),
			$host_count),$print_data_to_stdout);
	}

}else{
	cacti_log("ERROR: Either there are no items in the cache or polling is disabled",$print_data_to_stdout);
}

/* Let the poller server know about cmd.php being finished */
db_execute("insert into poller_time (poller_id, start_time, end_time) values (0, NOW(), NOW())");

?>
示例#12
0
function db_fetch_assoc($sql) {
	global $cnn_id;

	if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) {
		cacti_log("DEBUG: SQL Assoc: \"" . str_replace("\n", "", str_replace("\r", "", str_replace("\t", " ", $sql))) . "\"", FALSE);
	}

	$data = array();
	$cnn_id->SetFetchMode(ADODB_FETCH_ASSOC);
	$query = $cnn_id->Execute($sql);

	if ($query) {
		while ((!$query->EOF) && ($query)) {
			$data{sizeof($data)} = $query->fields;
			$query->MoveNext();
		}
		return($data);
	}else{
		cacti_log("ERROR: SQL Assoc Failed \"" . str_replace("\n", "", str_replace("\r", "", str_replace("\t", " ", $sql))) . "\"");
	}
}
示例#13
0
function export_log($stMessage) {
	if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) {
		cacti_log($stMessage, true, "EXPORT");
	}
}
示例#14
0
function upgrade_to_0_8_8() {
	require_once("../lib/import.php");

	/*
	 * Authenication System upgrade
	 */
	/* Create new tables */
	db_install_execute("0.8.8","
		CREATE TABLE `auth_control` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `name` varchar(100) NOT NULL default '',
		  `description` varchar(255) default NULL,
		  `object_type` int(8) unsigned NOT NULL default '0',
		  `enabled` int(1) unsigned NOT NULL default '1',
		  `updated_when` datetime NOT NULL default '0000-00-00 00:00:00',
		  `updated_by` varchar(100) NOT NULL default '',
		  `created_when` datetime NOT NULL default '0000-00-00 00:00:00',
		  `created_by` varchar(100) NOT NULL default '',
		  PRIMARY KEY  (`id`),
		  UNIQUE KEY `constraint_index` (`name`,`object_type`),
		  KEY `name` (`name`),
		  KEY `enabled` (`enabled`),
		  KEY `object_type` (`object_type`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `auth_data` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `control_id` mediumint(8) unsigned NOT NULL default '0',
		  `plugin_id` mediumint(8) unsigned NOT NULL default '0',
		  `category` varchar(25) NOT NULL default 'SYSTEM',
		  `name` varchar(100) NOT NULL default '',
		  `value` varchar(255) default NULL,
		  `enable_user_edit` int(1) unsigned NOT NULL default '0',
		  `updated_when` datetime NOT NULL default '0000-00-00 00:00:00',
		  `updated_by` varchar(100) NOT NULL default '',
		  PRIMARY KEY  (`id`),
		  UNIQUE KEY `constraint_index` (`control_id`,`plugin_id`,`category`,`name`),
		  KEY `control_id` (`control_id`),
		  KEY `name` (`name`),
		  KEY `plugin_id` (`plugin_id`),
		  KEY `category` (`category`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `auth_graph_perms` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `item_id` mediumint(8) unsigned NOT NULL default '0',
		  `type` mediumint(8) unsigned NOT NULL default '0',
		  `control_id` mediumint(8) unsigned NOT NULL default '0',
		  PRIMARY KEY  (`id`),
		  KEY `item_id` (`item_id`),
		  KEY `type` (`type`),
		  KEY `control_id` (`control_id`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `auth_link` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `control_id` mediumint(8) unsigned NOT NULL default '0',
		  `parent_id` mediumint(8) unsigned NOT NULL default '0',
		  PRIMARY KEY  (`id`),
		  KEY `control_id` (`control_id`),
		  KEY `parent_id` (`parent_id`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `auth_perm` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `name` varchar(100) NOT NULL default '',
		  `description` text NOT NULL,
		  `category` varchar(100) default NULL,
		  `plugin_id` mediumint(8) unsigned NOT NULL default '0',
		  PRIMARY KEY  (`id`),
		  KEY `name` (`name`),
		  KEY `plugin_id` (`plugin_id`),
		  KEY `category` (`category`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `auth_perm_link` (
		  `id` mediumint(8) unsigned NOT NULL auto_increment,
		  `control_id` mediumint(8) unsigned NOT NULL default '0',
		  `perm_id` mediumint(8) unsigned NOT NULL default '0',
		  PRIMARY KEY  (`id`),
		  KEY `control_id` (`control_id`),
		  KEY `perm_id` (`perm_id`)
		) TYPE=MyISAM");
	/* Upgrade current users and permissions */

	/* add the poller id for hosts to allow for multiple pollers */
	db_install_execute("0.8.8", "ALTER TABLE `host` ADD COLUMN `poller_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' AFTER id, ADD INDEX `poller_id`(`poller_id`);");

	/* add the poller id for poller_output to allow for multiple pollers */
	db_install_execute("0.8.8", "ALTER TABLE poller_output ADD COLUMN `poller_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' AFTER `time`, ADD INDEX `poller_id`(`poller_id`);");

	/* add the poller id for hosts to allow for multiple pollers */
	db_install_execute("0.8.8", "ALTER TABLE `poller` ADD COLUMN `disabled` CHAR(2) DEFAULT '' AFTER `id`, ADD COLUMN `description` VARCHAR(45) NOT NULL DEFAULT '' AFTER `disabled`;");

	/* add rrd_compute_rpn for data source items */
	db_install_execute("0.8.8", "ALTER TABLE `data_template_rrd` ADD COLUMN `t_rrd_compute_rpn` CHAR(2) DEFAULT NULL AFTER `rrd_minimum`, ADD COLUMN `rrd_compute_rpn` VARCHAR(150) DEFAULT '' AFTER `t_rrd_compute_rpn`;");

	/* add --alt-y-grid as an option */
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates_graph` ADD COLUMN `t_alt_y_grid` CHAR(2) DEFAULT 0 AFTER `auto_scale_rigid`, ADD COLUMN `alt_y_grid` CHAR(2) DEFAULT '' AFTER `t_alt_y_grid`;");

	/* increase size for upper/lower limit for use with |query_*| variables */
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates_graph` MODIFY `lower_limit` VARCHAR(255)");
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates_graph` MODIFY `upper_limit` VARCHAR(255)");

	/* add some fields required for hosts to table host_template */
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_community` VARCHAR(100) DEFAULT NULL AFTER `name`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_version` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `snmp_community`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_username` VARCHAR(50) DEFAULT NULL AFTER `snmp_version`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_password` VARCHAR(50) DEFAULT NULL AFTER `snmp_username`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_auth_protocol` CHAR(5) DEFAULT '' AFTER `snmp_password`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_priv_passphrase` VARCHAR(200) DEFAULT '' AFTER `snmp_auth_protocol`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_priv_protocol` CHAR(6) DEFAULT '' AFTER `snmp_priv_passphrase`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_context` VARCHAR(64) DEFAULT '' AFTER `snmp_priv_protocol`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_port` MEDIUMINT(5) UNSIGNED NOT NULL DEFAULT '161' AFTER `snmp_context`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `snmp_timeout` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '500' AFTER `snmp_port`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `availability_method` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '1' AFTER `snmp_timeout`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `ping_method` SMALLINT(5) UNSIGNED DEFAULT '0' AFTER `availability_method`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `ping_port` INT(12) UNSIGNED DEFAULT '0' AFTER `ping_method`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `ping_timeout` INT(12) UNSIGNED DEFAULT '500' AFTER `ping_port`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `ping_retries` INT(12) UNSIGNED DEFAULT '2' AFTER `ping_timeout`");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `max_oids` INT(12) UNSIGNED DEFAULT '10' AFTER `ping_retries`");

	/* create a sites table */
	db_install_execute("0.8.8", "CREATE TABLE  `sites` (
			`id` int(10) unsigned NOT NULL auto_increment,
			`name` varchar(100) NOT NULL default '',
			`address1` varchar(100) default '',
			`address2` varchar(100) default '',
			`city` varchar(50) default '',
			`state` varchar(20) default '',
			`postal_code` varchar(20) default '',
			`country` varchar(30) default '',
			`timezone` varchar(40) default '',
			`alternate_id` varchar(30) default '',
			`notes` text,
			PRIMARY KEY  (`id`),
			KEY `name` (`name`),
			KEY `city` (`city`),
			KEY `state` (`state`),
			KEY `postal_code` (`postal_code`),
			KEY `country` (`country`),
			KEY `alternate_id` (`alternate_id`)
			) ENGINE=MyISAM;");

	/* add a site column to the host table */
	db_install_execute("0.8.8", "ALTER TABLE `host` ADD COLUMN `site_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER id, ADD INDEX `site_id`(`site_id`);");

	/*
	 * now update current entries of table host_template
	 * make sure to use current global default settings in order not to change
	 * current behaviour when creating new hosts from those templates
	 */
	$snmp_community	= read_config_option("snmp_community", true);
	$snmp_version = read_config_option("snmp_ver", true);
	$snmp_username = read_config_option("snmp_username", true);
	$snmp_password = read_config_option("snmp_password", true);
	$snmp_auth_protocol = read_config_option("snmp_auth_protocol", true);
	$snmp_priv_passphrase = read_config_option("snmp_priv_passphrase", true);
	$snmp_priv_protocol = read_config_option("snmp_priv_protocol", true);
	$snmp_context = read_config_option("snmp_context", true);
	$snmp_port = read_config_option("snmp_port", true);
	$snmp_timeout = read_config_option("snmp_timeout", true);
	$availability_method = read_config_option("availability_method", true);
	$ping_method = read_config_option("ping_method", true);
	$ping_port = read_config_option("ping_port", true);
	$ping_timeout = read_config_option("ping_timeout", true);
	$ping_retries = read_config_option("ping_retries", true);
	$max_oids = read_config_option("max_get_size", true);

	db_install_execute("0.8.8", "UPDATE `host_template` " .
			"SET  `snmp_community` = '" . $snmp_community . "' ," .
				" `snmp_version` = $snmp_version," .
				" `snmp_username` = '" . $snmp_username . "' ," .
				" `snmp_password` = '" . $snmp_password . "' ," .
				" `snmp_auth_protocol` = '" . $snmp_auth_protocol . "' ," .
				" `snmp_priv_passphrase` = '" . $snmp_priv_passphrase . "' ," .
				" `snmp_priv_protocol` = '" . $snmp_priv_protocol . "' ," .
				" `snmp_context` = '" . $snmp_context . "' ," .
				" `snmp_port` = $snmp_port," .
				" `snmp_timeout` = $snmp_timeout," .
				" `availability_method` = $availability_method," .
				" `ping_method` = $ping_method," .
				" `ping_port` = $ping_port," .
				" `ping_timeout` = $ping_timeout," .
				" `ping_retries` = $ping_retries," .
				" `max_oids` = $max_oids");

	/* add reindexing to host_template_snmp_query */
	db_install_execute("0.8.8", "ALTER TABLE `host_template_snmp_query` ADD COLUMN `reindex_method` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `snmp_query_id`");
	db_install_execute("0.8.8", "UPDATE `host_template_snmp_query` SET `reindex_method` = '1'");
	/*
	 * Plugin Architecture
	 */
	/* Create new tables */
	db_install_execute("0.8.8","
		CREATE TABLE `plugin_config` (
		  `id` int(8) NOT NULL auto_increment,
		  `directory` varchar(32) NOT NULL default '',
		  `name` varchar(64) NOT NULL default '',
		  `status` tinyint(2) NOT NULL default '0',
		  `author` varchar(64) NOT NULL default '',
		  `webpage` varchar(255) NOT NULL default '',
		  `version` varchar(8) NOT NULL default '',
		  PRIMARY KEY  (`id`),
		  KEY `status` (`status`),
		  KEY `directory` (`directory`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `plugin_db_changes` (
		  `id` int(10) NOT NULL auto_increment,
		  `plugin` varchar(16) NOT NULL default '',
		  `table` varchar(64) NOT NULL default '',
		  `column` varchar(64) NOT NULL default '',
		  `method` varchar(16) NOT NULL default '',
		  PRIMARY KEY  (`id`),
		  KEY `plugin` (`plugin`),
		  KEY `method` (`method`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8","
		CREATE TABLE `plugin_hooks` (
		  `id` int(8) NOT NULL auto_increment,
		  `name` varchar(32) NOT NULL default '',
		  `hook` varchar(64) NOT NULL default '',
		  `file` varchar(255) NOT NULL default '',
		  `function` varchar(128) NOT NULL default '',
		  `status` int(8) NOT NULL default '0',
		  PRIMARY KEY  (`id`),
		  KEY `hook` (`hook`),
		  KEY `status` (`status`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8", "INSERT INTO `plugin_hooks` VALUES (1, 'internal', 'config_arrays', '', 'plugin_config_arrays', 1)");
	db_install_execute("0.8.8", "INSERT INTO `plugin_hooks` VALUES (2, 'internal', 'draw_navigation_text', '', 'plugin_draw_navigation_text', 1)");

	db_install_execute("0.8.8","
		CREATE TABLE `plugin_realms` (
		  `id` int(8) NOT NULL auto_increment,
		  `plugin` varchar(32) NOT NULL default '',
		  `file` text NOT NULL default '',
		  `display` varchar(64) NOT NULL default '',
		  PRIMARY KEY  (`id`),
		  KEY `plugin` (`plugin`)
		) TYPE=MyISAM");
	db_install_execute("0.8.8", "INSERT INTO `plugin_realms` VALUES (1, 'internal', 'plugins.php', 'Plugin Management')");

	/* wrong lower limit for generic OID graph template */
	db_install_execute("0.8.8", "UPDATE graph_templates_graph SET lower_limit='0', vertical_label='' WHERE id=47");

	/* rename templates */
	/* graph templates */
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='UCD-SNMP - diskTable - Hard Drive Space' where name='ucd/net - Available Disk Space'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='UCD-SNMP - systemStats - CPU Usage' where name='ucd/net - CPU Usage'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - ICMP - Ping Host' where name='Unix - Ping Latency'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - ps ax - Processes' where name='Unix - Processes'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - Uptime - Load Average' where name='Unix - Load Average'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - who - Logged in Users' where name='Unix - Logged in Users'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='UCD-SNMP - loadTable - Load Average' where name='ucd/net - Load Average'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - meminfo - Memory' where name='Linux - Memory Usage'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='UCD-SNMP - memory - Memory Usage' where name='ucd/net - Memory Usage'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='Linux Localhost - df - Hard Drive Space' where name='Unix - Available Disk Space'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='HOST-RESSOURCES - hrStorageTable - Hard Drive Space' where name='Host MIB - Available Disk Space'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='HOST-RESSOURCES - hrProcessorTable - CPU Utilization' where name='Host MIB - CPU Utilization'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='HOST-RESSOURCES - hrSystemNumUsers - Logged in Users' where name='Host MIB - Logged in Users'");
	db_install_execute("0.8.8", "UPDATE graph_templates SET name='HOST-RESSOURCES - hrSystemProcesses - Processes' where name='Host MIB - Processes'");
	/* data templates */
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - diskTable - Hard Drive Space'  WHERE name='ucd/net - Hard Drive Space'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - systemStats - CPU Usage: System'  WHERE name='ucd/net - CPU Usage - System'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - systemStats - CPU Usage: User'  WHERE name='ucd/net - CPU Usage - User'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - systemStats - CPU Usage: Nice'  WHERE name='ucd/net - CPU Usage - Nice'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - Uptime - Load Average'  WHERE name='Unix - Load Average'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - meminfo - Memory: Free'  WHERE name='Linux - Memory - Free'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - meminfo - Memory: Free Swap'  WHERE name='Linux - Memory - Free Swap'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - ps ax - Processes'  WHERE name='Unix - Processes'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - who - Logged in Users'  WHERE name='Unix - Logged in Users'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - ICMP - Ping Host'  WHERE name='Unix - Ping Host'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - loadTable - Load Average: 1 Minute'  WHERE name='ucd/net - Load Average - 1 Minute'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - loadTable - Load Average: 5 Minutes'  WHERE name='ucd/net - Load Average - 5 Minute'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - loadTable - Load Average: 15 Minutes'  WHERE name='ucd/net - Load Average - 15 Minute'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - memory - Buffers'  WHERE name='ucd/net - Memory - Buffers'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - memory - Free'  WHERE name='ucd/net - Memory - Free'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='Linux Localhost - df - Hard Drive Space'  WHERE name='Unix - Hard Drive Space'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='HOST-RESSOURCES - hrStorageTable - Hard Drive Space'  WHERE name='Host MIB - Hard Drive Space'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='HOST-RESSOURCES - hrProcessorTable - CPU Utilization'  WHERE name='Host MIB - CPU Utilization'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='HOST-RESSOURCES - hrSystemProcesses - Processes'  WHERE name='Host MIB - Processes'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='HOST-RESSOURCES - hrSystemNumUsers - Logged in Users'  WHERE name='Host MIB - Logged in Users'");
	db_install_execute("0.8.8", "UPDATE data_template SET name='UCD-SNMP - memory - Cache'  WHERE name='ucd/net - Memory - Cache'");
	/* data queries */
	db_install_execute("0.8.8", "UPDATE snmp_query SET name='UCD-SNMP - diskTable - Hard Drive Space' where name='ucd/net -  Get Monitored Partitions'");
	db_install_execute("0.8.8", "UPDATE snmp_query SET name='Linux Localhost - df - Hard Drive Space' where name='Unix - Get Mounted Partitions'");
	db_install_execute("0.8.8", "UPDATE snmp_query SET name='HOST-RESSOURCES - hrStorageTable - Hard Drive Space' where name='SNMP - Get Mounted Partitions'");
	db_install_execute("0.8.8", "UPDATE snmp_query SET name='HOST-RESSOURCES - hrProcessorTable - CPU Utilization' where name='SNMP - Get Processor Information'");

	/* enable lossless reindexing in Cacti */
	db_install_execute("0.8.8", "ALTER TABLE host_snmp_cache ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `oid`, ADD INDEX present USING BTREE (present)");
	db_install_execute("0.8.8", "ALTER TABLE poller_item ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`, ADD INDEX present USING BTREE (present)");
	db_install_execute("0.8.8", "ALTER TABLE poller_reindex ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`, ADD INDEX present USING BTREE (present)");

	/* add image storage to graph templates, data queries, and device templates */
	db_install_execute("0.8.8", "ALTER TABLE `data_template` ADD COLUMN `description` varchar(255) NOT NULL AFTER `name`;");
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates` ADD COLUMN `description` varchar(255) NOT NULL AFTER `name`;");
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates` ADD COLUMN `image` varchar(64) NOT NULL AFTER `description`");
	db_install_execute("0.8.8", "ALTER TABLE `snmp_query` ADD COLUMN `image` varchar(64) NOT NULL AFTER `description`;");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `description` varchar(255) NOT NULL AFTER `name`;");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `image` varchar(64) NOT NULL AFTER `description`;");

	/* changes for template propagation */
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `override_defaults` CHAR(2) NOT NULL DEFAULT '' AFTER `image`;");
	db_install_execute("0.8.8", "ALTER TABLE `host_template` ADD COLUMN `override_permitted` CHAR(2) NOT NULL DEFAULT 'on' AFTER `override_defaults`;");
	db_install_execute("0.8.8", "ALTER TABLE `host` ADD COLUMN `template_enabled` CHAR(2) NOT NULL DEFAULT '' AFTER `host_template_id`;");

	/* Add SNMPv3 Context to SNMP Input Methods */
	/* first we must see if the user was smart enough to add it themselves */
	$context1 = db_fetch_row("SELECT id FROM data_input_fields WHERE data_input_id=1 AND data_name='snmp_context' AND input_output='in' AND type_code='snmp_context'");
	if ($context1 > 0) {
		# nop
	} else {
		db_install_execute("0.8.8", "INSERT INTO data_input_fields VALUES (DEFAULT, '8e42450d52c46ebe76a57d7e51321d36',1,'SNMP Context (v3)','snmp_context','in','',0,'snmp_context','','')");
	}
	$context2 = db_fetch_row("SELECT id FROM data_input_fields WHERE data_input_id=2 AND data_name='snmp_context' AND input_output='in' AND type_code='snmp_context'");
	if ($context2 > 0) {
		# nop
	} else {
		db_install_execute("0.8.8", "INSERT INTO data_input_fields VALUES (DEFAULT, 'b5ce68ca4e9e36d221459758ede01484',2,'SNMP Context (v3)','snmp_context','in','',0,'snmp_context','','')");
	}

	db_install_execute("0.8.8", "UPDATE data_input_fields SET name='SNMP Authentication Protocol (v3)' WHERE name='SNMP Authenticaion Protocol (v3)'");

	db_install_execute("0.8.8", "ALTER TABLE host ADD COLUMN polling_time decimal(10,5) NOT NULL DEFAULT '0.00000' AFTER `avg_time`");

	# graph_templates_graph
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_right_axis char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN right_axis varchar(20) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_right_axis_label char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN right_axis_label varchar(200) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_right_axis_format char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN right_axis_format mediumint(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_only_graph char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN only_graph char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_full_size_mode char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN full_size_mode char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_no_gridfit char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN no_gridfit char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_x_grid char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN x_grid mediumint(8) unsigned NOT NULL default '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_unit_length char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN unit_length varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_back char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_back char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_canvas char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_canvas char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_shadea char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_shadea char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_shadeb char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_shadeb char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_grid char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_grid char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_mgrid char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_mgrid char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_font char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_font char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_axis char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_axis char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_frame char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_frame char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_colortag_arrow char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN colortag_arrow char(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_font_render_mode char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN font_render_mode varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_font_smoothing_threshold char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN font_smoothing_threshold int(8) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_graph_render_mode char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN graph_render_mode varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_pango_markup char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN pango_markup char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_interlaced char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN interlaced char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_tab_width char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN tab_width mediumint(4) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_watermark char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN watermark varchar(255) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_force_rules_legend char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN force_rules_legend char(2) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_legend_position char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN legend_position varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_legend_direction char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN legend_direction varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_grid_dash char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN grid_dash varchar(10) DEFAULT NULL");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN t_border char(2) DEFAULT '0'");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_graph ADD COLUMN border char(2) DEFAULT NULL");
	# create new table graph_templates_xaxis
	db_install_execute("0.8.8","
		CREATE TABLE `graph_templates_xaxis` (
		  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Table Id',
		  `hash` varchar(32) NOT NULL DEFAULT '' COMMENT 'Unique Hash',
		  `name` varchar(100) NOT NULL DEFAULT '' COMMENT 'Name of X-Axis Preset',
		  PRIMARY KEY (`id`)
		) ENGINE=MyISAM  COMMENT='X-Axis Presets'");
	db_install_execute("0.8.8", "INSERT INTO `graph_templates_xaxis` VALUES(1, 'a09c5cab07a6e10face1710cec45e82f', 'Default')");
	# create new table graph_templates_xaxis_items
	db_install_execute("0.8.8","
		CREATE TABLE `graph_templates_xaxis_items` (
		  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Row Id',
		  `hash` varchar(32) NOT NULL DEFAULT '' COMMENT 'Unique Hash',
		  `item_name` varchar(100) NOT NULL COMMENT 'Name of this Item',
		  `xaxis_id` int(12) unsigned NOT NULL DEFAULT '0' COMMENT 'Id of related X-Axis Preset',
		  `timespan` int(12) unsigned NOT NULL DEFAULT '0' COMMENT 'Graph Timespan that shall match this Item',
		  `gtm` VARCHAR( 10 ) NOT NULL DEFAULT '' COMMENT 'Global Grid Timespan',
		  `gst` smallint(4) unsigned NOT NULL COMMENT 'Global Grid Timespan Steps',
		  `mtm` VARCHAR( 10 ) NOT NULL DEFAULT '' COMMENT 'Major Grid Timespan',
		  `mst` smallint(4) unsigned NOT NULL COMMENT 'Major Grid Timespan Steps',
		  `ltm` VARCHAR( 10 ) NOT NULL DEFAULT '' COMMENT 'Label Grid Timespan',
		  `lst` smallint(4) unsigned NOT NULL COMMENT 'Label Grid Timespan Steps',
		  `lpr` int(12) unsigned NOT NULL COMMENT 'Label Placement Relative',
		  `lfm` varchar(100) NOT NULL COMMENT 'Label Format',
		  PRIMARY KEY (`id`)
		) ENGINE=MyISAM COMMENT='Items for X-Axis Presets'");
	db_install_execute("0.8.8", "INSERT INTO `graph_templates_xaxis_items` VALUES(1, '60c2066a1c45fab021d32fe72cbf4f49', 'Day', 1, 86400, 'HOUR', 4, 'HOUR', 2, 'HOUR', 2, 23200, '%H')");
	db_install_execute("0.8.8", "INSERT INTO `graph_templates_xaxis_items` VALUES(2, 'd867f8fc2730af212d0fd6708385cf89', 'Week', 1, 604800, 'DAY', 1, 'DAY', 1, 'DAY', 1, 259200, '%d')");
	db_install_execute("0.8.8", "INSERT INTO `graph_templates_xaxis_items` VALUES(3, '06304a1840da88f3e0438ac147219003', 'Month', 1, 2678400, 'WEEK', 1, 'WEEK', 1, 'WEEK', 1, 1296000, '%W')");
	db_install_execute("0.8.8", "INSERT INTO `graph_templates_xaxis_items` VALUES(4, '33ac10e60fd855e74736bee43bda4134', 'Year', 1, 31622400, 'MONTH', 2, 'MONTH', 1, 'MONTH', 2, 15811200, '%m')");

	/* upgrade to the graph trees */
	db_install_execute("0.8.8", "ALTER TABLE `graph_tree_items`
		ADD COLUMN `parent_id` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0' AFTER `id`,
		ADD COLUMN `site_id` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0' AFTER `title`;");

	/* make tree's a per user object.  System tree's have a user_id of 0 */
	db_install_execute("0.8.8", "ALTER TABLE `graph_tree` ADD COLUMN `user_id` INTEGER UNSIGNED NOT NULL DEFAULT '0' AFTER `id`, ADD INDEX `user_id`(`user_id`);");

	/* get all nodes whose parent_id is not 0 */
	$tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE order_key NOT LIKE '___000%';");
	if (sizeof($tree_items)) {
	foreach($tree_items AS $item) {
		$translated_key = rtrim($item["order_key"], "0\r\n");
		$missing_len    = strlen($translated_key) % CHARS_PER_TIER;
		if ($missing_len > 0) {
			$translated_key .= substr("000", 0, $missing_len);
		}
		$parent_key_len = strlen($translated_key) - CHARS_PER_TIER;
		$parent_key     = substr($translated_key, 0, $parent_key_len);
		$parent_id      = db_fetch_cell("SELECT id FROM graph_tree_items WHERE graph_tree_id=" . $item["graph_tree_id"] . " AND order_key LIKE '" . $parent_key . "000%'");
		if ($parent_id != "") {
			db_execute("UPDATE graph_tree_items SET parent_id=$parent_id WHERE id=" . $item["id"]);
		}else{
			cacti_log("Some error occurred processing children", false);
		}
	}
	}

	/* make the poller's ip address varchar() */
	db_install_execute("0.8.8", "ALTER TABLE poller CHANGE COLUMN ip_address ip_address varchar(30) not null default ''");

	/* insert the default poller into the database */
	db_install_execute("0.8.8", "INSERT INTO `poller` VALUES (1,'','Main Poller','localhost','127.0.0.1','0000-00-00 00:00:00');");

	/* update all devices to use poller 1, or the main poller */
	db_install_execute("0.8.8", "UPDATE host SET poller_id=1 WHERE poller_id=0");

	/* update the poller_items table to reflect the host change */
	db_install_execute("0.8.8", "UPDATE poller_item SET poller_id=1 WHERE poller_id=0");

	/* rename host -> device for tables and columns
	 * we have some updates to those tables in this file already
	 * so please take care not to change sequence */
	$_indexes = db_fetch_assoc("SHOW INDEX FROM data_local WHERE `Column_name`='host_id'");
	if (sizeof($_indexes)) {
		foreach($_indexes as $_index) {
			db_install_execute("0.8.8", "ALTER TABLE data_local DROP INDEX " . $_index["Key_name"]);
		}
	}
	db_install_execute("0.8.8", "ALTER TABLE data_local CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` )");
	db_install_execute("0.8.8", "ALTER TABLE graph_local DROP INDEX `host_id`");
	db_install_execute("0.8.8", "ALTER TABLE graph_local CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` )");
	db_install_execute("0.8.8", "ALTER TABLE graph_tree_items DROP INDEX `host_id`");
	db_install_execute("0.8.8", "ALTER TABLE graph_tree_items CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` ), CHANGE `host_grouping_type` `device_grouping_type` TINYINT(3) UNSIGNED NOT NULL DEFAULT 1");
	db_install_execute("0.8.8", "RENAME TABLE `host`  TO `device`");
	db_install_execute("0.8.8", "ALTER TABLE `device` CHANGE `host_template_id` `device_template_id` MEDIUMINT(8) UNSIGNED NOT NULL");
	db_install_execute("0.8.8", "RENAME TABLE `host_graph`  TO `device_graph`");
	db_install_execute("0.8.8", "ALTER TABLE device_graph CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL");
	db_install_execute("0.8.8", "RENAME TABLE `host_snmp_cache`  TO `device_snmp_cache`");
	db_install_execute("0.8.8", "ALTER TABLE device_snmp_cache DROP INDEX `host_id`");
	db_install_execute("0.8.8", "ALTER TABLE device_snmp_cache CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` )");
	db_install_execute("0.8.8", "RENAME TABLE `host_snmp_query`  TO `device_snmp_query`");
	db_install_execute("0.8.8", "ALTER TABLE device_snmp_query DROP INDEX `host_id`");
	db_install_execute("0.8.8", "ALTER TABLE device_snmp_query CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` )");
	db_install_execute("0.8.8", "RENAME TABLE `host_template`  TO `device_template`");
	db_install_execute("0.8.8", "RENAME TABLE `host_template_graph`  TO `device_template_graph`");
	db_install_execute("0.8.8", "ALTER TABLE device_template_graph DROP INDEX `host_template_id`");
	db_install_execute("0.8.8", "ALTER TABLE device_template_graph CHANGE `host_template_id` `device_template_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_template_id` ( `device_template_id` )");
	db_install_execute("0.8.8", "RENAME TABLE `host_template_snmp_query`  TO `device_template_snmp_query`");
	db_install_execute("0.8.8", "ALTER TABLE device_template_snmp_query DROP INDEX `host_template_id`");
	db_install_execute("0.8.8", "ALTER TABLE device_template_snmp_query CHANGE `host_template_id` `device_template_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_template_id` ( `device_template_id` )");
	db_install_execute("0.8.8", "ALTER TABLE poller_item DROP INDEX `host_id`");
	db_install_execute("0.8.8", "ALTER TABLE poller_item CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL, ADD INDEX `device_id` ( `device_id` )");
	db_install_execute("0.8.8", "ALTER TABLE poller_reindex CHANGE `host_id` `device_id` MEDIUMINT(8) UNSIGNED NOT NULL");
	db_install_execute("0.8.8", "ALTER TABLE user_auth CHANGE `policy_hosts` `policy_devices` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1");

	# table column updates using REPLACE
	db_install_execute("0.8.8", "UPDATE data_template_data SET name=REPLACE(name,'|host_','|device_') WHERE name like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE graph_templates_graph SET title=REPLACE(title,'|host_','|device_') WHERE title like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE graph_templates_graph SET upper_limit=REPLACE(upper_limit,'|host_','|device_') WHERE upper_limit like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE graph_templates_graph SET lower_limit=REPLACE(lower_limit,'|host_','|device_') WHERE lower_limit like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE graph_templates_graph SET vertical_label=REPLACE(vertical_label,'|host_','|device_') WHERE vertical_label like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE snmp_query_graph_rrd_sv SET `text`=REPLACE(`text`,'|host_','|device_') WHERE `text` like '%%|host_%%'");
	db_install_execute("0.8.8", "UPDATE snmp_query_graph_sv SET `text`=REPLACE(`text`,'|host_','|device_') WHERE `text` like '%%|host_%%'");

	/* New Indexes */
	db_install_execute("0.8.8","ALTER TABLE `data_input_data` 		ADD INDEX `data_template_data_id` 				(`data_template_data_id`)");
	db_install_execute("0.8.8","ALTER TABLE `data_local` 			ADD INDEX `device_id_snmp_query_id_snmp_index` 	(`device_id`,`snmp_query_id`,`snmp_index`)");
	db_install_execute("0.8.8","ALTER TABLE `data_template_data` 	ADD INDEX `data_source_path` 					(`data_source_path`)");
	db_install_execute("0.8.8","ALTER TABLE `data_template_rrd` 	ADD INDEX `local_data_id_data_source_name`  	(`local_data_id`,`data_source_name`)");
	db_install_execute("0.8.8","ALTER TABLE `device_snmp_cache` 	ADD INDEX `device_id_snmp_query_id_snmp_index` 	(`device_id`,`snmp_query_id`,`snmp_index`)");
	db_install_execute("0.8.8","ALTER TABLE `device_snmp_cache` 	ADD INDEX `device_id_snmp_query_id` 			(`device_id`,`snmp_query_id`)");
	db_install_execute("0.8.8","ALTER TABLE `graph_templates_item` 	ADD INDEX `graph_template_id_local_graph_id`  	(`graph_template_id`,`local_graph_id`)");
	db_install_execute("0.8.8","ALTER TABLE `graph_templates_item` 	ADD INDEX `local_graph_template_item_id` 		(`local_graph_template_item_id`)");
	db_install_execute("0.8.8","ALTER TABLE `poller_item` 			ADD INDEX `local_data_id_rrd_path` 				(`local_data_id`,`rrd_path`)");
	db_install_execute("0.8.8","ALTER TABLE `poller_item` 			ADD INDEX `device_id_rrd_next_step` 			(`device_id`,`rrd_next_step`)");
	db_install_execute("0.8.8","ALTER TABLE `poller_item` 			ADD INDEX `device_id_snmp_port` 				(`device_id`,`snmp_port`)");
	db_install_execute("0.8.8","ALTER TABLE `user_log` 				ADD INDEX `user_id`								(`user_id`)");

	/* Create new tables */
	db_install_execute("0.8.8","CREATE TABLE `log` (
			`id` bigint(20) unsigned NOT NULL default '0',
			`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
			`facility` tinyint(1) unsigned NOT NULL default '0',
			`severity` int(1) NOT NULL default '0',
			`poller_id` smallint(5) unsigned NOT NULL default '0',
			`device_id` mediumint(8) unsigned NOT NULL default '0',
			`data_id` mediumint(8) unsigned NOT NULL default '0',
			`username` varchar(100) NOT NULL default 'system',
			`source` varchar(50) NOT NULL default 'localhost',
			`plugin_name` varchar(64) NOT NULL default '',
			`message` text NOT NULL,
			PRIMARY KEY  (`id`),
			KEY `facility` (`facility`),
			KEY `severity` (`severity`),
			KEY `device_id` (`device_id`),
			KEY `data_id` (`data_id`),
			KEY `poller_id` (`poller_id`),
			KEY `username` (`username`),
			KEY `timestamp` (`timestamp`),
			KEY `plugin_name` (`plugin_name`)
			) TYPE=MyISAM");

	/* changes to insert VDEF into table graph_templates_item just behind CDEF */
	db_install_execute("0.8.8", "ALTER TABLE `graph_templates_item` ADD `vdef_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0 AFTER `cdef_id`");

	/* create new table VDEF */
	db_install_execute("0.8.8", "CREATE TABLE vdef (
  		id mediumint(8) unsigned NOT NULL auto_increment,
  		hash varchar(32) NOT NULL default '',
  		name varchar(255) NOT NULL default '',
  		PRIMARY KEY  (id)
		) TYPE=MyISAM;");

	/* fill table VDEF */
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (1, 'e06ed529238448773038601afb3cf278', 'Maximum');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (2, 'e4872dda82092393d6459c831a50dc3b', 'Minimum');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (3, '5ce1061a46bb62f36840c80412d2e629', 'Average');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (4, '06bd3cbe802da6a0745ea5ba93af554a', 'Last (Current)');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (5, '631c1b9086f3979d6dcf5c7a6946f104', 'First');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (6, '6b5335843630b66f858ce6b7c61fc493', 'Total: Current Data Source');");
	db_install_execute("0.8.8", "INSERT INTO `vdef` VALUES (7, 'c80d12b0f030af3574da68b28826cd39', '95th Percentage: Current Data Source');");

	/* create new table VDEF_ITEMS */
	db_install_execute("0.8.8", "CREATE TABLE vdef_items (
  		id mediumint(8) unsigned NOT NULL auto_increment,
  		hash varchar(32) NOT NULL default '',
  		vdef_id mediumint(8) unsigned NOT NULL default 0,
  		sequence mediumint(8) unsigned NOT NULL default 0,
  		type tinyint(2) NOT NULL default 0,
  		value varchar(150) NOT NULL default '',
  		PRIMARY KEY  (id),
  		KEY vdef_id (vdef_id)
		) TYPE=MyISAM;");

	/* fill table VDEF */
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (1, '88d33bf9271ac2bdf490cf1784a342c1', 1, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (2, 'a307afab0c9b1779580039e3f7c4f6e5', 1, 2, 1, '1');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (3, '0945a96068bb57c80bfbd726cf1afa02', 2, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (4, '95a8df2eac60a89e8a8ca3ea3d019c44', 2, 2, 1, '2');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (5, 'cc2e1c47ec0b4f02eb13708cf6dac585', 3, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (6, 'a2fd796335b87d9ba54af6a855689507', 3, 2, 1, '3');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (7, 'a1d7974ee6018083a2053e0d0f7cb901', 4, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (8, '26fccba1c215439616bc1b83637ae7f3', 4, 2, 1, '5');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (9, 'a8993b265f4c5398f4a47c44b5b37a07', 5, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (10, '5a380d469d611719057c3695ce1e4eee', 5, 2, 1, '6');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (11, '65cfe546b17175fad41fcca98c057feb', 6, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (12, 'f330b5633c3517d7c62762cef091cc9e', 6, 2, 1, '7');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (13, 'f1bf2ecf54ca0565cf39c9c3f7e5394b', 7, 1, 4, 'CURRENT_DATA_SOURCE');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (14, '11a26f18feba3919be3af426670cba95', 7, 2, 6, '95');");
	db_install_execute("0.8.8", "INSERT INTO `vdef_items` VALUES (15, 'e7ae90275bc1efada07c19ca3472d9db', 7, 3, 1, '8');");

	# graph_templates_items: split LINEx into LINE and a line_width of x
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_item ADD COLUMN line_width DECIMAL(4,2) DEFAULT 0 AFTER graph_type_id");
	db_install_execute("0.8.8", "UPDATE graph_templates_item SET `line_width`=1 WHERE `graph_type_id`=4"); # LINE1
	db_install_execute("0.8.8", "UPDATE graph_templates_item SET `line_width`=2 WHERE `graph_type_id`=5"); # LINE2
	db_install_execute("0.8.8", "UPDATE graph_templates_item SET `line_width`=3 WHERE `graph_type_id`=6"); # LINE3

	# graph_templates_items: add DASHES and DASH-OFFSET
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_item ADD COLUMN dashes varchar(20) DEFAULT NULL AFTER line_width");
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_item ADD COLUMN dash_offset mediumint(4) DEFAULT NULL AFTER dashes");

	# graph_templates_items: add TEXTALIGN
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_item ADD COLUMN textalign varchar(10) default NULL AFTER consolidation_function_id");

	# graph_templates_items: add SHIFT
	db_install_execute("0.8.8", "ALTER TABLE graph_templates_item ADD COLUMN shift char(2) default NULL AFTER vdef_id");

	/* implement per device threads setting for spine */
	db_install_execute("0.8.8", "ALTER TABLE device ADD COLUMN device_threads tinyint(2) unsigned NOT NULL default '1' AFTER max_oids");
	db_install_execute("0.8.8", "ALTER TABLE device_template ADD COLUMN device_threads tinyint(2) unsigned NOT NULL default '1' AFTER max_oids");

	/* new cdef's for background colorization */
	$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='2544acefc5fef30366c71336166ed141';");
	if ($cdef_id == 0) {
		db_install_execute("0.8.8", "INSERT INTO `cdef` VALUES(DEFAULT, '2544acefc5fef30366c71336166ed141', 'Time: Daytime')");
		$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='2544acefc5fef30366c71336166ed141';");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'ac0dea239ef3279c9b5ee04990fd4ec0', $cdef_id, 1, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '12f2bd71d5cbc078b9712c54d21c4f59', $cdef_id, 2, 6, '86400')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'bf35d7e5ae6df56398ea0f34a77311fc', $cdef_id, 3, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '31a9b3ff3b402f0446e6f6454b4d47c2', $cdef_id, 4, 4, 'TIME_SHIFT_START')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '996b718fc70353deb676e9037af9eadd', $cdef_id, 5, 1, '23')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '9c48bd2133670fd5158264ac25df6bb6', $cdef_id, 6, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '50c205e8bd5bb19b7fbee0ec2dee44cb', $cdef_id, 7, 6, '86400')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '14ee4ad2c7f91ab6406e1ecec6f4bcdc', $cdef_id, 8, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '38023f18060f2586e3504bbdd2634cc3', $cdef_id, 9, 4, 'TIME_SHIFT_END')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '1dbfee1b96a11492e58128ee8de93925', $cdef_id, 10, 1, '21')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6979b0680858c8d153530d9390f6a4e9', $cdef_id, 11, 1, '37')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'f9d37c6480c3555c9d6d2d8910ef2da7', $cdef_id, 12, 1, '36')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6c2604fd53780532c93c16d82c0337fd', $cdef_id, 13, 4, 'CURRENT_DATA_SOURCE')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'c2652379ba1c6523dc036e0a312536c4', $cdef_id, 14, 2, '3')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '63bf07a965b64fc41faa4bf01ae8a39d', $cdef_id, 15, 1, '29')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '2a9dea57a4f5d12cd0e2e66a31186a35', $cdef_id, 16, 1, '36')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '014839ebf8261c501d1da6c2c5217a0c', $cdef_id, 17, 4, 'CURRENT_DATA_SOURCE')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '01c946b79d68fad871e6e9437cba924f', $cdef_id, 18, 2, '3')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '4d0879e3c65c5af4e35d41a1631dcbe5', $cdef_id, 19, 1, '29')");
	}

	$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='8bd388f585b624a7bbad97101a2b7ee9';");
	if ($cdef_id == 0) {
		db_install_execute("0.8.8", "INSERT INTO `cdef` VALUES(DEFAULT, '8bd388f585b624a7bbad97101a2b7ee9', 'Time: Nighttime')");
		$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='8bd388f585b624a7bbad97101a2b7ee9';");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '1c9452055499efaddded29c74ee21880', $cdef_id, 1, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '36af4d7c5a8acf09bda1a3a5f1409979', $cdef_id, 2, 6, '86400')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '74cf8897d5ada9da271c64e82a1384ac', $cdef_id, 3, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '053c5efacd6787b6e41ed109043ba256', $cdef_id, 4, 4, 'TIME_SHIFT_START')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'da39b6410ab37833842511f46182717d', $cdef_id, 5, 1, '21')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '652afbee7025a256b8dc3c49e75b27fc', $cdef_id, 6, 1, '37')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '26a63ba997e1f904c71bb7c9eb5e76e5', $cdef_id, 7, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6f83ed61e0743176f03dd790f31521ea', $cdef_id, 8, 6, '86400')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6b49d9dc72576a7ada160f0befc77c85', $cdef_id, 9, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '22f0dd9a5e0e189424ea29fe1383e29d', $cdef_id, 10, 4, 'TIME_SHIFT_END')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'd3f3a319e8fcfac10bd06fb247d236af', $cdef_id, 11, 1, '23')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '1cf7208bfa84c61f788f327500b712a6', $cdef_id, 12, 1, '37')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'c29025779a287d2f7b946e9ffbba3c24', $cdef_id, 13, 1, '36')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '690852ea78bf45796ef21947e27528be', $cdef_id, 14, 4, 'CURRENT_DATA_SOURCE')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '09061dcd9762280ffd3994c8274b19f8', $cdef_id, 15, 2, '3')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '60be0afe23bef9fdb7e6cabd9067eb32', $cdef_id, 16, 1, '29')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'f4a6609839d199ecb12c2f05b5d3a7b6', $cdef_id, 17, 1, '29')");
	}

	$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='b4ef0a1c5e471dc6bae6a13ace5c57e7';");
	if ($cdef_id == 0) {
		db_install_execute("0.8.8", "INSERT INTO `cdef` VALUES(DEFAULT, 'b4ef0a1c5e471dc6bae6a13ace5c57e7', 'Time: Weekend')");
		$cdef_id = 	db_fetch_cell("SELECT id FROM cdef WHERE hash='b4ef0a1c5e471dc6bae6a13ace5c57e7';");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'd4f93d57657e6c3ae2053a4a760a0c7b', $cdef_id, 1, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '00a793341980c41728c6ee665718001c', $cdef_id, 2, 6, '604800')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '0a7eaf7192e5e44a425f5e8986850190', $cdef_id, 3, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'ceb07e26bf15c561b12004c5e32d7f1f', $cdef_id, 4, 6, '172800')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '3a3bfafebd173fdbbd8c07d2e2dd661f', $cdef_id, 5, 1, '23')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '4c080ecaaa7260886ea148869d4d0456', $cdef_id, 6, 1, '42')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'bd57afcd9879e29e29bb796ba8d6188d', $cdef_id, 7, 6, '604800')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'cd14cd9adfbae04973a75b90880e7d64', $cdef_id, 8, 2, '5')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '3bed46dd43a64d54acc4f0723cff0bc7', $cdef_id, 9, 6, '345600')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6fa62ee12bb8ba8936e39ea4303f92fd', $cdef_id, 10, 1, '21')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'f26848c08c2fb385126f90107494ce64', $cdef_id, 11, 1, '37')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'b8a5dde83327cac6705cdaa58300153b', $cdef_id, 12, 1, '36')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'f6aa118b35e269101ca3049cc4a323db', $cdef_id, 13, 4, 'CURRENT_DATA_SOURCE')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '967beb159b1ea744460ff3439ab205eb', $cdef_id, 14, 2, '3')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'f30028a71a1f4333703c70f8e499b03a', $cdef_id, 15, 1, '29')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '6888be191630a0964fdb9eaeb01cecaf', $cdef_id, 16, 1, '36')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '77c456204e43a9053c68b51750d5df75', $cdef_id, 17, 4, 'CURRENT_DATA_SOURCE')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, 'ce271b7a9809646a1fe4a7cd286fd98a', $cdef_id, 18, 2, '3')");
		db_install_execute("0.8.8", "INSERT INTO `cdef_items` VALUES(DEFAULT, '8bcd193850b37953ffe940fdf2a26aa6', $cdef_id, 19, 1, '29')");
	}

	/* adjust GPRINTs
	 * here's the deal
	 * All GPRINTs following an CF=AVERAGE/MAX/MIN/LAST non-GPRINT have to be changed to CF=AVERAGE/MAX/MIN/LAST
	 * (this is called the "parent" CF)
	 * the graph_type_id has to be changed as well according to:
	 * old CF | old GPRINT | new CF | new GPRINT
	 *   AVG  |   GPRINT   | parent | GRPINT_AVG
	 *   MAX  |   GPRINT   | parent | GRPINT_MAX
	 *   MIN  |   GPRINT   | parent | GRPINT_MIN
	 *   LAST |   GPRINT   | parent | GRPINT_LAST
	 */
	# first, handle templated graphs
	$graph_templates = db_fetch_assoc("SELECT id FROM graph_templates ORDER BY id ASC");
	if (sizeof($graph_templates)) {
		foreach ($graph_templates as $template) {
			$graph_template_items = db_fetch_assoc("SELECT * " .
								"FROM graph_templates_item " .
								"WHERE local_graph_id = 0 " .
								"AND graph_template_id = " . $template["id"] .  " " .
								"ORDER BY graph_template_id ASC, sequence ASC");
			update_pre_088_graph_items($graph_template_items);
		}
	}
	# now handle non-templated graphs
	$graphs = db_fetch_assoc("SELECT id FROM graph_local WHERE graph_template_id = 0 ORDER BY id ASC");
	if (sizeof($graphs)) {
		foreach ($graphs as $graph) {
			$graph_items = db_fetch_assoc("SELECT * " .
								"FROM graph_templates_item " .
								"WHERE local_graph_id = " . $graph["id"] . " " .
								"AND graph_template_id = 0 " .
								"ORDER BY local_graph_id ASC, sequence ASC");
			update_pre_088_graph_items($graph_items);
		}
	}

	/* change the name and description for data input method "Unix - Get Load Average" from 10min to 15min */
	$dim_id = db_fetch_cell("SELECT id FROM `data_input` WHERE input_string LIKE '%%scripts/loadavg_multi.pl%%' LIMIT 0,1");
	$field_id = db_fetch_cell("SELECT id FROM `data_input_fields` WHERE data_name LIKE '%%10min%%' AND data_input_id =" . $dim_id . " LIMIT 0,1");
	db_install_execute("0.8.8", "UPDATE data_input_fields SET `name`='15 Minute Average', `data_name`='15min' WHERE `id`=" . $field_id);

}
示例#15
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $method = SNMP_VALUE_LIBRARY, $environ = SNMP_POLLER)
{
    global $config, $banned_snmp_strings;
    $snmp_oid_included = true;
    $snmp_auth = '';
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option('snmp_retries');
        if ($retries == '') {
            $retries = 3;
        }
    }
    /* do not attempt to poll invalid combinations */
    if ($version == 0 || !is_numeric($version) || !is_numeric($max_oids) || !is_numeric($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == '' && $version != 3) {
        return array();
    }
    $path_snmpbulkwalk = read_config_option('path_snmpbulkwalk');
    if (snmp_get_method($version) == SNMP_METHOD_PHP && (!strlen($context) || $version != 3) && ($version == 1 || version_compare(phpversion(), '5.1') >= 0 || !file_exists($path_snmpbulkwalk))) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        /* force php to return numeric oid's */
        cacti_oid_numeric_format();
        snmp_set_quick_print(0);
        /* set the output format to numeric */
        snmp_set_valueretrieval($method);
        if ($version == '1') {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == '2') {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
        }
        if ($temp_array === false) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
            $o = 0;
            for (reset($temp_array); $i = key($temp_array); next($temp_array)) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$o]['oid'] = preg_replace('/^\\./', '', $i);
                    $snmp_array[$o]['value'] = format_snmp_string($temp_array[$i], $snmp_oid_included);
                }
                $o++;
            }
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == '1') {
            $snmp_auth = '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
        } elseif ($version == '2') {
            $snmp_auth = '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
            $version = '2c';
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == '3') {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            if (strlen($priv_pass)) {
                $priv_pass = '******' . snmp_escape_string($priv_pass) . ' -x ' . snmp_escape_string($priv_proto);
            } else {
                $priv_pass = '';
            }
            if (strlen($context)) {
                $context = '-n ' . snmp_escape_string($context);
            } else {
                $context = '';
            }
            $snmp_auth = trim('-u ' . snmp_escape_string($username) . ' -l ' . snmp_escape_string($proto) . ' -a ' . snmp_escape_string($auth_proto) . ' -A ' . snmp_escape_string($password) . ' ' . $priv_pass . ' ' . $context);
            /* v3 - username/password */
        }
        if (file_exists($path_snmpbulkwalk) && $version > 1 && $max_oids > 1) {
            $temp_array = exec_into_array(cacti_escapeshellcmd($path_snmpbulkwalk) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr{$max_oids} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
        } else {
            $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option('path_snmpwalk')) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
        }
        if (substr_count(implode(' ', $temp_array), 'Timeout:')) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
            for ($i = 0; $i < count($temp_array); $i++) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$i]['oid'] = trim(preg_replace('/(.*) =.*/', "\\1", $temp_array[$i]));
                    $snmp_array[$i]['value'] = format_snmp_string($temp_array[$i], true);
                }
            }
        }
    }
    return $snmp_array;
}
示例#16
0
function parse_xml_hash($hash)
{
    if (preg_match("/hash_([a-f0-9]{2})([a-f0-9]{4})([a-f0-9]{32})/", $hash, $matches)) {
        $parsed_hash["type"] = check_hash_type($matches[1]);
        $parsed_hash["version"] = strval(check_hash_version($matches[2]));
        $parsed_hash["hash"] = $matches[3];
        /* an error has occured */
        if ($parsed_hash["type"] === false || $parsed_hash["version"] === false) {
            return false;
        }
    } else {
        cacti_log(__FUNCTION__ . " ERROR wrong hash format", false);
        return false;
    }
    return $parsed_hash;
}
示例#17
0
function add_graphs()
{
    global $config;
    /* check for summary changes first */
    $host_template = read_config_option("hmib_summary_host_template");
    $host_app_dq = read_config_option("hmib_dq_applications");
    $host_type_dq = read_config_option("hmib_dq_host_type");
    if (!empty($host_template)) {
        /* check to see if the template exists */
        debug("Host Template Set");
        if (db_fetch_cell("SELECT count(*) FROM host_template WHERE id={$host_template}")) {
            debug("Host Template Exists");
            $host_id = db_fetch_cell("SELECT id FROM host WHERE host_template_id={$host_template}");
            if (empty($host_id)) {
                debug("Host MIB Summary Device Not Found, Adding");
            } else {
                debug("Host Exists Hostname is '" . db_fetch_cell("SELECT description FROM host WHERE id={$host_id}") . "'");
            }
            add_summary_graphs($host_id, $host_template);
        } else {
            cacti_log("WARNING: Unable to find Host MIB Summary Host Template", true, "HMIB");
        }
    } else {
        cacti_log("NOTE: Host MIB Summary Host Template Not Specified", true, "HMIB");
    }
    add_host_based_graphs();
}
示例#18
0
function convert_readstrings() {
	global $config;

	if (defined('CACTI_BASE_PATH')) {
		$config["base_path"] = CACTI_BASE_PATH;
	}

	include_once($config["base_path"] . "/lib/functions.php");

	$sql = "SELECT DISTINCT " .
		"snmp_readstrings, " .
		"snmp_version, " .
		"snmp_port, " .
		"snmp_timeout, " .
		"snmp_retries " .
		"FROM mac_track_devices";
	cacti_log($sql, false, "MACTRACK");
	$devices = db_fetch_assoc($sql);
	cacti_log(serialize($devices), false, "MACTRACK");

	if (sizeof($devices)) {
		$i = 0;
		foreach($devices as $device) {
			# create new SNMP Option Set
			unset($save);
			$save["id"] = 0;
			$save["name"] = "Custom_" . $i++;
			$snmp_id = sql_save($save, "mac_track_snmp");
			cacti_log("new option entry: " . $snmp_id, false, "MACTRACK");

			# add each single option derived from readstrings
			$read_strings = explode(":",$device["snmp_readstrings"]);
			if (sizeof($read_strings)) {
				foreach($read_strings as $snmp_readstring) {
					unset($save);
					$save["id"]						= 0;
					$save["snmp_id"] 				= $snmp_id;
					$save["sequence"] 				= get_sequence('', 'sequence', 'mac_track_snmp_items', 'snmp_id=' . $snmp_id);

					$save["snmp_readstring"] 		= $snmp_readstring;
					$save["snmp_version"] 			= $device["snmp_version"];
					$save["snmp_port"]				= $device["snmp_port"];
					$save["snmp_timeout"]			= $device["snmp_timeout"];
					$save["snmp_retries"]			= $device["snmp_retries"];
					$save["snmp_username"]			= "";
					$save["snmp_password"]			= "";
					$save["snmp_auth_protocol"]		= "";
					$save["snmp_priv_passphrase"]	= "";
					$save["snmp_priv_protocol"]		= "";
					$save["snmp_context"]			= "";
					$save["max_oids"]				= "";

					$item_id = sql_save($save, "mac_track_snmp_items");
					cacti_log("new option item entry: " . $item_id, false, "MACTRACK");
				}
			} # each readstring added as SNMP Option item

			# now, let's find all devices, that used this snmp_readstrings
			$sql = "UPDATE mac_track_devices SET snmp_options=" . $snmp_id .
					" WHERE snmp_readstrings='" . $device["snmp_readstrings"] .
					"' AND snmp_version=" . $device["snmp_version"] .
					" AND snmp_port=" . $device["snmp_port"] .
					" AND snmp_timeout=" . $device["snmp_timeout"] .
					" AND snmp_retries=" . $device["snmp_retries"];
			cacti_log($sql, false, "MACTRACK");
			$ok = db_execute($sql);
		}
	}
	db_execute("replace into settings (name,value) values ('mt_convert_readstrings', 'on')");
	# we keep the field:snmp_readstrings in mac_track_devices, it should be deprecated first
	# next mactrack release may delete that field, then
}
示例#19
0
        $bakfile = "/tmp/" . str_replace(".rrd", "", basename($rrdfile)) . ".backup." . $seed . ".rrd";
    }
} elseif (substr_count(PHP_OS, "WIN")) {
    $tempdir = getenv("TEMP");
    $xmlfile = $tempdir . "/" . str_replace(".rrd", "", basename($rrdfile)) . ".dump." . $seed;
    $bakfile = $tempdir . "/" . str_replace(".rrd", "", basename($rrdfile)) . ".backup." . $seed . ".rrd";
} else {
    $tempdir = "/tmp";
    $xmlfile = "/tmp/" . str_replace(".rrd", "", basename($rrdfile)) . ".dump." . $seed;
    $bakfile = "/tmp/" . str_replace(".rrd", "", basename($rrdfile)) . ".backup." . $seed . ".rrd";
}
if ($html) {
    echo "<table cellpadding='3' cellspacing='0' class='spikekill_data' id='spikekill_data'>";
}
if ($using_cacti) {
    cacti_log("NOTE: Removing Spikes for '{$rrdfile}', Method:'{$method}'", false, "WEBUI");
}
/* execute the dump command */
echo ($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Creating XML file '{$xmlfile}' from '{$rrdfile}'" . ($html ? "</td></tr>\n" : "\n");
if ($using_cacti) {
    shell_exec(read_config_option("path_rrdtool") . " dump {$rrdfile} > {$xmlfile}");
} else {
    shell_exec("rrdtool dump {$rrdfile} > {$xmlfile}");
}
/* read the xml file into an array*/
if (file_exists($xmlfile)) {
    $output = file($xmlfile);
    /* remove the temp file */
    unlink($xmlfile);
} else {
    if ($using_cacti) {
示例#20
0
 +-------------------------------------------------------------------------+
*/
define("MAX_DISPLAY_PAGES", 21);
/* allow guest account to see this page */
$guest_account = true;
/* initialize cacti environment */
chdir('../../');
include "./include/auth.php";
/* syslog specific database setup and functions */
include 'plugins/syslog/config.php';
include_once 'plugins/syslog/functions.php';
$title = "Syslog Viewer";
/* make sure syslog is setup correctly */
if (!syslog_check_dependencies()) {
    include_once dirname(__FILE__) . "/include/top_syslog_header.php";
    cacti_log("SYSLOG: You are missing a required dependency, please install the '<a href='http://cactiusers.org/'>Settings'</a> plugin.", true, "SYSTEM");
    print "<br><br><center><font color=red>You are missing a dependency for Syslog, please install the '<a href='http://cactiusers.org'>Settings</a>' plugin.</font></color>";
    exit;
}
/* set the default tab */
load_current_session_value("tab", "sess_syslog_tab", "syslog");
$current_tab = $_REQUEST["tab"];
/* validate the syslog post/get/request information */
if ($current_tab != "stats") {
    syslog_request_validation($current_tab);
}
/* draw the tabs */
/* display the main page */
if (isset($_REQUEST["export"])) {
    syslog_export($current_tab);
    /* clear output so reloads wont re-download */
示例#21
0
文件: rrd.php 项目: songchin/Cacti
function rrdtool_function_tune($rrd_tune_array) {
	global $config;

	include($config["include_path"] . "/global_arrays.php");

	$data_source_name = get_data_source_item_name($rrd_tune_array["data_source_id"]);
	$data_source_type = $data_source_types{$rrd_tune_array["data-source-type"]};
	$data_source_path = get_data_source_path($rrd_tune_array["data_source_id"], true);

	if ($rrd_tune_array["heartbeat"] != "") {
		$rrd_tune .= " --heartbeat $data_source_name:" . $rrd_tune_array["heartbeat"];
	}

	if ($rrd_tune_array["minimum"] != "") {
		$rrd_tune .= " --minimum $data_source_name:" . $rrd_tune_array["minimum"];
	}

	if ($rrd_tune_array["maximum"] != "") {
		$rrd_tune .= " --maximum $data_source_name:" . $rrd_tune_array["maximum"];
	}

	if ($rrd_tune_array["data-source-type"] != "") {
		$rrd_tune .= " --data-source-type $data_source_name:" . $data_source_type;
	}

	if ($rrd_tune_array["data-source-rename"] != "") {
		$rrd_tune .= " --data-source-rename $data_source_name:" . $rrd_tune_array["data-source-rename"];
	}

	if ($rrd_tune != "") {
		if (file_exists($data_source_path) == true) {
			$fp = popen(read_config_option("path_rrdtool") . " tune $data_source_path $rrd_tune", "r");
			pclose($fp);

			if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
				cacti_log("CACTI2RRD: " . read_config_option("path_rrdtool") . " tune $data_source_path $rrd_tune");
			}
		}
	}
}
示例#22
0
					if (!validate_result($result)) {
						$result = "U";
					}

					if (strpos($result,"\n") != 0) {
						fputs(STDOUT, $result);
						fflush(STDOUT);
					} else {
						fputs(STDOUT, $result . "\n");
						fflush(STDOUT);
					}
				} else {
					cacti_log("WARNING: Function does not exist", false, "PHPSVR");
					fputs(STDOUT, "WARNING: Function does not exist\n");
				}
			}
		}
	}else{
		cacti_log("ERROR: Input Expected, Script Server Terminating", false, "PHPSVR");
		fputs(STDOUT, "ERROR: Input Expected, Script Server Terminating\n");
		exit (-1);
	}

	/* end the process if the runtime exceeds MAX_POLLER_RUNTIME */
	if (($start + MAX_POLLER_RUNTIME) < time()) {
		cacti_log("Maximum runtime of " . MAX_POLLER_RUNTIME . " seconds exceeded for the Script Server. Exiting.", true, "PHPSVR");
		exit (-1);
	}
}
?>
示例#23
0
			cacti_log("ERROR: Unknown poller command issued", true, "PCOMMAND");
		}

		/* record current_time */
		list($micro,$seconds) = split(" ", microtime());
		$current = $seconds + $micro;

		/* end if runtime has been exceeded */
		if (($current-$start) > MAX_RECACHE_RUNTIME) {
			cacti_log("ERROR: Poller Command processing timed out after processing '" . $command . "'",true,"PCOMMAND");
			break;
		}
	}

	db_execute("delete from poller_command where poller_id=0");
}

/* take time to log performance data */
list($micro,$seconds) = split(" ", microtime());
$recache = $seconds + $micro;

$recache_stats = sprintf("RecacheTime:%01.4f HostsRecached:%s",	round($recache - $start, 4), $recached_hosts);

if ($recached_hosts > 0) {
	cacti_log("STATS: " . $recache_stats, true, "RECACHE");
}

/* insert poller stats into the settings table */
db_execute("replace into settings (name,value) values ('stats_recache','$recache_stats')");

?>
示例#24
0
					fputs(STDOUT, $result);
					fflush(STDOUT);
				} else {
					fputs(STDOUT, $result . "\n");
					fflush(STDOUT);
				}

				if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
					cacti_log("SERVER: " . $in_string . " output " . $result, false, "PHPSVR");
				}
			} else {
				cacti_log("WARNING: Function does not exist\n", false, "PHPSVR");
				fputs(STDOUT, "WARNING: Function does not exist\n");
			}
		}elseif ($in_string == "quit") {
			fputs(STDOUT, "PHP Script Server Shutdown request received, exiting\n");
			if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) {
				cacti_log("DEBUG: PHP Script Server Shutdown request received, exiting", false, "PHPSVR");
			}
			break;
		}else {
			cacti_log("WARNING: Problems with input", false, "PHPSVR");
			fputs(STDOUT, "ERROR: Problems with input\n");
		}
	}else {
		cacti_log("ERROR: Input Expected, Script Server Terminating", false, "PHPSVR");
		fputs(STDOUT, "ERROR: Input Expected, Script Server Terminating\n");
		exit (-1);
	}
}
?>
示例#25
0
文件: ldap.php 项目: teddywen/cacti
 function Search()
 {
     $output = array();
     /* function check */
     if (!function_exists("ldap_connect")) {
         $output["error_num"] = 99;
         $output["error_text"] = "PHP LDAP not enabled";
         return $output;
     }
     /* validation */
     if (empty($this->username)) {
         $output["dn"] = "";
         $output["error_num"] = "1";
         $output["error_text"] = "No username defined";
         cacti_log("LDAP_SEARCH: No username defined", false, "AUTH");
         return $output;
     }
     /* Encode username */
     $this->username = html_entity_decode($this->username, ENT_COMPAT | ENT_HTML401, "UTF-8");
     /* strip bad chars from username - prevent altering filter from username */
     $this->username = str_replace("&", "", $this->username);
     $this->username = str_replace("|", "", $this->username);
     $this->username = str_replace("(", "", $this->username);
     $this->username = str_replace(")", "", $this->username);
     $this->username = str_replace("*", "", $this->username);
     $this->username = str_replace(">", "", $this->username);
     $this->username = str_replace("<", "", $this->username);
     $this->username = str_replace("!", "", $this->username);
     $this->username = str_replace("=", "", $this->username);
     $this->dn = str_replace("<username>", $this->username, $this->dn);
     if ($this->mode == "0") {
         /* Just bind mode, make dn and return */
         $output["dn"] = $this->dn;
         $output["error_num"] = "0";
         $output["error_text"] = "User found";
         return $output;
     } elseif ($this->mode == "2") {
         /* Specific */
         if (empty($this->specific_dn) || empty($this->specific_password)) {
             $output["dn"] = $this->dn;
             $output["error_num"] = "14";
             $output["error_text"] = "Specific DN and Password required";
             return $output;
         }
     } elseif ($this->mode == "1") {
         /* assume anonymous */
         $this->specific_dn = "";
         $this->specific_password = "";
     }
     $this->search_filter = str_replace("<username>", $this->username, $this->search_filter);
     /* Fix encoding on ldap specific search DN and password */
     $this->specific_password = html_entity_decode($this->specific_password, ENT_COMPAT | ENT_HTML401, "UTF-8");
     $this->specific_dn = html_entity_decode($this->specific_dn, ENT_COMPAT | ENT_HTML401, "UTF-8");
     /* Searching mode */
     if ($this->encryption == "1") {
         /* This only works with OpenLDAP, I'm pretty sure this will not work with Solaris, Tony */
         $ldap_conn = @ldap_connect("ldaps://" . $this->host . ":" . $this->port_ssl);
     } else {
         $ldap_conn = @ldap_connect($this->host, $this->port);
     }
     if ($ldap_conn) {
         /* Set protocol version */
         if (!@ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $this->version)) {
             /* protocol error */
             $output["dn"] = "";
             $output["error_num"] = "4";
             $output["error_text"] = "Protocol error, unable to set version";
             cacti_log("LDAP_SEARCH: " . $output["error_text"], false, "AUTH");
             @ldap_close($ldap_conn);
             return $output;
         }
         /* set referrals */
         if ($this->referrals == "0") {
             if (!@ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0)) {
                 /* referrals set error */
                 $output["dn"] = "";
                 $output["error_num"] = "13";
                 $output["error_text"] = "Unable to set referrals option";
                 cacti_log("LDAP_SEARCH: " . $output["error_text"], false, "AUTH");
                 @ldap_close($ldap_conn);
                 return $output;
             }
         }
         /* start TLS if requested */
         if ($this->encryption == "2") {
             if (!@ldap_start_tls($ldap_conn)) {
                 /* TLS startup error */
                 $output["dn"] = "";
                 $output["error_num"] = "5";
                 $output["error_text"] = "Protocol error, unable to start TLS communications";
                 cacti_log("LDAP_SEARCH: " . $output["error_text"], false, "AUTH");
                 @ldap_close($ldap_conn);
                 return $output;
             }
         }
         /* bind to the directory */
         if (ldap_bind($ldap_conn, $this->specific_dn, $this->specific_password)) {
             /* Search */
             $ldap_results = ldap_search($ldap_conn, $this->search_base, $this->search_filter, array("dn"));
             if ($ldap_results) {
                 $ldap_entries = ldap_get_entries($ldap_conn, $ldap_results);
                 if ($ldap_entries["count"] == "1") {
                     /* single response return user dn */
                     $output["dn"] = $ldap_entries["0"]["dn"];
                     $output["error_num"] = "0";
                     $output["error_text"] = "User found";
                     cacti_log("LDAP_SEARCH: User found, DN '%s'" . $output["dn"], false, "AUTH");
                 } elseif ($ldap_entries["count"] > 1) {
                     /* more than 1 result */
                     $output["dn"] = "";
                     $output["error_num"] = "13";
                     $output["error_text"] = "More than one matching user found";
                 } else {
                     /* no search results */
                     $output["dn"] = "";
                     $output["error_num"] = "3";
                     $output["error_text"] = "Unable to find users DN";
                 }
             } else {
                 /* no search results, user not found*/
                 $output["dn"] = "";
                 $output["error_num"] = "3";
                 $output["error_text"] = "Unable to find users DN";
             }
         } else {
             /* unable to bind */
             $ldap_error = ldap_errno($ldap_conn);
             if ($ldap_error == 0x3) {
                 /* protocol error */
                 $output["dn"] = "";
                 $output["error_num"] = "6";
                 $output["error_text"] = "Protocol error";
             } elseif ($ldap_error == 0x31) {
                 /* invalid credentials */
                 $output["dn"] = "";
                 $output["error_num"] = "7";
                 $output["error_text"] = "Invalid credentials";
             } elseif ($ldap_error == 0x32) {
                 /* insuffient access */
                 $output["dn"] = "";
                 $output["error_num"] = "8";
                 $output["error_text"] = "Insufficient access";
             } elseif ($ldap_error == 0x51) {
                 /* unable to connect to server */
                 $output["dn"] = "";
                 $output["error_num"] = "9";
                 $output["error_text"] = "Unable to connect to server";
             } elseif ($ldap_error == 0x55) {
                 /* timeout */
                 $output["dn"] = "";
                 $output["error_num"] = "10";
                 $output["error_text"] = "Connection Timeout";
             } else {
                 /* general bind error */
                 $output["dn"] = "";
                 $output["error_num"] = "11";
                 $output["error_text"] = "General bind error, LDAP result: " . ldap_error($ldap_conn);
             }
         }
     } else {
         /* unable to setup connection */
         $output["dn"] = "";
         $output["error_num"] = "2";
         $output["error_text"] = "Unable to create LDAP connection object";
     }
     @ldap_close($ldap_conn);
     if ($output["error_num"] > 0) {
         cacti_log("LDAP_SEARCH: " . $output["error_text"], false, "AUTH");
     }
     return $output;
 }
示例#26
0
debug("Last Run Was '" . date('Y-m-d H:i:s', $last_run) . "', Frequency is '" . $frequency / 60 . "' Minutes");
if ($frequency == 0) {
    echo "NOTE:  Graph Automation is Disabled\n";
} elseif ($frequency > 0 && $start - $last_run > $frequency || $frequency > 0 && $forcerun) {
    list($micro, $seconds) = explode(' ', microtime());
    $start = $seconds + $micro;
    echo "NOTE:  Starting Automation Process\n";
    db_execute("REPLACE INTO settings (name,value) VALUES ('mikrotik_automation_lastrun', '{$start}')");
    add_graphs();
    list($micro, $seconds) = explode(' ', microtime());
    $end = $seconds + $micro;
    $cacti_stats = sprintf('Time:%01.4f ', round($end - $start, 2));
    /* log to the database */
    db_execute("REPLACE INTO settings (name,value) VALUES ('stats_mikrotik_graphs', '" . $cacti_stats . "')");
    /* log to the logfile */
    cacti_log('MIKROTIK GRAPH STATS: ' . $cacti_stats, true, 'SYSTEM');
} else {
    echo "NOTE:  Its Not Time to Run Automation\n";
}
exit(0);
function add_graphs()
{
    global $config;
    //	/* check for summary changes first */
    //	$host_template = read_config_option('mikrotik_summary_host_template');
    //	$host_type_dq  = read_config_option('mikrotik_dq_host_type');
    //	if (!empty($host_template)) {
    //		/* check to see if the template exists */
    //		debug('Host Template Set');
    //
    //		if (db_fetch_cell("SELECT count(*) FROM host_template WHERE id=$host_template")) {
示例#27
0
文件: ping.php 项目: MrWnn/cacti
 function ping($avail_method = AVAIL_SNMP_AND_PING, $ping_type = PING_ICMP, $timeout = 500, $retries = 3)
 {
     /* initialize variables */
     $ping_ping = true;
     $ping_snmp = true;
     $this->ping_status = "down";
     $this->ping_response = "Ping not performed due to setting.";
     $this->snmp_status = "down";
     $this->snmp_response = "SNMP not performed due to setting or ping result.";
     $this->avail_method = $avail_method;
     /* short circuit for availability none */
     if ($avail_method == AVAIL_NONE) {
         $this->ping_status = "0.00";
         return true;
     }
     if (!function_exists("socket_create") && $avail_method != AVAIL_NONE) {
         $avail_method = AVAIL_SNMP;
         cacti_log("WARNING: sockets support not enabled in PHP, falling back to SNMP ping");
     }
     if ($retries <= 0 || $retries > 5) {
         $this->retries = 2;
     } else {
         $this->retries = $retries;
     }
     if ($timeout <= 0) {
         $this->timeout = 500;
     } else {
         $this->timeout = $timeout;
     }
     /* decimal precision is 0.0000 */
     $this->precision = 5;
     /* snmp pinging has been selected at a minimum */
     $ping_result = false;
     $snmp_result = false;
     /* icmp/udp ping test */
     if ($avail_method == AVAIL_SNMP_AND_PING || $avail_method == AVAIL_SNMP_OR_PING || $avail_method == AVAIL_PING) {
         if ($ping_type == PING_ICMP) {
             $ping_result = $this->ping_icmp();
         } else {
             if ($ping_type == PING_UDP) {
                 $ping_result = $this->ping_udp();
             } else {
                 if ($ping_type == PING_TCP) {
                     $ping_result = $this->ping_tcp();
                 }
             }
         }
     }
     /* snmp test */
     if ($avail_method == AVAIL_SNMP_OR_PING && $ping_result == true) {
         $snmp_result = true;
         $this->snmp_status = 0.0;
     } else {
         if ($avail_method == AVAIL_SNMP_AND_PING && $ping_result == false) {
             $snmp_result = false;
         } else {
             if ($avail_method == AVAIL_SNMP || $avail_method == AVAIL_SNMP_AND_PING || $avail_method == AVAIL_SNMP_GET_SYSDESC || $avail_method == AVAIL_SNMP_GET_NEXT) {
                 if ($this->host["snmp_community"] == "" && $this->host["snmp_version"] != 3) {
                     /* snmp version 1/2 without community string assume SNMP test to be successful
                        due to backward compatibility issues */
                     $snmp_result = true;
                     $this->snmp_status = 0.0;
                 } else {
                     $snmp_result = $this->ping_snmp();
                 }
             }
         }
     }
     switch ($avail_method) {
         case AVAIL_SNMP_OR_PING:
             if ($this->host["snmp_community"] == "" && $this->host["snmp_version"] != 3) {
                 if ($ping_result) {
                     return true;
                 } else {
                     return false;
                 }
             } elseif ($snmp_result) {
                 return true;
             } elseif ($ping_result) {
                 return true;
             } else {
                 return false;
             }
         case AVAIL_SNMP_AND_PING:
             if ($this->host["snmp_community"] == "" && $this->host["snmp_version"] != 3) {
                 if ($ping_result) {
                     return true;
                 } else {
                     return false;
                 }
             } elseif ($snmp_result && $ping_result) {
                 return true;
             } else {
                 return false;
             }
         case AVAIL_SNMP:
         case AVAIL_SNMP_GET_NEXT:
         case AVAIL_SNMP_GET_SYSDESC:
             if ($snmp_result) {
                 return true;
             } else {
                 return false;
             }
         case AVAIL_PING:
             if ($ping_result) {
                 return true;
             } else {
                 return false;
             }
         default:
             return false;
     }
 }
示例#28
0
function plgexample_update_host_status () {
	global $config;
	// Return if we aren't set to notify
	$deadnotify = (read_config_option('alert_deadnotify') == 'on');
	if (!$deadnotify) return 0;
	include_once($config['base_path'] . '/plugins/thold/thold_functions.php');

	$alert_email = read_config_option('alert_email');
	$ping_failure_count = read_config_option('ping_failure_count');
	// Lets find hosts that were down, but are now back up
	$failed = read_config_option('thold_failed_hosts', true);
	$failed = explode(',', $failed);
	if (!empty($failed)) {
		foreach($failed as $id) {
			if ($id != '') {
				$host = db_fetch_row('SELECT id, status, description, hostname FROM host WHERE id = ' . $id);
				if ($host['status'] == HOST_UP) {
					$subject = 'Host Notice : ' . $host['description'] . ' (' . $host['hostname'] . ') returned from DOWN state';
					$msg = $subject;
					if ($alert_email == '') {
						cacti_log('THOLD: Can not send Host Recovering email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
					} else {
						thold_mail($alert_email, '', $subject, $msg, '');
					}
				}
			}
		}
	}

	// Lets find hosts that are down
	$hosts = db_fetch_assoc('SELECT id, description, hostname, status_last_error FROM host WHERE disabled="" AND status=' . HOST_DOWN . ' AND status_event_count=' . $ping_failure_count);
	$total_hosts = sizeof($hosts);
	if (count($hosts)) {
		foreach($hosts as $host) {
			$subject = 'Host Error : ' . $host['description'] . ' (' . $host['hostname'] . ') is DOWN';
			$msg = 'Host Error : ' . $host['description'] . ' (' . $host['hostname'] . ') is DOWN<br>Message : ' . $host['status_last_error'];
			if ($alert_email == '') {
				cacti_log('THOLD: Can not send Host Down email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
			} else {
				thold_mail($alert_email, '', $subject, $msg, '');
			}
		}
	}

	// Now lets record all failed hosts
	$hosts = db_fetch_assoc('SELECT id FROM host WHERE status != ' . HOST_UP);
	$failed = array();
	if (!empty($hosts)) {
		foreach ($hosts as $host) {
			$failed[] = $host['id'];
		}
	}
	$failed = implode(',', $failed);
	db_execute("REPLACE INTO settings (name, value) VALUES ('thold_failed_hosts', '$failed')");

	return $total_hosts;
}
示例#29
0
function update_host_status($status, $host_id, &$hosts, &$ping, $ping_availability, $print_data_to_stdout) {
	$issue_log_message   = false;
	$ping_failure_count  = read_config_option("ping_failure_count");
	$ping_recovery_count = read_config_option("ping_recovery_count");

	if ($status == HOST_DOWN) {
		/* update total polls, failed polls and availability */
		$hosts[$host_id]["failed_polls"]++;
		$hosts[$host_id]["total_polls"]++;
		$hosts[$host_id]["availability"] = 100 * ($hosts[$host_id]["total_polls"] - $hosts[$host_id]["failed_polls"]) / $hosts[$host_id]["total_polls"];

		/* determine the error message to display */
		if ($ping_availability == AVAIL_SNMP_AND_PING) {
			if ($hosts[$host_id]["snmp_community"] == "") {
				$hosts[$host_id]["status_last_error"] = $ping->ping_response;
			}else {
				$hosts[$host_id]["status_last_error"] = $ping->snmp_response . ", " . $ping->ping_response;
			}
		}elseif ($ping_availability == AVAIL_SNMP) {
			if ($hosts[$host_id]["snmp_community"] == "") {
				$hosts[$host_id]["status_last_error"] = "Device does not require SNMP";
			}else {
				$hosts[$host_id]["status_last_error"] = $ping->snmp_response;
			}
		}else {
			$hosts[$host_id]["status_last_error"] = $ping->ping_response;
		}

		/* determine if to send an alert and update remainder of statistics */
		if ($hosts[$host_id]["status"] == HOST_UP) {
			/* increment the event failure count */
			$hosts[$host_id]["status_event_count"]++;

			/* if it's time to issue an error message, indicate so */
			if ($hosts[$host_id]["status_event_count"] >= $ping_failure_count) {
				/* host is now down, flag it that way */
				$hosts[$host_id]["status"] = HOST_DOWN;

				$issue_log_message = true;

				/* update the failure date only if the failure count is 1 */
				if ($ping_failure_count == 1) {
					$hosts[$host_id]["status_fail_date"] = date("Y-m-d h:i:s");
				}
			/* host is down, but not ready to issue log message */
			} else {
				/* host down for the first time, set event date */
				if ($hosts[$host_id]["status_event_count"] == 1) {
					$hosts[$host_id]["status_fail_date"] = date("Y-m-d h:i:s");
				}
			}
		/* host is recovering, put back in failed state */
		} elseif ($hosts[$host_id]["status"] == HOST_RECOVERING) {
			$hosts[$host_id]["status_event_count"] = 1;
			$hosts[$host_id]["status"] = HOST_DOWN;

		/* host was unknown and now is down */
		} elseif ($hosts[$host_id]["status"] == HOST_UNKNOWN) {
			$hosts[$host_id]["status"] = HOST_DOWN;
			$hosts[$host_id]["status_event_count"] = 0;
		} else {
			$hosts[$host_id]["status_event_count"]++;
		}
	/* host is up!! */
	} else {
		/* update total polls and availability */
		$hosts[$host_id]["total_polls"]++;
		$hosts[$host_id]["availability"] = 100 * ($hosts[$host_id]["total_polls"] - $hosts[$host_id]["failed_polls"]) / $hosts[$host_id]["total_polls"];

		/* determine the ping statistic to set and do so */
		if ($ping_availability == AVAIL_SNMP_AND_PING) {
			if ($hosts[$host_id]["snmp_community"] == "") {
				$ping_time = $ping->ping_status;
			}else {
				/* calculate the average of the two times */
				$ping_time = ($ping->snmp_status + $ping->ping_status) / 2;
			}
		}elseif ($ping_availability == AVAIL_SNMP) {
			if ($hosts[$host_id]["snmp_community"] == "") {
				$ping_time = 0.000;
			}else {
				$ping_time = $ping->snmp_status;
			}
		}else {
			$ping_time = $ping->ping_status;
		}

		/* update times as required */
		$hosts[$host_id]["cur_time"] = $ping_time;

		/* maximum time */
		if ($ping_time > $hosts[$host_id]["max_time"])
			$hosts[$host_id]["max_time"] = $ping_time;

		/* minimum time */
		if ($ping_time < $hosts[$host_id]["min_time"])
			$hosts[$host_id]["min_time"] = $ping_time;

		/* average time */
		$hosts[$host_id]["avg_time"] = (($hosts[$host_id]["total_polls"]-1-$hosts[$host_id]["failed_polls"])
			* $hosts[$host_id]["avg_time"] + $ping_time) / ($hosts[$host_id]["total_polls"]-$hosts[$host_id]["failed_polls"]);

		/* the host was down, now it's recovering */
		if (($hosts[$host_id]["status"] == HOST_DOWN) || ($hosts[$host_id]["status"] == HOST_RECOVERING )) {
			/* just up, change to recovering */
			if ($hosts[$host_id]["status"] == HOST_DOWN) {
				$hosts[$host_id]["status"] = HOST_RECOVERING;
				$hosts[$host_id]["status_event_count"] = 1;
			} else {
				$hosts[$host_id]["status_event_count"]++;
			}

			/* if it's time to issue a recovery message, indicate so */
			if ($hosts[$host_id]["status_event_count"] >= $ping_recovery_count) {
				/* host is up, flag it that way */
				$hosts[$host_id]["status"] = HOST_UP;

				$issue_log_message = true;

				/* update the recovery date only if the recovery count is 1 */
				if ($ping_recovery_count == 1) {
					$hosts[$host_id]["status_rec_date"] = date("Y-m-d h:i:s");
				}

				/* reset the event counter */
				$hosts[$host_id]["status_event_count"] = 0;
			/* host is recovering, but not ready to issue log message */
			} else {
				/* host recovering for the first time, set event date */
				if ($hosts[$host_id]["status_event_count"] == 1) {
					$hosts[$host_id]["status_rec_date"] = date("Y-m-d h:i:s");
				}
			}
		} else {
		/* host was unknown and now is up */
			$hosts[$host_id]["status"] = HOST_UP;
			$hosts[$host_id]["status_event_count"] = 0;
		}
	}
	/* if the user wants a flood of information then flood them */
	if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) {
		if (($hosts[$host_id]["status"] == HOST_UP) || ($hosts[$host_id]["status"] == HOST_RECOVERING)) {
			/* log ping result if we are to use a ping for reachability testing */
			if ($ping_availability == AVAIL_SNMP_AND_PING) {
				cacti_log("Host[$host_id] PING: " . $ping->ping_response, $print_data_to_stdout);
				cacti_log("Host[$host_id] SNMP: " . $ping->snmp_response, $print_data_to_stdout);
			} elseif ($ping_availability == AVAIL_SNMP) {
				if ($hosts[$host_id]["snmp_community"] == "") {
					cacti_log("Host[$host_id] SNMP: Device does not require SNMP", $print_data_to_stdout);
				}else{
					cacti_log("Host[$host_id] SNMP: " . $ping->snmp_response, $print_data_to_stdout);
				}
			} else {
				cacti_log("Host[$host_id] PING: " . $ping->ping_response, $print_data_to_stdout);
			}
		} else {
			if ($ping_availability == AVAIL_SNMP_AND_PING) {
				cacti_log("Host[$host_id] PING: " . $ping->ping_response, $print_data_to_stdout);
				cacti_log("Host[$host_id] SNMP: " . $ping->snmp_response, $print_data_to_stdout);
			} elseif ($ping_availability == AVAIL_SNMP) {
				cacti_log("Host[$host_id] SNMP: " . $ping->snmp_response, $print_data_to_stdout);
			} else {
				cacti_log("Host[$host_id] PING: " . $ping->ping_response, $print_data_to_stdout);
			}
		}
	}

	/* if there is supposed to be an event generated, do it */
	if ($issue_log_message) {
		if ($hosts[$host_id]["status"] == HOST_DOWN) {
			cacti_log("Host[$host_id] ERROR: HOST EVENT: Host is DOWN Message: " . $hosts[$host_id]["status_last_error"], $print_data_to_stdout);
		} else {
			cacti_log("Host[$host_id] NOTICE: HOST EVENT: Host Returned from DOWN State: ", $print_data_to_stdout);
		}
	}

	db_execute("update host set
		status = '" . $hosts[$host_id]["status"] . "',
		status_event_count = '" . $hosts[$host_id]["status_event_count"] . "',
		status_fail_date = '" . $hosts[$host_id]["status_fail_date"] . "',
		status_rec_date = '" . $hosts[$host_id]["status_rec_date"] . "',
		status_last_error = '" . $hosts[$host_id]["status_last_error"] . "',
		min_time = '" . $hosts[$host_id]["min_time"] . "',
		max_time = '" . $hosts[$host_id]["max_time"] . "',
		cur_time = '" . $hosts[$host_id]["cur_time"] . "',
		avg_time = '" . $hosts[$host_id]["avg_time"] . "',
		total_polls = '" . $hosts[$host_id]["total_polls"] . "',
		failed_polls = '" . $hosts[$host_id]["failed_polls"] . "',
		availability = '" . $hosts[$host_id]["availability"] . "'
		where hostname = '" . $hosts[$host_id]["hostname"] . "'");
}
示例#30
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $environ = SNMP_POLLER)
{
    global $config, $banned_snmp_strings;
    $snmp_oid_included = true;
    $snmp_auth = '';
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option("snmp_retries");
        if ($retries == "") {
            $retries = 3;
        }
    }
    /* determine default max_oids */
    if ($max_oids == 0 || !is_numeric($max_oids)) {
        $max_oids = read_config_option("max_get_size");
        if ($max_oids == "") {
            $max_oids = 10;
        }
    }
    /* do not attempt to poll invalid combinations */
    if ($version == 0 || !is_numeric($version) || !is_numeric($max_oids) || !is_numeric($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == "" && $version != 3) {
        return array();
    }
    $path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");
    if (snmp_get_method($version) == SNMP_METHOD_PHP && (!strlen($context) || $version != 3) && ($version == 1 || version_compare(phpversion(), "5.1") >= 0 || !file_exists($path_snmpbulkwalk))) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        /* force php to return numeric oid's */
        if (function_exists("snmp_set_oid_numeric_print")) {
            snmp_set_oid_numeric_print(TRUE);
        }
        if (function_exists("snmprealwalk")) {
            $snmp_oid_included = false;
        }
        snmp_set_quick_print(0);
        if ($version == "1") {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == "2") {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($priv_proto == "[None]" || $priv_pass == '') {
                $proto = "authNoPriv";
                $priv_proto = "";
            } else {
                $proto = "authPriv";
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
        }
        if ($temp_array === false) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != "") {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        $o = 0;
        for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
            if ($temp_array[$i] != "NULL") {
                $snmp_array[$o]["oid"] = preg_replace("/^\\./", "", $i);
                $snmp_array[$o]["value"] = format_snmp_string($temp_array[$i], $snmp_oid_included);
            }
            $o++;
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == "1") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? snmp_escape_string($community) : "-c " . snmp_escape_string($community);
            /* v1/v2 - community string */
        } elseif ($version == "2") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? snmp_escape_string($community) : "-c " . snmp_escape_string($community);
            /* v1/v2 - community string */
            $version = "2c";
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == "3") {
            if ($priv_proto == "[None]" || $priv_pass == '') {
                $proto = "authNoPriv";
                $priv_proto = "";
            } else {
                $proto = "authPriv";
            }
            if (strlen($priv_pass)) {
                $priv_pass = "******" . snmp_escape_string($priv_pass) . " -x " . snmp_escape_string($priv_proto);
            } else {
                $priv_pass = "";
            }
            if (strlen($context)) {
                $context = "-n " . snmp_escape_string($context);
            } else {
                $context = "";
            }
            $snmp_auth = trim("-u " . snmp_escape_string($username) . " -l " . snmp_escape_string($proto) . " -a " . snmp_escape_string($auth_proto) . " -A " . snmp_escape_string($password) . " " . $priv_pass . " " . $context);
            /* v3 - username/password */
        }
        if (read_config_option("snmp_version") == "ucd-snmp") {
            /* escape the command to be executed and vulnerable parameters
             * numeric parameters are not subject to command injection
             * snmp_auth is treated seperately, see above */
            $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option("path_snmpwalk")) . " -v{$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} {$snmp_auth} " . cacti_escapeshellarg($oid));
        } else {
            if (file_exists($path_snmpbulkwalk) && $version > 1 && $max_oids > 1) {
                $temp_array = exec_into_array(cacti_escapeshellcmd($path_snmpbulkwalk) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr{$max_oids} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            } else {
                $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option("path_snmpwalk")) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            }
        }
        if (substr_count(implode(" ", $temp_array), "Timeout:")) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != "") {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        for ($i = 0; $i < count($temp_array); $i++) {
            if ($temp_array[$i] != "NULL") {
                $snmp_array[$i]["oid"] = trim(preg_replace("/(.*) =.*/", "\\1", $temp_array[$i]));
                $snmp_array[$i]["value"] = format_snmp_string($temp_array[$i], true);
            }
        }
    }
    return $snmp_array;
}