"); $delimeter = substr($str_out,$delimeter+1,1); /* there are two ways to gather data within cacti. we either spawn a new process and get data from that or call an internal function and get data there. the second option is new (0.6.5) which allows things such as internal snmp support without the need to spawn any processes. */ if (mysql_result($sql_id, $i, "type") == "") { /* we ARE going to spawn a process */ while ($i_field < $rows_field) { $str = ereg_replace("<" . mysql_result($sql_id_field, $i_field, "dataname") . ">", mysql_result($sql_id_field, $i_field, "value"),$str); $i_field++; } $str = ereg_replace("", $path_cacti,$str); $str = ereg_replace("", $config["path_snmpget"]["value"],$str); $str = ereg_replace("", $config["path_php_binary"]["value"],$str); /* take output string and parse it on the delimiter */ $out_data_array = ParseDelimitedLine(`$str`,$delimeter); //print "\nDEBUG: CMD: " . `$str` . "\n"; }else{ /* we ARE NOT going to spawn a process */ switch (mysql_result($sql_id, $i, "type")) { case 'snmp': include_once ("include/snmp_functions.php"); $out_data_array = ParseDelimitedLine(internal_snmp_query(mysql_result($sql_id, $i, "id"), mysql_result($sql_id, $i, "srcid"), "snmp"), $delimeter); break; case 'snmp_net': include_once ("include/snmp_functions.php"); $out_data_array = ParseDelimitedLine(internal_snmp_query(mysql_result($sql_id, $i, "id"), mysql_result($sql_id, $i, "srcid"), "snmp_net"), $delimeter); break; } } /* find out if this DS has multiple outputs */ $sql_id_multi = mysql_query("select id from rrd_ds where subdsid=" . mysql_result($sql_id, $i, "id"), $cnn_id); if (mysql_num_rows($sql_id_multi) == 0) { $multi_data_source = false; }else{ $multi_data_source = true; } /* make the output string */ $out_array = ParseDelimitedLine($str_out, $delimeter); $o = 0; while ($o < count($out_array)) { if (mysql_result($sql_id, $i, "srcid") == 0) { LogData("ERROR: Data Source: '" . mysql_result($sql_id, $i, "name") . "' does not " . "have a data input source assigned to it. No data will be gathered; if cacti " . "does not gather data for this data source please deactivate it."); }else{ /* remove all < and > characters from the output array */ $out_array[$o] = ereg_replace("[<]|[>]", "" ,$out_array[$o]); /* UPDATE: in previous versions, we would parse the output string to see what output vars are in use. This is sort of hacked, since it has the potential to break. Instead we are going to get the same data from the database, plus this saves us having to call ParseDelimitedLine() one extra time */ if ($multi_data_source == true) { $sql_id_fields = mysql_query("select f.id, d.id as dsid from src_fields f left join rrd_ds d on f.id=d.subfieldid where f.dataname=\"$out_array[$o]\" and f.srcid=" . mysql_result($sql_id, $i, "srcid") . " and d.subdsid=" . mysql_result($sql_id, $i, "id") . " and f.inputoutput=\"out\"", $cnn_id); }else{ $sql_id_fields = mysql_query("select id from src_fields where dataname=\"$out_array[$o]\" and srcid=" . mysql_result($sql_id, $i, "srcid") . " and inputoutput=\"out\"", $cnn_id); } /* get the current data source id depending on whether this is a multi-ds or not */ if ($multi_data_source == true) { $current_data_source_id = mysql_result($sql_id_fields, 0, "dsid"); }else{ $current_data_source_id = mysql_result($sql_id, $i, "id"); } //print "DEBUG: DS: $current_data_source_id, FIELD: $out_array[$o]=$out_data_array[$o]\n"; $sql_id_data = mysql_query("select id from src_data where fieldid=" . mysql_result($sql_id_fields, 0, "id") . " and dsid=$current_data_source_id",$cnn_id); if (mysql_num_rows($sql_id_data) == 0) { $new_data_id = 0; }else{ $new_data_id = mysql_result($sql_id_data, 0, "id"); } $sql_id_field_save = mysql_query("replace into src_data (id,fieldid,dsid,value) values($new_data_id," . mysql_result($sql_id_fields, 0, "id") . ", $current_data_source_id,\"$out_data_array[$o]\")",$cnn_id); } $o++; } /* call cacti's functions; no not print source */ rrdtool_function_create(mysql_result($sql_id, $i, "id"), false); /* only update data if we are gathering data for this data source */ if (mysql_result($sql_id, $i, "srcid") != 0) { rrdtool_function_update(mysql_result($sql_id, $i, "id"), $multi_data_source, false); } $i++; } /* dump static images/html file if user wants it */ if ($config["path_html_export"]["value"] != "") { if ($config["path_html_export_skip"]["value"] == "1") { include("export.php"); }else{ if ($config["path_html_export_skip"]["value"] == $config["path_html_export_ctr"]["value"]) { mysql_query("update settings set value=1 where name=\"path_html_export_ctr\"", $cnn_id); include("export.php"); }else{ if ($config["path_html_export_ctr"]["value"] == "") { mysql_query("update settings set value=1 where name=\"path_html_export_ctr\"", $cnn_id); }else{ mysql_query("update settings set value=" . ($config["path_html_export_ctr"]["value"] + 1) . " where name=\"path_html_export_ctr\"", $cnn_id); } } } } ?>