", $config["base_path"], $xml_file_path); if (!file_exists($xml_file_path)) { debug_log_insert("data_query", "Could not find data query XML file at '$xml_file_path'"); return false; } debug_log_insert("data_query", "Found data query XML file at '$xml_file_path'"); $data = implode("",file($xml_file_path)); return xml2array($data); } function query_script_host($host_id, $snmp_query_id) { $script_queries = get_data_query_array($snmp_query_id); if ($script_queries == false) { debug_log_insert("data_query", "Error parsing XML file into an array."); return false; } debug_log_insert("data_query", "XML file parsed ok."); /* get a complete path for out target script */ $script_path = substitute_data_query_path($script_queries["script_path"]); /* get any extra arguments that need to be passed to the script */ if (!empty($script_queries["arg_prepend"])) { $extra_arguments = substitute_host_data($script_queries["arg_prepend"], "|", "|", $host_id); }else{ $extra_arguments = ""; } /* fetch specified index at specified OID */ $script_index_array = exec_into_array("$script_path $extra_arguments " . $script_queries["arg_index"]); debug_log_insert("data_query", "Executing script for list of indexes '$script_path $extra_arguments " . $script_queries["arg_index"] . "'"); db_execute("delete from host_snmp_cache where host_id=$host_id and snmp_query_id=$snmp_query_id"); while (list($field_name, $field_array) = each($script_queries["fields"])) { if ($field_array["direction"] == "input") { $script_data_array = exec_into_array("$script_path $extra_arguments " . $script_queries["arg_query"] . " " . $field_array["query_name"]); debug_log_insert("data_query", "Executing script query '$script_path $extra_arguments " . $script_queries["arg_query"] . " " . $field_array["query_name"] . "'"); for ($i=0;($i ifIndex [index_value] => 3 [output_type] => 13 ) */ function data_query_field_list($data_template_data_id) { $field = db_fetch_assoc("select data_input_fields.type_code, data_input_data.value from data_input_fields,data_input_data where data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=$data_template_data_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')"); $field = array_rekey($field, "type_code", "value"); if ((!isset($field["index_type"])) || (!isset($field["index_value"])) || (!isset($field["output_type"]))) { return 0; }else{ return $field; } } /* encode_data_query_index - encodes a data query index value so that it can be included inside of a form @arg $index - the index name to encode @returns - the encoded data query index */ function encode_data_query_index($index) { return md5($index); } /* encode_data_query_index - decodes a data query index value so that it can be read from a form @arg $encoded_index - the index that was encoded with encode_data_query_index() @arg $data_query_id - the id of the data query that this index belongs to @arg $encoded_index - the id of the host that this index belongs to @returns - the decoded data query index */ function decode_data_query_index($encoded_index, $data_query_id, $host_id) { /* yes, i know MySQL has a MD5() function that would make this a bit quicker. however i would like to keep things abstracted for now so Cacti works with ADODB fully when i get around to porting my db calls */ $indexes = db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=$host_id and snmp_query_id=$data_query_id group by snmp_index"); if (sizeof($indexes) > 0) { foreach ($indexes as $index) { if (encode_data_query_index($index["snmp_index"]) == $encoded_index) { return $index["snmp_index"]; } } } } ?>