1) {
$a_date = $a_parts[1];
}
$b_date = '99999999';
if (count($b_parts) > 1) {
$b_date = $b_parts[1];
}
// Invert the order, replace _'s with +'s to make them sort after .'s, prefix the date
// This makes cacti_stderr.log appear after cacti.log in date descending order with
// no date files first
return strcmp($b_date . '-' . str_replace('_','+',$b_parts[0]), $a_date . '-' . str_replace('_','+',$a_parts[0]));
}
function filter($clogAdmin, $selectedFile) {
global $page_refresh_interval, $log_tail_lines, $config;
?>
array('name' => 'DS', 'regex' => '( DS\[)([, \d]+)(\])', 'func' => 'clog_regex_datasource'),
2 => array('name' => 'DQ', 'regex' => '( DQ\[)([, \d]+)(\])', 'func' => 'clog_regex_dataquery'),
3 => array('name' => 'Device', 'regex' => '( Device\[)([, \d]+)(\])', 'func' => 'clog_regex_device'),
4 => array('name' => 'Poller', 'regex' => '( Poller\[)([, \d]+)(\])', 'func' => 'clog_regex_poller'),
5 => array('name' => 'RRA', 'regex' => "([_\/])(\d+)(\.rrd')", 'func' => 'clog_regex_rra'),
6 => array('name' => 'GT', 'regex' => '( GT\[)([, \d]+)(\])', 'func' => 'clog_regex_graphtemplates'),
7 => array('name' => 'Graph', 'regex' => '( Graph\[)([, \d]+)(\])', 'func' => 'clog_regex_graphs'),
8 => array('name' => 'Graphs', 'regex' => '( Graphs\[)([, \d]+)(\])', 'func' => 'clog_regex_graphs')
);
$regex_array = api_plugin_hook_function('clog_regex_array',$regex_array);
$regex_complete = '';
foreach ($regex_array as $regex_key => $regex_setting) {
$regex_complete .= (strlen($regex_complete)?')|(':'').$regex_setting['regex'];
}
$regex_complete = '~('.$regex_complete.')~';
$regex_array['complete'] = $regex_complete;
}
return $regex_array;
}
function clog_regex_parser($matches) {
$result = $matches[0];
$match = $matches[0];
$key_match = -1;
for ($index = 1; $index < cacti_sizeof($matches); $index++) {
if ($match == $matches[$index]) {
$key_match = $index;
break;
}
}
if ($key_match != -1) {
$key_setting = ($key_match - 1) / 4 + 1;
$regex_array = clog_get_regex_array();
if (cacti_sizeof($regex_array)) {
if (array_key_exists($key_setting, $regex_array)) {
$regex_setting = $regex_array[$key_setting];
$rekey_array = array();
for ($j = 0; $j < 4; $j++) {
$rekey_array[$j] = $matches[$key_match + $j];
}
if (function_exists($regex_setting['func'])) {
$result=call_user_func_array($regex_setting['func'],array($rekey_array));
} else {
$result=$match;
}
}
}
}
return $result;
}
function clog_regex_device($matches) {
global $config;
$result = $matches[0];
$dev_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($dev_ids)) {
$result = '';
$hosts = db_fetch_assoc_prepared('SELECT id, description
FROM host
WHERE id in (?)',
array(implode(',',$dev_ids)));
$hostDescriptions = array();
if (cacti_sizeof($hosts)) {
foreach ($hosts as $host) {
$hostDescriptions[$host['id']] = html_escape($host['description']);
}
}
foreach ($dev_ids as $host_id) {
$result .= $matches[1].'' . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:$host_id) . '' . $matches[3];
}
}
return $result;
}
function clog_regex_datasource($matches) {
global $config;
$result = $matches[0];
$ds_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($ds_ids)) {
$result = '';
$graph_rows = array_rekey(db_fetch_assoc_prepared('SELECT DISTINCT
gtg.local_graph_id AS id
FROM graph_templates_graph AS gtg
INNER JOIN graph_templates_item AS gti
ON gtg.local_graph_id=gti.local_graph_id
INNER JOIN data_template_rrd AS dtr
ON gti.task_item_id=dtr.id
WHERE gtg.local_graph_id>0
AND dtr.local_data_id iN (?)',
array($matches[2])),'id','id');
$graph_results = '';
if (cacti_sizeof($graph_rows)) {
$graph_ids = implode(',',$graph_rows);
$graph_array = array( 0 => '', 1 => ' Graphs[', 2 => $graph_ids, 3 => ']');
$graph_results = clog_regex_graphs($graph_array);
}
$result .= $matches[1];
$i = 0;
$ds_ids = array_unique($ds_ids);
$ds_titles = clog_get_datasource_titles($ds_ids);
if (!isset($ds_titles)) {
$ds_titles = array();
}
foreach($ds_ids as $ds_id) {
$ds_title = $ds_id;
if (array_key_exists($ds_id, $ds_titles)) {
$ds_title = $ds_titles[$ds_id];
}
$result .= ($i == 0 ? '':', ') . "" . $ds_title . '';
$i++;
}
$result .= $matches[3] . $graph_results;
}
return $result;
}
function clog_regex_poller($matches) {
global $config;
$result = $matches[0];
$poller_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($poller_ids)) {
$result = '';
$pollers = db_fetch_assoc_prepared('SELECT id, name
FROM poller
WHERE id in (?)',
array(implode(',',$poller_ids)));
$pollerDescriptions = array();
if (cacti_sizeof($pollers)) {
foreach ($pollers as $poller) {
$pollerDescriptions[$poller['id']] = html_escape($poller['name']);
}
}
foreach ($poller_ids as $poller_id) {
$result .= $matches[1].'' . (isset($pollerDescriptions[$poller_id]) ? $pollerDescriptions[$poller_id]:$poller_id) . '' . $matches[3];
}
}
return $result;
}
function clog_regex_dataquery($matches) {
global $config;
$result = $matches[0];
$query_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($query_ids)) {
$result = '';
$querys = db_fetch_assoc_prepared('SELECT id, name
FROM snmp_query
WHERE id in (?)',
array(implode(',',$query_ids)));
$queryDescriptions = array();
if (cacti_sizeof($querys)) {
foreach ($querys as $query) {
$queryDescriptions[$query['id']] = html_escape($query['name']);
}
}
foreach ($query_ids as $query_id) {
$result .= $matches[1].'' . (isset($queryDescriptions[$query_id]) ? $queryDescriptions[$query_id]:$query_id) . '' . $matches[3];
}
}
return $result;
}
function clog_regex_rra($matches) {
global $config;
$result = $matches[0];
$local_data_ids = $matches[2];
if (strlen($local_data_ids)) {
$datasource_array = array( 0 => '', 1 => ' DS[', 2 => $local_data_ids, 3 => ']');
$datasource_result = clog_regex_datasource($datasource_array);
if (strlen($datasource_result)) {
$result .= ' '. $datasource_result;
}
}
return $result;
}
function clog_regex_graphs($matches) {
global $config;
$result = $matches[0];
$query_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($query_ids)) {
$result = '';
$graph_add = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
$title = '';
$i = 0;
$querys = db_fetch_assoc_prepared('SELECT DISTINCT
gtg.local_graph_id AS id,
gtg.title_cache AS title
FROM graph_templates_graph AS gtg
INNER JOIN graph_templates_item AS gti
ON gtg.local_graph_id=gti.local_graph_id
INNER JOIN data_template_rrd AS dtr
ON gti.task_item_id=dtr.id
WHERE gtg.local_graph_id in (?)',
array(implode(',',$query_ids)));
$result .= $matches[1] . " 0 ? '%2C' : '') . $query_id;
$title .= ($title != '' ? ', ':'') . html_escape((isset($queryDescriptions[$query_id]) ? $queryDescriptions[$query_id]:$query_id));
$i++;
}
$result .= html_escape($graph_add) . '\'>' . $title . '' . $matches[3];
}
return $result;
}
function clog_regex_graphtemplates($matches) {
global $config;
$result = $matches[0];
$query_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($query_ids)) {
$result = '';
$querys = db_fetch_assoc_prepared('SELECT id, name
FROM graph_templates
WHERE id in (?)',
array(implode(',',$query_ids)));
$queryDescriptions = array();
if (cacti_sizeof($querys)) {
foreach ($querys as $query) {
$queryDescriptions[$query['id']] = html_escape($query['name']);
}
}
foreach ($query_ids as $query_id) {
$result .= $matches[1].'' . (isset($queryDescriptions[$query_id]) ? $queryDescriptions[$query_id]:$query_id) . '' . $matches[3];
}
}
return $result;
}