function api_data_query_snmp_execute_field($host_id, $data_query_field_id) { require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php"); require_once(CACTI_BASE_PATH . "/lib/sys/snmp.php"); require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); /* fetch information about the data query field */ $data_query_field = api_data_query_field_get($data_query_field_id); /* fetch information about the associated device */ $device = api_device_get($host_id); debug_log_insert("data_query", "Walking OID '" . $data_query_field["source"] . "'"); /* walk the base snmp oid to get a raw list of values */ $snmp_output = cacti_snmp_walk( $device["hostname"], $device["snmp_community"], $data_query_field["source"], $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); /* make sure some data has been returned */ if (!$snmp_output) { debug_log_insert("data_query", _("No SNMP data returned when walking OID '" . $data_query_field["source"] . "'")); return false; } debug_log_insert("data_query", _("Parsing output using method type '" . $data_query_field["method_type"] . "'")); $values_array = array(); switch ($data_query_field["method_type"]) { /* use the values returned from the snmpwalk without modification */ case DATA_QUERY_FIELD_METHOD_VALUE: foreach ($snmp_output as $row) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $row["value"]); } break; /* apply a regular expression to the values returned from the snmpwalk */ case DATA_QUERY_FIELD_METHOD_VALUE_PARSE: foreach ($snmp_output as $row) { /* a match was found; grab the first hit */ if (ereg($data_query_field["method_value"], $row["value"], $matches)) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $matches[1]); /* no match was found. use an empty string */ }else{ $values_array{$row["oid"]} = array("value" => "", "value_parsed" => ""); } } break; /* use the last N octets of the oid for each value */ case DATA_QUERY_FIELD_METHOD_OID_OCTET: foreach ($snmp_output as $row) { $octets = explode(".", $row["oid"]); $_new_oid = ""; /* start at the sizeof(array)-Nth item, and move forward */ for ($i=$data_query_field["method_value"]; $i>0; $i--) { $_new_oid .= $octets{sizeof($octets)-$i} . ($i > 1 ? "." : ""); } $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $_new_oid); } break; /* apply a regular expression to the oid's returned from the snmpwalk */ case DATA_QUERY_FIELD_METHOD_OID_PARSE: foreach ($snmp_output as $row) { /* a match was found; grab the first hit */ if (ereg($data_query_field["method_value"], $row["oid"], $matches)) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $matches[1]); /* no match was found. use an empty string */ }else{ $values_array{$row["oid"]} = array("value" => "", "value_parsed" => ""); } } break; } return $values_array; }
function data_query_field_edit() { $_data_query_field_id = get_get_var_number("id"); $_data_query_id = get_get_var_number("data_query_id"); if (empty($_data_query_field_id)) { $header_label = "[new]"; $_field_type = get_get_var("field_type"); } else { $data_query_field = api_data_query_field_get($_data_query_field_id); $_field_type = $data_query_field["type"]; $header_label = "[edit: " . $data_query_field["name"] . "]"; } $data_query = api_data_query_get($_data_query_id); form_start("data_queries.php", "form_data_query"); html_start_box("<strong>" . _("Data Query Fields") . "</strong> {$header_label}"); _data_query_field_field__name("name", isset($data_query_field["name"]) ? $data_query_field["name"] : "", isset($data_query_field["id"]) ? $data_query_field["id"] : "0"); _data_query_field_field__name_desc("name_desc", isset($data_query_field["name_desc"]) ? $data_query_field["name_desc"] : "", isset($data_query_field["id"]) ? $data_query_field["id"] : "0"); if ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { _data_query_field_field__source_snmp("source", isset($data_query_field["source"]) ? $data_query_field["source"] : "", isset($data_query_field["id"]) ? $data_query_field["id"] : "0"); } else { if ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY || $data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { _data_query_field_field__source_script("source", isset($data_query_field["source"]) ? $data_query_field["source"] : "", isset($data_query_field["id"]) ? $data_query_field["id"] : "0"); } } if ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { _data_query_field_field__method(isset($data_query_field["method_type"]) ? $data_query_field["method_type"] : "", isset($data_query_field["method_value"]) ? $data_query_field["method_value"] : "", isset($data_query_field["id"]) ? $data_query_field["id"] : "0"); } html_end_box(); form_hidden_box("data_query_field_id", $_data_query_field_id); form_hidden_box("data_query_id", $_data_query_id); form_hidden_box("field_type", $_field_type); form_save_button("data_queries.php?action=edit&id={$_data_query_id}", "save_data_query_field"); }