Ejemplo n.º 1
0
function thold_build_cdef($id, $value, $rra, $ds)
{
    $oldvalue = $value;
    $cdefs = db_fetch_assoc("select * from cdef_items where cdef_id = {$id} order by sequence");
    if (sizeof($cdefs)) {
        foreach ($cdefs as $cdef) {
            if ($cdef['type'] == 4) {
                $cdef['type'] = 6;
                switch ($cdef['value']) {
                    case 'CURRENT_DATA_SOURCE':
                        $cdef['value'] = $oldvalue;
                        // get_current_value($rra, $ds, 0);
                        break;
                    case 'CURRENT_GRAPH_MAXIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'upper_limit', 0);
                        break;
                    case 'CURRENT_GRAPH_MINIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'lower_limit', 0);
                        break;
                    case 'CURRENT_DS_MINIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'rrd_minimum', 0);
                        break;
                    case 'CURRENT_DS_MAXIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'rrd_maximum', 0);
                        break;
                    case 'VALUE_OF_HDD_TOTAL':
                        $cdef['value'] = get_current_value($rra, 'hdd_total', 0);
                        break;
                    case 'ALL_DATA_SOURCES_NODUPS':
                        // you can't have DUPs in a single data source, really...
                    // you can't have DUPs in a single data source, really...
                    case 'ALL_DATA_SOURCES_DUPS':
                        $cdef['value'] = 0;
                        $all_dsns = array();
                        $all_dsns = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE local_data_id = {$rra}");
                        if (is_array($all_dsns)) {
                            foreach ($all_dsns as $dsn) {
                                $cdef['value'] += get_current_value($rra, $dsn['data_source_name'], 0);
                            }
                        }
                        break;
                    default:
                        print 'CDEF property not implemented yet: ' . $cdef['value'];
                        return $oldvalue;
                        break;
                }
            } elseif ($cdef['type'] == 6) {
                $regresult = preg_match('/^\\|query_(.*)\\|$/', $cdef['value'], $matches);
                if ($regresult > 0) {
                    // Grab result for query
                    $cdef['value'] = db_fetch_cell("SELECT `h`.`field_value`\r\n\t\t\t\t\tFROM `poller_item` p, `host_snmp_cache` h\r\n\t\t\t\t\tWHERE `p`.`local_data_id` = '" . $rra . "'\r\n\t\t\t\t\tAND `p`.`host_id` = `h`.`host_id`\r\n\t\t\t\t\tAND `h`.`field_name` = '" . $matches[1] . "'\r\n\t\t\t\t\tAND `p`.`rrd_name` = 'traffic_in'\r\n\t\t\t\t\tAND SUBSTRING_INDEX(`p`.`arg1`, '.', -1 ) = `h`.`snmp_index`", FALSE);
                }
            }
            $cdef_array[] = $cdef;
        }
    }
    $x = count($cdef_array);
    if ($x == 0) {
        return $oldvalue;
    }
    $stack = array();
    // operation stack for RPN
    array_push($stack, $cdef_array[0]);
    // first one always goes on
    $cursor = 1;
    // current pointer through RPN operations list
    while ($cursor < $x) {
        $type = $cdef_array[$cursor]['type'];
        switch ($type) {
            case 6:
                array_push($stack, $cdef_array[$cursor]);
                break;
            case 2:
                // this is a binary operation. pop two values, and then use them.
                $v1 = thold_expression_rpn_pop($stack);
                $v2 = thold_expression_rpn_pop($stack);
                $result = thold_rpn($v2['value'], $v1['value'], $cdef_array[$cursor]['value']);
                // put the result back on the stack.
                array_push($stack, array('type' => 6, 'value' => $result));
                break;
            default:
                print 'Unknown RPN type: ';
                print $cdef_array[$cursor]['type'];
                return $oldvalue;
                break;
        }
        $cursor++;
    }
    return $stack[0]['value'];
}
Ejemplo n.º 2
0
function thold_build_cdef(&$cdefs, $value, $rra, $ds)
{
    $oldvalue = $value;
    if (sizeof($cdefs)) {
        foreach ($cdefs as $cdef) {
            if ($cdef['type'] == 4) {
                $cdef['type'] = 6;
                switch ($cdef['value']) {
                    case 'CURRENT_DATA_SOURCE':
                        $cdef['value'] = $oldvalue;
                        // get_current_value($rra, $ds, 0);
                        break;
                    case 'CURRENT_GRAPH_MAXIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'upper_limit', 0);
                        break;
                    case 'CURRENT_GRAPH_MINIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'lower_limit', 0);
                        break;
                    case 'CURRENT_DS_MINIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'rrd_minimum', 0);
                        break;
                    case 'CURRENT_DS_MAXIMUM_VALUE':
                        $cdef['value'] = get_current_value($rra, 'rrd_maximum', 0);
                        break;
                    case 'VALUE_OF_HDD_TOTAL':
                        $cdef['value'] = get_current_value($rra, 'hdd_total', 0);
                        break;
                    case 'ALL_DATA_SOURCES_NODUPS':
                        // you can't have DUPs in a single data source, really...
                    // you can't have DUPs in a single data source, really...
                    case 'ALL_DATA_SOURCES_DUPS':
                        $cdef['value'] = 0;
                        $all_dsns = array();
                        $all_dsns = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE local_data_id = {$rra}");
                        if (is_array($all_dsns)) {
                            foreach ($all_dsns as $dsn) {
                                $cdef['value'] += get_current_value($rra, $dsn['data_source_name'], 0);
                            }
                        }
                        break;
                    default:
                        print 'CDEF property not implemented yet: ' . $cdef['value'];
                        return $oldvalue;
                        break;
                }
            } elseif ($cdef['type'] == 6) {
                $regresult = preg_match('/^\\|query_([A-Za-z0-9_]+)\\|$/', $cdef['value'], $matches);
                if ($regresult > 0) {
                    $sql_query = "SELECT host_snmp_cache.field_value\n\t\t\t\t\tFROM data_local \n\t\t\t\t\tINNER JOIN host_snmp_cache \n\t\t\t\t\tON host_snmp_cache.host_id = data_local.host_id\n\t\t\t\t\tAND host_snmp_cache.snmp_query_id = data_local.snmp_query_id\n\t\t\t\t\tAND host_snmp_cache.snmp_index = data_local.snmp_index\n\t\t\t\t\tWHERE data_local.id = {$rra} AND host_snmp_cache.field_name = '" . $matches[1] . "'";
                    $cdef['value'] = db_fetch_cell($sql_query);
                }
            }
            $cdef_array[] = $cdef;
        }
    }
    $x = count($cdef_array);
    if ($x == 0) {
        return $oldvalue;
    }
    $stack = array();
    // operation stack for RPN
    array_push($stack, $cdef_array[0]);
    // first one always goes on
    $cursor = 1;
    // current pointer through RPN operations list
    while ($cursor < $x) {
        $type = $cdef_array[$cursor]['type'];
        switch ($type) {
            case 6:
                array_push($stack, $cdef_array[$cursor]);
                break;
            case 2:
                // this is a binary operation. pop two values, and then use them.
                $v1 = thold_expression_rpn_pop($stack);
                $v2 = thold_expression_rpn_pop($stack);
                $result = thold_rpn($v2['value'], $v1['value'], $cdef_array[$cursor]['value']);
                // put the result back on the stack.
                array_push($stack, array('type' => 6, 'value' => $result));
                break;
            default:
                print 'Unknown RPN type: ';
                print $cdef_array[$cursor]['type'];
                return $oldvalue;
                break;
        }
        $cursor++;
    }
    return $stack[0]['value'];
}