function iconskml() { //get all icons in the icon folder and create an icon list global $config; $kmlDomain = read_config_option("gpsmap_kmldomain"); $iconlist = ""; $icons = opendir($config['base_path'] . '/plugins/gpsmap/images/icons'); while (false !== ($icon = readdir($icons))) { if ($icon != "." && $icon != "..") { list($icon, $tail) = explode('.', $icon); switch ($tail) { case "png": case "jpg": case "jpeg": case "gif": $iconlist .= "<Style id=\"" . $icon . "\">"; $iconlist .= "<IconStyle id=\"my" . $icon . "\">"; $iconlist .= "<Icon>"; $iconlist .= "<href>http://" . $kmlDomain . $config['url_path'] . "plugins/gpsmap/images/icons/" . $icon . "." . $tail . "</href>"; $iconlist .= "<scale>1.0</scale>"; $iconlist .= "</Icon>"; $iconlist .= "</IconStyle>"; $iconlist .= "</Style>\n"; break; default: //Not an icon we want to load break; } } } return $iconlist; }
function api_user_changepassword($user_id, $password_new, $password_old="") { /* validate we can change the password */ if (read_config_option("auth_method") != "1") { return 1; } /* validate old password */ if (!empty($password_old)) { if (!sizeof(db_fetch_row("select id from user_auth where id =" . sql_sanitize($user_id) . " and password = '******' and realm = 0"))) { /* Password validation error */ return 2; } } /* validate user exists */ if (sizeof(db_fetch_row("select id from user_auth where id =" . sql_sanitize($user_id) . " and realm = 0"))) { if (db_execute("update user_auth set password = '******',must_change_password = '', password_change_last = NOW() where id = " . sql_sanitize($user_id)) == 1) { /* password changed */ return 0; }else{ /* error */ return 1; } }else{ /* user not found */ return 3; } /* all else fails return error */ return 1; }
public static function getConfigOption($settingName, $defaultValue = "") { $result = read_config_option($settingName); if ($result == "" && $defaultValue != "") { self::log("No result for %s, using default\n", $defaultValue); $result = $defaultValue; } return $result; }
function settings_check_upgrade() { $current = plugin_settings_version(); $current = $current['version']; $old = read_config_option('plugin_settings_version'); if ($current != $old) { // settings_setup_table (); } db_execute("REPLACE INTO settings (name, value) VALUES ('plugin_settings_version', '{$current}')"); }
function input_remove() { if (read_config_option("remove_verification") == "on" && !isset($_GET["confirm"])) { require_once CACTI_BASE_PATH . "/include/top_header.php"; form_confirm(_("Are You Sure?"), _("Are you sure you want to delete the input item") . " <strong>'" . db_fetch_cell("select name from graph_template_item_input where id=" . $_GET["id"]) . "'</strong>? NOTE: Deleting this input will <strong>not</strong> affect graphs that use this template.", "graph_templates.php?action=edit&id=" . $_GET["graph_template_id"], "graph_templates_inputs.php?action=remove&id=" . $_GET["id"] . "&graph_template_id=" . $_GET["graph_template_id"]); require_once CACTI_BASE_PATH . "/include/bottom_footer.php"; exit; } if (read_config_option("remove_verification") == "" || isset($_GET["confirm"])) { api_graph_template_item_input_remove($_GET["id"]); } }
function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "") { $snmp = explode(":", $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $snmp_auth_username = ""; $snmp_auth_password = ""; $snmp_auth_protocol = ""; $snmp_priv_passphrase = ""; $snmp_priv_protocol = ""; $snmp_context = ""; $snmp_community = ""; if ($snmp_version == 3) { $snmp_auth_username = $snmp[4]; $snmp_auth_password = $snmp[5]; $snmp_auth_protocol = $snmp[6]; $snmp_priv_passphrase = $snmp[7]; $snmp_priv_protocol = $snmp[8]; $snmp_context = $snmp[9]; } else { $snmp_community = $snmp[3]; } $oids = array("total" => ".1.3.6.1.2.1.25.2.3.1.5", "totalin" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4"); if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); for ($i = 0; $i < sizeof($return_arr); $i++) { print $return_arr[$i] . "\n"; } } elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); for ($i = 0; $i < sizeof($arr_index); $i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } } elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; $value = api_plugin_hook_function('hmib_get_disk', array("host_id" => $host_id, "arg" => $arg, "index" => $index)); if (is_array($value)) { if ($arg == "total" || $arg == "used") { $sau = eregi_replace("[^0-9]", "", db_fetch_cell("select field_value from host_snmp_cache where host_id={$host_id} and field_name='hrStorageAllocationUnits' and snmp_index='{$index}'")); return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER) * $sau; } else { return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER); } } else { return $value; } } }
function settings() { global $colors, $themes; $themes["default"] = _("System Default (Global Setting)"); /* you cannot have per-user settings if cacti's user management is not turned on */ if (read_config_option("auth_method") == "0") { raise_message(6); display_output_messages(); return; } /* get user settings */ $user = api_user_info( array( "id" => $_SESSION["sess_user_id"] ) ); print "<form method='post'>\n"; html_start_box("<strong>" . _("User Settings") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); ?> <tr bgcolor='<?php print $colors["header_panel_background"];?>'> <td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>General</td> </tr> <?php $form_array = array( "current_theme" => array( "friendly_name" => _("Visual Theme"), "description" => _("The Cacti theme to use. Changes the look of Cacti."), "method" => "drop_array", "array" => $themes, "value" => api_user_theme($_SESSION["sess_user_id"]), "default" => "default" ) ); draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); html_end_box(); form_hidden_box("save_component_user","1",""); form_save_button((isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"), "save"); }
function ss_host_cpu_get_indexes($hostname, $snmp_community, $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, $snmp_port, $snmp_timeout) { $arr = ss_host_cpu_reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); $return_arr = array(); $j = 0; for ($i = 0; $i < sizeof($arr); $i++) { if (is_numeric($arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function api_reapply_suggested_graph_title($local_graph_id) { global $config; /* get graphs template id */ $graph_template_id = db_fetch_cell("select graph_template_id from graph_templates_graph where local_graph_id=" . $local_graph_id); /* if a non-template graph, simply return */ if ($graph_template_id == 0) { return; } /* get the host associated with this graph */ $graph_local = db_fetch_row("select host_id, graph_template_id, snmp_query_id, snmp_index from graph_local where id=" . $local_graph_id); $snmp_query_graph_id = db_fetch_cell("select id from snmp_query_graph where graph_template_id=" . $graph_local["graph_template_id"] . " and snmp_query_id=" . $graph_local["snmp_query_id"]); /* get the suggested values from the suggested values cache */ $suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_graph_id . " order by sequence"); if (sizeof($suggested_values) > 0) { foreach ($suggested_values as $suggested_value) { /* once we find a match; don't try to find more */ if (!isset($suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]})) { $subs_string = substitute_snmp_query_data($suggested_value["text"], $graph_local["host_id"], $graph_local["snmp_query_id"], $graph_local["snmp_index"], read_config_option("max_data_query_field_length")); /* if there are no '|' characters, all of the substitutions were successful */ if (!strstr($subs_string, "|query")) { db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' where local_graph_id=" . $local_graph_id); /* once we find a working value, stop */ $suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true; } } } } /* suggested values: graph */ if (isset($suggested_values_array[$graph_template_id]["graph_template"])) { while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) { db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $local_graph_id); } } /* suggested values: graph item */ if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) { while (list($graph_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["graph_template_item"])) { while (list($field_name, $field_value) = each($field_array)) { $graph_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=$graph_template_item_id and local_graph_id=" . $local_graph_id); db_execute("update graph_templates_item set $field_name='$field_value' where id=$graph_item_id"); } } } }
function mactrack_vmacs() { global $site_actions, $config, $item_rows; mactrack_vmacs_validate_request_vars(); if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } html_start_box(__('MacTrack Vendor Mac Filter'), '100%', '', '3', 'center', ''); mactrack_vmac_filter(); html_end_box(); $sql_where = ''; $vmacs = mactrack_vmacs_get_vmac_records($sql_where, $row_limit); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM mac_track_oui_database\n\t\t{$sql_where}"); $nav = html_nav_bar('mactrack_vendormacs.php', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 9, __('Vendor Macs')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('vendor_mac' => array(__('Vendor MAC'), 'ASC'), 'vendor_name' => array(__('Corporation'), 'ASC'), 'vendor_address' => array(__('Address'), 'ASC')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($vmacs)) { foreach ($vmacs as $vmac) { form_alternate_row(); ?> <td class='linkEditMain'><?php print $vmac['vendor_mac']; ?> </td> <td><?php print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $vmac['vendor_name']) : $vmac['vendor_name']; ?> </td> <td><?php print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $vmac['vendor_address']) : $vmac['vendor_address']; ?> </td> </tr> <?php } } else { print '<tr><td><em>' . __('No MacTrack Vendor MACS') . '</em></td></tr>'; } html_end_box(false); if (sizeof($vmacs)) { print $nav; } }
function ss_mikrotik_snmpget($hostid = '', $oid = '') { global $config; include_once $config['base_path'] . '/lib/snmp.php'; if ($hostid > 0) { $host = db_fetch_row("SELECT hostname, snmp_community, snmp_version, snmp_username, snmp_password, \n\t\t\tsnmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, \n\t\t\tsnmp_port, snmp_timeout, max_oids \n\t\t\tFROM host \n\t\t\tWHERE id={$hostid}"); if (sizeof($host)) { $get = cacti_snmp_get($host['hostname'], $host['snmp_community'], $oid, $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI); if (!empty($get)) { return $get; } } } return '0'; }
function gpsmap_upgrade_database() { global $config, $database_default, $old; include_once $config['library_path'] . '/database.php'; gpsmap_setup_database(); if ($old < "1.6") { mysql_query("ALTER TABLE `host` CHANGE COLUMN latitude latitude DECIMAL(13,10) NOT NULL;"); mysql_query("ALTER TABLE `host` ALTER COLUMN latitude SET DEFAULT `0.0000000000`;"); mysql_query("ALTER TABLE `host` CHANGE COLUMN longitude longitude DECIMAL(13,10) NOT NULL;"); mysql_query("ALTER TABLE `host` ALTER COLUMN longitude SET DEFAULT `0.0000000000`;"); } include_once $config['base_path'] . '/plugins/gpsmap/setup.php'; $v = plugin_gpsmap_version(); $oldv = read_config_option('plugin_gpsmap_version'); }
function gpsmap_check_upgrade() { global $config; $files = array('gpsmap.php', 'gpstemplates.php', 'poller.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $current = plugin_gpsmap_version(); $current = $current['version']; $old = read_config_option('plugin_gpsmap_version', TRUE); if ($current != $old) { include_once $config['base_path'] . '/plugins/gpsmap/includes/database.php'; gpsmap_upgrade_database(); } }
function substitute_path_variables($path) { require_once(CACTI_BASE_PATH . "/lib/sys/string.php"); /* script query */ $path = clean_up_path(str_replace("|path_cacti|", CACTI_BASE_PATH, $path)); $path = clean_up_path(str_replace("|path_php_binary|", read_config_option("path_php_binary"), $path)); /* data source */ $path = clean_up_path(str_replace("<path_rra>", CACTI_BASE_PATH . "/rra", $path)); /* script */ $path = clean_up_path(str_replace("<path_cacti>", CACTI_BASE_PATH, $path)); $path = clean_up_path(str_replace("<path_snmpget>", read_config_option("path_snmpget"), $path)); $path = clean_up_path(str_replace("<path_php_binary>", read_config_option("path_php_binary"), $path)); return $path; }
function read_graph_config_option($config_name) { /* users must have cacti user auth turned on to use this */ if ((read_config_option("auth_method") == "0") || (!isset($_SESSION["sess_user_id"]))) { return read_default_graph_config_option($config_name); } if (!isset($_SESSION["sess_graph_config_array"][$config_name])) { $db_setting = db_fetch_row("select value from settings_graphs where name='$config_name' and user_id=" . $_SESSION["sess_user_id"]); if (isset($db_setting["value"])) { $_SESSION["sess_graph_config_array"][$config_name] = $db_setting["value"]; }else{ $_SESSION["sess_graph_config_array"][$config_name] = read_default_graph_config_option($config_name); } } return $_SESSION["sess_graph_config_array"][$config_name]; }
function api_poller_get_rrd_next_step($rrd_step = 300, $num_rrd_items = 1) { global $config; $poller_interval = read_config_option("poller_interval"); $rrd_next_step = 0; if ($rrd_step != $poller_interval && isset($poller_interval)) { if (!isset($config["rrd_step_counter"])) { $rrd_step_counter = read_config_option("rrd_step_counter"); } else { $rrd_step_counter = $config["rrd_step_counter"]; } if ($num_rrd_items == 1) { $config["rrd_num_counter"] = 0; } else { if (!isset($config["rrd_num_counter"])) { $config["rrd_num_counter"] = 1; } else { $config["rrd_num_counter"]++; } } $modulus = $rrd_step / $poller_interval; if ($modulus < 1 || $rrd_step_counter == 0) { $rrd_next_step = 0; } else { $rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus); } if ($num_rrd_items == 1) { $rrd_step_counter++; } else { if ($num_rrd_items == $config["rrd_num_counter"]) { $rrd_step_counter++; $config["rrd_num_counter"] = 0; } } if ($rrd_step_counter >= $modulus) { $rrd_step_counter = 0; } /* save rrd_step_counter */ $config["rrd_step_counter"] = $rrd_step_counter; db_execute("replace into settings (name, value) values ('rrd_step_counter','{$rrd_step_counter}')"); } return $rrd_next_step; }
/** * set_time_zone() - toogle between system and custom time zone * * @time_zone - time zone * @return - returns true (successful) or false (failed) */ function set_time_zone($time_zone) { /* lock this function if time zone support is disabled */ if(read_config_option("i18n_timezone_support")) { /* if defined only system or custom time zone will be accepted. Avoid that plugins will setup another time zone. */ if(defined('CACTI_CUSTOM_TIME_ZONE') & $time_zone != CACTI_SYSTEM_TIME_ZONE && $time_zone != CACTI_CUSTOM_TIME_ZONE) { return false; }else { /* use date functions if possible (PHP>=5.1.0) */ if(function_exists('date_default_timezone_set')) { return (@date_default_timezone_set($time_zone)) ? true : false; /* try to setup time zone if safe mode is not enabled. */ }else { return (@putenv("TZ=" . $time_zone)) ? true : false; } } } return false; }
function ss_cammpoller() { global $database_username; global $database_password; global $database_hostname; global $database_default; global $database_type; /* db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type);*/ $stats = db_fetch_cell("select value from settings where name='stats_camm'"); if (read_config_option("camm_use_syslog") == "0") { $count_syslogs = db_fetch_cell("select count(*) from " . read_config_option("camm_syslog_db_name") . ".plugin_camm_syslog;"); } else { $count_syslogs = 0; } $count_traps = db_fetch_cell("select count(*) from plugin_camm_snmptt;"); $count_unk_traps = db_fetch_cell("select count(*) from plugin_camm_snmptt_unk;"); $max_row = db_fetch_cell("select value from settings where name='camm_max_row_all'"); $ruledel_traps = db_fetch_cell("select value from settings where name='camm_stats_ruledel'"); return trim($stats . "count_traps:" . $count_traps . " count_unk_traps:" . $count_unk_traps . " max_row:" . $max_row . " ruledel_traps:" . $ruledel_traps . " count_syslogs:" . $count_syslogs); }
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"); }
function ss_fping($hostname, $ping_sweeps = 6, $ping_type = "ICMP", $port = 80) { /* record start time */ list($micro, $seconds) = split(" ", microtime()); $ss_fping_start = $seconds + $micro; $ping = new Net_Ping(); $time = array(); $total_time = 0; $failed_results = 0; $ping->host["hostname"] = gethostbyname($hostname); $ping->retries = 1; $ping->port = $port; $max = 0.0; $min = 9999.99; $dev = 0.0; $script_timeout = read_config_option("script_timeout"); $ping_timeout = read_config_option("ping_timeout"); switch ($ping_type) { case "ICMP": $method = PING_ICMP; break; case "TCP": $method = PING_TCP; break; case "UDP": $method = PING_UDP; break; } $i = 0; while ($i < $ping_sweeps) { $result = $ping->ping(AVAIL_PING, $method, read_config_option("ping_timeout"), 1); if (!$result) { $failed_results++; } else { $time[$i] = $ping->ping_status; $total_time += $ping->ping_status; if ($ping->ping_status < $min) { $min = $ping->ping_status; } if ($ping->ping_status > $max) { $max = $ping->ping_status; } } $i++; /* get current time */ list($micro, $seconds) = split(" ", microtime()); $ss_fping_current = $seconds + $micro; /* if called from script server, end one second before a timeout occurs */ if (isset($called_by_script_server) && $ss_fping_current - $ss_fping_start + $ping_timeout / 1000 + 1 > $script_timeout) { $ping_sweeps = $i; break; } } if ($failed_results == $ping_sweeps) { return "loss:100.00"; } else { $loss = $failed_results / $ping_sweeps * 100; $avg = $total_time / ($ping_sweeps - $failed_results); /* calculate standard deviation */ $predev = 0; foreach ($time as $sample) { $predev += pow($sample - $avg, 2); } $dev = sqrt($predev / count($time)); return sprintf("min:%0.4f avg:%0.4f max:%0.4f dev:%0.4f loss:%0.4f", $min, $avg, $max, $dev, $loss); } }
function upgrade_to_0_8_7() { /* add slope mode as an option */ db_install_execute("0.8.7", "ALTER TABLE `graph_templates_graph` ADD COLUMN `t_slope_mode` CHAR(2) DEFAULT 0 AFTER `vertical_label`, ADD COLUMN `slope_mode` CHAR(2) DEFAULT 'on' AFTER `t_slope_mode`;"); /* change the width of the last error field */ db_install_execute("0.8.7", "ALTER TABLE `host` MODIFY COLUMN `status_last_error` VARCHAR(255);"); /* fix rrd min and max values for data templates */ db_install_execute("0.8.7", "ALTER TABLE `data_template_rrd` MODIFY COLUMN `rrd_maximum` VARCHAR(20) NOT NULL DEFAULT 0, MODIFY COLUMN `rrd_minimum` VARCHAR(20) NOT NULL DEFAULT 0"); /* speed up the poller */ db_install_execute("0.8.7", "ALTER TABLE `host` ADD INDEX `disabled`(`disabled`)"); db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD INDEX `rrd_next_step`(`rrd_next_step`)"); /* speed up the UI */ db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD INDEX `action`(`action`)"); db_install_execute("0.8.7", "ALTER TABLE `user_auth` ADD INDEX `username`(`username`)"); db_install_execute("0.8.7", "ALTER TABLE `user_auth` ADD INDEX `realm`(`realm`)"); db_install_execute("0.8.7", "ALTER TABLE `user_log` ADD INDEX `username`(`username`)"); db_install_execute("0.8.7", "ALTER TABLE `data_input` ADD INDEX `name`(`name`)"); /* Add enable/disable to users */ db_install_execute("0.8.7", "ALTER TABLE `user_auth` ADD COLUMN `enabled` CHAR(2) DEFAULT 'on'"); db_install_execute("0.8.7", "ALTER TABLE `user_auth` ADD INDEX `enabled`(`enabled`)"); /* add additional fields to the host table */ db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `availability_method` SMALLINT(5) UNSIGNED NOT NULL default '2' AFTER `snmp_timeout`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `ping_method` SMALLINT(5) UNSIGNED default '0' AFTER `availability_method`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `ping_port` INT(12) UNSIGNED default '0' AFTER `ping_method`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `ping_timeout` INT(12) UNSIGNED default '500' AFTER `ping_port`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `ping_retries` INT(12) UNSIGNED default '2' AFTER `ping_timeout`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `max_oids` INT(12) UNSIGNED default '10' AFTER `ping_retries`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `notes` TEXT AFTER `hostname`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `snmp_auth_protocol` CHAR(5) default '' AFTER `snmp_password`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `snmp_priv_passphrase` varchar(200) default '' AFTER `snmp_auth_protocol`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `snmp_priv_protocol` CHAR(6) default '' AFTER `snmp_priv_passphrase`"); db_install_execute("0.8.7", "ALTER TABLE `host` ADD COLUMN `snmp_context` VARCHAR(64) default '' AFTER `snmp_priv_protocol`"); /* additional poller items fields required */ db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD COLUMN `snmp_auth_protocol` CHAR(5) default '' AFTER `snmp_password`"); db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD COLUMN `snmp_priv_passphrase` varchar(200) default '' AFTER `snmp_auth_protocol`"); db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD COLUMN `snmp_priv_protocol` CHAR(6) default '' AFTER `snmp_priv_passphrase`"); db_install_execute("0.8.7", "ALTER TABLE `poller_item` ADD COLUMN `snmp_context` VARCHAR(64) default '' AFTER `snmp_priv_protocol`"); /* Convert to new authentication system */ $global_auth = "on"; $global_auth_db = db_fetch_row("SELECT value FROM settings WHERE name = 'global_auth'"); if (sizeof($global_auth_db)) { $global_auth = $global_auth_db["value"]; } $ldap_enabled = ""; $ldap_enabled_db = db_fetch_row("SELECT value FROM settings WHERE name = 'ldap_enabled'"); if (sizeof($ldap_enabled_db)) { $ldap_enabled = $ldap_enabled_db["value"]; } if ($global_auth == "on") { if ($ldap_enabled == "on") { db_install_execute("0.8.7", "INSERT INTO settings VALUES ('auth_method','3')"); } else { db_install_execute("0.8.7", "INSERT INTO settings VALUES ('auth_method','1')"); } } else { db_install_execute("0.8.7", "INSERT INTO settings VALUES ('auth_method','0')"); } db_install_execute("0.8.7", "UPDATE `settings` SET value = '0' WHERE name = 'guest_user' and value = ''"); db_install_execute("0.8.7", "UPDATE `settings` SET name = 'user_template' WHERE name = 'ldap_template'"); db_install_execute("0.8.7", "UPDATE `settings` SET value = '0' WHERE name = 'user_template' and value = ''"); db_install_execute("0.8.7", "DELETE FROM `settings` WHERE name = 'global_auth'"); db_install_execute("0.8.7", "DELETE FROM `settings` WHERE name = 'ldap_enabled'"); /* host settings for availability */ $ping_method = read_config_option("ping_method"); $ping_retries = read_config_option("ping_retries"); $ping_timeout = read_config_option("ping_timeout"); $availability_method = read_config_option("availability_method"); $hosts = db_fetch_assoc("SELECT id, snmp_community, snmp_version FROM host"); if (sizeof($hosts)) { foreach ($hosts as $host) { if (strlen($host["snmp_community"] != 0)) { if ($host["snmp_version"] == "3") { if ($availability_method == AVAIL_SNMP) { db_install_execute("0.8.7", "UPDATE host SET snmp_priv_protocol='[None]', snmp_auth_protocol='MD5', availability_method=" . AVAIL_SNMP . ", ping_method=" . PING_UDP . ",ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { if ($availability_method == AVAIL_SNMP_AND_PING) { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET snmp_priv_protocol='[None]', availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET snmp_priv_protocol='[None]', availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } else { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET snmp_priv_protocol='[None]', availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET snmp_priv_protocol='[None]', availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } } } else { if ($availability_method == AVAIL_SNMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP . ", ping_method=" . PING_UDP . ",ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { if ($availability_method == AVAIL_SNMP_AND_PING) { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } else { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } } } } else { if ($availability_method == AVAIL_SNMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP . ", ping_method=" . PING_UDP . ", ping_timeout = " . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { if ($availability_method == AVAIL_SNMP_AND_PING) { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_SNMP_AND_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } else { if ($ping_method == PING_ICMP) { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } else { db_install_execute("0.8.7", "UPDATE host SET availability_method=" . AVAIL_PING . ", ping_method=" . $ping_method . ", ping_port=33439, ping_timeout=" . $ping_timeout . ", ping_retries=" . $ping_retries . " WHERE id=" . $host["id"]); } } } } } } /* Add SNMPv3 to SNMP Input Methods */ db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, '20832ce12f099c8e54140793a091af90',1,'SNMP Authenticaion Protocol (v3)','snmp_auth_protocol','in','',0,'snmp_auth_protocol','','')"); db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, 'c60c9aac1e1b3555ea0620b8bbfd82cb',1,'SNMP Privacy Passphrase (v3)','snmp_priv_passphrase','in','',0,'snmp_priv_passphrase','','')"); db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, 'feda162701240101bc74148415ef415a',1,'SNMP Privacy Protocol (v3)','snmp_priv_protocol','in','',0,'snmp_priv_protocol','','')"); db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, '2cf7129ad3ff819a7a7ac189bee48ce8',2,'SNMP Authenticaion Protocol (v3)','snmp_auth_protocol','in','',0,'snmp_auth_protocol','','')"); db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, '6b13ac0a0194e171d241d4b06f913158',2,'SNMP Privacy Passphrase (v3)','snmp_priv_passphrase','in','',0,'snmp_priv_passphrase','','')"); db_install_execute("0.8.7", "INSERT INTO data_input_fields VALUES (DEFAULT, '3a33d4fc65b8329ab2ac46a36da26b72',2,'SNMP Privacy Protocol (v3)','snmp_priv_protocol','in','',0,'snmp_priv_protocol','','')"); /* Add 1 min rra */ db_install_execute("0.8.7", "INSERT INTO rra VALUES (DEFAULT,'283ea2bf1634d92ce081ec82a634f513','Hourly (1 Minute Average)',0.5,1,500,14400)"); $rrd_id = mysql_insert_id(); db_install_execute("0.8.7", "INSERT INTO `rra_cf` VALUES ({$rrd_id},1), ({$rrd_id},3)"); /* rename cactid path to spine path */ db_install_execute("0.8.7", "UPDATE settings SET name='path_spine' WHERE name='path_cactid'"); }
function get_host_array() { if (read_config_option("global_auth") == "on") { $current_user = db_fetch_row("select policy_hosts from user_auth where id=" . $_SESSION["sess_user_id"]); if ($current_user["policy_hosts"] == "1") { $sql_where = "where user_auth_perms.user_id is null"; }elseif ($current_user["policy_hosts"] == "2") { $sql_where = "where user_auth_perms.user_id is not null"; } $host_list = db_fetch_assoc("select host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name, user_auth_perms.user_id from host left join user_auth_perms on (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") $sql_where order by host.description,host.hostname"); }else{ $host_list = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); } return $host_list; }
function export_build_graphs($fp, $path, $tree_id, $parent_tree_item_id) { /* start the count of graphs */ $total_graphs_created = 0; $cacti_export_path = read_config_option("path_html_export"); $req=""; if (get_tree_item_type($parent_tree_item_id)=="host") { $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_templates_graph left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_local.host_id=".get_host_id($parent_tree_item_id)." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; }else { /* searching for the graph_tree_items of the tree_id which are graphs */ $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id, graph_tree_items.id as gtid from graph_templates_graph left join graph_tree_items on (graph_templates_graph.local_graph_id=graph_tree_items.local_graph_id) left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_tree_items.graph_tree_id =".$tree_id." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; } $graphs=db_fetch_assoc($req); $rras = db_fetch_assoc("select rra.id, rra.name from rra order by timespan"); /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); /* for each graph... */ $i = 0; foreach($graphs as $graph) { /* this test gives us the graph_tree_items which are just under the parent_graph_tree_item */ if (((get_tree_item_type($parent_tree_item_id)=="header") || ($parent_tree_item_id == 0)) && (get_parent_id($graph["gtid"], "graph_tree_items","graph_tree_id = ".$tree_id) != $parent_tree_item_id)) { /* do nothing */ }else { /* settings for preview graphs */ $graph_data_array["graph_height"] = "100"; $graph_data_array["graph_width"] = "300"; $graph_data_array["graph_nolegend"] = true; $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/thumb_".$graph["local_graph_id"].".png"; rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* generate html files for each graph */ $fp_graph_index = fopen($cacti_export_path."/".$path."/graph_".$graph["local_graph_id"].".html", "w"); fwrite($fp_graph_index, HTML_HEADER_TREE); draw_html_left_tree($fp_graph_index,$tree_id); fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE); fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>"); fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO); fwrite($fp_graph_index, "<td>"); /* reset vars for actual graph image creation */ reset($rras); unset($graph_data_array); /* generate graphs for each rra */ foreach ($rras as $rra) { $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/graph_".$graph["local_graph_id"]."_".$rra["id"].".png"; rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* write image related html */ fwrite($fp_graph_index, "<div align=center><img src='graph_".$graph["local_graph_id"]."_".$rra["id"].".png' border=0></div>\n <div align=center><strong>".$rra["name"]."</strong></div><br>"); } fwrite($fp_graph_index, "</tr></table>"); fwrite($fp_graph_index, HTML_FOOTER_TREE); fclose($fp_graph_index); /* main graph page html */ fwrite($fp, "<td align='center' width='\" . (98 / 2) . \"%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n"); $i++; if (($i == 2)) { $i = 0; fwrite($fp, "</tr><tr>"); } } } /* close the rrdtool pipe */ rrd_close($rrdtool_pipe); return $total_graphs_created; }
function api_plugin_user_realm_auth($filename = '') { global $user_realms, $user_auth_realms, $user_auth_realm_filenames; /* list all realms that this user has access to */ if (!isset($user_realms)) { if (read_config_option('global_auth') == 'on' || read_config_option('auth_method') != 0) { $user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"], false); $user_realms = array_rekey($user_realms, "realm_id", "realm_id"); } else { $user_realms = $user_auth_realms; } } if ($filename != '' && isset($user_auth_realm_filenames[basename($filename)])) { if (isset($user_realms[$user_auth_realm_filenames[basename($filename)]])) { return TRUE; } } return FALSE; }
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); }
function Ldap() { /* Initialize LDAP parameters for Authenticate */ $this->dn = read_config_option("ldap_dn"); $this->host = read_config_option("ldap_server"); $this->port = read_config_option("ldap_port"); $this->port_ssl = read_config_option("ldap_port_ssl"); $this->version = read_config_option("ldap_version"); $this->encryption = read_config_option("ldap_encryption"); $this->referrals = read_config_option("ldap_referrals"); if (read_config_option("ldap_group_require") == "on") { $this->group_require = true; } else { $this->group_require = false; } $this->group_dn = read_config_option("ldap_group_dn"); $this->group_attrib = read_config_option("ldap_group_attrib"); $this->group_member_type = read_config_option("ldap_group_member_type"); /* Initialize LDAP parameters for Search */ $this->mode = read_config_option("ldap_mode"); $this->specific_dn = read_config_option("ldap_specific_dn"); $this->specific_password = read_config_option("ldap_specific_password"); $this->search_base = read_config_option("ldap_search_base"); $this->search_filter = read_config_option("ldap_search_filter"); return true; }
/** create_complete_graph_from_template - creates a graph and all necessary data sources based on a graph template @param int $graph_template_id - the id of the graph template that will be used to create the new graph @param int $device_id - the id of the device to associate the new graph and data sources with @param array $snmp_query_array - if the new data sources are to be based on a data query, specify the necessary data query information here. it must contain the following information: $snmp_query_array["snmp_query_id"] $snmp_query_array["snmp_index_on"] $snmp_query_array["snmp_query_graph_id"] $snmp_query_array["snmp_index"] @param array $suggested_values_array - any additional information to be included in the new graphs or data sources must be included in the array. data is to be included in the following format: $values["cg"][graph_template_id]["graph_template"][field_name] = $value // graph template $values["cg"][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value // graph template item $values["cg"][data_template_id]["data_template"][field_name] = $value // data template $values["cg"][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value // data template item $values["sg"][data_query_id][graph_template_id]["graph_template"][field_name] = $value // graph template (w/ data query) $values["sg"][data_query_id][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value // graph template item (w/ data query) $values["sg"][data_query_id][data_template_id]["data_template"][field_name] = $value // data template (w/ data query) $values["sg"][data_query_id][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value // data template item (w/ data query) */ function create_complete_graph_from_template($graph_template_id, $device_id, $snmp_query_array, &$suggested_values_array) { global $config; include_once(CACTI_BASE_PATH . "/lib/data_query.php"); /* create the graph */ $save["id"] = 0; $save["graph_template_id"] = $graph_template_id; $save["device_id"] = $device_id; $cache_array["local_graph_id"] = sql_save($save, "graph_local"); change_graph_template($cache_array["local_graph_id"], $graph_template_id, true); if (is_array($snmp_query_array)) { /* suggested values for snmp query code */ $suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " order by sequence"); if (sizeof($suggested_values) > 0) { foreach ($suggested_values as $suggested_value) { /* once we find a match; don't try to find more */ if (!isset($suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]})) { $subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false); /* if there are no '|' characters, all of the substitutions were successful */ if (!strstr($subs_string, "|query")) { db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_graph_id=" . $cache_array["local_graph_id"]); /* once we find a working value, stop */ $suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true; } } } } } /* suggested values: graph */ if (isset($suggested_values_array[$graph_template_id]["graph_template"])) { while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) { db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $cache_array["local_graph_id"]); } } /* suggested values: graph item */ if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) { while (list($graph_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["graph_template_item"])) { while (list($field_name, $field_value) = each($field_array)) { $graph_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=$graph_template_item_id and local_graph_id=" . $cache_array["local_graph_id"]); db_execute("update graph_templates_item set $field_name='$field_value' where id=$graph_item_id"); } } } update_graph_title_cache($cache_array["local_graph_id"]); /* create each data source */ $data_templates = db_fetch_assoc("select data_template.id, data_template.name, data_template_rrd.data_source_name from (data_template, data_template_rrd, graph_templates_item) where graph_templates_item.task_item_id=data_template_rrd.id and data_template_rrd.data_template_id=data_template.id and data_template_rrd.local_data_id=0 and graph_templates_item.local_graph_id=0 and graph_templates_item.graph_template_id=" . $graph_template_id . " group by data_template.id order by data_template.name"); if (sizeof($data_templates) > 0) { foreach ($data_templates as $data_template) { unset($save); $save["id"] = 0; $save["data_template_id"] = $data_template["id"]; $save["device_id"] = $device_id; $cache_array["local_data_id"]{$data_template["id"]} = sql_save($save, "data_local"); change_data_template($cache_array["local_data_id"]{$data_template["id"]}, $data_template["id"]); $data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]}); if (is_array($snmp_query_array)) { /* suggested values for snmp query code */ $suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_rrd_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " and data_template_id=" . $data_template["id"] . " order by sequence"); if (sizeof($suggested_values) > 0) { foreach ($suggested_values as $suggested_value) { /* once we find a match; don't try to find more */ if (!isset($suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]})) { $subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false); /* if there are no '|' characters, all of the substitutions were successful */ if (!strstr($subs_string, "|query")) { if (sizeof(db_fetch_row("show columns from data_template_data like '" . $suggested_value["field_name"] . "'"))) { db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]}); } /* once we find a working value, stop */ $suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]} = true; if ((sizeof(db_fetch_row("show columns from data_template_rrd like '" . $suggested_value["field_name"] . "'"))) && (!substr_count($subs_string, "|"))) { db_execute("update data_template_rrd set " . $suggested_value["field_name"] . "='" . $subs_string . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]}); } } } } } } if (is_array($snmp_query_array)) { $data_input_field = array_rekey(db_fetch_assoc("SELECT data_input_fields.id, data_input_fields.type_code FROM (snmp_query,data_input,data_input_fields) WHERE snmp_query.data_input_id=data_input.id AND data_input.id=data_input_fields.data_input_id AND (data_input_fields.type_code='index_type' OR data_input_fields.type_code='index_value' OR data_input_fields.type_code='output_type') AND snmp_query.id=" . $snmp_query_array["snmp_query_id"]), "type_code", "id"); $snmp_cache_value = db_fetch_cell("SELECT field_value FROM device_snmp_cache WHERE device_id='$device_id' AND snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "' AND field_name='" . $snmp_query_array["snmp_index_on"] . "' AND snmp_index='" . $snmp_query_array["snmp_index"] . "'"); /* save the value to index on (ie. ifindex, ifip, etc) */ db_execute("REPLACE INTO data_input_data (data_input_field_id, data_template_data_id, t_value, value) VALUES (" . $data_input_field["index_type"] . ", $data_template_data_id, '', '" . $snmp_query_array["snmp_index_on"] . "')"); /* save the actual value (ie. 3, 192.168.1.101, etc) */ db_execute("REPLACE INTO data_input_data (data_input_field_id,data_template_data_id,t_value,value) VALUES (" . $data_input_field["index_value"] . ",$data_template_data_id,'','" . addslashes($snmp_cache_value) . "')"); /* set the expected output type (ie. bytes, errors, packets) */ db_execute("REPLACE INTO data_input_data (data_input_field_id,data_template_data_id,t_value,value) VALUES (" . $data_input_field["output_type"] . ",$data_template_data_id,'','" . $snmp_query_array["snmp_query_graph_id"] . "')"); /* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */ update_data_source_data_query_cache($cache_array["local_data_id"]{$data_template["id"]}); } /* suggested values: data source */ if (isset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) { reset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]}); while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) { db_execute("UPDATE data_template_data SET $field_name='$field_value' WHERE local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]}); } } /* suggested values: data source item */ if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) { reset($suggested_values_array[$graph_template_id]["data_template_item"]); while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) { while (list($field_name, $field_value) = each($field_array)) { $data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=$data_template_item_id and local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]}); db_execute("UPDATE data_template_rrd SET $field_name='$field_value' WHERE id=$data_source_item_id"); } } } /* suggested values: custom data */ if (isset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) { reset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]}); while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) { db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values ($data_input_field_id,$data_template_data_id,'','$field_value')"); } } update_data_source_title_cache($cache_array["local_data_id"]{$data_template["id"]}); } } /* connect the dots: graph -> data source(s) */ $template_item_list = db_fetch_assoc("select graph_templates_item.id, data_template_rrd.id as data_template_rrd_id, data_template_rrd.data_template_id from (graph_templates_item,data_template_rrd) where graph_templates_item.task_item_id=data_template_rrd.id and graph_templates_item.graph_template_id=$graph_template_id and local_graph_id=0 and task_item_id>0"); /* loop through each item affected and update column data */ if (sizeof($template_item_list) > 0) { foreach ($template_item_list as $template_item) { $local_data_id = $cache_array["local_data_id"]{$template_item["data_template_id"]}; $graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]); $data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id=$local_data_id"); if (!empty($data_template_rrd_id)) { db_execute("update graph_templates_item set task_item_id='$data_template_rrd_id' where id=$graph_template_item_id"); } } } /* this will not work until the ds->graph dots are connected */ if (is_array($snmp_query_array)) { update_graph_data_query_cache($cache_array["local_graph_id"]); } # now that we have the id of the new host, we may plugin postprocessing code $save["id"] = $cache_array["local_graph_id"]; $save["graph_template_id"] = $graph_template_id; // attention: unset! if (is_array($snmp_query_array)) { $save["snmp_query_id"] = $snmp_query_array["snmp_query_id"]; $save["snmp_index"] = $snmp_query_array["snmp_index"]; } else { $save["snmp_query_id"] = 0; $save["snmp_index"] = 0; } api_plugin_hook_function('create_complete_graph_from_template', $save); return $cache_array; }
/* let PHP run just as long as it has to */ ini_set('max_execution_time', '0'); $no_http_headers = true; require dirname(__FILE__) . '/include/global.php'; $event_manager_interval = read_config_option('event_manager_interval'); log_save('Event Manager Starting', SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true); $counter = time() - $event_manager_interval; while (true) { /* We want to have the event manager process every XX seconds, so sleep until its processing time */ while ($counter > time() - $event_manager_interval) { Sleep(1); } /* Start our timer now, so it includes the actual processing time in the processing interval */ $counter = time(); /* Set the status to show which events are being processed */ $status_id = event_save_status(); /* Get all events so we can begin processing */ $events = event_list(array('status' => $status_id)); /* Loop through each event for processing */ foreach ($events as $event) { log_save('Processing Event ' . $event['id'], SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true); event_process($event['id']); } /* Remove all events that were set to be processed */ event_deleted_processed($status_id); if (date('s', time()) < $event_manager_interval) { unset($_SESSION['sess_config_array']['event_manager_interval']); $event_manager_interval = read_config_option('event_manager_interval'); } } log_save('Event Manager exitting', SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true);
function mactrack_view() { global $title, $colors, $mactrack_rows, $config; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("issues")); input_validate_input_number(get_request_var_request("bwusage")); input_validate_input_number(get_request_var_request("device")); input_validate_input_number(get_request_var_request("site")); input_validate_input_number(get_request_var_request("type")); /* ==================================================== */ /* clean up filter */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up totals */ if (isset($_REQUEST["totals"])) { $_REQUEST["totals"] = sanitize_search_string(get_request_var("totals")); } /* clean up */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) { kill_session_var("sess_mactrack_int_current_page"); kill_session_var("sess_mactrack_int_rows"); kill_session_var("sess_mactrack_int_totals"); kill_session_var("sess_mactrack_int_device_id"); kill_session_var("sess_mactrack_int_state"); kill_session_var("sess_mactrack_int_site"); kill_session_var("sess_mactrack_int_device"); kill_session_var("sess_mactrack_int_issues"); kill_session_var("sess_mactrack_int_bwusage"); kill_session_var("sess_mactrack_int_type"); kill_session_var("sess_mactrack_int_period"); kill_session_var("sess_mactrack_int_filter"); kill_session_var("sess_mactrack_int_sort_column"); kill_session_var("sess_mactrack_int_sort_direction"); $_REQUEST["page"] = 1; if (isset($_REQUEST["clear_x"])) { unset($_REQUEST["device_id"]); unset($_REQUEST["totals"]); unset($_REQUEST["state"]); unset($_REQUEST["site"]); unset($_REQUEST["totals"]); unset($_REQUEST["device"]); unset($_REQUEST["issues"]); unset($_REQUEST["bwusage"]); unset($_REQUEST["type"]); unset($_REQUEST["period"]); unset($_REQUEST["filter"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += mactrack_check_changed("device_id", "sess_mactrack_int_device_id"); $changed += mactrack_check_changed("site", "sess_mactrack_int_site"); $changed += mactrack_check_changed("totals", "sess_mactrack_int_totals"); $changed += mactrack_check_changed("device", "sess_mactrack_int_device"); $changed += mactrack_check_changed("issues", "sess_mactrack_int_issues"); $changed += mactrack_check_changed("bwusage", "sess_mactrack_int_bwusage"); $changed += mactrack_check_changed("type", "sess_mactrack_int_type"); $changed += mactrack_check_changed("period", "sess_mactrack_int_period"); $changed += mactrack_check_changed("filter", "sess_mactrack_int_filter"); $changed += mactrack_check_changed("rows", "sess_mactrack_int_rows"); $changed += mactrack_check_changed("sort_column", "sess_mactrack_int_sort_column"); $changed += mactrack_check_changed("sort_direction", "sess_mactrack_int_sort_direction"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_mactrack_int_current_page", "1"); load_current_session_value("totals", "sess_mactrack_int_totals", "on"); load_current_session_value("rows", "sess_mactrack_int_rows", read_config_option("num_rows_device")); load_current_session_value("device_id", "sess_mactrack_int_device_id", "-1"); load_current_session_value("site", "sess_mactrack_int_site", "-1"); load_current_session_value("issues", "sess_mactrack_int_issues", "-3"); load_current_session_value("bwusage", "sess_mactrack_int_bwusage", read_config_option("mactrack_interface_high")); load_current_session_value("type", "sess_mactrack_int_type", "-1"); load_current_session_value("device", "sess_mactrack_int_device", "-1"); load_current_session_value("period", "sess_mactrack_int_period", "-2"); load_current_session_value("filter", "sess_mactrack_int_filter", ""); load_current_session_value("sort_column", "sess_mactrack_int_sort_column", "device_name"); load_current_session_value("sort_direction", "sess_mactrack_int_sort_direction", "DESC"); include_once("./plugins/mactrack/general_header.php"); print "<script type='text/javascript' src='" . $config["url_path"] . "plugins/mactrack/mactrack.js'></script>"; $sql_where = ""; if ($_REQUEST["rows"] == -1) { $row_limit = read_config_option("num_rows_device"); }elseif ($_REQUEST["rows"] == -2) { $row_limit = 99999999; }else{ $row_limit = $_REQUEST["rows"]; } $stats = mactrack_get_records($sql_where, TRUE, $row_limit); mactrack_tabs(); html_start_box("<strong>Scanned Device Interfaces</strong>", "100%", $colors["header"], "3", "center", ""); mactrack_filter_table(); html_end_box(); //Last device restart: if ($_REQUEST["device"]!=-1){ html_start_box("", "100%", $colors["header"], "3", "center", ""); print "<tr>"; if (sizeof($stats)>0) $last_run_time = max(strtotime($stats[0]["last_up_time"]),strtotime($stats[0]["last_down_time"])); else $last_run_time = read_config_option("mt_last_run_time", TRUE); $diff = strtotime("now") - $last_run_time; $upTime = ($stats[0]["sysUptime"]/100) + $diff; $days = intval($upTime / (60*60*24)); $remainder = $upTime % (60*60*24); $hours = intval($remainder / (60*60)); $remainder = $remainder % (60*60); $minutes = intval($remainder / (60)); $upTime = $days . "d:" . $hours . "h:" . $minutes . "m"; print "<td style='text-align:right'><strong>Last device restart:</strong> ".$upTime."</td>"; print "</tr>"; html_end_box(false); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $rows_query_string = "SELECT COUNT(*) FROM mac_track_interfaces INNER JOIN mac_track_devices ON mac_track_interfaces.device_id=mac_track_devices.device_id INNER JOIN mac_track_device_types ON mac_track_device_types.device_type_id=mac_track_devices.device_type_id $sql_where"; //echo $rows_query_string; $total_rows = db_fetch_cell($rows_query_string); /* generate page list */ if ($total_rows > 0) { $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_interfaces.php?report=interfaces"); $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'> <td colspan='22'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . (($row_limit*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < $row_limit) || ($total_rows < ($row_limit*$_REQUEST["page"]))) ? $total_rows : ($row_limit*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; }else{ $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'> <td colspan='22'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='center' class='textHeaderDark'> No Rows Found </td>\n </tr> </table> </td> </tr>\n"; } print $nav; $display_text = mactrack_display_array(); html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($stats) > 0) { //$stats = order_by_name($stats); foreach ($stats as $stat) { /* find the background color and enclose it */ $bgc = mactrack_int_row_color($stat); if ($bgc) { print "<tr id='row_" . $stat["device_id"] . "_" . $stat["ifName"] . "' style='background-color:#$bgc;'>\n"; $i++; }else{ if (($i % 2) == 1) { $current_color = $colors["alternate"]; }else{ $current_color = $colors["light"]; } print "<tr id='row_" . $stat["device_id"] . "' style='background-color:#$bgc;'>\n"; $i++; } print mactrack_format_interface_row($stat); } }else{ print "<tr><td colspan='7'><em>No Scanner Devices Found</em></td></tr>"; } /* put the nav bar on the bottom as well */ print $nav; html_end_box(false); html_start_box("", "100%", $colors["header"], "3", "center", ""); print "<tr>"; mactrack_legend_row("mt_int_up_bgc", "Interface Up"); mactrack_legend_row("mt_int_up_wo_alias_bgc", "No Alias"); mactrack_legend_row("mt_int_errors_bgc", "Errors Present"); mactrack_legend_row("mt_int_discards_bgc", "Discards Present"); mactrack_legend_row("mt_int_unmapped_bgc", "Unmapped to Tree"); mactrack_legend_row("mt_int_no_graph_bgc", "No Graphs"); mactrack_legend_row("mt_int_no_device_bgc", "Not Integrated"); mactrack_legend_row("mt_int_down_bgc", "Interface Down"); print "</tr>"; html_end_box(false); mactrack_display_stats(); print "<div id='response'></div>"; print "<script> function printreport(id){ if (id==-1 ||typeof id == 'undefined') alert('To generate the report, you must select one device.'); else window.open('https://monitorizacion.urjc.es/cacti/plugins/mactrack/pdfreport.php?did='+id, '_blank'); } </script>"; include_once("./include/bottom_footer.php"); }
exit; } /* don't even bother with the guest code if we're already logged in */ if ((isset($guest_account)) && (empty($_SESSION["sess_user_id"]))) { $guest_user_id = db_fetch_cell("select id from user_auth where username='******'"); /* cannot find guest user */ if (!empty($guest_user_id)) { $_SESSION["sess_user_id"] = $guest_user_id; } } /* if we are a guest user in a non-guest area, wipe credentials */ if (!empty($_SESSION["sess_user_id"])) { if ((!isset($guest_account)) && (db_fetch_cell("select id from user_auth where username='******'") == $_SESSION["sess_user_id"])) { kill_session_var("sess_user_id"); } } if (empty($_SESSION["sess_user_id"])) { include("./auth_login.php"); exit; }elseif (!empty($_SESSION["sess_user_id"])) { $realm_id = 0; if (isset($user_auth_realm_filenames{basename($_SERVER["PHP_SELF"])})) { $realm_id = $user_auth_realm_filenames{basename($_SERVER["PHP_SELF"])}; } if ((!db_fetch_assoc("select