本文整理汇总了PHP中convert_units函数的典型用法代码示例。如果您正苦于以下问题:PHP convert_units函数的具体用法?PHP convert_units怎么用?PHP convert_units使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_units函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: drawSideValues
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'));
}
}
示例2: drawLegend
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;
}
}
示例3: get
//.........这里部分代码省略.........
$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);
}
示例4: zbx_date2str
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);
示例5: zbx_date2str
$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) {
示例6: discovery_check_type2str
$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);
示例7: getItemFunctionalValue
/**
* 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;
}
}
}
示例8: discovery_check_type2str
$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);
}
示例9: CSpan
$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'));
示例10: _zeT
$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';
示例11: check_values
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;
}
示例12: resolveMapLabelMacros
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;
}
示例13: format_lastvalue
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;
}
示例14: CCol
}
$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';
示例15: getItemListFormat
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;
}