cacti-0.8.8f/0000755000175000001440000000000012553175277012031 5ustar romanuserscacti-0.8.8f/graph_templates_inputs.php0000644000175000001440000002376512553175277017340 0ustar romanusers 0)) { while (list($item_id, $item_id) = each($new_members)) { push_out_graph_input($graph_template_input_id, $item_id, (isset($new_members) ? $new_members : array())); } } db_execute("delete from graph_template_input_defs where graph_template_input_id=$graph_template_input_id"); if (sizeof($selected_graph_items) > 0) { foreach ($selected_graph_items as $graph_template_item_id) { db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ($graph_template_input_id,$graph_template_item_id)"); } } }else{ raise_message(2); } } if (is_error_message()) { header("Location: graph_templates_inputs.php?action=input_edit&graph_template_input_id=" . (empty($graph_template_input_id) ? $_POST["graph_template_input_id"] : $graph_template_input_id) . "&graph_template_id=" . $_POST["graph_template_id"]); exit; }else{ header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]); exit; } } } /* ------------------------------------ input - Graph Template Item Inputs ------------------------------------ */ function input_remove() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("graph_template_id")); /* ==================================================== */ if ((read_config_option("deletion_verification") == "on") && (!isset($_GET["confirm"]))) { include("./include/top_header.php"); form_confirm("Are You Sure?", "Are you sure you want to delete the input item '" . htmlspecialchars(db_fetch_cell("select name from graph_template_input where id=" . $_GET["id"]), ENT_QUOTES) . "'? NOTE: Deleting this item will NOT affect graphs that use this template.", htmlspecialchars("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]), htmlspecialchars("graph_templates_inputs.php?action=input_remove&id=" . $_GET["id"] . "&graph_template_id=" . $_GET["graph_template_id"])); include("./include/bottom_footer.php"); exit; } if ((read_config_option("deletion_verification") == "") || (isset($_GET["confirm"]))) { db_execute("delete from graph_template_input where id=" . $_GET["id"]); db_execute("delete from graph_template_input_defs where graph_template_input_id=" . $_GET["id"]); } } function input_edit() { global $consolidation_functions, $graph_item_types, $struct_graph_item, $fields_graph_template_input_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("graph_template_id")); /* ==================================================== */ $header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]"; /* get a list of all graph item field names and populate an array for user display */ while (list($field_name, $field_array) = each($struct_graph_item)) { if ($field_array["method"] != "view") { $graph_template_items[$field_name] = $field_array["friendly_name"]; } } if (!empty($_GET["id"])) { $graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]); } html_start_box("Graph Item Inputs " . htmlspecialchars($header_label), "100%", "", "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_graph_template_input_edit, (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET) )); if (!(isset($_GET["id"]))) { $_GET["id"] = 0; } $item_list = db_fetch_assoc("select CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name, graph_templates_item.text_format, graph_templates_item.id as graph_templates_item_id, graph_templates_item.graph_type_id, graph_templates_item.consolidation_function_id, graph_template_input_defs.graph_template_input_id from graph_templates_item left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ") left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id) left join data_local on (data_template_rrd.local_data_id=data_local.id) left join data_template_data on (data_local.id=data_template_data.local_data_id) where graph_templates_item.local_graph_id=0 and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . " order by graph_templates_item.sequence"); form_alternate_row();?> Associated Graph Items
Select the graph items that you want to accept user input for. 0) { foreach ($item_list as $item) { if ($item["graph_template_input_id"] == "") { $old_value = ""; }else{ $old_value = "on"; $any_selected_item = $item["graph_templates_item_id"]; } if ($graph_item_types{$item["graph_type_id"]} == "GPRINT") { $start_bold = ""; $end_bold = ""; }else{ $start_bold = ""; $end_bold = ""; } $name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold"; form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name, "", "", $_GET["graph_template_id"]); print "
"; $i++; } }else{ print "No Items"; } ?> This script is only meant to run at the command line."); } ini_set("max_execution_time", "0"); $no_http_headers = true; include (dirname(__FILE__) . "/../include/global.php"); include_once ($config["base_path"] . "/lib/api_data_source.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); /* utility requires input parameters */ if (sizeof($parms) == 0) { print "ERROR: You must supply input parameters\n\n"; display_help(); exit; } $debug = FALSE; $host_id = ""; $filter = ""; foreach ($parms as $parameter) { @ list ($arg, $value) = @ explode("=", $parameter); switch ($arg) { case "-id" : case "--id" : $host_id = $value; break; case "-s" : case "--filter" : $filter = $value; break; case "-d" : case "--debug" : $debug = TRUE; break; case "-h" : case "--help" : case "-v" : case "--verbose" : case "--version" : display_help(); exit; default : print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* form the 'where' clause for our main sql query */ if (strlen($filter)) { $sql_where = "AND (data_template_data.name_cache like '%%" . $filter . "%%'" . " OR data_template_data.local_data_id like '%%" . $filter . "%%'" . " OR data_template.name like '%%" . $filter . "%%'" . " OR data_input.name like '%%" . $filter . "%%')"; } else { $sql_where = ""; } if (strtolower($host_id) == "all") { /* Act on all graphs */ } elseif (substr_count($host_id, "|")) { $hosts = explode("|", $host_id); $host_str = ""; foreach ($hosts as $host) { if (strlen($host_str)) { $host_str .= ", '" . $host . "'"; } else { $host_str .= "'" . $host . "'"; } } $sql_where .= " AND data_local.host_id IN ($host_str)"; } elseif ($host_id == "0") { $sql_where .= " AND data_local.host_id=0"; } elseif (!empty ($host_id)) { $sql_where .= " AND data_local.host_id=" . $host_id; } else { print "ERROR: You must specify either a host_id or 'All' to proceed.\n"; display_help(); exit; } $data_source_list = db_fetch_assoc("SELECT data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_input.name as data_input_name, data_template.name as data_template_name, data_local.host_id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where"); /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Interrupting during rename can cause issues\n"; debug("There are '" . sizeof($data_source_list) . "' Data Sources to rename"); $i = 1; foreach ($data_source_list as $data_source) { if (!$debug) print "."; debug("Data Source Name '" . $data_source["name_cache"] . "' starting"); api_reapply_suggested_data_source_title($data_source["local_data_id"]); update_data_source_title_cache($data_source["local_data_id"]); debug("Data Source Rename Done for Data Source '" . addslashes(get_data_source_title($data_source["local_data_id"])) . "'"); $i++; } /* display_help - displays the usage of the function */ function display_help() { print "Cacti Reapply Data Sources Names Script 1.0, Copyright 2008 - The Cacti Group\n\n"; print "usage: poller_data_sources_reapply_names.php --id=[host_id|All][host_id1|host_id2|...] [--filter=[search_string] [--debug] [-h] [--help] [-v] [--version]\n\n"; print "--id=host_id - The host_id or 'All' or a pipe delimited list of host_id's\n"; print "--filter=search_str - A data template name or data source title to search for\n"; print "--debug - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print ("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/index.php0000644000175000001440000000005412553175277014417 0ustar romanusers cacti-0.8.8f/cli/add_device.php0000644000175000001440000002626412553175277015372 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } /* We are not talking to the browser */ $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"]."/lib/api_automation_tools.php"); include_once($config["base_path"]."/lib/utility.php"); include_once($config["base_path"]."/lib/api_data_source.php"); include_once($config["base_path"]."/lib/api_graph.php"); include_once($config["base_path"]."/lib/snmp.php"); include_once($config["base_path"]."/lib/data_query.php"); include_once($config["base_path"]."/lib/api_device.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); if (sizeof($parms)) { /* setup defaults */ $description = ""; $ip = ""; $template_id = 0; $community = read_config_option("snmp_community"); $snmp_ver = read_config_option("snmp_ver"); $disable = 0; $notes = ""; $snmp_username = read_config_option("snmp_username"); $snmp_password = read_config_option("snmp_password"); $snmp_auth_protocol = read_config_option("snmp_auth_protocol"); $snmp_priv_passphrase = read_config_option("snmp_priv_passphrase"); $snmp_priv_protocol = read_config_option("snmp_priv_protocol"); $snmp_context = ""; $snmp_port = read_config_option("snmp_port"); $snmp_timeout = read_config_option("snmp_timeout"); $avail = read_config_option("availability_method"); $ping_method = read_config_option("ping_method"); $ping_port = read_config_option("ping_port"); $ping_timeout = read_config_option("ping_timeout"); $ping_retries = read_config_option("ping_retries"); $max_oids = read_config_option("max_get_size"); $device_threads = 1; $displayHostTemplates = FALSE; $displayCommunities = FALSE; $quietMode = FALSE; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-d": $debug = TRUE; break; case "--description": $description = trim($value); break; case "--ip": $ip = trim($value); break; case "--template": $template_id = $value; break; case "--community": $community = trim($value); break; case "--version": $snmp_ver = trim($value); break; case "--notes": $notes = trim($value); break; case "--disable": $disable = $value; break; case "--username": $snmp_username = trim($value); break; case "--password": $snmp_password = trim($value); break; case "--authproto": $snmp_auth_protocol = trim($value); break; case "--privproto": $snmp_priv_protocol = trim($value); break; case "--privpass": $snmp_priv_passphrase = trim($value); break; case "--port": $snmp_port = $value; break; case "--timeout": $snmp_timeout = $value; break; case "--avail": switch($value) { case "none": $avail = '0'; /* tried to use AVAIL_NONE, but then ereg failes on validation, sigh */ break; case "ping": $avail = AVAIL_PING; break; case "snmp": $avail = AVAIL_SNMP; break; case "pingsnmp": $avail = AVAIL_SNMP_AND_PING; break; default: echo "ERROR: Invalid Availability Parameter: ($value)\n\n"; display_help(); exit(1); } break; case "--ping_method": switch(strtolower($value)) { case "icmp": $ping_method = PING_ICMP; break; case "tcp": $ping_method = PING_TCP; break; case "udp": $ping_method = PING_UDP; break; default: echo "ERROR: Invalid Ping Method: ($value)\n\n"; display_help(); exit(1); } break; case "--ping_port": if (is_numeric($value) && ($value > 0)) { $ping_port = $value; }else{ echo "ERROR: Invalid Ping Port: ($value)\n\n"; display_help(); exit(1); } break; case "--ping_retries": if (is_numeric($value) && ($value > 0)) { $ping_retries = $value; }else{ echo "ERROR: Invalid Ping Retries: ($value)\n\n"; display_help(); exit(1); } break; case "--max_oids": if (is_numeric($value) && ($value > 0)) { $max_oids = $value; }else{ echo "ERROR: Invalid Max OIDS: ($value)\n\n"; display_help(); exit(1); } break; case "--version": case "-V": case "-H": case "--help": display_help(); exit(0); case "--list-communities": $displayCommunities = TRUE; break; case "--list-host-templates": $displayHostTemplates = TRUE; break; case "--quiet": $quietMode = TRUE; break; default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help(); exit(1); } } if ($displayCommunities) { displayCommunities($quietMode); exit(0); } if ($displayHostTemplates) { displayHostTemplates(getHostTemplates(), $quietMode); exit(0); } /* process the various lists into validation arrays */ $host_templates = getHostTemplates(); $hosts = getHostsByDescription(); $addresses = getAddresses(); /* process templates */ if (!isset($host_templates[$template_id])) { echo "ERROR: Unknown template id ($template_id)\n"; exit(1); } /* process host description */ if (isset($hosts[$description])) { db_execute("update host set hostname='$ip' where id=" . $hosts[$description]); echo "This host already exists in the database ($description) device-id: (" . $hosts[$description] . ")\n"; exit(1); } if ($description == "") { echo "ERROR: You must supply a description for all hosts!\n"; exit(1); } /* process ip */ if (isset($addresses[$ip])) { db_execute("update host set description = '$description' where id = " . $addresses[$ip]); echo "ERROR: This IP already exists in the database ($ip) device-id: (" . $addresses[$ip] . ")\n"; exit(1); } if ($ip == "") { echo "ERROR: You must supply an IP address for all hosts!\n"; exit(1); } /* process snmp information */ if ($snmp_ver < 0 || $snmp_ver > 3) { echo "ERROR: Invalid snmp version ($snmp_ver)\n"; exit(1); }elseif ($snmp_ver > 0) { if ($snmp_port <= 1 || $snmp_port > 65534) { echo "ERROR: Invalid port. Valid values are from 1-65534\n"; exit(1); } if ($snmp_timeout <= 0 || $snmp_timeout > 20000) { echo "ERROR: Invalid timeout. Valid values are from 1 to 20000\n"; exit(1); } } /* community/user/password verification */ if ($snmp_ver < 3) { /* snmp community can be blank */ }else{ if ($snmp_username == "" || $snmp_password == "") { echo "ERROR: When using snmpv3 you must supply an username and password\n"; exit(1); } } /* validate the disable state */ if ($disable != 1 && $disable != 0) { echo "ERROR: Invalid disable flag ($disable)\n"; exit(1); } if ($disable == 0) { $disable = ""; }else{ $disable = "on"; } echo "Adding $description ($ip) as \"" . $host_templates[$template_id] . "\" using SNMP v$snmp_ver with community \"$community\"\n"; $host_id = api_device_save(0, $template_id, $description, $ip, $community, $snmp_ver, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disable, $avail, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, $device_threads); if (is_error_message()) { echo "ERROR: Failed to add this device\n"; exit(1); } else { echo "Success - new device-id: ($host_id)\n"; exit(0); } }else{ display_help(); exit(0); } function display_help() { echo "Add Device Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; echo "A simple command line utility to add a device in Cacti\n\n"; echo "usage: add_device.php --description=[description] --ip=[IP] --template=[ID] [--notes=\"[]\"] [--disable]\n"; echo " [--avail=[ping]] --ping_method=[icmp] --ping_port=[N/A, 1-65534] --ping_retries=[2]\n"; echo " [--version=[1|2|3]] [--community=] [--port=161] [--timeout=500]\n"; echo " [--username= --password=] [--authproto=] [--privpass= --privproto=] [--context=]\n"; echo " [--quiet]\n\n"; echo "Required:\n"; echo " --description the name that will be displayed by Cacti in the graphs\n"; echo " --ip self explanatory (can also be a FQDN)\n"; echo "Optional:\n"; echo " --template 0, is a number (read below to get a list of templates)\n"; echo " --notes '', General information about this host. Must be enclosed using double quotes.\n"; echo " --disable 0, 1 to add this host but to disable checks and 0 to enable it\n"; echo " --avail pingsnmp, [ping][none, snmp, pingsnmp]\n"; echo " --ping_method tcp, icmp|tcp|udp\n"; echo " --ping_port '', 1-65534\n"; echo " --ping_retries 2, the number of time to attempt to communicate with a host\n"; echo " --version 1, 1|2|3, snmp version\n"; echo " --community '', snmp community string for snmpv1 and snmpv2. Leave blank for no community\n"; echo " --port 161\n"; echo " --timeout 500\n"; echo " --username '', snmp username for snmpv3\n"; echo " --password '', snmp password for snmpv3\n"; echo " --authproto '', snmp authentication protocol for snmpv3\n"; echo " --privpass '', snmp privacy passphrase for snmpv3\n"; echo " --privproto '', snmp privacy protocol for snmpv3\n"; echo " --context '', snmp context for snmpv3\n"; echo " --max_oids 10, 1-60, the number of OID's that can be obtained in a single SNMP Get request\n\n"; echo "List Options:\n"; echo " --list-host-templates\n"; echo " --list-communities\n"; echo " --quiet - batch mode value return\n\n"; } ?> cacti-0.8.8f/cli/poller_graphs_reapply_names.php0000644000175000001440000001234612553175277021077 0ustar romanusersThis script is only meant to run at the command line."); } ini_set("max_execution_time", "0"); $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/api_graph.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); /* utility requires input parameters */ if (sizeof($parms) == 0) { print "ERROR: You must supply input parameters\n\n"; display_help(); exit; } $debug = FALSE; $host_id = ""; $filter = ""; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-id": $host_id = $value; break; case "-s": $filter = $value; break; case "-d": $debug = TRUE; break; case "-h": display_help(); exit; case "-v": display_help(); exit; case "--version": display_help(); exit; case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* form the 'where' clause for our main sql query */ if (strlen($filter)) { $sql_where = "AND (graph_templates_graph.title_cache like '%%" . $filter . "%%'" . " OR graph_templates.name like '%%" . $filter . "%%')"; }else{ $sql_where = ""; } if ($host_id == "All") { /* Act on all graphs */ }elseif (substr_count($host_id, "|")) { $hosts = explode("|", $host_id); $host_str = ""; foreach($hosts as $host) { if (strlen($host_str)) { $host_str .= ", '" . $host . "'"; }else{ $host_str .= "'" . $host . "'"; } } $sql_where .= " AND graph_local.host_id IN ($host_str)"; }elseif ($host_id == "0") { $sql_where .= " AND graph_local.host_id=0"; }elseif (!empty($host_id)) { $sql_where .= " AND graph_local.host_id=" . $host_id; }else{ print "ERROR: You must specify either a host_id or 'All' to proceed.\n"; display_help(); exit; } $graph_list = db_fetch_assoc("SELECT 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_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Interrupting during rename can cause issues\n"; debug("There are '" . sizeof($graph_list) . "' Graphs to rename"); $i = 1; foreach ($graph_list as $graph) { if (!$debug) print "."; debug("Graph Name '" . $graph["title_cache"] . "' starting"); api_reapply_suggested_graph_title($graph["local_graph_id"]); update_graph_title_cache($graph["local_graph_id"]); debug("Graph Rename Done for Graph '" . $graph["title_cache"] . "'"); $i++; } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Reapply Graph Names Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: poller_graphs_reapply_names.php -id=[host_id|All][host_id1|host_id2|...] [-s=[search_string] [-d] [-h] [--help] [-v] [--version]\n\n"; print "-id=host_id - The host_id or 'All' or a pipe delimited list of host_id's\n"; print "-s=search_str - A graph template name or graph title to search for\n"; print "-d - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/.htaccess0000644000175000001440000000004112553052754014363 0ustar romanusers Order deny,allow Deny from all cacti-0.8.8f/cli/data_template_associate_rra.php0000644000175000001440000001174212553175277021021 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } /* We are not talking to the browser */ $no_http_headers = true; include (dirname(__FILE__) . "/../include/global.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; $me = array_shift($parms); $debug = FALSE; # no debug mode $data_template_id = 0; $quietMode = false; $rra = ''; if (sizeof($parms)) { foreach ($parms as $parameter) { @ list ($arg, $value) = @ explode("=", $parameter); switch ($arg) { case "-d": case "--debug": $debug = TRUE; break; case "--rra": $rra = trim($value); break; case "--data-template-id" : $data_template_id = trim($value); break; case "-V": case "-H": case "--help": case "--version": display_help($me); exit(0); case "--quiet": $quietMode = TRUE; break; default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help($me); exit(1); } } $data_template = db_fetch_row("SELECT * from data_template WHERE id=$data_template_id"); if (sizeof($data_template)) { if (!$quietMode) print "Working on Data Template Id $data_template_id:" . $data_template["name"]."\n"; } else { print "ERROR: Invalid data template id given: $data_template_id\n"; exit(1); } $data_rra = explode(':', $rra); if (sizeof($data_rra)) { foreach ($data_rra as $rra_id) { $rra_curr = db_fetch_row("SELECT * FROM rra WHERE id=" . $rra_id); if (sizeof($rra_curr)) { if (!$quietMode) print "Working on RRA Id $rra_id:" . $rra_curr["name"].":".$rra_curr["x_files_factor"].":".$rra_curr["steps"].":".$rra_curr["rows"].":".$rra_curr["timespan"]."\n"; } else { print "ERROR: Invalid rra id given: $rra_id\n"; exit(1); } } associate($data_template["id"], $data_rra, $debug, $quietMode); } else { print "ERROR: Invalid rra definition given: $rra\n"; exit(1); } } else { display_help($me); exit (0); } function associate($data_template_id, $data_rra, $debug, $quiet) { /* get a list of data sources using this template * including the template itself */ $data_sources = db_fetch_assoc("SELECT data_template_data.id FROM data_template_data WHERE data_template_id=$data_template_id"); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { if (!$quiet) print "Working on data source id " . $data_source["id"] . "\n"; if ($debug) continue; /* make sure to update the 'data_template_data_rra' table for each data source */ db_execute("DELETE FROM data_template_data_rra WHERE data_template_data_id=" . $data_source["id"]); reset($data_rra); if (sizeof($data_rra) > 0) { foreach ($data_rra as $rra) { db_execute("INSERT INTO data_template_data_rra (data_template_data_id,rra_id) VALUES (" . $data_source["id"] . "," . $rra . ")"); } } } } return; } function display_help($me) { echo "Data Template Associate RRA Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; echo "A simple command line utility to associate RRA definitions to a data template in Cacti\n\n"; echo "usage: $me --rra='rra-1:..:rra-n' --data-template-id=[ID]\n"; echo "Required:\n"; echo " --rra the rra ids that shall be associated, seperated by colon\n"; echo " --data-template-id the data template id\n"; } ?> cacti-0.8.8f/cli/add_graphs.php0000644000175000001440000004446212553175277015417 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"]."/lib/api_automation_tools.php"); include_once($config["base_path"]."/lib/data_query.php"); include_once($config["base_path"]."/lib/utility.php"); include_once($config["base_path"]."/lib/sort.php"); include_once($config["base_path"]."/lib/template.php"); include_once($config["base_path"]."/lib/api_data_source.php"); include_once($config["base_path"]."/lib/api_graph.php"); include_once($config["base_path"]."/lib/snmp.php"); include_once($config["base_path"]."/lib/data_query.php"); include_once($config["base_path"]."/lib/api_device.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); if (sizeof($parms)) { /* setup defaults */ $graph_type = ""; $templateGraph = array(); $dsGraph = array(); $dsGraph["snmpFieldSpec"] = ""; $dsGraph["snmpQueryId"] = ""; $dsGraph["snmpQueryType"] = ""; $dsGraph["snmpField"] = ""; $dsGraph["snmpValue"] = ""; $dsGraph["reindex_method"] = DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME; $input_fields = array(); $values["cg"] = array(); $hosts = getHosts(); $graphTemplates = getGraphTemplates(); $graphTitle = ""; $cgInputFields = ""; $hostId = 0; $templateId = 0; $hostTemplateId = 0; $force = 0; $listHosts = FALSE; $listGraphTemplates = FALSE; $listSNMPFields = FALSE; $listSNMPValues = FALSE; $listQueryTypes = FALSE; $listSNMPQueries = FALSE; $listInputFields = FALSE; $quietMode = FALSE; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter, 2); switch($arg) { case "--graph-type": $graph_type = $value; break; case "--graph-title": $graphTitle = $value; break; case "--graph-template-id": $templateId = $value; break; case "--host-template-id": $hostTemplateId = $value; break; case "--host-id": $hostId = $value; break; case "--input-fields": $cgInputFields = $value; break; case "--snmp-query-id": $dsGraph["snmpQueryId"] = $value; break; case "--snmp-query-type-id": $dsGraph["snmpQueryType"] = $value; break; case "--snmp-field": $dsGraph["snmpField"] = $value; break; case "--snmp-value": $dsGraph["snmpValue"] = $value; break; case "--reindex-method": if (is_numeric($value) && ($value >= DATA_QUERY_AUTOINDEX_NONE) && ($value <= DATA_QUERY_AUTOINDEX_FIELD_VERIFICATION)) { $dsGraph["reindex_method"] = $value; } else { switch (strtolower($value)) { case "none": $dsGraph["reindex_method"] = DATA_QUERY_AUTOINDEX_NONE; break; case "uptime": $dsGraph["reindex_method"] = DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME; break; case "index": $dsGraph["reindex_method"] = DATA_QUERY_AUTOINDEX_INDEX_NUM_CHANGE; break; case "fields": $dsGraph["reindex_method"] = DATA_QUERY_AUTOINDEX_FIELD_VERIFICATION; break; default: echo "ERROR: You must supply a valid reindex method for this graph!\n"; exit(1); } } break; case "--list-hosts": $listHosts = TRUE; break; case "--list-snmp-fields": $listSNMPFields = TRUE; break; case "--list-snmp-values": $listSNMPValues = TRUE; break; case "--list-query-types": $listQueryTypes = TRUE; break; case "--list-snmp-queries": $listSNMPQueries = TRUE; break; case "--force": $force = TRUE; break; case "--quiet": $quietMode = TRUE; break; case "--list-input-fields": $listInputFields = TRUE; break; case "--list-graph-templates": $listGraphTemplates = TRUE; break; case "--version": case "-V": case "-H": case "--help": display_help(); exit(0); default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help(); exit(1); } } if ($listGraphTemplates) { /* is a Host Template Id is given, print the related Graph Templates */ if ($hostTemplateId > 0) { $graphTemplates = getGraphTemplatesByHostTemplate($hostTemplateId); if (!sizeof($graphTemplates)) { echo "ERROR: You must supply a valid --host-template-id before you can list its graph templates\n"; echo "Try --list-graph-template-id --host-template-id=[ID]\n"; exit(1); } } displayGraphTemplates($graphTemplates, $quietMode); exit(0); } if ($listInputFields) { if ($templateId > 0) { $input_fields = getInputFields($templateId, $quietMode); displayInputFields($input_fields, $quietMode); } else { echo "ERROR: You must supply an graph-template-id before you can list its input fields\n"; echo "Try --graph-template-id=[ID] --list-input-fields\n"; exit(1); } exit(0); } if ($listHosts) { displayHosts($hosts, $quietMode); exit(0); } /* get the existing snmp queries */ $snmpQueries = getSNMPQueries(); if ($listSNMPQueries) { displaySNMPQueries($snmpQueries, $quietMode); exit(0); } /* Some sanity checking... */ if ($dsGraph["snmpQueryId"] != "") { if (!isset($snmpQueries[$dsGraph["snmpQueryId"]])) { echo "ERROR: Unknown snmp-query-id (" . $dsGraph["snmpQueryId"] . ")\n"; echo "Try --list-snmp-queries\n"; exit(1); } /* get the snmp query types for comparison */ $snmp_query_types = getSNMPQueryTypes($dsGraph["snmpQueryId"]); if ($listQueryTypes) { displayQueryTypes($snmp_query_types, $quietMode); exit(0); } if ($dsGraph["snmpQueryType"] != "") { if (!isset($snmp_query_types[$dsGraph["snmpQueryType"]])) { echo "ERROR: Unknown snmp-query-type-id (" . $dsGraph["snmpQueryType"] . ")\n"; echo "Try --snmp-query-id=" . $dsGraph["snmpQueryId"] . " --list-query-types\n"; exit(1); } } if (!($listHosts || # you really want to create a new graph $listSNMPFields || # add this check to avoid reindexing on any list option $listSNMPValues || $listQueryTypes || $listSNMPQueries || $listInputFields)) { /* if data query is not yet associated, * add it and run it once to get the cache filled */ /* is this data query already associated (independent of the reindex method)? */ $exists_already = db_fetch_cell("SELECT COUNT(host_id) FROM host_snmp_query WHERE host_id=$hostId AND snmp_query_id=" . $dsGraph["snmpQueryId"]); if ((isset($exists_already)) && ($exists_already > 0)) { /* yes: do nothing, everything's fine */ }else{ db_execute("REPLACE INTO host_snmp_query (host_id,snmp_query_id,reindex_method) " . "VALUES (". $hostId . "," . $dsGraph["snmpQueryId"] . "," . $dsGraph["reindex_method"] . ")"); /* recache snmp data, this is time consuming, * but should happen only once even if multiple graphs * are added for the same data query * because we checked above, if dq was already associated */ run_data_query($hostId, $dsGraph["snmpQueryId"]); } } } /* Verify the host's existance */ if (!isset($hosts[$hostId]) || $hostId == 0) { echo "ERROR: Unknown Host ID ($hostId)\n"; echo "Try --list-hosts\n"; exit(1); } /* process the snmp fields */ $snmpFields = getSNMPFields($hostId, $dsGraph["snmpQueryId"]); if ($listSNMPFields) { displaySNMPFields($snmpFields, $hostId, $quietMode); exit(0); } $snmpValues = array(); /* More sanity checking */ if ($dsGraph["snmpField"] != "") { if (!isset($snmpFields[$dsGraph["snmpField"]])) { echo "ERROR: Unknown snmp-field " . $dsGraph["snmpField"] . " for host $hostId\n"; echo "Try --list-snmp-fields\n"; exit(1); } $snmpValues = getSNMPValues($hostId, $dsGraph["snmpField"], $dsGraph["snmpQueryId"]); if ($dsGraph["snmpValue"] != "") { if(!isset($snmpValues[$dsGraph["snmpValue"]])) { echo "ERROR: Unknown snmp-value for field " . $dsGraph["snmpField"] . " - " . $dsGraph["snmpValue"] . "\n"; echo "Try --snmp-field=" . $dsGraph["snmpField"] . " --list-snmp-values\n"; exit(1); } } } if ($listSNMPValues) { if ($dsGraph["snmpField"] == "") { echo "ERROR: You must supply an snmp-field before you can list its values\n"; echo "Try --list-snmp-fields\n"; exit(1); } displaySNMPValues($snmpValues, $hostId, $dsGraph["snmpField"], $quietMode); exit(0); } if (!isset($graphTemplates[$templateId])) { echo "ERROR: Unknown graph-template-id (" . $templateId . ")\n"; echo "Try --list-graph-templates\n"; exit(1); } if ((!isset($templateId)) || (!isset($hostId))) { echo "ERROR: Must have at least a host-id and a graph-template-id\n\n"; display_help(); exit(1); } if (strlen($cgInputFields)) { $fields = explode(" ", $cgInputFields); if ($templateId > 0) { $input_fields = getInputFields($templateId, $quietMode); } if (sizeof($fields)) { foreach ($fields as $option) { $data_template_id = 0; $option_value = explode("=", $option); if (substr_count($option_value[0], ":")) { $compound = explode(":", $option_value[0]); $data_template_id = $compound[0]; $field_name = $compound[1]; }else{ $field_name = $option_value[0]; } /* check for the input fields existance */ $field_found = FALSE; if (sizeof($input_fields)) { foreach ($input_fields as $key => $row) { if (substr_count($key, $field_name)) { if ($data_template_id == 0) { $data_template_id = $row["data_template_id"]; } $field_found = TRUE; break; } } } if (!$field_found) { echo "ERROR: Unknown input-field (" . $field_name . ")\n"; echo "Try --list-input-fields\n"; exit(1); } $value = $option_value[1]; $values["cg"][$templateId]["custom_data"][$data_template_id][$input_fields[$data_template_id . ":" . $field_name]["data_input_field_id"]] = $value; } } } $returnArray = array(); if ($graph_type == "cg") { $existsAlready = db_fetch_cell("SELECT id FROM graph_local WHERE graph_template_id=$templateId AND host_id=$hostId"); if ((isset($existsAlready)) && ($existsAlready > 0) && (!$force)) { $dataSourceId = db_fetch_cell("SELECT data_template_rrd.local_data_id FROM graph_templates_item, data_template_rrd WHERE graph_templates_item.local_graph_id = " . $existsAlready . " AND graph_templates_item.task_item_id = data_template_rrd.id LIMIT 1"); echo "NOTE: Not Adding Graph - this graph already exists - graph-id: ($existsAlready) - data-source-id: ($dataSourceId)\n"; exit(1); }else{ $returnArray = create_complete_graph_from_template($templateId, $hostId, "", $values["cg"]); $dataSourceId = ""; } if ($graphTitle != "") { db_execute("UPDATE graph_templates_graph SET title=\"$graphTitle\" WHERE local_graph_id=" . $returnArray["local_graph_id"]); update_graph_title_cache($returnArray["local_graph_id"]); } foreach($returnArray["local_data_id"] as $item) { push_out_host($hostId, $item); if (strlen($dataSourceId)) { $dataSourceId .= ", " . $item; }else{ $dataSourceId = $item; } } /* add this graph template to the list of associated graph templates for this host */ db_execute("replace into host_graph (host_id,graph_template_id) values (" . $hostId . "," . $templateId . ")"); echo "Graph Added - graph-id: (" . $returnArray["local_graph_id"] . ") - data-source-ids: ($dataSourceId)\n"; }elseif ($graph_type == "ds") { if (($dsGraph["snmpQueryId"] == "") || ($dsGraph["snmpQueryType"] == "") || ($dsGraph["snmpField"] == "") || ($dsGraph["snmpValue"] == "")) { echo "ERROR: For graph-type of 'ds' you must supply more options\n"; display_help(); exit(1); } $snmp_query_array = array(); $snmp_query_array["snmp_query_id"] = $dsGraph["snmpQueryId"]; $snmp_query_array["snmp_index_on"] = get_best_data_query_index_type($hostId, $dsGraph["snmpQueryId"]); $snmp_query_array["snmp_query_graph_id"] = $dsGraph["snmpQueryType"]; $snmp_indexes = db_fetch_assoc("SELECT snmp_index FROM host_snmp_cache WHERE host_id=" . $hostId . " AND snmp_query_id=" . $dsGraph["snmpQueryId"] . " AND field_name='" . $dsGraph["snmpField"] . "' AND field_value='" . $dsGraph["snmpValue"] . "'"); if (sizeof($snmp_indexes)) { foreach ($snmp_indexes as $snmp_index) { $snmp_query_array["snmp_index"] = $snmp_index["snmp_index"]; $existsAlready = db_fetch_cell("SELECT id FROM graph_local WHERE graph_template_id=$templateId AND host_id=$hostId AND snmp_query_id=" . $dsGraph["snmpQueryId"] . " AND snmp_index='" . $snmp_query_array["snmp_index"] . "'"); if (isset($existsAlready) && $existsAlready > 0) { if ($graphTitle != "") { db_execute("UPDATE graph_templates_graph SET title = \"$graphTitle\" WHERE local_graph_id = $existsAlready"); update_graph_title_cache($existsAlready); } $dataSourceId = db_fetch_cell("SELECT data_template_rrd.local_data_id FROM graph_templates_item, data_template_rrd WHERE graph_templates_item.local_graph_id = " . $existsAlready . " AND graph_templates_item.task_item_id = data_template_rrd.id LIMIT 1"); echo "NOTE: Not Adding Graph - this graph already exists - graph-id: ($existsAlready) - data-source-id: ($dataSourceId)\n"; continue; } $empty = array(); /* Suggested Values are not been implemented */ $returnArray = create_complete_graph_from_template($templateId, $hostId, $snmp_query_array, $empty); if ($graphTitle != "") { db_execute("UPDATE graph_templates_graph SET title=\"$graphTitle\" WHERE local_graph_id=" . $returnArray["local_graph_id"]); update_graph_title_cache($returnArray["local_graph_id"]); } $dataSourceId = db_fetch_cell("SELECT data_template_rrd.local_data_id FROM graph_templates_item, data_template_rrd WHERE graph_templates_item.local_graph_id = " . $returnArray["local_graph_id"] . " AND graph_templates_item.task_item_id = data_template_rrd.id LIMIT 1"); foreach($returnArray["local_data_id"] as $item) { push_out_host($hostId, $item); if (strlen($dataSourceId)) { $dataSourceId .= ", " . $item; }else{ $dataSourceId = $item; } } echo "Graph Added - graph-id: (" . $returnArray["local_graph_id"] . ") - data-source-ids: ($dataSourceId)\n"; } }else{ echo "ERROR: Could not find snmp-field " . $dsGraph["snmpField"] . " (" . $dsGraph["snmpValue"] . ") for host-id " . $hostId . " (" . $hosts[$hostId]["hostname"] . ")\n"; echo "Try --host-id=" . $hostId . " --list-snmp-fields\n"; exit(1); } }else{ echo "ERROR: Graph Types must be either 'cg' or 'ds'\n"; exit(1); } exit(0); }else{ display_help(); exit(1); } function display_help() { echo "Add Graphs Script 1.2, Copyright 2008 - The Cacti Group\n\n"; echo "A simple command line utility to add graphs in Cacti\n\n"; echo "usage: add_graphs.php --graph-type=[cg|ds] --graph-template-id=[ID]\n"; echo " --host-id=[ID] [--graph-title=title] [graph options] [--force] [--quiet]\n\n"; echo "For cg graphs:\n"; echo " [--input-fields=\"[data-template-id:]field-name=value ...\"] [--force]\n\n"; echo " --input-fields If your data template allows for custom input data, you may specify that\n"; echo " here. The data template id is optional and applies where two input fields\n"; echo " have the same name.\n"; echo " --force If you set this flag, then new cg graphs will be created, even though they\n"; echo " may already exist\n\n"; echo "For ds graphs:\n"; echo " --snmp-query-id=[ID] --snmp-query-type-id=[ID] --snmp-field=[SNMP Field] --snmp-value=[SNMP Value]\n\n"; echo " [--graph-title=] Defaults to what ever is in the graph template/data-source template.\n\n"; echo " [--reindex-method=] the reindex method to be used for that data query\n"; echo " if data query already exists, the reindex method will not be changed\n"; echo " 0|None = no reindexing\n"; echo " 1|Uptime = Uptime goes Backwards (Default)\n"; echo " 2|Index = Index Count Changed\n"; echo " 3|Fields = Verify all Fields\n"; echo "List Options:\n"; echo " --list-hosts\n"; echo " --list-graph-templates [--host-template-id=[ID]]\n"; echo " --list-input-fields --graph-template-id=[ID]\n"; echo " --list-snmp-queries\n"; echo " --list-query-types --snmp-query-id [ID]\n"; echo " --list-snmp-fields --host-id=[ID] [--snmp-query-id=[ID]]\n"; echo " --list-snmp-values --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Field]\n\n"; echo "'cg' graphs are for things like CPU temp/fan speed, while \n"; echo "'ds' graphs are for data-source based graphs (interface stats etc.)\n"; } ?> cacti-0.8.8f/cli/rebuild_poller_cache.php0000644000175000001440000001066412553175277017446 0ustar romanusersThis script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/utility.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); $debug = FALSE; $host_id = 0; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-d": case "--debug": $debug = TRUE; break; case "--host-id": $host_id = trim($value); if (!is_numeric($host_id)) { echo "ERROR: You must supply a valid host-id to run this script!\n"; exit(1); } break; case "-h": case "-v": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* obtain timeout settings */ $max_execution = ini_get("max_execution_time"); /* set new timeout */ ini_set("max_execution_time", "0"); /* get the data_local Id's for the poller cache */ if ($host_id > 0) { $poller_data = db_fetch_assoc("SELECT id FROM data_local WHERE host_id=$host_id"); } else { $poller_data = db_fetch_assoc("SELECT id FROM data_local"); } /* initialize some variables */ $current_ds = 1; $total_ds = sizeof($poller_data); /* setting local_data_ids to an empty array saves time during updates */ $local_data_ids = array(); $poller_items = array(); /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time\n"; debug("There are '" . sizeof($poller_data) . "' data source elements to update."); /* start rebuilding the poller cache */ if (sizeof($poller_data) > 0) { foreach ($poller_data as $data) { if (!$debug) print "."; $local_data_ids[] = $data["id"]; $poller_items = array_merge($poller_items, update_poller_cache($data["id"])); debug("Data Source Item '$current_ds' of '$total_ds' updated"); $current_ds++; } if (sizeof($local_data_ids)) { poller_update_poller_cache_from_buffer($local_data_ids, $poller_items); } } if (!$debug) print "\n"; /* poller cache rebuilt, restore runtime parameters */ ini_set("max_execution_time", $max_execution); /* display_help - displays the usage of the function */ function display_help () { print "Cacti Rebuild Poller Cache Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: rebuild_poller_cache.php [--host-id=ID] [-d | --debug] [-h | --help | -v | --version]\n\n"; print "-d | --debug - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/convert_innodb.php0000644000175000001440000001005312553175277016321 0ustar romanusersThis script is only meant to run at the command line."); } $no_http_headers = true; include("../include/global.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); global $debug; $debug = FALSE; $size = 300000; $rebuild = FALSE; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-d": case "--debug": $debug = TRUE; break; case "-r": case "--rebuild": $rebuild = TRUE; break; case "-s": case "--size": $size = $value; break; case "-h": case "-v": case "-V": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } echo "Converting All Non-Memory Cacti Database Tables to Innodb with Less than '$size' Records\n"; $engines = db_fetch_assoc("SHOW ENGINES"); foreach($engines as $engine) { if (strtolower($engine["Engine"]) == "innodb" && strtolower($engine["Support"] == "off")) { echo "InnoDB Engine is not enabled\n"; exit; } } $file_per_table = db_fetch_row("show global variables like 'innodb_file_per_table'"); if (strtolower($file_per_table["Value"]) != "on") { echo "innodb_file_per_table not enabled"; exit; } $tables = db_fetch_assoc("SHOW TABLE STATUS"); if (sizeof($tables)) { foreach($tables AS $table) { if ($table["Engine"] == "MyISAM" || ($table["Engine"] == "InnoDB" && $rebuild)) { if ($table["Rows"] < $size) { echo "Converting Table -> '" . $table['Name'] . "'"; $status = db_execute("ALTER TABLE " . $table['Name'] . " ENGINE=Innodb"); echo ($status == 0 ? " Failed" : " Successful") . "\n"; }else{ echo "Skipping Table -> '" . $table['Name'] . " too many rows '" . $table["Rows"] . "'\n"; } }else{ echo "Skipping Table ->'" . $table['Name'] . "\n"; } } } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Database Conversion Tool v1.0, Copyright 2010 - The Cacti Group\n\n"; print "usage: convert_innodb.php [-d] [-h] [--form] [--help] [-v] [-V] [--version]\n\n"; print "-d | --debug - Display verbose output during execution\n"; print "-s | --size=N - The largest table size in records to convert\n"; print "-v -V --version - Display this help message\n"; print "-h --help - display this help message\n"; } ?> cacti-0.8.8f/cli/poller_output_empty.php0000644000175000001440000000656412553175277017457 0ustar romanusersThis script is only meant to run at the command line."); } /* we are not talking to the browser */ $no_http_headers = true; /* start initialization section */ include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/poller.php"); include_once($config["base_path"] . "/lib/data_query.php"); include_once($config["base_path"] . "/lib/graph_export.php"); include_once($config["base_path"] . "/lib/rrd.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-h": display_help(); exit; case "-v": display_help(); exit; case "--version": display_help(); exit; case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* record the start time */ list($micro,$seconds) = explode(" ", microtime()); $start = $seconds + $micro; /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); $rrds_processed = 0; while (db_fetch_cell("SELECT count(*) FROM poller_output") > 0) { $rrds_processed = $rrds_processed + process_poller_output($rrdtool_pipe, FALSE); } echo "There were $rrds_processed, RRD updates made this pass\n"; rrd_close($rrdtool_pipe); /* display_help - displays the usage of the function */ function display_help () { print "Cacti Empty Poller Output Table Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: poller_output_empty.php [-h] [--help] [-v] [--version]\n\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } ?> cacti-0.8.8f/cli/poller_reindex_hosts.php0000644000175000001440000001311112553175277017541 0ustar romanusersThis script is only meant to run at the command line."); } ini_set("max_execution_time", "0"); $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/snmp.php"); include_once($config["base_path"] . "/lib/data_query.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); /* utility requires input parameters */ if (sizeof($parms) == 0) { print "ERROR: You must supply input parameters\n\n"; display_help(); exit; } $debug = FALSE; $host_id = ""; $query_id = "All"; /* just to mimic the old behaviour */ $host_descr = ""; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-id": case "--id": $host_id = $value; break; case "-qid": case "--qid": $query_id = $value; break; case "-host-descr": case "--host-descr": $host_descr = $value; break; case "-d": case "--debug": $debug = TRUE; break; case "-h": case "-v": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* determine the hosts to reindex */ if (strtolower($host_id) == "all") { $sql_where = ""; }else if (is_numeric($host_id)) { $sql_where = " WHERE host_id = '$host_id'"; }else{ print "ERROR: You must specify either a host_id or 'All' to proceed.\n"; display_help(); exit; } /* determine data queries to rerun */ if (strtolower($query_id) == "all") { /* do nothing */ }else if (is_numeric($query_id)) { $sql_where .= (strlen($sql_where) ? " AND snmp_query_id=$query_id": " WHERE snmp_query_id=$query_id"); }else{ print "ERROR: You must specify either a query_id or 'all' to proceed.\n"; display_help(); exit; } /* allow for additional filtering on host description */ if (strlen($host_descr)) { $sql_where .= (strlen($sql_where) ? " AND host.description like '%%" . $host_descr . "%%' AND host.id=host_snmp_query.host_id" : " WHERE host.description like '%%" . $host_descr . "%%' AND host.id=host_snmp_query.host_id"); $data_queries = db_fetch_assoc("SELECT host_id, snmp_query_id FROM host_snmp_query,host" . $sql_where); } else { $data_queries = db_fetch_assoc("SELECT host_id, snmp_query_id FROM host_snmp_query" . $sql_where); } /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Reindexing can take quite some time\n"; debug("There are '" . sizeof($data_queries) . "' data queries to run"); $i = 1; if (sizeof($data_queries)) { foreach ($data_queries as $data_query) { if (!$debug) print "."; debug("Data query number '" . $i . "' host: '".$data_query["host_id"]."' SNMP Query Id: '".$data_query["snmp_query_id"]."' starting"); run_data_query($data_query["host_id"], $data_query["snmp_query_id"]); debug("Data query number '" . $i . "' host: '".$data_query["host_id"]."' SNMP Query Id: '".$data_query["snmp_query_id"]."' ending"); $i++; } } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Reindex Host Script 1.2, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: poller_reindex_hosts.php --id=[host_id|All] [--qid=[ID|All]] [--host-descr=[description]]\n"; print " [-d] [-h] [--help] [-v] [--version]\n\n"; print "--id=host_id - The host_id to have data queries reindexed or 'All' to reindex all hosts\n"; print "--qid=query_id - Only index on a specific data query id; defaults to 'All'\n"; print "--host-descr=description - The host description to filter by (SQL filters acknowledged)\n"; print "--debug - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/import_template.php0000644000175000001440000001255512553175277016526 0ustar romanusersThis script is only meant to run at the command line."); } /* We are not talking to the browser */ $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"] . "/lib/import.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); if (sizeof($parms)) { $filename = ""; $import_custom_rra_settings = false; $rra_set = ""; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "--filename": $filename = trim($value); break; case "--with-template-rras": $import_custom_rra_settings = true; break; case "--with-user-rras": $rra_set = trim($value); break; default: echo "ERROR: Invalid Argument: ($arg)\n\n"; exit(1); } } if($rra_set != "") { if ($import_custom_rra_settings) { echo "ERROR: '--with-template-rras' given and '--with-user-rras' given. Ignoring '--with-user-rras'\n"; } else { $rra_array = explode(':', $rra_set); if (sizeof($rra_array)) { foreach ($rra_array as $key => $value) { $name = db_fetch_cell("SELECT name FROM rra WHERE id=" . intval($value)); if (strlen($name)) { echo "using RRA $name\n"; } else { echo "RRA id $value not found\n"; unset($rra_array[$key]); } } } } }else{ $rra_array = array(); if (!$import_custom_rra_settings) { echo "ERROR: neither '--with-template-rras' given nor '--with-user-rras' given. Exiting'\n"; return false; } } if($filename != "") { if(file_exists($filename) && is_readable($filename)) { $fp = fopen($filename,"r"); $xml_data = fread($fp,filesize($filename)); fclose($fp); echo "Read ".strlen($xml_data)." bytes of XML data\n"; $debug_data = import_xml_data($xml_data, $import_custom_rra_settings, $rra_array); while (list($type, $type_array) = each($debug_data)) { print "** " . $hash_type_names[$type] . "\n"; while (list($index, $vals) = each($type_array)) { if ($vals["result"] == "success") { $result_text = " [success]"; }else{ $result_text = " [fail]"; } if ($vals["type"] == "update") { $type_text = " [update]"; }else{ $type_text = " [new]"; } echo " $result_text " . $vals["title"] . " $type_text\n"; $dep_text = ""; $errors = false; if ((isset($vals["dep"])) && (sizeof($vals["dep"]) > 0)) { while (list($dep_hash, $dep_status) = each($vals["dep"])) { if ($dep_status == "met") { $dep_status_text = "Found Dependency: "; } else { $dep_status_text = "Unmet Dependency: "; $errors = true; } $dep_text .= " + $dep_status_text " . hash_to_friendly_name($dep_hash, true) . "\n"; } } /* dependency errors need to be reported */ if ($errors) { echo $dep_text; exit(-1); } } } } else { echo "ERROR: file $filename is not readable, or does not exist\n\n"; exit(1); } } else { echo "ERROR: no filename specified\n\n"; display_help(); exit(1); } } else { echo "ERROR: no parameters given\n\n"; display_help(); exit(1); } function display_help() { echo "Add Graphs Script 1.1, Copyright 2010 - The Cacti Group\n\n"; echo "A simple command line utility to import a Template into Cacti\n\n"; echo "usage: import_template.php --filename=[filename] [--with-template-rras] [--with-user-rras=[n[:m]...]]\n"; echo "Required:\n"; echo " --filename the name of the XML file to import\n"; echo "Optional:\n"; echo " --with-template-rras also import custom RRA definitions from the template\n"; echo " --with-user-rras use your own set of RRA like '1:2:3:4'\n"; } cacti-0.8.8f/cli/reorder_data_query.php0000644000175000001440000002111212553175277017166 0ustar romanusersThis script is only meant to run at the command line."); } ini_set("max_execution_time", "0"); $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/snmp.php"); include_once($config["base_path"] . "/lib/data_query.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); /* utility requires input parameters */ if (sizeof($parms) == 0) { print "ERROR: You must supply input parameters\n\n"; display_help(); exit; } $debug = FALSE; $host_id = "all"; $host_descr = ""; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-id": case "--id": $host_id = $value; break; case "-qid": case "--qid": $query_id = $value; break; case "-d": case "--debug": $debug = TRUE; break; case "-h": case "-v": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } $sql_where = "WHERE data_input_fields.type_code='output_type'"; /* determine the hosts to reindex */ if (strtolower($host_id) == "all") { /* NOP */ }else if (is_numeric($host_id)) { $sql_where .= (strlen($sql_where) ? " AND " : " WHERE " ) . "data_local.host_id = '$host_id'"; }else{ print "ERROR: You must specify either a host_id or 'All' to proceed.\n"; display_help(); exit; } /* determine data queries to rerun */ if (is_numeric($query_id)) { $sql_where .= (strlen($sql_where) ? " AND " : " WHERE " ) . "data_local.snmp_query_id='$query_id'"; }else{ print "ERROR: You must specify either a query_id or 'all' to proceed.\n"; display_help(); exit; } /* get all object that have to be scanned */ $data_queries = db_fetch_assoc("SELECT " . "`data_local`.`host_id`, " . "`data_local`.`snmp_query_id`, " . "`data_local`.`snmp_index`, " . "`data_template_data`.`local_data_id`, " . "`data_template_data`.`data_input_id`, " . "`data_input_data`.`data_template_data_id`, " . "`data_input_data`.`data_input_field_id`, " . "`data_input_data`.`value` " . "FROM data_local " . "LEFT JOIN data_template_data ON data_local.id=data_template_data.local_data_id " . "LEFT JOIN data_input_fields ON data_template_data.data_input_id = data_input_fields.data_input_id " . "LEFT JOIN data_input_data ON ( " . "data_template_data.id = data_input_data.data_template_data_id " . "AND data_input_fields.id = data_input_data.data_input_field_id " . ") " . $sql_where . " "); /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Reordering can take quite some time\n"; debug("There are '" . sizeof($data_queries) . "' data query index items to run"); $i = 1; if (sizeof($data_queries)) { foreach ($data_queries as $data_query) { if (!$debug) print "."; /* fetch current index_order from data_query XML definition and put it into host_snmp_query */ update_data_query_sort_cache($data_query["host_id"], $data_query["snmp_query_id"]); /* build array required for function call */ $data_query["snmp_index_on"] = get_best_data_query_index_type($data_query["host_id"], $data_query["snmp_query_id"]); /* as we request the output_type, "value" gives the snmp_query_graph_id */ $data_query["snmp_query_graph_id"] = $data_query["value"]; debug("Data Query #'" . $i . "' host: '" . $data_query["host_id"] . "' SNMP Query Id: '" . $data_query["snmp_query_id"] . "' Index: " . $data_query["snmp_index"] . "' Index On: " . $data_query["snmp_index_on"] ); update_snmp_index_order($data_query); $i++; } } /** * perform sql updates for all required tables for new index_sort_order * @arg array $snmp_query_array * $host_id * snmp_query_id * snmp_index_on * snmp_query_graph_id * snmp_index * $data_template_data_id * $local_data_id * * this code stems from lib/template.php, function create_complete_graph_from_template */ function update_snmp_index_order($data_query) { if (is_array($data_query)) { $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=" . $data_query["snmp_query_id"]), "type_code", "id"); $snmp_cache_value = db_fetch_cell("SELECT field_value " . "FROM host_snmp_cache " . "WHERE host_id='" . $data_query["host_id"] . "' " . "AND snmp_query_id='" . $data_query["snmp_query_id"] . "' " . "AND field_name='" . $data_query["snmp_index_on"] . "' " . "AND snmp_index='" . $data_query["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_query["data_template_data_id"] . ", '', '" . $data_query["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_query["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_query["data_template_data_id"] . ",'','" . $data_query["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($data_query["local_data_id"]); } } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Reorder Data Query Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: reorder_data_query.php --id=[host_id|All] [--qid=[query_id]]\n"; print " [-d] [-h] [--help] [-v] [--version]\n\n"; print "--id=host_id - The host_id to have data queries reindexed; defaults to 'All' to reindex all hosts\n"; print "--qid=query_id - Only index on a specific data query id\n"; print "--debug - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/add_perms.php0000644000175000001440000001533412553175277015255 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"]."/lib/api_automation_tools.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); if (sizeof($parms) == 0) { display_help(); exit(1); }else{ $userId = 0; /* TODO replace magic numbers by global constants, treat user_admin as well */ $itemTypes = array('graph' => 1, 'tree' => 2, 'host' => 3, 'graph_template' => 4); $itemType = 0; $itemId = 0; $hostId = 0; $quietMode = FALSE; $displayGroups = FALSE; $displayUsers = FALSE; $displayTrees = FALSE; $displayHosts = FALSE; $displayGraphs = FALSE; $displayGraphTemplates = FALSE; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "--user-id": $userId = $value; break; case "--item-type": /* TODO replace magic numbers by global constants, treat user_admin as well */ if ( ($value == "graph") || ($value == "tree") || ($value == "host") || ($value == "graph_template")) { $itemType = $itemTypes[$value]; }else{ echo "ERROR: Invalid Item Type: ($value)\n\n"; display_help(); exit(1); } break; case "--item-id": $itemId = $value; break; case "--host-id": $hostId = $value; break; case "--list-groups": $displayGroups = TRUE; break; case "--list-users": $displayUsers = TRUE; break; case "--list-trees": $displayTrees = TRUE; break; case "--list-hosts": $displayHosts = TRUE; break; case "--list-graphs": $displayGraphs = TRUE; break; case "--list-graph-templates": $displayGraphTemplates = TRUE; break; case "--quiet": $quietMode = TRUE; break; case "--version": case "-V": case "-H": case "--help": display_help(); exit(0); default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help(); exit(1); } } if ($displayGroups) { displayGroups($quietMode); exit(1); } if ($displayUsers) { displayUsers($quietMode); exit(1); } if ($displayTrees) { displayTrees($quietMode); exit(1); } if ($displayHosts) { $hosts = getHosts(); displayHosts($hosts, $quietMode); exit(1); } if ($displayGraphs) { if (!isset($hostId) || ($hostId === 0) || (!db_fetch_cell("SELECT id FROM host WHERE id=$hostId"))) { echo "ERROR: You must supply a valid host_id before you can list its graphs\n"; echo "Try --list-hosts\n"; display_help(); exit(1); } else { displayHostGraphs($hostId, $quietMode); exit(1); } } if ($displayGraphTemplates) { $graphTemplates = getGraphTemplates(); displayGraphTemplates($graphTemplates, $quietMode); exit(1); } /* verify, that a valid userid is provided */ $userIds = array(); if (isset($userId) && $userId > 0) { /* verify existing user id */ if ( db_fetch_cell("SELECT id FROM user_auth WHERE id=$userId") ) { array_push($userIds, $userId); } else { echo "ERROR: Invalid Userid: ($value)\n\n"; display_help(); exit(1); } } /* now, we should have at least one verified userid */ /* verify --item-id */ if ($itemType == 0) { echo "ERROR: --item-type missing. Please specify.\n\n"; display_help(); exit(1); } if ($itemId == 0) { echo "ERROR: --item-id missing. Please specify.\n\n"; display_help(); exit(1); } /* TODO replace magic numbers by global constants, treat user_admin as well */ switch ($itemType) { case 1: /* graph */ if ( !db_fetch_cell("SELECT local_graph_id FROM graph_templates_graph WHERE local_graph_id=$itemId") ) { echo "ERROR: Invalid Graph item id: ($itemId)\n\n"; display_help(); exit(1); } break; case 2: /* tree */ if ( !db_fetch_cell("SELECT id FROM graph_tree WHERE id=$itemId") ) { echo "ERROR: Invalid Tree item id: ($itemId)\n\n"; display_help(); exit(1); } break; case 3: /* host */ if ( !db_fetch_cell("SELECT id FROM host WHERE id=$itemId") ) { echo "ERROR: Invalid Host item id: ($itemId)\n\n"; display_help(); exit(1); } break; case 4: /* graph_template */ if ( !db_fetch_cell("SELECT id FROM graph_templates WHERE id=$itemId") ) { print "ERROR: Invalid Graph Template item id: ($itemId)\n\n"; display_help(); exit(1); } break; } /* verified item-id */ foreach ($userIds as $id) { db_execute("replace into user_auth_perms (user_id, item_id, type) values ($id, $itemId, $itemType)"); } } function display_help() { echo "Add Permissions Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; echo "A simple command line utility to add permissions to tree items in Cacti\n\n"; echo "usage: add_perms.php [ --user-id=[ID] ]\n"; echo " --item-type=[graph|tree|host|graph_template]\n"; echo " --item-id [--quiet]\n\n"; echo "Where item-id is the id of the object of type item-type\n"; echo "List Options:\n"; echo " --list-users\n"; echo " --list-trees\n"; echo " --list-graph-templates\n"; echo " --list-graphs --host-id=[ID]\n"; } ?> cacti-0.8.8f/cli/upgrade_database.php0000644000175000001440000001313312553175277016565 0ustar romanusersThis script is only meant to run at the command line.'); } /* allow the upgrade script to run for as long as it needs to */ ini_set('max_execution_time', '0'); include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"]."/lib/data_query.php"); include_once($config["base_path"]."/lib/utility.php"); /* UPDATE THIS FOR NEW VERSIONS!! */ $includes = array( '0.8' => '', '0.8.1' => '0_8_to_0_8_1.php', '0.8.2' => '0_8_1_to_0_8_2.php', '0.8.2a' => '0_8_2_to_0_8_2a.php', '0.8.3' => '0_8_2a_to_0_8_3.php', '0.8.3a' => '', '0.8.4' => '0_8_3_to_0_8_4.php', '0.8.5' => '0_8_4_to_0_8_5.php', '0.8.5a' => '', '0.8.6' => '0_8_5a_to_0_8_6.php', '0.8.6a' => '0_8_6_to_0_8_6a.php', '0.8.6b' => '', '0.8.6c' => '', '0.8.6d' => '0_8_6c_to_0_8_6d.php', '0.8.6e' => '0_8_6d_to_0_8_6e.php', '0.8.6f' => '', '0.8.6g' => '0_8_6f_to_0_8_6g.php', '0.8.6h' => '0_8_6g_to_0_8_6h.php', '0.8.6i' => '0_8_6h_to_0_8_6i.php', '0.8.6j' => '', '0.8.6k' => '', '0.8.7' => '0_8_6j_to_0_8_7.php', '0.8.7a' => '0_8_7_to_0_8_7a.php', '0.8.7b' => '0_8_7a_to_0_8_7b.php', '0.8.7c' => '0_8_7b_to_0_8_7c.php', '0.8.7d' => '0_8_7c_to_0_8_7d.php', '0.8.7e' => '0_8_7d_to_0_8_7e.php', '0.8.7f' => '0_8_7e_to_0_8_7f.php', '0.8.7g' => '0_8_7f_to_0_8_7g.php', '0.8.7h' => '0_8_7g_to_0_8_7h.php', '0.8.7i' => '0_8_7h_to_0_8_7i.php', '0.8.8' => '0_8_7i_to_0_8_8.php', '0.8.8a' => '0_8_8_to_0_8_8a.php', '0.8.8b' => '0_8_8a_to_0_8_8b.php', '0.8.8c' => '0_8_8b_to_0_8_8c.php', '0.8.8d' => '0_8_8c_to_0_8_8d.php', '0.8.8e' => '0_8_8d_to_0_8_8e.php', '0.8.8f' => '0_8_8e_to_0_8_8f.php', ); $old_cacti_version = db_fetch_cell('select cacti from version'); /* try to find current (old) version in the array */ $old_version_index = (isset($includes[$old_cacti_version]) ? $old_cacti_version : ''); /* do a version check */ if ($old_cacti_version == $config['cacti_version']) { print "Your Cacti is already up to date.\n"; exit; } else if ($old_cacti_version < 0.7) { print 'You are attempting to install cacti ' . $config['cacti_version'] . " onto a 0.6.x database.\nTo continue, you must create a new database, import 'cacti.sql' into it,\nand update 'include/config.php' to point to the new database.\n"; exit; } else if (empty($old_cacti_version)) { print "You have created a new database, but have not yet imported the 'cacti.sql' file.\n"; exit; } else if ($old_version_index == '') { print "Invalid Cacti version $old_cacti_version, cannot upgrade to " . $config['cacti_version'] . "\n"; exit; } /* loop from the old version to the current, performing updates for each version in between */ $start = FALSE; foreach ($includes as $v => $file) { if ($file != '' && $start) { print "Upgrading to " . $v . "\n"; include($config["base_path"] . '/install/' . $file); $func = "upgrade_to_" . str_replace('.', '_', $v); $func(); db_install_errors ($v); } if ($v == $config['cacti_version']) { break; } if ($old_cacti_version == $v) { $start = TRUE; } } /* it's always a good idea to re-populate the poller cache to make sure everything is refreshed and up-to-date */ repopulate_poller_cache(); db_execute("UPDATE version SET cacti = '" . $config['cacti_version'] . "'"); function db_install_errors ($cacti_version) { if (isset($_SESSION["sess_sql_install_cache"])) { foreach ($_SESSION["sess_sql_install_cache"] as $sc) { if (isset($sc[$cacti_version])) { foreach ($sc[$cacti_version] as $value => $sql) { if ($value == 0) { print " DB Error: $sql\n"; } } } } } } function db_install_execute($cacti_version, $sql) { $sql_install_cache = (isset($_SESSION["sess_sql_install_cache"]) ? $_SESSION["sess_sql_install_cache"] : array()); if (db_execute($sql)) { $sql_install_cache{sizeof($sql_install_cache)}[$cacti_version][1] = $sql; }else{ $sql_install_cache{sizeof($sql_install_cache)}[$cacti_version][0] = $sql; } $_SESSION["sess_sql_install_cache"] = $sql_install_cache; } cacti-0.8.8f/cli/add_tree.php0000644000175000001440000002323712553175277015067 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); include_once($config["base_path"]."/lib/api_automation_tools.php"); include_once($config["base_path"].'/lib/tree.php'); include_once($config["base_path"].'/lib/api_tree.php'); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); if (sizeof($parms)) { /* setup defaults */ $type = ''; # tree or node $name = ''; # Name of a tree or node $sortMethod = 'alpha'; # manual, alpha, natural, numeric $parentNode = 0; # When creating a node, the parent node of this node (or zero for root-node) $treeId = 0; # When creating a node, it has to go in a tree $nodeType = ''; # Should be 'header', 'graph' or 'host' when creating a node $graphId = 0; # The ID of the graph to add (gets added to parentNode) $rra_id = 1; # The rra_id for the graph to display: 1 = daily, 2 = weekly, 3 = monthly, 4 = yearly $sortMethods = array('manual' => 1, 'alpha' => 2, 'natural' => 4, 'numeric' => 3); $nodeTypes = array('header' => 1, 'graph' => 2, 'host' => 3); $hostId = 0; $hostGroupStyle = 1; # 1 = Graph Template, 2 = Data Query Index $quietMode = FALSE; $displayHosts = FALSE; $displayTrees = FALSE; $displayNodes = FALSE; $displayRRAs = FALSE; $displayGraphs = FALSE; $hosts = getHosts(); foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "--type": $type = trim($value); break; case "--name": $name = trim($value); break; case "--sort-method": $sortMethod = trim($value); break; case "--parent-node": $parentNode = $value; break; case "--tree-id": $treeId = $value; break; case "--node-type": $nodeType = trim($value); break; case "--graph-id": $graphId = $value; break; case "--rra-id": $rra_id = $value; break; case "--host-id": $hostId = $value; break; case "--quiet": $quietMode = TRUE; break; case "--list-hosts": $displayHosts = TRUE; break; case "--list-trees": $displayTrees = TRUE; break; case "--list-nodes": $displayNodes = TRUE; break; case "--list-rras": $displayRRAs = TRUE; break; case "--list-graphs": $displayGraphs = TRUE; break; case "--host-group-style": $hostGroupStyle = trim($value); break; case "--quiet": $quietMode = TRUE; break; case "--version": case "-V": case "-H": case "--help": display_help(); exit(0); default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help(); exit(1); } } if ($displayHosts) { displayHosts($hosts, $quietMode); exit(0); } if ($displayTrees) { displayTrees($quietMode); exit(0); } if ($displayNodes) { if (!isset($treeId)) { echo "ERROR: You must supply a tree_id before you can list its nodes\n"; echo "Try --list-trees\n"; exit(1); } displayTreeNodes($treeId, $nodeType, $parentNode, $quietMode); exit(0); } if ($displayRRAs) { displayRRAs($quietMode); exit(0); } if ($displayGraphs) { if (!isset($hostId) || $hostId == 0) { echo "ERROR: You must supply a host_id before you can list its graphs\n"; echo "Try --list-hosts\n"; exit(1); } displayHostGraphs($hostId, $quietMode); exit(0); } if ($type == 'tree') { # Add a new tree if (empty($name)) { echo "ERROR: You must supply a name with --name\n"; display_help(); exit(1); } $treeOpts = array(); $treeOpts["id"] = 0; # Zero means create a new one rather than save over an existing one $treeOpts["name"] = $name; if ($sortMethod == "manual"|| $sortMethod == "alpha" || $sortMethod == "numeric" || $sortMethod == "natural") { $treeOpts["sort_type"] = $sortMethods[$sortMethod]; } else { echo "ERROR: Invalid sort-method: ($sortMethod)\n"; display_help(); exit(1); } $existsAlready = db_fetch_cell("select id from graph_tree where name = '$name'"); if ($existsAlready) { echo "ERROR: Not adding tree - it already exists - tree-id: ($existsAlready)\n"; exit(1); } $treeId = sql_save($treeOpts, "graph_tree"); sort_tree(SORT_TYPE_TREE, $treeId, $treeOpts["sort_type"]); echo "Tree Created - tree-id: ($treeId)\n"; exit(0); } elseif ($type == 'node') { # Add a new node to a tree if ($nodeType == "header"|| $nodeType == "graph" || $nodeType == "host") { $itemType = $nodeTypes[$nodeType]; } else { echo "ERROR: Invalid node-type: ($nodeType)\n"; display_help(); exit(1); } if (!is_numeric($parentNode)) { echo "ERROR: parent-node $parentNode must be numeric > 0\n"; display_help(); exit(1); } elseif ($parentNode > 0 ) { $parentNodeExists = db_fetch_cell("SELECT id FROM graph_tree_items WHERE graph_tree_id=$treeId AND id=$parentNode"); if (!isset($parentNodeExists)) { echo "ERROR: parent-node $parentNode does not exist\n"; exit(1); } } if ($nodeType == 'header') { # Header --name must be given if (empty($name)) { echo "ERROR: You must supply a name with --name\n"; display_help(); exit(1); } # Blank out the graphId, rra_id, hostID and host_grouping_style fields $graphId = 0; $rra_id = 0; $hostId = 0; $hostGroupStyle = 1; }else if($nodeType == 'graph') { # Blank out name, hostID, host_grouping_style $name = ''; $hostId = 0; $hostGroupStyle = 1; # verify rra-id if (!is_numeric($rra_id)) { echo "ERROR: rra-id $rra_id must be numeric > 0\n"; display_help(); exit(1); } elseif ($rra_id > 0 ) { $rraExists = db_fetch_cell("SELECT id FROM rra WHERE id=$rra_id"); if (!isset($rraExists)) { echo "ERROR: rra-id $rra_id does not exist\n"; exit(1); } } $graphs = db_fetch_assoc("SELECT " . "id " . "FROM graph_local " . "WHERE graph_local.id=" . $graphId); if (!sizeof($graphs)) { echo "ERROR: No such graph-id ($graphId) exists. Try --list-graphs\n"; exit(1); } }else if ($nodeType == 'host') { # Blank out graphId, rra_id, name fields $graphId = 0; $rra_id = 0; $name = ''; if (!isset($hosts[$hostId])) { echo "ERROR: No such host-id ($hostId) exists. Try --list-hosts\n"; exit(1); } if ($hostGroupStyle != 1 && $hostGroupStyle != 2) { echo "ERROR: Host Group Style must be 1 or 2 (Graph Template or Data Query Index)\n"; display_help(); exit(1); } } # $nodeId could be a Header Node, a Graph Node, or a Host node. $nodeId = api_tree_item_save(0, $treeId, $itemType, $parentNode, $name, $graphId, $rra_id, $hostId, $hostGroupStyle, $sortMethods[$sortMethod], false); echo "Added Node node-id: ($nodeId)\n"; exit(0); } else { echo "ERROR: Unknown type: ($type)\n"; display_help(); exit(1); } } else { display_help(); exit(0); } function display_help() { echo "Add Tree Script 1.0, Copyright 2004-2015 - The Cacti Group\n\n"; echo "A simple command line utility to add objects to a tree in Cacti\n\n"; echo "usage: add_tree.php --type=[tree|node] [type-options] [--quiet]\n\n"; echo "Tree options:\n"; echo " --name=[Tree Name]\n"; echo " --sort-method=[manual|alpha|natural|numeric]\n\n"; echo "Node options:\n"; echo " --node-type=[header|host|graph]\n"; echo " --tree-id=[ID]\n"; echo " [--parent-node=[ID] [Node Type Options]]\n\n"; echo "Header node options:\n"; echo " --name=[Name]\n\n"; echo "Host node options:\n"; echo " --host-id=[ID]\n"; echo " [--host-group-style=[1|2]]\n"; echo " (host group styles:\n"; echo " 1 = Graph Template,\n"; echo " 2 = Data Query Index)\n\n"; echo "Graph node options:\n"; echo " --graph-id=[ID]\n"; echo " [--rra-id=[ID]]\n\n"; echo "List Options:\n"; echo " --list-hosts\n"; echo " --list-trees\n"; echo " --list-nodes --tree-id=[ID]\n"; echo " --list-rras\n"; echo " --list-graphs --host-id=[ID]\n"; } ?> cacti-0.8.8f/cli/host_update_template.php0000644000175000001440000001374412553175277017534 0ustar romanusersThis script is only meant to run at the command line."); } ini_set("max_execution_time", "0"); $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/snmp.php"); include_once($config["base_path"] . "/lib/data_query.php"); include_once($config["base_path"] . "/lib/api_automation_tools.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); /* utility requires input parameters */ if (sizeof($parms) == 0) { print "ERROR: You must supply input parameters\n\n"; display_help(); exit; } $debug = FALSE; $template = ""; $hostid = ""; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "--host-template": case "--host-template-id": $template = $value; break; case "--host-id": $host_id = $value; break; case "--list-host-templates": displayHostTemplates(getHostTemplates()); exit(0); case "-d": case "--debug": $debug = TRUE; break; case "-h": case "-v": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* determine the hosts to reindex */ if (strtolower($host_id) == "all") { $sql_where = ""; }else if (is_numeric($host_id)) { $sql_where = " WHERE id='$host_id'"; }else{ print "ERROR: You must specify either a host_id or 'all' to proceed.\n\n"; display_help(); exit; } /* determine data queries to rerun */ if (is_numeric($template)) { $sql_where .= (strlen($sql_where) ? " AND host_template_id=$template": "WHERE host_template_id=$template"); }else{ print "ERROR: You must specify a Host Template to proceed.\n\n"; display_help(); exit; } /* verify that the host template is accurate */ if (db_fetch_cell("SELECT id FROM host_template WHERE id=$template") > 0) { $hosts = db_fetch_assoc("SELECT * FROM host $sql_where"); if (sizeof($hosts)) { foreach($hosts as $host) { echo "NOTE: Updating Host '" . $host["description"] . "'\n"; $snmp_queries = db_fetch_assoc("SELECT snmp_query_id FROM host_template_snmp_query WHERE host_template_id=" . $host["host_template_id"]); if (sizeof($snmp_queries) > 0) { echo "NOTE: Updating Data Queries. There were '" . sizeof($snmp_queries) . "' Found\n"; foreach ($snmp_queries as $snmp_query) { echo "NOTE: Updating Data Query ID '" . $snmp_query["snmp_query_id"] . "'\n"; db_execute("REPLACE INTO host_snmp_query (host_id,snmp_query_id,reindex_method) VALUES (" . $host["id"] . ", " . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")"); /* recache snmp data */ run_data_query($host["id"], $snmp_query["snmp_query_id"]); } } $graph_templates = db_fetch_assoc("SELECT graph_template_id FROM host_template_graph WHERE host_template_id=" . $host["host_template_id"]); if (sizeof($graph_templates) > 0) { echo "NOTE: Updating Graph Templates. There were '" . sizeof($graph_templates) . "' Found\n"; foreach ($graph_templates as $graph_template) { db_execute("REPLACE INTO host_graph (host_id, graph_template_id) VALUES (" . $host["id"] . ", " . $graph_template["graph_template_id"] . ")"); api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host["id"], "graph_template_id" => $graph_template["graph_template_id"])); } } } } }else{ echo "ERROR: The selected Host Template does not exist, try --list-host-templates\n\n"; exit(1); } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Retemplate Host Script 1.0, Copyright 2004-2015 - The Cacti Group\n"; print "usage: host_update_template.php --host-id=[host-id|All] [--host-template=[ID]] [-d] [-h] [--help] [-v] [--version]\n\n"; print "--host-id=host_id - The host_id to have templates reapplied 'all' to do all hosts\n"; print "--host-template=ID - Which Host Template to Refresh\n\n"; print "Optional:\n"; print "-d --debug - Display verbose output during execution\n"; print "-v --version - Display this help message\n"; print "-h --help - Display this help message\n"; print "List Options:\n\n"; print "--list-host-templates - Lists all available Host Templates\n\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?> cacti-0.8.8f/cli/analyze_database.php0000644000175000001440000000645212553175277016607 0ustar romanusers#!/usr/bin/php -q This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); global $debug; $debug = FALSE; $form = ""; $start = time(); foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-d": case "--debug": $debug = TRUE; break; case "-v": case "-V": case "--version": case "--help": case "-h": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } echo "Analyzing All Cacti Database Tables\n"; $tables = db_fetch_assoc("SHOW TABLES FROM " . $database_default); if (sizeof($tables)) { foreach($tables AS $table) { echo "Analyzing Table -> '" . $table['Tables_in_' . $database_default] . "'"; $status = db_execute("ANALYZE TABLE " . $table['Tables_in_' . $database_default] . $form); echo ($status == 0 ? " Failed" : " Successful") . "\n"; } cacti_log("ANALYSIS STATS: Analyzing Cacti Tables Complete. Total time " . (time() - $start) . " seconds.", false, "SYSTEM"); } /* display_help - displays the usage of the function */ function display_help () { print "Cacti Database Analyze Tool v1.0, Copyright 2004-2015 - The Cacti Group\n\n"; print "usage: analyze_database.php [-d|--debug] [-h|--help|-v|-V|--version]\n\n"; print "-d | --debug - Display verbose output during execution\n"; print "-v -V --version - Display this help message\n"; print "-h --help - display this help message\n"; } ?> cacti-0.8.8f/cli/structure_rra_paths.php0000644000175000001440000002010412553175277017411 0ustar romanusersThis script is only meant to run at the command line."); } $no_http_headers = TRUE; $proceed = FALSE; include(dirname(__FILE__) . "/../include/global.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); $hostId = NULL; if (sizeof($parms)) { foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "--proceed": $proceed = TRUE; break; case "--version": case "-V": case "-H": case "--help": display_help(); exit(0); case "--hostId": $hostId = $value; break; default: echo "ERROR: Invalid Argument: ($arg)\n\n"; display_help(); exit(1); } } } if ($proceed == FALSE) { echo "\nFATAL: You Must Explicitally Instruct This Script to Proceed with the '--proceed' Option\n\n"; display_help(); exit -1; } /* check ownership of the current base path */ $base_rra_path = $config["rra_path"]; $owner_id = fileowner($base_rra_path); $group_id = filegroup($base_rra_path); /* turn off the poller */ disable_poller(); $poller_running = shell_exec("ps -ef | grep poller.php | wc -l"); if ($poller_running == "1") { /* turn on the poller */ enable_poller(); echo "FATAL: The Poller is Currently Running\n"; exit -4; } /* turn on extended paths from in the database */ set_config_option("extended_paths", "on"); /* fetch all DS having wrong path */ $data_sources = db_fetch_assoc("SELECT local_data_id, host_id, data_source_path, CONCAT('/', host_id, '/', local_data_id, '.rrd') AS new_data_source_path, REPLACE(data_source_path, '', '$base_rra_path') AS rrd_path, REPLACE(CONCAT('/', host_id, '/', local_data_id, '.rrd'), '', '$base_rra_path') AS new_rrd_path FROM data_template_data INNER JOIN data_local ON data_local.id=data_template_data.local_data_id INNER JOIN host ON host.id=data_local.host_id WHERE data_source_path != CONCAT('/', host_id, '/', local_data_id, '.rrd')" . ($hostId === NULL ? "" : " AND host_id=$hostId")); /* setup some counters */ $done_count = 0; $warn_count = 0; /* scan all data sources */ foreach ($data_sources as $info) { $new_base_path = "$base_rra_path" . "/" . $info["host_id"]; $new_rrd_path = $info["new_rrd_path"]; $old_rrd_path = $info["rrd_path"]; /* create one subfolder for every host */ if (!is_dir($new_base_path)) { /* see if we can create the dirctory for the new file */ if (mkdir($new_base_path, 0775)) { echo "NOTE: New Directory '$new_base_path' Created for RRD Files\n"; if ($config["cacti_server_os"] != "win32") { if (chown($new_base_path, $owner_id) && chgrp($new_base_path, $group_id)) { echo "NOTE: New Directory '$new_base_path' Permissions Set\n"; } else { /* turn on the poller */ enable_poller(); echo "FATAL: Could not Set Permissions for Directory '$new_base_path'\n"; exit -5; } } } else { /* turn on the poller */ enable_poller(); echo "FATAL: Could NOT Make New Directory '$new_base_path'\n"; exit -1; } } /* copy the file, update the database and remove the old file */ if (!file_exists($old_rrd_path)) { $warn_count++; echo "WARNING: Legacy RRA Path '$old_rrd_path' Does not exist, Skipping\n"; /* alter database */ update_database($info); } elseif (link($old_rrd_path, $new_rrd_path)) { $done_count++; echo "NOTE: HardLink Complete:'" . $old_rrd_path . "' -> '" . $new_rrd_path . "'\n"; if ($config["cacti_server_os"] != "win32") { if (chown($new_rrd_path, $owner_id) && chgrp($new_rrd_path, $group_id)) { echo "NOTE: Permissions set for '$new_rrd_path'\n"; }else{ /* turn on the poller */ enable_poller(); echo "FATAL: Could not Set Permissions for File '$new_rrd_path'\n"; exit -6; } } /* alter database */ update_database($info); if (unlink($old_rrd_path)) { echo "NOTE: Old File '$old_rrd_path' Removed\n"; } else { /* turn on the poller */ enable_poller(); echo "FATAL: Old File '$old_rrd_path' Could not be removed\n"; exit -2; } } else { /* turn on the poller */ enable_poller(); echo "FATAL: Could not Copy RRD File '$old_rrd_path' to '$new_rrd_path'\n"; exit -3; } } /* finally re-enable the poller */ enable_poller(); echo "NOTE: Process Complete, '$done_count' Completed, '$warn_count' Skipped\n"; /* update database */ function update_database($info) { /* upate table poller_item */ db_execute("UPDATE poller_item SET rrd_path = '" . $info["new_rrd_path"] . "' WHERE local_data_id=" . $info["local_data_id"]); /* update table data_template_data */ db_execute("UPDATE data_template_data SET data_source_path='" . $info["new_data_source_path"] . "' WHERE local_data_id=" . $info["local_data_id"]); echo "NOTE: Database Changes Complete for File '" . $info["new_rrd_path"] . "'\n"; } /* turn on the poller */ function enable_poller() { set_config_option('poller_enabled', 'on'); } /* turn off the poller */ function disable_poller() { set_config_option('poller_enabled', ''); } function display_help() { echo "Structured RRA Paths Utility, Copyright 2008-2015 - The Cacti Group\n\n"; echo "A simple command line utility that converts a Cacti system from using\n"; echo "legacy RRA paths to using structured RRA paths with the following\n"; echo "naming convention: /host_id/local_data_id.rrd\n\n"; echo "This utility is designed for very large Cacti systems.\n\n"; echo "On Linux OS, superuser is required to apply file ownership.\n\n"; echo "The utility follows the process below:\n"; echo " 1) Disables the Cacti Poller\n"; echo " 2) Checks for a Running Poller.\n\n"; echo "If it Finds a Running Poller, it will:\n"; echo " 1) Re-enable the Poller\n"; echo " 2) Exit\n\n"; echo "Else, it will:\n"; echo " 1) Enable Structured Paths in the Console (Settings->Paths)\n\n"; echo "Then, for Each File, it will:\n"; echo " 1) Create the Structured Path, if Necessary\n"; echo " 2) Copy the File to the Strucured Path Using the New Name\n"; echo " 3) Alter the two Database Tables Required\n"; echo " 4) Remove the Old File\n\n"; echo "Once all Files are Complete, it will\n"; echo " 1) Re-enable the Cacti Poller\n\n"; echo "If the utility encounters a problem along the way, it will:\n"; echo " 1) Re-enable the poller\n"; echo " 2) Exit\n\n"; echo "usage: structure_rra_paths.php --proceed [--help | -H | --version | -V] [--hostId=]\n\n"; } ?> cacti-0.8.8f/cli/copy_user.php0000644000175000001440000000577112553175277015333 0ustar romanusersThis script is only meant to run at the command line."); } if (empty($_SERVER["argv"][2])) { print "\nIt is highly recommended that you use the web interface to copy users as this script will only copy Local Cacti users.\n\n"; print "Syntax:\n php copy_cacti_user.php