Exemplo n.º 1
0
 protected function drawSideValues()
 {
     $sides = array();
     if ($this->axisSideLeft) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     if ($this->axisSideRight) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     foreach ($sides as $axis) {
         $min = $this->minValue[$axis];
         $max = $this->maxValue[$axis];
         $hstr_count = $this->gridLinesCount;
         if ($this->column) {
             if (GRAPH_YAXIS_SIDE_LEFT == $axis) {
                 $shiftXLeft = $this->shiftXleft;
                 $str_pad = STR_PAD_LEFT;
             } else {
                 $shiftXLeft = $this->shiftXleft + $this->sizeX + $this->shiftXCaptionLeft + 2;
                 // +2 because of some mistake somewhere in calculations! FIX IT!
                 $str_pad = STR_PAD_RIGHT;
             }
             for ($i = 0; $i <= $hstr_count; $i++) {
                 $str = str_pad(convert_units($this->sizeY * $i / $hstr_count * ($max - $min) / $this->sizeY + $min, $this->units[$axis]), 14, ' ', $str_pad);
                 imagestring($this->im, 1, $shiftXLeft, $this->sizeY - $this->sizeY * $i / $hstr_count - 4 + $this->shiftY + $this->shiftYCaptionTop, $str, $this->getColor('Dark Red No Alpha'));
             }
         } else {
             if (in_array($this->type, array(GRAPH_TYPE_BAR, GRAPH_TYPE_BAR_STACKED))) {
                 if (GRAPH_YAXIS_SIDE_LEFT == $axis) {
                     $shiftYBottom = $this->shiftY + $this->shiftYCaptionTop - 2;
                     // -2 because of some mistake somewhere in calculations! FIX IT!
                     $str_pad = STR_PAD_RIGHT;
                 } else {
                     $shiftYBottom = $this->shiftY + $this->sizeY + $this->shiftYCaptionTop + $this->shiftYCaptionBottom;
                     $str_pad = STR_PAD_LEFT;
                 }
                 for ($i = 0; $i <= $hstr_count; $i++) {
                     $str = str_pad(convert_units($this->sizeX * $i / $hstr_count * ($max - $min) / $this->sizeX + $min, $this->units[$axis]), 14, ' ', $str_pad);
                     imagestringup($this->im, 1, $this->shiftXleft + ($this->sizeX * $i / $hstr_count - 4) + $this->shiftXCaptionLeft, $shiftYBottom, $str, $this->getColor('Dark Red No Alpha'));
                 }
             }
         }
     }
     if (!is_null($this->xLabel)) {
         imagestring($this->im, 2, $this->shiftXleft + $this->sizeX / 2 - 20, $this->fullSizeY - 14, $this->xLabel, $this->getColor('Black No Alpha'));
     }
     if (!is_null($this->yLabel)) {
         imagestringup($this->im, 2, 0, $this->shiftY + $this->sizeY / 2 + 20, $this->yLabel, $this->getColor('Black No Alpha'));
     }
 }
 protected function drawLegend()
 {
     $shiftY = $this->shiftY + $this->shiftYLegend;
     $max_host_len = 0;
     $max_name_len = 0;
     for ($i = 0; $i < $this->num; $i++) {
         if (zbx_strlen($this->items[$i]['host']) > $max_host_len) {
             $max_host_len = zbx_strlen($this->items[$i]['host']);
         }
         if (zbx_strlen($this->items[$i]['name']) > $max_name_len) {
             $max_name_len = zbx_strlen($this->items[$i]['name']);
         }
     }
     for ($i = 0; $i < $this->num; $i++) {
         $color = $this->getColor($this->items[$i]['color'], 0);
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         switch ($this->items[$i]['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fnc_name = 'min';
                 $datavalue = $data->min;
                 break;
             case CALC_FNC_MAX:
                 $fnc_name = 'max';
                 $datavalue = $data->max;
                 break;
             case CALC_FNC_LST:
                 $fnc_name = 'last';
                 $datavalue = $data->lst;
                 break;
             case CALC_FNC_AVG:
             default:
                 $fnc_name = 'avg';
                 $datavalue = $data->avg;
         }
         $proc = $datavalue * 100 / $this->sum;
         if (isset($data) && isset($datavalue)) {
             $strvalue = sprintf(_('Value') . ': %s (' . (round($proc) != $proc ? '%0.2f' : '%s') . '%%)', convert_units($datavalue, $this->items[$i]['units']), $proc);
             $str = sprintf('%s: %s [%s] ', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['name'], $max_name_len, ' '), $fnc_name);
         } else {
             $strvalue = sprintf(_('Value: no data'));
             $str = sprintf('%s: %s [ ' . _('no data') . ' ]', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['name'], $max_name_len, ' '));
         }
         imagefilledrectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $color);
         imagerectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $this->getColor('Black No Alpha'));
         imageText($this->im, 8, 0, $this->shiftXleft + 15, $this->sizeY + $shiftY + 14 * $i + 5, $this->getColor($this->graphtheme['textcolor'], 0), $str);
         $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 25;
         imagefilledrectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $color);
         imagerectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $this->GetColor('Black No Alpha'));
         imagetext($this->im, 8, 0, $shiftX + 5, $this->shiftY + 10 + 14 * $i + 10, $this->getColor($this->graphtheme['textcolor'], 0), $strvalue);
     }
     if ($this->sizeY < 120) {
         return;
     }
 }
Exemplo n.º 3
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $this->dataId = 'discovery';
     $sort_field = $this->data['sort'];
     $sort_order = $this->data['sortorder'];
     $druleid = $this->data['druleid'];
     // discovery rules
     $options = ['output' => ['druleid', 'name'], 'selectDHosts' => ['dhostid', 'status', 'lastup', 'lastdown'], 'filter' => ['status' => DRULE_STATUS_ACTIVE]];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
         // set selected discovery rule id
     }
     $drules = API::DRule()->get($options);
     if ($drules) {
         order_result($drules, 'name');
     }
     // discovery services
     $options = ['selectHosts' => ['hostid', 'name', 'status'], 'output' => ['dserviceid', 'type', 'key_', 'port', 'status', 'lastup', 'lastdown', 'ip', 'dns'], 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limitSelects' => 1];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
     } else {
         $options['druleids'] = zbx_objectValues($drules, 'druleid');
     }
     $dservices = API::DService()->get($options);
     // user macros
     $macros = API::UserMacro()->get(['output' => ['macro', 'value'], 'globalmacro' => true]);
     $macros = zbx_toHash($macros, 'macro');
     // services
     $services = [];
     foreach ($dservices as $dservice) {
         $key_ = $dservice['key_'];
         if ($key_ !== '') {
             if (array_key_exists($key_, $macros)) {
                 $key_ = $macros[$key_]['value'];
             }
             $key_ = ': ' . $key_;
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $services[$service_name] = 1;
     }
     ksort($services);
     // discovery services to hash
     $dservices = zbx_toHash($dservices, 'dserviceid');
     // discovery hosts
     $dhosts = API::DHost()->get(['druleids' => zbx_objectValues($drules, 'druleid'), 'selectDServices' => ['dserviceid', 'ip', 'dns', 'type', 'status', 'key_'], 'output' => ['dhostid', 'lastdown', 'lastup', 'druleid']]);
     $dhosts = zbx_toHash($dhosts, 'dhostid');
     $header = [make_sorting_header(_('Discovered device'), 'ip', $sort_field, $sort_order, 'zabbix.php?action=discovery.view'), _('Monitored host'), _('Uptime') . '/' . _('Downtime')];
     foreach ($services as $name => $foo) {
         $header[] = (new CColHeader($name))->addClass('vertical_rotation');
     }
     // create table
     $table = (new CTableInfo())->makeVerticalRotation()->setHeader($header);
     foreach ($drules as $drule) {
         $discovery_info = [];
         foreach ($drule['dhosts'] as $dhost) {
             if ($dhost['status'] == DHOST_STATUS_DISABLED) {
                 $hclass = 'disabled';
                 $htime = $dhost['lastdown'];
             } else {
                 $hclass = 'enabled';
                 $htime = $dhost['lastup'];
             }
             // $primary_ip stores the primary host ip of the dhost
             $primary_ip = '';
             foreach ($dhosts[$dhost['dhostid']]['dservices'] as $dservice) {
                 $dservice = $dservices[$dservice['dserviceid']];
                 $hostName = '';
                 $host = reset($dservices[$dservice['dserviceid']]['hosts']);
                 if (!is_null($host)) {
                     $hostName = $host['name'];
                 }
                 if ($primary_ip !== '') {
                     if ($primary_ip === $dservice['ip']) {
                         $htype = 'primary';
                     } else {
                         $htype = 'slave';
                     }
                 } else {
                     $primary_ip = $dservice['ip'];
                     $htype = 'primary';
                 }
                 if (!array_key_exists($dservice['ip'], $discovery_info)) {
                     $discovery_info[$dservice['ip']] = ['ip' => $dservice['ip'], 'dns' => $dservice['dns'], 'type' => $htype, 'class' => $hclass, 'host' => $hostName, 'time' => $htime];
                 }
                 if ($dservice['status'] == DSVC_STATUS_DISABLED) {
                     $class = ZBX_STYLE_INACTIVE_BG;
                     $time = 'lastdown';
                 } else {
                     $class = ZBX_STYLE_ACTIVE_BG;
                     $time = 'lastup';
                 }
                 $key_ = $dservice['key_'];
                 if ($key_ !== '') {
                     if (array_key_exists($key_, $macros)) {
                         $key_ = $macros[$key_]['value'];
                     }
                     $key_ = NAME_DELIMITER . $key_;
                 }
                 $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
                 $discovery_info[$dservice['ip']]['services'][$service_name] = ['class' => $class, 'time' => $dservice[$time]];
             }
         }
         if ($druleid == 0 && $discovery_info) {
             $col = new CCol([bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')']);
             $col->setColSpan(count($services) + 3);
             $table->addRow($col);
         }
         order_result($discovery_info, $sort_field, $sort_order);
         foreach ($discovery_info as $ip => $h_data) {
             $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
             $row = [$h_data['type'] == 'primary' ? (new CSpan($ip . $dns))->addClass($h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(array_key_exists('host', $h_data) ? $h_data['host'] : ''), (new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(['value' => time() - $h_data['time'], 'units' => 'uptime'])))->addClass($h_data['class'])];
             foreach ($services as $name => $foo) {
                 $class = null;
                 $time = SPACE;
                 $hint = (new CDiv(SPACE))->addClass($class);
                 $hint_table = null;
                 if (array_key_exists($name, $h_data['services'])) {
                     $class = $h_data['services'][$name]['class'];
                     $time = $h_data['services'][$name]['time'];
                     $hint_table = (new CTableInfo())->setAttribute('style', 'width: auto;');
                     if ($class == ZBX_STYLE_ACTIVE_BG) {
                         $hint_table->setHeader(_('Uptime'));
                     } else {
                         $hint_table->setHeader(_('Downtime'));
                     }
                     $hint_table->addRow((new CCol(zbx_date2age($h_data['services'][$name]['time'])))->addClass($class));
                 }
                 $column = (new CCol($hint))->addClass($class);
                 if (!is_null($hint_table)) {
                     $column->setHint($hint_table);
                 }
                 $row[] = $column;
             }
             $table->addRow($row);
         }
     }
     return $this->getOutput($table, true, $this->data);
 }
Exemplo n.º 4
0
    if (isset($db_item['lastclock'])) {
        $lastclock = zbx_date2str(_('d M Y H:i:s'), $db_item['lastclock']);
    } else {
        $lastclock = ' - ';
    }
    // column "lastvalue"
    $lastvalue = formatItemValue($db_item);
    // column "change"
    $digits = $db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT ? 2 : 0;
    if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) && bcsub($db_item['lastvalue'], $db_item['prevvalue'], $digits) != 0) {
        $change = '';
        if ($db_item['lastvalue'] - $db_item['prevvalue'] > 0) {
            $change = '+';
        }
        // for 'unixtime' change should be calculated as uptime
        $change .= convert_units(bcsub($db_item['lastvalue'], $db_item['prevvalue'], $digits), $db_item['units'] == 'unixtime' ? 'uptime' : $db_item['units'], 0);
        $change = nbsp($change);
    } else {
        $change = ' - ';
    }
    // column "action"
    if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
        $actions = new CLink(_('Graph'), 'history.php?action=showgraph&itemid=' . $db_item['itemid']);
    } else {
        $actions = new CLink(_('History'), 'history.php?action=showvalues&itemid=' . $db_item['itemid']);
    }
    $item_status = $db_item['status'] == ITEM_STATUS_NOTSUPPORTED ? 'unknown' : null;
    array_push($app_rows, new CRow(array(SPACE, is_show_all_nodes() ? $db_host['item_cnt'] ? SPACE : get_node_name_by_elid($db_item['itemid']) : null, $_REQUEST['hostid'] ? null : SPACE, new CCol(SPACE . SPACE . $description, $item_status), new CCol($lastclock, $item_status), new CCol($lastvalue, $item_status), new CCol($change, $item_status), new CCol($actions, $item_status))));
}
unset($app_rows);
unset($db_host);
Exemplo n.º 5
0
    $db_host['item_cnt']++;
    if (!uint_in_array(0, $_REQUEST['applications']) && !isset($show_all_apps)) {
        continue;
    }
    if (isset($db_item['lastclock'])) {
        $lastclock = zbx_date2str(S_DATE_FORMAT_YMDHMS, $db_item['lastclock']);
    } else {
        $lastclock = new CCol(' - ');
    }
    $lastvalue = format_lastvalue($db_item);
    if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) && $db_item['lastvalue'] - $db_item['prevvalue'] != 0) {
        if ($db_item['lastvalue'] - $db_item['prevvalue'] < 0) {
            $change = convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
            $change = nbsp($change);
        } else {
            $change = '+' . convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
            $change = nbsp($change);
        }
    } else {
        $change = new CCol(' - ');
    }
    if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
        $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid'], 'action');
    } else {
        $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid'], 'action');
    }
    array_push($app_rows, new CRow(array(is_show_subnodes() ? $db_host['item_cnt'] ? SPACE : get_node_name_by_elid($db_item['itemid']) : null, $_REQUEST['hostid'] ? NULL : ($db_host['item_cnt'] ? SPACE : $db_item['host']), str_repeat(SPACE, 6) . $description, $lastclock, new CCol($lastvalue), $change, $actions)));
}
unset($app_rows);
unset($db_host);
foreach ($db_hosts as $hostid => $db_host) {
Exemplo n.º 6
0
                 $key_ = $gMacros[$key_]['value'];
             }
             $key_ = ': ' . $key_;
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $discovery_info[$dservice['ip']]['services'][$service_name] = array('class' => $class, 'time' => $dservice[$time]);
     }
 }
 if ($druleid == 0 && !empty($discovery_info)) {
     $col = new CCol(array(bold($drule['name']), SPACE . '(' . count($discovery_info) . SPACE . S_ITEMS . ')'));
     $col->setColSpan(count($services) + 3);
     $table->addRow(array(get_node_name_by_elid($drule['druleid']), $col));
 }
 order_result($discovery_info, $_REQUEST['sort'], $_REQUEST['sortorder']);
 foreach ($discovery_info as $ip => $h_data) {
     $table_row = array(get_node_name_by_elid($h_data['druleid']), $h_data['type'] == 'primary' ? new CSpan($ip, $h_data['class']) : new CSpan(SPACE . SPACE . $ip), new CSpan(empty($h_data['host']) ? '-' : $h_data['host']), new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(time() - $h_data['time'], 'uptime'), $h_data['class']));
     foreach ($services as $name => $foo) {
         $class = null;
         $time = SPACE;
         $hint = new CDiv(SPACE, $class);
         $hintTable = null;
         if (isset($h_data['services'][$name])) {
             $class = $h_data['services'][$name]['class'];
             $time = $h_data['services'][$name]['time'];
             $hintTable = new CTableInfo();
             $hintTable->setAttribute('style', 'width: auto;');
             if ($class == 'active') {
                 $hintTable->setHeader(S_UP_TIME);
             } else {
                 if ($class == 'inactive') {
                     $hintTable->setHeader(S_DOWN_TIME);
Exemplo n.º 7
0
/**
 * Retrieves from DB historical data for items and applies functional calculations.
 * If fails for some reason, returns UNRESOLVED_MACRO_STRING.
 *
 * @param array		$item
 * @param string	$item['value_type']	type of item, allowed: ITEM_VALUE_TYPE_FLOAT and ITEM_VALUE_TYPE_UINT64
 * @param string	$item['itemid']		ID of item
 * @param string	$item['units']		units of item
 * @param string	$function			function to apply to time period from param, allowed: min, max and avg
 * @param string	$parameter			formatted parameter for function, example: "2w" meaning 2 weeks
 *
 * @return string item functional value from history
 */
function getItemFunctionalValue($item, $function, $parameter)
{
    // check whether function is allowed
    if (!in_array($function, array('min', 'max', 'avg')) || $parameter === '') {
        return UNRESOLVED_MACRO_STRING;
    }
    $parameter = convertFunctionValue($parameter);
    if (bccomp($parameter, 0) == 0) {
        return UNRESOLVED_MACRO_STRING;
    }
    // allowed item types for min, max and avg function
    $historyTables = array(ITEM_VALUE_TYPE_FLOAT => 'history', ITEM_VALUE_TYPE_UINT64 => 'history_uint');
    if (!isset($historyTables[$item['value_type']])) {
        return UNRESOLVED_MACRO_STRING;
    } else {
        // search for item function data in DB corresponding history table
        $result = DBselect('SELECT ' . $function . '(value) AS value' . ' FROM ' . $historyTables[$item['value_type']] . ' WHERE clock>' . (time() - $parameter) . ' AND itemid=' . zbx_dbstr($item['itemid']) . ' HAVING COUNT(*)>0');
        if ($row = DBfetch($result)) {
            return convert_units(array('value' => $row['value'], 'units' => $item['units']));
        } else {
            return UNRESOLVED_MACRO_STRING;
        }
    }
}
Exemplo n.º 8
0
         $time = 'lastup';
         if (DSVC_STATUS_DISABLED == $dservice['status']) {
             $class = 'inactive';
             $time = 'lastdown';
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . (empty($dservice['key_']) ? '' : ':' . $dservice['key_']);
         $discovery_info[$dhost['ip']]['services'][$service_name] = array('class' => $class, 'time' => $dservice[$time]);
     }
 }
 if ($druleid == 0 && !empty($discovery_info)) {
     $col = new CCol(array(bold($drule['name']), SPACE . '(' . count($discovery_info) . SPACE . S_ITEMS . ')'));
     $col->setColSpan(count($services) + 3);
     $table->addRow(array(get_node_name_by_elid($drule['druleid']), $col));
 }
 foreach ($discovery_info as $ip => $h_data) {
     $table_row = array(get_node_name_by_elid($h_data['druleid']), new CSpan($ip, $h_data['class']), new CSpan(empty($h_data['host']) ? '-' : $h_data['host']), new CSpan($h_data['time'] == 0 ? '' : convert_units(time() - $h_data['time'], 'uptime'), $h_data['class']));
     foreach ($services as $name => $foo) {
         $class = null;
         $time = SPACE;
         $hint = new CDiv(SPACE, $class);
         $hintTable = new CTableInfo();
         $hintTable->setAttribute('style', 'width: auto;');
         if (isset($h_data['services'][$name])) {
             $class = $h_data['services'][$name]['class'];
             $time = $h_data['services'][$name]['time'];
             if ($class == 'active') {
                 $hintTable->setHeader(S_UP_TIME);
             } else {
                 if ($class == 'inactive') {
                     $hintTable->setHeader(S_DOWN_TIME);
                 }
        $operation['mediatypeid'] = 0;
    }
    $details = new CSpan(get_operation_desc(SHORT_DESCRIPTION, $operation));
    $details->setHint(get_operation_desc(LONG_DESCRIPTION, $operation));
    if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS) {
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($operation['esc_step_from'] < 1) {
            $operation['esc_step_from'] = 1;
        }
        $esc_steps_txt = $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        // display N-N as N
        $esc_steps_txt = $operation['esc_step_from'] == $operation['esc_step_to'] ? $operation['esc_step_from'] : $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        $esc_period_txt = $operation['esc_period'] ? $operation['esc_period'] : _('Default');
        $esc_delay_txt = $delay[$operation['esc_step_from']] ? convert_units($delay[$operation['esc_step_from']], 'uptime') : _('Immediately');
        $operationRow = array($esc_steps_txt, $details, $esc_delay_txt, $esc_period_txt, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
    } else {
        $operationRow = array($details, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
    }
    $operationsTable->addRow($operationRow, null, 'operations_' . $operationid);
    $operation['opmessage_grp'] = isset($operation['opmessage_grp']) ? zbx_toHash($operation['opmessage_grp'], 'usrgrpid') : null;
    $operation['opmessage_usr'] = isset($operation['opmessage_usr']) ? zbx_toHash($operation['opmessage_usr'], 'userid') : null;
    $operation['opcommand_grp'] = isset($operation['opcommand_grp']) ? zbx_toHash($operation['opcommand_grp'], 'groupid') : null;
    $operation['opcommand_hst'] = isset($operation['opcommand_hst']) ? zbx_toHash($operation['opcommand_hst'], 'hostid') : null;
}
$footer = array();
if (empty($this->data['new_operation'])) {
    $footer[] = new CSubmit('new_operation', _('New'), null, 'link_menu');
}
$operationFormList->addRow(_('Action operations'), new CDiv(array($operationsTable, $footer), 'objectgroup inlineblock border_dotted ui-corner-all'));
Exemplo n.º 10
0
         $table->setHeader(array(_zeT("Data")));
         break;
     case 'html':
         $table->setHeader(array(_zeT('Instant'), _zeT('Value'), _zeT('Type')));
         break;
 }
 $points = "";
 $descUnidade = "";
 for ($i = 0; $i < $cont; $i++) {
     switch ($formato) {
         case 'csv':
             $table->addRow(array(quotestr($report[$i]['momento']) . ";" . quotestr($report[$i]['valor']) . ";" . quotestr($report[$i]['tipo']) . ";"));
             break;
         case 'html':
             $momento = new CCol($report[$i]['momento'], 1);
             $valor = convert_units(array('value' => $report[$i]['valor'], 'units' => $unidade));
             $valor = new CCol($valor, 1);
             $tipo = new CCol($report[$i]['tipo'], 1);
             $table->addRow(array($momento, $valor, $tipo));
             break;
     }
     // Tratando o valor para o gráfico caso seja formatação de Byte
     if ($unidade == 'B') {
         $maximo = $maximo - 1;
         if ($maximo < 1024) {
             $fator = 1;
             $descUnidade = 'B';
         } else {
             if ($maximo < 1048576) {
                 $fator = 1024;
                 $descUnidade = 'KB';
Exemplo n.º 11
0
 function check_values($input_data)
 {
     $msg = "";
     if ($input_data['value'] === "") {
         $msg = ucphr('CHECK_VALUE');
     }
     $input_data['value'] = eq_to_number($input_data['value']);
     if ($input_data['quantity'] === "") {
         $msg = ucphr('CHECK_QUANTITY');
     }
     if (!isset($input_data['unit_type'])) {
         $input_data['unit_type'] = get_unit_from_eq($input_data['quantity']);
     }
     // should before modification of quantity
     $input_data['quantity'] = convert_units($input_data['quantity']);
     $stock = new stock_object($input_data['obj_id']);
     if ($stock->data['quantity'] + $input_data['quantity'] < 0 && $stock->data['quantity'] >= 0) {
         $msg = ucphr('CHECK_QUANTITY');
     }
     $input_data['user'] = $_SESSION['userid'];
     if ($msg) {
         echo "<script language=\"javascript\">\n\t\t\t\twindow.alert(\"" . $msg . "\");\n\t\t\t</script>\n";
         return -2;
     }
     return $input_data;
 }
Exemplo n.º 12
0
function resolveMapLabelMacros($label, $replaceHost = null)
{
    if (null === $replaceHost) {
        $pattern = "/{" . ZBX_PREG_HOST_FORMAT . ":.+\\.(last|max|min|avg)\\([0-9]+\\)}/Uu";
    } else {
        $pattern = "/{(" . ZBX_PREG_HOST_FORMAT . "|{HOSTNAME}):.+\\.(last|max|min|avg)\\([0-9]+\\)}/Uu";
    }
    preg_match_all($pattern, $label, $matches);
    foreach ($matches[0] as $expr) {
        $macro = $expr;
        if ($replaceHost !== null && zbx_strpos($macro, '{HOSTNAME}') == 1) {
            $macro = substr_replace($macro, $replaceHost, 1, 10);
        }
        $trigExpr = new CTriggerExpression(array('expression' => $macro));
        if (!empty($trigExpr->errors)) {
            continue;
        }
        $itemHost = reset($trigExpr->data['hosts']);
        $key = reset($trigExpr->data['items']);
        $function = reset($trigExpr->data['functions']);
        $parameter = reset($trigExpr->data['functionParams']);
        $item = CItem::get(array('filter' => array('host' => $itemHost, 'key_' => $key), 'output' => API_OUTPUT_EXTEND));
        $item = reset($item);
        if (!$item) {
            $label = str_replace($expr, '???', $label);
            continue;
        }
        switch ($item['value_type']) {
            case ITEM_VALUE_TYPE_FLOAT:
                $history_table = 'history';
                break;
            case ITEM_VALUE_TYPE_UINT64:
                $history_table = 'history_uint';
                break;
            case ITEM_VALUE_TYPE_TEXT:
                $history_table = 'history_text';
                break;
            case ITEM_VALUE_TYPE_LOG:
                $history_table = 'history_log';
                break;
            case ITEM_VALUE_TYPE_STR:
                $history_table = 'history_str';
                break;
            default:
                $history_table = 'history_str';
        }
        if (0 == strcmp($function, 'last')) {
            if (null === $item['lastvalue']) {
                $label = str_replace($expr, '(' . S_NO_DATA_SMALL . ')', $label);
            } else {
                switch ($item['value_type']) {
                    case ITEM_VALUE_TYPE_FLOAT:
                    case ITEM_VALUE_TYPE_UINT64:
                        $value = convert_units($item['lastvalue'], $item['units']);
                        break;
                    default:
                        $value = $item['lastvalue'];
                }
                $label = str_replace($expr, $value, $label);
            }
        } else {
            if (0 == strcmp($function, 'min') || 0 == strcmp($function, 'max') || 0 == strcmp($function, 'avg')) {
                if ($item['value_type'] != ITEM_VALUE_TYPE_FLOAT && $item['value_type'] != ITEM_VALUE_TYPE_UINT64) {
                    $label = str_replace($expr, '???', $label);
                    continue;
                }
                $sql = 'SELECT ' . $function . '(value) as value ' . ' FROM ' . $history_table . ' WHERE clock>' . (time() - $parameter) . ' AND itemid=' . $item['itemid'];
                $result = DBselect($sql);
                if (null === ($row = DBfetch($result)) || null === $row['value']) {
                    $label = str_replace($expr, '(' . S_NO_DATA_SMALL . ')', $label);
                } else {
                    $label = str_replace($expr, convert_units($row['value'], $item['units']), $label);
                }
            }
        }
    }
    return $label;
}
Exemplo n.º 13
0
function format_lastvalue($db_item)
{
    if ($db_item["value_type"] == ITEM_VALUE_TYPE_LOG) {
        $row = DBfetch(DBselect('SELECT value FROM history_log WHERE itemid=' . $db_item['itemid'] . ' ORDER BY clock DESC', 1));
        if ($row) {
            $lastvalue = $row['value'];
            if (strlen($lastvalue) > 20) {
                $lastvalue = substr($lastvalue, 0, 20) . " ...";
            }
            $lastvalue = nbsp(htmlspecialchars($lastvalue));
        } else {
            $lastvalue = '-';
        }
    } else {
        if (isset($db_item["lastvalue"])) {
            if ($db_item["value_type"] == ITEM_VALUE_TYPE_FLOAT) {
                $lastvalue = convert_units($db_item["lastvalue"], $db_item["units"]);
            } else {
                if ($db_item["value_type"] == ITEM_VALUE_TYPE_UINT64) {
                    $lastvalue = convert_units($db_item["lastvalue"], $db_item["units"]);
                } else {
                    if ($db_item["value_type"] == ITEM_VALUE_TYPE_TEXT) {
                        $lastvalue = "...";
                    } else {
                        if ($db_item["value_type"] == ITEM_VALUE_TYPE_STR) {
                            $lastvalue = nbsp(htmlspecialchars(substr($db_item["lastvalue"], 0, 20)));
                            if (strlen($db_item["lastvalue"]) > 20) {
                                $lastvalue .= " ...";
                            }
                        } else {
                            $lastvalue = "Unknown value type";
                        }
                    }
                }
            }
            if ($db_item["valuemapid"] > 0) {
            }
            $lastvalue = replace_value_by_map($lastvalue, $db_item["valuemapid"]);
        } else {
            $lastvalue = "-";
        }
    }
    return $lastvalue;
}
Exemplo n.º 14
0
                }
                $table->addRow(array($linhaCSV));
                break;
            case 'html':
                for ($x = 0; $x < $cont2; $x++) {
                    $linha[$x] = new CCol($report[$i][$x] . ($x == 7 || $x == 8 ? $linhasDesc : " "), 1);
                }
                $table->addRow($linha);
                break;
        }
    }
    $descricao = new CCol('');
    $descricao->setAttribute('colspan', '6');
    $descricao->setAttribute('align', 'right');
    if ($formato !== 'csv') {
        if ($view == "G") {
            $table->addRow(array('Total', $historyTotal . $linhasDesc, $trendTotal . $linhasDesc, convert_units(array('value' => $storageTotal, 'units' => 'B')), $vpsTotal . ' vps'));
        } else {
            $table->addRow(array($descricao, 'Total', $historyTotal . $linhasDesc, $trendTotal . $linhasDesc, convert_units(array('value' => $storageTotal, 'units' => 'B')), $vpsTotal . ' vps'));
        }
    }
    $numrows = new CDiv();
    $numrows->setAttribute('name', 'numrows');
    $hostprof_wdgt->addHeader($numrows);
    $paging = getPagingLine($report);
    $hostprof_wdgt->addItem($table);
} else {
    $hostprof_wdgt->addItem(_zeT('Enter the parameters for research!'));
}
$hostprof_wdgt->show();
include_once 'include/page_footer.php';
Exemplo n.º 15
0
 public function getItemListFormat($list = array())
 {
     $itemList = $list['list_item'];
     $parame = $list['parame'];
     $search_key = $parame['item_name_search'];
     $order_result_list = array();
     $search = 0;
     if (empty($search_key)) {
         $search_key_list = array();
     } else {
         $search_key_list = explode(",", $search_key);
     }
     if (count($search_key_list) >= 1) {
         $search = 1;
     }
     foreach ($itemList as $each_item) {
         $each_item = (array) $each_item;
         $item = get_item_by_itemid($each_item['itemid']);
         $newItem = $item;
         // $newItem['name'] = itemName($item);
         $newItem['name'] = $item['name'];
         $newItem['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
         $host = get_host_by_hostid($item['hostid']);
         $newItem['hostname'] = $host['name'];
         if (strpos($item['units'], ',') !== false) {
             list($newItem['units'], $newItem['unitsLong']) = explode(',', $item['units']);
         } else {
             $newItem['unitsLong'] = '';
         }
         if ($search == 0) {
             $newItem['graphid'] = $each_item['graphid'];
             $order_result_list[$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
         } else {
             foreach ($search_key_list as $each_search_key) {
                 $each_search_key = trim($each_search_key);
                 //按关键字进行筛选
                 if (strpos(strtolower($newItem['name']), strtolower($each_search_key)) === false) {
                     //echo "bupipei<br>";
                 } else {
                     $newItem['calc_fnc'] = is_null($each_item['calc_fnc']) ? CALC_FNC_AVG : $each_item->calc_fnc;
                     $newItem['calc_type'] = GRAPH_ITEM_SIMPLE;
                     $newItem['graphid'] = $each_item['graphid'];
                     $item_info_new = array_merge($newItem, $parame);
                     $data = self::GetItemValues($item_info_new);
                     if (isset($data) && isset($data['min'])) {
                         $lastvalue = convert_units(self::getLastValueBy($data), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $min = convert_units(min($data['min']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $avg = convert_units($data['avg_orig'], $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $max = convert_units(max($data['max']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         //return array("lastvalue"=>$lastvalue,'min'=>$min,'avg'=>$avg,'max'=>$max);
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => self::getLastValueBy($data), 'min' => min($data['min']), 'avg' => $data['avg_orig'], 'max' => max($data['max']), 'hostname' => $newItem['hostname'], 'chazhi' => max($data['max']) - min($data['min']));
                     } else {
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
                     }
                     break;
                 }
             }
         }
     }
     return $order_result_list;
 }
Exemplo n.º 16
0
 protected function drawRightSide()
 {
     if ($this->yaxisright == 1) {
         $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT];
         $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT];
         for ($item = 0; $item < $this->num; $item++) {
             if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
                 $units = $this->items[$item]['units'];
                 break;
             }
         }
         $hstr_count = $this->gridLinesCount;
         for ($i = 0; $i <= $hstr_count; $i++) {
             $str = str_pad(convert_units($this->sizeY * $i / $hstr_count * ($maxY - $minY) / $this->sizeY + $minY, $units), 10, ' ');
             imagestring($this->im, 1, $this->sizeX + $this->shiftXleft + 2, $this->sizeY - $this->sizeY * $i / $hstr_count - 4 + $this->shiftY, $str, $this->getColor('Dark Red No Alpha'));
         }
         if ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY + $this->shiftY && $this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY) {
             imageline($this->im, $this->shiftXleft, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->shiftXleft + $this->sizeX, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->getColor(GRAPH_ZERO_LINE_COLOR_RIGHT));
             //*/
         }
     }
 }
Exemplo n.º 17
0
 protected function drawSideValues()
 {
     $sides = array();
     if ($this->axisSideLeft) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     if ($this->axisSideRight) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     foreach ($sides as $axis) {
         $min = $this->minValue[$axis];
         $max = $this->maxValue[$axis];
         $hstr_count = $this->gridLinesCount;
         if ($this->column) {
             for ($i = 0; $i <= $hstr_count; $i++) {
                 $str = convert_units(array('value' => $this->sizeY * $i / $hstr_count * ($max - $min) / $this->sizeY + $min, 'units' => $this->units[$axis]));
                 $sideShift = 0;
                 if (GRAPH_YAXIS_SIDE_LEFT == $axis) {
                     $dims = imageTextSize(8, 0, $str);
                     $sideShift = -1 * ($dims['width'] + 10);
                 } else {
                     $sideShift = $this->sizeX + 10;
                 }
                 imagetext($this->im, 8, 0, $this->shiftXleft + $this->shiftXCaptionLeft + $sideShift, $this->sizeY - $this->sizeY * $i / $hstr_count + $this->shiftY + $this->shiftYCaptionTop + 6, $this->getColor($this->graphtheme['textcolor'], 0), $str);
             }
         } elseif (uint_in_array($this->type, array(GRAPH_TYPE_BAR, GRAPH_TYPE_BAR_STACKED))) {
             if (GRAPH_YAXIS_SIDE_LEFT == $axis) {
                 $shiftYBottom = $this->shiftY + $this->shiftYCaptionTop - 2;
                 // -2 because of some mistake somewhere in calculations! FIX IT!
             } else {
                 $shiftYBottom = $this->shiftY + $this->sizeY + $this->shiftYCaptionTop + $this->shiftYCaptionBottom;
             }
             for ($i = 0; $i <= $hstr_count; $i++) {
                 $str = convert_units(array('value' => $this->sizeX * $i / $hstr_count * ($max - $min) / $this->sizeX + $min, 'units' => $this->units[$axis]));
                 $sideShift = 0;
                 if (GRAPH_YAXIS_SIDE_LEFT == $axis) {
                     $dims = imageTextSize(8, 90, $str);
                     $sideShift = $dims['height'];
                 }
                 imageText($this->im, 8, 90, $this->shiftXleft + ($this->sizeX * $i / $hstr_count - 4) + $this->shiftXCaptionLeft, $shiftYBottom - $sideShift, $this->getColor($this->graphtheme['textcolor'], 0), $str);
             }
         }
     }
     if (!is_null($this->xLabel)) {
         $dims = imageTextSize(10, 0, $this->xLabel);
         imageText($this->im, 10, 0, $this->shiftXCaptionLeft + $this->shiftXleft + $this->sizeX / 2 - $dims['width'] / 2, $this->fullSizeY - 10 - $dims['height'], $this->getColor($this->graphtheme['textcolor'], 0), $this->xLabel);
     }
     if (!is_null($this->yLabel)) {
         $dims = imageTextSize(10, 90, $this->yLabel);
         imageText($this->im, 10, 90, $this->shiftXleft + $dims['width'], $this->shiftY + $this->sizeY / 2 + $dims['height'] / 2, $this->getColor($this->graphtheme['textcolor'], 0), $this->yLabel);
     }
 }
Exemplo n.º 18
0
function make_datastore_table($hostid, $datastores)
{
    $table = new CTableInfo();
    $table->setHeader(array(_('Datastore Name'), _('Free Space'), _('Capacity')));
    foreach ($datastores as $datastore) {
        $name_col = new CCol($datastore["name"]);
        $freeSpace = convert_units($datastore["freeSpace"], "B");
        $capacity = convert_units($datastore["capacity"], "B");
        $free_space_col = new CCol($freeSpace);
        $capacity_col = new CCol($capacity);
        $r = new CRow(array($name_col, $free_space_col, $capacity_col));
        $table->addRow($r);
    }
    return $table;
}
Exemplo n.º 19
0
 if ($lastHistory) {
     $lastClock = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $lastHistory['clock']);
     $lastValue = formatHistoryValue($lastHistory['value'], $item, false);
 } else {
     $lastClock = UNKNOWN_VALUE;
     $lastValue = UNKNOWN_VALUE;
 }
 // column "change"
 $digits = $item['value_type'] == ITEM_VALUE_TYPE_FLOAT ? 2 : 0;
 if (isset($lastHistory['value']) && isset($prevHistory['value']) && ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) && bcsub($lastHistory['value'], $prevHistory['value'], $digits) != 0) {
     $change = '';
     if ($lastHistory['value'] - $prevHistory['value'] > 0) {
         $change = '+';
     }
     // for 'unixtime' change should be calculated as uptime
     $change .= convert_units(array('value' => bcsub($lastHistory['value'], $prevHistory['value'], $digits), 'units' => $item['units'] == 'unixtime' ? 'uptime' : $item['units']));
     $change = nbsp($change);
 } else {
     $change = UNKNOWN_VALUE;
 }
 // column "action"
 $showLink = ($config['hk_history_global'] && $config['hk_history'] == 0 || $item['history'] == 0) && ($config['hk_trends_global'] && $config['hk_trends'] == 0 || $item['trends'] == 0);
 $checkbox = new CCheckBox('itemids[' . $item['itemid'] . ']', null, null, $item['itemid']);
 $checkbox->removeAttribute('id');
 if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
     $actions = $showLink ? UNKNOWN_VALUE : new CLink(_('Graph'), 'history.php?action=' . HISTORY_GRAPH . '&itemids[]=' . $item['itemid']);
 } else {
     $actions = $showLink ? UNKNOWN_VALUE : new CLink(_('History'), 'history.php?action=' . HISTORY_VALUES . '&itemids[]=' . $item['itemid']);
     $checkbox->setEnabled(false);
 }
 $stateCss = $item['state'] == ITEM_STATE_NOTSUPPORTED ? 'unknown' : '';
Exemplo n.º 20
0
            continue;
        }
    }
    if (isset($db_item['lastclock'])) {
        $lastclock = zbx_date2str(S_LATEST_ITEMS_TRIGGERS_DATE_FORMAT, $db_item['lastclock']);
    } else {
        $lastclock = new CCol(' - ');
    }
    $lastvalue = format_lastvalue($db_item);
    if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) && $db_item['lastvalue'] - $db_item['prevvalue'] != 0) {
        $change = '';
        if ($db_item['lastvalue'] - $db_item['prevvalue'] > 0) {
            $change = '+';
        }
        $digits = $db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT ? 2 : 0;
        $change = $change . convert_units(bcsub($db_item['lastvalue'], $db_item['prevvalue'], $digits), $db_item['units'], 0);
        $change = nbsp($change);
    } else {
        $change = new CCol(' - ');
    }
    if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
        $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid']);
    } else {
        $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid']);
    }
    array_push($app_rows, new CRow(array(SPACE, is_show_all_nodes() ? $db_host['item_cnt'] ? SPACE : get_node_name_by_elid($db_item['itemid']) : null, $_REQUEST['hostid'] ? NULL : ($db_host['item_cnt'] ? SPACE : $db_item['host']), SPACE . SPACE . $description, $lastclock, new CCol($lastvalue), $change, $actions)));
}
unset($app_rows);
unset($db_host);
foreach ($db_hosts as $hostid => $db_host) {
    if (!isset($tab_rows[$hostid])) {
 function list_rows($arr, $row)
 {
     global $tpl;
     global $display;
     $col = 0;
     if (!$this->disable_mass_delete) {
         $display->rows[$row][$col] = '<input type="checkbox" name="delete[]" value="' . $arr['id'] . '">';
         $display->width[$row][$col] = '1%';
         $col++;
     }
     foreach ($arr as $field => $value) {
         if (isset($this->allow_single_update) && in_array($field, $this->allow_single_update)) {
             $link = $this->link_base . '&amp;command=update_field&amp;data[id]=' . $arr['id'] . '&amp;data[field]=' . $field;
             if ($this->limit_start) {
                 $link .= '&amp;data[limit_start]=' . $this->limit_start;
             }
             if ($this->orderby) {
                 $link .= '&amp;data[orderby]=' . $this->orderby;
             }
             if ($this->sort) {
                 $link .= '&amp;data[sort]=' . $this->sort;
             }
             $display->links[$row][$col] = $link;
         } elseif (method_exists($this, 'form')) {
             $link = $this->file . '?class=' . get_class($this) . '&amp;command=edit&amp;data[id]=' . $arr['id'];
         } else {
             $link = '';
         }
         if ($field == 'name' && CONF_SHOW_SUMMARY_ON_LIST) {
             $ingred = new ingredient($arr['id']);
             $value .= '<span class="admin_ingreds_list">';
             $dishes = $ingred->find_connected_dishes();
             if (!empty($dishes['included']) && is_array($dishes['included'])) {
                 $value .= '<br/>' . ucphr('INCLUDED') . ': ';
                 foreach ($dishes['included'] as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             if (!empty($dishes['available']) && is_array($dishes['available'])) {
                 $value .= '<br/>' . ucphr('AVAILABLE') . ': ';
                 foreach ($dishes['available'] as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             $value .= '</span>';
         } elseif ($field == 'unit_type') {
             $value = get_user_unit($arr['unit_type']);
         } elseif ($field == 'quantity') {
             $unit = get_user_unit($arr['unit_type']);
             $default_unit = get_default_unit($arr['unit_type']);
             $value = convert_units($value . ' ' . $default_unit, $unit);
         }
         $display->rows[$row][$col] = $value;
         if ($link && $field == 'name') {
             $display->links[$row][$col] = $link;
         }
         if ($link) {
             $display->clicks[$row][$col] = 'redir(\'' . $link . '\');';
         }
         $col++;
     }
 }
Exemplo n.º 22
0
 protected function drawLegend()
 {
     $shiftY = $this->shiftY + $this->shiftYLegend;
     $max_host_len = 0;
     $max_desc_len = 0;
     for ($i = 0; $i < $this->num; $i++) {
         if (strlen($this->items[$i]['host']) > $max_host_len) {
             $max_host_len = strlen($this->items[$i]['host']);
         }
         if (strlen($this->items[$i]['description']) > $max_desc_len) {
             $max_desc_len = strlen($this->items[$i]['description']);
         }
     }
     for ($i = 0; $i < $this->num; $i++) {
         $color = $this->GetColor($this->items[$i]['color']);
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         switch ($this->items[$i]['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fnc_name = 'min';
                 $datavalue = $data->min;
                 break;
             case CALC_FNC_MAX:
                 $fnc_name = 'max';
                 $datavalue = $data->max;
                 break;
             case CALC_FNC_LST:
                 $fnc_name = 'last';
                 $datavalue = $data->lst;
                 break;
             case CALC_FNC_AVG:
             default:
                 $fnc_name = 'avg';
                 $datavalue = $data->avg;
         }
         $proc = $datavalue * 100 / $this->sum;
         //		convert_units($datavalue,$this->items[$i]["units"]),
         if (isset($data) && isset($datavalue)) {
             $strvalue = sprintf(S_VALUE . ': %s (' . (round($proc) != $proc ? '%0.2f' : '%s') . "%s)", convert_units($datavalue, $this->items[$i]["units"]), $proc, '%');
             $str = sprintf('%s: %s [%s] ', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' '), $fnc_name);
         } else {
             $strvalue = sprintf(S_VALUE . ': ' . S_NO_DATA_SMALL);
             $str = sprintf('%s: %s [ ' . S_NO_DATA_SMALL . ' ]', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' '));
         }
         ImageFilledRectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 12 * $i, $this->shiftXleft + 5, $this->sizeY + $shiftY + 5 + 12 * $i, $color);
         ImageRectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 12 * $i, $this->shiftXleft + 5, $this->sizeY + $shiftY + 5 + 12 * $i, $this->GetColor('Black No Alpha'));
         ImageString($this->im, 2, $this->shiftXleft + 9, $this->sizeY + $shiftY - 5 + 12 * $i, $str, $this->GetColor('Black No Alpha'));
         $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 10;
         //		SDI($shiftX.','.$this->sizeX);
         ImageFilledRectangle($this->im, $shiftX, $this->shiftY + 10 + 5 + 12 * $i, $shiftX + 5, $this->shiftY + 10 + 10 + 12 * $i, $color);
         ImageRectangle($this->im, $shiftX, $this->shiftY + 10 + 5 + 12 * $i, $shiftX + 5, $this->shiftY + 10 + 10 + 12 * $i, $this->GetColor('Black No Alpha'));
         ImageString($this->im, 2, $shiftX + 9, $this->shiftY + 10 + 12 * $i, $strvalue, $this->GetColor('Black No Alpha'));
     }
     if ($this->sizeY < 120) {
         return;
     }
 }
Exemplo n.º 23
0
             }
             $key_ = NAME_DELIMITER . $key_;
         }
         $serviceName = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $discovery_info[$dservice['ip']]['services'][$serviceName] = array('class' => $class, 'time' => $dservice[$time]);
     }
 }
 if (empty($this->data['druleid']) && !empty($discovery_info)) {
     $col = new CCol(array(bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')'));
     $col->setColSpan(count($this->data['services']) + 3);
     $discoveryTable->addRow($col);
 }
 order_result($discovery_info, $this->data['sort'], $this->data['sortorder']);
 foreach ($discovery_info as $ip => $h_data) {
     $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
     $row = array($h_data['type'] == 'primary' ? new CSpan($ip . $dns, $h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(empty($h_data['host']) ? '-' : $h_data['host']), new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(array('value' => time() - $h_data['time'], 'units' => 'uptime')), $h_data['class']));
     foreach ($this->data['services'] as $name => $foo) {
         $class = null;
         $time = SPACE;
         $hint = new CDiv(SPACE, $class);
         $hintTable = null;
         if (isset($h_data['services'][$name])) {
             $class = $h_data['services'][$name]['class'];
             $time = $h_data['services'][$name]['time'];
             $hintTable = new CTableInfo();
             $hintTable->setAttribute('style', 'width: auto;');
             if ($class == 'active') {
                 $hintTable->setHeader(_('Uptime'));
             } elseif ($class == 'inactive') {
                 $hintTable->setHeader(_('Downtime'));
             }
Exemplo n.º 24
0
function get_act_operations_form($action = null)
{
    $tblOper = new CTableInfo(S_NO_OPERATIONS_DEFINED);
    $tblOper->addOption('style', 'background-color: #CCC;');
    if (isset($_REQUEST['actionid']) && empty($action)) {
        $action = get_action_by_actionid($_REQUEST['actionid']);
    }
    $operations = get_request('operations', array());
    if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) {
        $eventsource = $action['eventsource'];
        $evaltype = $action['evaltype'];
        $esc_period = $action['esc_period'];
        /* prepate operations */
        $db_operations = DBselect('SELECT * ' . ' FROM operations' . ' WHERE actionid=' . $_REQUEST['actionid'] . ' ORDER BY esc_step_from,operationtype,object,operationid');
        while ($operation_data = DBfetch($db_operations)) {
            $operation_data = array('operationtype' => $operation_data['operationtype'], 'operationid' => $operation_data['operationid'], 'object' => $operation_data['object'], 'objectid' => $operation_data['objectid'], 'shortdata' => $operation_data['shortdata'], 'longdata' => $operation_data['longdata'], 'esc_period' => $operation_data['esc_period'], 'esc_step_from' => $operation_data['esc_step_from'], 'esc_step_to' => $operation_data['esc_step_to'], 'default_msg' => $operation_data['default_msg'], 'evaltype' => $operation_data['evaltype']);
            $operation_data['opconditions'] = array();
            $sql = 'SELECT * FROM opconditions WHERE operationid=' . $operation_data['operationid'];
            $db_opconds = DBselect($sql);
            while ($db_opcond = DBfetch($db_opconds)) {
                $operation_data['opconditions'][] = $db_opcond;
            }
            if (str_in_array($operation_data, $operations)) {
                continue;
            }
            array_push($operations, $operation_data);
        }
        unset($db_operations, $operation_data);
    } else {
        $eventsource = get_request('eventsource');
        $evaltype = get_request('evaltype');
        $esc_period = get_request('esc_period');
    }
    $esc_step_from = array();
    foreach ($operations as $key => $operation) {
        $esc_step_from[$key] = $operation['esc_step_from'];
    }
    array_multisort($esc_step_from, SORT_ASC, $operations);
    $tblOper->SetHeader(array(new CCheckBox('all_operations', null, 'CheckAll("' . S_ACTION . '","all_operations","g_operationid");'), isset($_REQUEST['escalation']) ? S_STEPS : null, S_DETAILS, isset($_REQUEST['escalation']) ? S_PERIOD . ' (' . S_SEC_SMALL . ')' : null, isset($_REQUEST['escalation']) ? S_DELAY : null, S_ACTION));
    $allowed_operations = get_operations_by_eventsource($eventsource);
    zbx_rksort($operations);
    $delay = count_operations_delay($operations, $esc_period);
    foreach ($operations as $id => $val) {
        if (!str_in_array($val['operationtype'], $allowed_operations)) {
            continue;
        }
        if (!isset($val['default_msg'])) {
            $val['default_msg'] = 0;
        }
        if (!isset($val['opconditions'])) {
            $val['opconditions'] = array();
        }
        $oper_details = new CSpan(get_operation_desc(SHORT_DESCRITION, $val));
        $oper_details->SetHint(nl2br(get_operation_desc(LONG_DESCRITION, $val)));
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($val['esc_step_from'] < 1) {
            $val['esc_step_from'] = 1;
        }
        if (isset($_REQUEST['escalation'])) {
            $esc_steps_txt = $val['esc_step_from'] . ' - ' . $val['esc_step_to'];
            $esc_period_txt = $val['esc_period'] ? $val['esc_period'] : S_DEFAULT;
            $esc_delay_txt = $delay[$val['esc_step_from']] ? convert_units($delay[$val['esc_step_from']], 'uptime') : S_AT_MOMENT;
        }
        $tblOper->addRow(array(new CCheckBox("g_operationid[]", 'no', null, $id), $esc_steps_txt, $oper_details, $esc_period_txt, $esc_delay_txt, new CButton('edit_operationid[' . $id . ']', S_EDIT)));
        $tblOper->addItem(new CVar('operations[' . $id . '][operationtype]', $val['operationtype']));
        $tblOper->addItem(new CVar('operations[' . $id . '][object]', $val['object']));
        $tblOper->addItem(new CVar('operations[' . $id . '][objectid]', $val['objectid']));
        $tblOper->addItem(new CVar('operations[' . $id . '][shortdata]', $val['shortdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][longdata]', $val['longdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_period]', $val['esc_period']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_from]', $val['esc_step_from']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_to]', $val['esc_step_to']));
        $tblOper->addItem(new CVar('operations[' . $id . '][default_msg]', $val['default_msg']));
        $tblOper->addItem(new CVar('operations[' . $id . '][evaltype]', $val['evaltype']));
        foreach ($val['opconditions'] as $opcondid => $opcond) {
            foreach ($opcond as $field => $value) {
                $tblOper->addItem(new CVar('operations[' . $id . '][opconditions][' . $opcondid . '][' . $field . ']', $value));
            }
        }
    }
    unset($operations);
    $tblOperFooter = new CTableInfo(null);
    $oper_buttons = array();
    if (!isset($_REQUEST['new_operation'])) {
        $oper_buttons[] = new CButton('new_operation', S_NEW);
    }
    if ($tblOper->ItemsCount() > 0) {
        $oper_buttons[] = new CButton('del_operation', S_DELETE_SELECTED);
    }
    $td = new CCol($oper_buttons);
    $td->addOption('colspan', isset($_REQUEST['escalation']) ? 6 : 3);
    $td->addOption('style', 'text-align: right;');
    $tblOperFooter->SetFooter($td);
    // end of condition list preparation
    return array($tblOper, $tblOperFooter);
}
Exemplo n.º 25
0
        $operation['mediatypeid'] = 0;
    }
    $details = new CSpan(get_operation_descr(SHORT_DESCRIPTION, $operation));
    $details->setHint(get_operation_descr(LONG_DESCRIPTION, $operation));
    if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS || $this->data['eventsource'] == EVENT_SOURCE_INTERNAL) {
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($operation['esc_step_from'] < 1) {
            $operation['esc_step_from'] = 1;
        }
        $esc_steps_txt = $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        // display N-N as N
        $esc_steps_txt = $operation['esc_step_from'] == $operation['esc_step_to'] ? $operation['esc_step_from'] : $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        $esc_period_txt = $operation['esc_period'] ? $operation['esc_period'] : _('Default');
        $esc_delay_txt = $delay[$operation['esc_step_from']] ? convert_units(array('value' => $delay[$operation['esc_step_from']], 'units' => 'uptime')) : _('Immediately');
        $operationRow = array($esc_steps_txt, $details, $esc_delay_txt, $esc_period_txt, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
    } else {
        $operationRow = array($details, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
    }
    $operationsTable->addRow($operationRow, null, 'operations_' . $operationid);
    $operation['opmessage_grp'] = isset($operation['opmessage_grp']) ? zbx_toHash($operation['opmessage_grp'], 'usrgrpid') : null;
    $operation['opmessage_usr'] = isset($operation['opmessage_usr']) ? zbx_toHash($operation['opmessage_usr'], 'userid') : null;
    $operation['opcommand_grp'] = isset($operation['opcommand_grp']) ? zbx_toHash($operation['opcommand_grp'], 'groupid') : null;
    $operation['opcommand_hst'] = isset($operation['opcommand_hst']) ? zbx_toHash($operation['opcommand_hst'], 'hostid') : null;
}
$footer = array();
if (empty($this->data['new_operation'])) {
    $footer[] = new CSubmit('new_operation', _('New'), null, 'link_menu');
}
$operationFormList->addRow(_('Action operations'), new CDiv(array($operationsTable, $footer), 'objectgroup inlineblock border_dotted ui-corner-all'));
Exemplo n.º 26
0
 protected function drawLegend()
 {
     $leftXShift = 20;
     $units = array('left' => 0, 'right' => 0);
     // draw item legend
     $legend = new CImageTextTable($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // item legend table header
     $row = array(array('text' => '', 'marginRight' => 5), array('text' => ''), array('text' => ''), array('text' => _('last'), 'align' => 1, 'fontsize' => 9), array('text' => _('min'), 'align' => 1, 'fontsize' => 9), array('text' => _('avg'), 'align' => 1, 'fontsize' => 9), array('text' => _('max'), 'align' => 1, 'fontsize' => 9));
     $legend->addRow($row);
     $rowNum = $legend->getNumRows();
     $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0;
     while ($i >= 0 && $i < $this->num) {
         $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
         switch ($this->items[$i]['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fncRealName = _('min');
                 break;
             case CALC_FNC_MAX:
                 $fncRealName = _('max');
                 break;
             case CALC_FNC_ALL:
                 $fncRealName = _('all');
                 break;
             case CALC_FNC_AVG:
             default:
                 $fncRealName = _('avg');
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         // draw color square
         if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
             $colorSquare = imagecreatetruecolor(11, 11);
         } else {
             $colorSquare = imagecreate(11, 11);
         }
         imagefill($colorSquare, 0, 0, $this->getColor($this->graphtheme['backgroundcolor'], 0));
         imagefilledrectangle($colorSquare, 0, 0, 10, 10, $color);
         imagerectangle($colorSquare, 0, 0, 10, 10, $this->getColor('Black'));
         // caption
         $itemCaption = $this->itemsHost ? $this->items[$i]['name_expanded'] : $this->items[$i]['hostname'] . NAME_DELIMITER . $this->items[$i]['name_expanded'];
         // draw legend of an item with data
         if (isset($data) && isset($data['min'])) {
             if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
                 $units['left'] = $this->items[$i]['units'];
             } else {
                 $units['right'] = $this->items[$i]['units'];
             }
             $legend->addCell($rowNum, array('image' => $colorSquare, 'marginRight' => 5));
             $legend->addCell($rowNum, array('text' => $itemCaption));
             $legend->addCell($rowNum, array('text' => '[' . $fncRealName . ']'));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => $this->getLastValue($i), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => min($data['min']), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => $data['avg_orig'], 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => max($data['max']), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
         } else {
             $legend->addCell($rowNum, array('image' => $colorSquare, 'marginRight' => 5));
             $legend->addCell($rowNum, array('text' => $itemCaption));
             $legend->addCell($rowNum, array('text' => '[ ' . _('no data') . ' ]'));
         }
         $rowNum++;
         if ($this->type == GRAPH_TYPE_STACKED) {
             $i--;
         } else {
             $i++;
         }
     }
     $legend->draw();
     // if graph is small, we are not drawing percent line and trigger legends
     if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) {
         return true;
     }
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // draw percentile
     if ($this->type == GRAPH_TYPE_NORMAL) {
         foreach ($this->percentile as $side => $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $percentile['percent'] = (double) $percentile['percent'];
                 $convertedUnit = convert_units(array('value' => $percentile['value'], 'units' => $units[$side]));
                 $legend->addCell($rowNum, array('text' => $percentile['percent'] . 'th percentile: ' . $convertedUnit . ' (' . $side . ')', ITEM_CONVERT_NO_UNITS));
                 if ($side == 'left') {
                     $color = $this->graphtheme['leftpercentilecolor'];
                 } else {
                     $color = $this->graphtheme['rightpercentilecolor'];
                 }
                 imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha'));
                 $rowNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $rowNum++;
     }
     $legend->draw();
 }
Exemplo n.º 27
0
function make_latest_data()
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    while ($db_app = DBfetch($db_applications)) {
        $db_items = DBselect('SELECT DISTINCT i.* ' . ' FROM items i,items_applications ia' . ' WHERE ia.applicationid=' . $db_app['applicationid'] . ' AND i.itemid=ia.itemid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . order_by('i.description,i.itemid,i.lastclock'));
        $app_rows = array();
        $item_cnt = 0;
        while ($db_item = DBfetch($db_items)) {
            $description = item_description($db_item);
            if (!zbx_empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) {
                continue;
            }
            ++$item_cnt;
            if (!uint_in_array($db_app['applicationid'], $_REQUEST['applications']) && !isset($show_all_apps)) {
                continue;
            }
            if (isset($db_item['lastclock'])) {
                $lastclock = date(S_DATE_FORMAT_YMDHMS, $db_item['lastclock']);
            } else {
                $lastclock = new CCol('-', 'center');
            }
            $lastvalue = format_lastvalue($db_item);
            if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && $db_item['value_type'] == 0 && $db_item['lastvalue'] - $db_item['prevvalue'] != 0) {
                if ($db_item['lastvalue'] - $db_item['prevvalue'] < 0) {
                    $change = convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                } else {
                    $change = '+' . convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                }
                $change = nbsp($change);
            } else {
                $change = new CCol('-', 'center');
            }
            if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
                $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid'], 'action');
            } else {
                $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid'], 'action');
            }
            array_push($app_rows, new CRow(array(is_show_all_nodes() ? SPACE : null, $_REQUEST['hostid'] > 0 ? NULL : SPACE, str_repeat(SPACE, 6) . $description, $lastclock, new CCol($lastvalue, $lastvalue == '-' ? 'center' : null), $change, $actions)));
        }
        if ($item_cnt > 0) {
            if (uint_in_array($db_app['applicationid'], $_REQUEST['applications']) || isset($show_all_apps)) {
                $link = new CLink(new CImg('images/general/opened.gif'), '?close=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            } else {
                $link = new CLink(new CImg('images/general/closed.gif'), '?open=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            }
            $col = new CCol(array($link, SPACE, bold($db_app['name']), SPACE . '(' . $item_cnt . SPACE . S_ITEMS . ')'));
            $col->setColSpan(5);
            $table->ShowRow(array(get_node_name_by_elid($db_app['hostid']), $_REQUEST['hostid'] > 0 ? NULL : $db_app['host'], $col));
            $any_app_exist = true;
            foreach ($app_rows as $row) {
                $table->ShowRow($row);
            }
        }
    }
}
Exemplo n.º 28
0
/**
 * Format item lastvalue depending on it's value type.
 *
 * @param array $item
 *
 * @return string
 */
function formatItemValueType(array $item)
{
    if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
        $value = convert_units($item['lastvalue'], $item['units']);
    } elseif ($item['value_type'] == ITEM_VALUE_TYPE_STR || $item['value_type'] == ITEM_VALUE_TYPE_TEXT || $item['value_type'] == ITEM_VALUE_TYPE_LOG) {
        $value = $item['lastvalue'];
        if (zbx_strlen($value) > 20) {
            $value = zbx_substr($value, 0, 20) . ' ...';
        }
    } else {
        $value = _('Unknown value type');
    }
    return $value;
}
Exemplo n.º 29
0
 protected function drawLegend()
 {
     $leftXShift = 20;
     $units = array('left' => 0, 'right' => 0);
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     $row = array(array('text' => ''), array('text' => ''), array('text' => S_LST_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MIN_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_AVG_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MAX_SMALL, 'align' => 1, 'fontsize' => 9));
     $legend->addRow($row);
     $colNum = $legend->getNumRows();
     $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0;
     while ($i >= 0 && $i < $this->num) {
         if ($this->items[$i]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
             $fnc_name = 'agr(' . $this->items[$i]['periods_cnt'] . ')';
             $color = $this->getColor('HistoryMinMax');
         } else {
             $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
             switch ($this->items[$i]['calc_fnc']) {
                 case CALC_FNC_MIN:
                     $fnc_name = S_MIN_SMALL;
                     break;
                 case CALC_FNC_MAX:
                     $fnc_name = S_MAX_SMALL;
                     break;
                 case CALC_FNC_ALL:
                     $fnc_name = S_ALL_SMALL;
                     break;
                 case CALC_FNC_AVG:
                 default:
                     $fnc_name = S_AVG_SMALL;
             }
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         if ($this->itemsHost) {
             $item_caption = $this->items[$i]['description'];
         } else {
             $item_caption = $this->items[$i]['host'] . ': ' . $this->items[$i]['description'];
         }
         if (isset($data) && isset($data['min'])) {
             if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
                 $units['left'] = $this->items[$i]['units'];
             } else {
                 $units['right'] = $this->items[$i]['units'];
             }
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[' . $fnc_name . ']'));
             $legend->addCell($colNum, array('text' => convert_units($this->getLastValue($i), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(min($data['min']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units($data['avg_orig'], $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(max($data['max']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
         } else {
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[ ' . S_NO_DATA_SMALL . ' ]'));
         }
         imagefilledrectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $color);
         imagerectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $this->getColor('Black'));
         $colNum++;
         if ($this->type == GRAPH_TYPE_STACKED) {
             $i--;
         } else {
             $i++;
         }
     }
     $legend->draw();
     // if graph is small, we are not drawing percent line and trigger legends
     if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) {
         return true;
     }
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw percentile
     if ($this->type == GRAPH_TYPE_NORMAL) {
         foreach ($this->percentile as $side => $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $percentile['percent'] = (double) $percentile['percent'];
                 $legend->addCell($colNum, array('text' => $percentile['percent'] . 'th percentile: ' . convert_units($percentile['value'], $units[$side]) . '  (' . $side . ')', ITEM_CONVERT_NO_UNITS));
                 if ($side == 'left') {
                     $color = $this->graphtheme['leftpercentilecolor'];
                 } else {
                     $color = $this->graphtheme['rightpercentilecolor'];
                 }
                 imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha'));
                 $colNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $colNum++;
     }
     $legend->draw();
 }
Exemplo n.º 30
0
 protected function drawLegend()
 {
     $shiftY = $this->shiftY + $this->shiftYLegend;
     $fontSize = 8;
     // check if host name will be displayed
     $displayHostName = count(array_unique(zbx_objectValues($this->items, 'hostname'))) > 1;
     // calculate function name X shift
     $functionNameXShift = 0;
     foreach ($this->items as $item) {
         $name = $displayHostName ? $item['hostname'] . ': ' . $item['name_expanded'] : $item['name_expanded'];
         $dims = imageTextSize($fontSize, 0, $name);
         if ($dims['width'] > $functionNameXShift) {
             $functionNameXShift = $dims['width'];
         }
     }
     // display items
     $i = 0;
     foreach ($this->items as $item) {
         $color = $this->getColor($item['color'], 0);
         // function name
         switch ($item['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fncName = 'min';
                 $fncRealName = _('min');
                 break;
             case CALC_FNC_MAX:
                 $fncName = 'max';
                 $fncRealName = _('max');
                 break;
             case CALC_FNC_LST:
                 $fncName = 'last';
                 $fncRealName = _('last');
                 break;
             case CALC_FNC_AVG:
             default:
                 $fncName = 'avg';
                 $fncRealName = _('avg');
         }
         if (isset($this->data[$item['itemid']][$item['calc_type']]) && isset($this->data[$item['itemid']][$item['calc_type']][$fncName])) {
             $dataValue = $this->data[$item['itemid']][$item['calc_type']][$fncName];
             $proc = $this->sum == 0 ? 0 : $dataValue * 100 / $this->sum;
             $strValue = sprintf(_('Value') . ': %s (' . (round($proc) != round($proc, 2) ? '%0.2f' : '%0.0f') . '%%)', convert_units(['value' => $dataValue, 'units' => $this->items[$i]['units']]), $proc);
             $str = '[' . $fncRealName . ']';
         } else {
             $strValue = _('Value: no data');
             $str = '[' . _('no data') . ']';
         }
         // item name
         imageText($this->im, $fontSize, 0, $this->shiftXleft + 15, $this->sizeY + $shiftY + 14 * $i + 5, $this->getColor($this->graphtheme['textcolor'], 0), $displayHostName ? $item['hostname'] . ': ' . $item['name_expanded'] : $item['name_expanded']);
         // function name
         imageText($this->im, $fontSize, 0, $this->shiftXleft + $functionNameXShift + 30, $this->sizeY + $shiftY + 14 * $i + 5, $this->getColor($this->graphtheme['textcolor'], 0), $str);
         // left square fill
         imagefilledrectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $color);
         // left square frame
         imagerectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $this->getColor('Black No Alpha'));
         $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 25;
         // right square fill
         imagefilledrectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $color);
         // right square frame
         imagerectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $this->GetColor('Black No Alpha'));
         // item value
         imagetext($this->im, $fontSize, 0, $shiftX + 5, $this->shiftY + 10 + 14 * $i + 10, $this->getColor($this->graphtheme['textcolor'], 0), $strValue);
         $i++;
     }
     if ($this->sizeY < 120) {
         return;
     }
 }