Example #1
0
     $old_param = $port[$param] ? 1 : 0;
     $new_param = isset($vars[$param_id]) && $vars[$param_id] ? 1 : 0;
     if ($old_param != $new_param) {
         $update_array[$param] = $new_param;
     }
 }
 if (count($update_array)) {
     //r($update_array);
     dbUpdate($update_array, 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
     $updated = TRUE;
 }
 // Check custom ifSpeed
 $old_ifSpeed_bool = isset($port['ifSpeed_custom']);
 $new_ifSpeed_bool = isset($vars['ifSpeed_custom_bool_' . $port_id]);
 if ($new_ifSpeed_bool) {
     $vars['ifSpeed_custom_' . $port_id] = intval(unit_string_to_numeric($vars['ifSpeed_custom_' . $port_id], 1000));
     if ($vars['ifSpeed_custom_' . $port_id] <= 0) {
         // Wrong ifSpeed, skip
         print_warning("Passed incorrect value for port speed.");
         $old_ifSpeed_bool = $new_ifSpeed_bool = FALSE;
         // Skip change
     }
 }
 if ($old_ifSpeed_bool && $new_ifSpeed_bool) {
     // Both set, compare values
     if ($vars['ifSpeed_custom_' . $port_id] != $port['ifSpeed_custom']) {
         //r($vars['ifSpeed_custom_' . $port_id]); r($port['ifSpeed_custom']);
         set_entity_attrib('port', $port_id, 'ifSpeed_custom', $vars['ifSpeed_custom_' . $port_id]);
         $updated = TRUE;
     }
 } else {
Example #2
0
    echo '</td>';
}
echo '</tr></table>';
$graph_array = $vars;
$graph_array['height'] = "300";
$graph_array['width'] = $graph_width;
echo generate_box_close();
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'graphs' . generate_url($vars));
// Datetime Field
$form['row'][0]['timestamp'] = array('type' => 'datetime', 'grid' => 10, 'grid_xs' => 10, 'presets' => TRUE, 'min' => '2007-04-03 16:06:59', 'max' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d H:i:s', $vars['from']), 'to' => date('Y-m-d H:i:s', $vars['to']));
$search_grid = 2;
if ($type == "port") {
    if ($subtype == "bits") {
        $speed_list = array('auto' => 'Autoscale', 'speed' => 'Interface Speed (' . formatRates($port['ifSpeed'], 4, 4) . ')');
        foreach ($config['graphs']['ports_scale_list'] as $entry) {
            $speed = intval(unit_string_to_numeric($entry, 1000));
            $speed_list[$entry] = formatRates($speed, 4, 4);
        }
        $form['row'][0]['scale'] = array('type' => 'select', 'name' => 'Scale', 'grid' => 2, 'width' => '100%', 'value' => isset($vars['scale']) ? $vars['scale'] : $config['graphs']['ports_scale_default'], 'values' => $speed_list);
        //reduce timestamp element grid sizes
        $form['row'][0]['timestamp']['grid'] -= 2;
    }
    if (in_array($subtype, array('bits', 'percent', 'upkts', 'pktsize'))) {
        $form['row'][0]['style'] = array('type' => 'select', 'name' => 'Graph style', 'grid' => 2, 'width' => '100%', 'value' => isset($vars['style']) ? $vars['style'] : $config['graphs']['style'], 'values' => array('default' => 'Default', 'mrtg' => 'MRTG'));
        //reduce timestamp element grid sizes
        $form['row'][0]['timestamp']['grid'] -= 1;
        unset($form['row'][0]['timestamp']['grid_xs']);
        $search_grid = 1;
    }
}
// Update button
function test_condition($value_a, $condition, $value_b)
{
    $value_a = trim($value_a);
    $value_b = trim($value_b);
    switch ($condition) {
        case 'ge':
        case '>=':
            if ($value_a >= unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'le':
        case '<=':
            if ($value_a <= unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'gt':
        case 'greater':
        case '>':
            if ($value_a > unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'lt':
        case 'less':
        case '<':
            if ($value_a < unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'notequals':
        case 'isnot':
        case 'ne':
        case '!=':
            if ($value_a != unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'equals':
        case 'eq':
        case 'is':
        case '==':
        case '=':
            if ($value_a == unit_string_to_numeric($value_b)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'match':
            $value_b = str_replace('*', '.*', $value_b);
            $value_b = str_replace('?', '.', $value_b);
            if (preg_match('/^' . $value_b . '$/', $value_a)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'notmatch':
        case '!match':
            $value_b = str_replace('*', '.*', $value_b);
            $value_b = str_replace('?', '.', $value_b);
            if (preg_match('/^' . $value_b . '$/', $value_a)) {
                $alert = FALSE;
            } else {
                $alert = TRUE;
            }
            break;
        case 'regexp':
        case 'regex':
            if (preg_match('/' . $value_b . '/', $value_a)) {
                $alert = TRUE;
            } else {
                $alert = FALSE;
            }
            break;
        case 'notregexp':
        case 'notregex':
        case '!regexp':
        case '!regex':
            if (preg_match('/' . $value_b . '/', $value_a)) {
                $alert = FALSE;
            } else {
                $alert = TRUE;
            }
            break;
        default:
            $alert = FALSE;
            break;
    }
    return $alert;
}
Example #4
0
 /**
  * @dataProvider providerUnitStringToNumeric
  */
 public function testUnitStringToNumeric($value, $result)
 {
     $this->assertSame($result, unit_string_to_numeric($value));
 }
Example #5
0
    $device = device_by_id_cache($port['device_id']);
    $title = generate_device_link($device);
    $title .= " :: Port  <b>" . generate_port_link($port) . "</b>";
    $title_array = array();
    $title_array[] = array('text' => $device['hostname'], 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'])));
    $title_array[] = array('text' => 'Ports', 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'ports')));
    $title_array[] = array('text' => rewrite_ifname($port['port_label']), 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id'])));
    $graph_title = short_hostname($device['hostname']) . " :: " . strtolower(short_ifname($port['ifDescr'], NULL, FALSE));
    $rrd_filename = get_port_rrdfilename($port, NULL, TRUE);
    if ($vars['type'] == 'port_bits') {
        $scale = isset($vars['scale']) ? $vars['scale'] : $config['graphs']['ports_scale_default'];
        if ($scale != 'auto') {
            if ($scale == 'speed' && $port['ifSpeed'] > 0) {
                $scale_max = $port['ifSpeed'];
                if ($graph_style != 'mrtg') {
                    $scale_min = -1 * $scale_max;
                }
            } else {
                $scale = intval(unit_string_to_numeric($scale, 1000));
                if (is_numeric($scale) && $scale > 0) {
                    $scale_max = $scale;
                    if ($graph_style != 'mrtg') {
                        $scale_min = -1 * $scale_max;
                    }
                }
            }
            $scale_rigid = isset($config['graphs']['ports_scale_force']) && $config['graphs']['ports_scale_force'];
        }
    }
}
// EOF