Esempio n. 1
0
    }
    // step response time
    $respTimeItem = $httpStepItemsByType[HTTPSTEP_ITEM_TYPE_TIME];
    if (!$status['afterError'] && isset($itemHistory[$respTimeItem['itemid']]) && $itemHistory[$respTimeItem['itemid']][0]['value'] > 0) {
        $respTime = formatHistoryValue($itemHistory[$respTimeItem['itemid']][0]['value'], $respTimeItem);
    } else {
        $respTime = UNKNOWN_VALUE;
    }
    // step response code
    $respItem = $httpStepItemsByType[HTTPSTEP_ITEM_TYPE_RSPCODE];
    if (!$status['afterError'] && isset($itemHistory[$respItem['itemid']]) && $itemHistory[$respItem['itemid']][0]['value'] > 0) {
        $resp = formatHistoryValue($itemHistory[$respItem['itemid']][0]['value'], $respItem);
    } else {
        $resp = UNKNOWN_VALUE;
    }
    $httpdetailsTable->addRow(array(CMacrosResolverHelper::resolveHttpTestName($httpTest['hostid'], $httpstep_data['name']), $speed, $respTime, $resp, new CSpan($status['msg'], $status['style'])));
}
if (!isset($httpTestData['lastfailedstep'])) {
    $status['msg'] = _('Never executed');
    $status['style'] = 'unknown';
} elseif ($httpTestData['lastfailedstep'] != 0) {
    $status['msg'] = $httpTestData['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httpTestData['error']);
    $status['style'] = 'disabled';
} else {
    $status['msg'] = _('OK');
    $status['style'] = 'enabled';
}
$httpdetailsTable->addRow(array(bold(_('TOTAL')), SPACE, bold($totalTime['value'] ? formatHistoryValue($totalTime['value'], $totalTime) : UNKNOWN_VALUE), SPACE, new CSpan($status['msg'], $status['style'] . ' bold')));
$httpdetailsWidget->addItem($httpdetailsTable);
$httpdetailsWidget->show();
echo SBR;
Esempio n. 2
0
if (!check_fields($fields)) {
    exit;
}
if ($httptestid = getRequest('httptestid', false)) {
    if (!API::HttpTest()->isReadable(array($_REQUEST['httptestid']))) {
        access_deny();
    }
    $color = array('current' => 0, 0 => array('next' => '1'), 1 => array('color' => 'Red', 'next' => '2'), 2 => array('color' => 'Dark Green', 'next' => '3'), 3 => array('color' => 'Blue', 'next' => '4'), 4 => array('color' => 'Dark Yellow', 'next' => '5'), 5 => array('color' => 'Cyan', 'next' => '6'), 6 => array('color' => 'Gray', 'next' => '7'), 7 => array('color' => 'Dark Red', 'next' => '8'), 8 => array('color' => 'Green', 'next' => '9'), 9 => array('color' => 'Dark Blue', 'next' => '10'), 10 => array('color' => 'Yellow', 'next' => '11'), 11 => array('color' => 'Black', 'next' => '1'));
    $items = array();
    $dbItems = DBselect('SELECT i.itemid' . ' FROM httpstepitem hi,items i,httpstep hs' . ' WHERE i.itemid=hi.itemid' . ' AND hs.httptestid=' . zbx_dbstr($httptestid) . ' AND hs.httpstepid=hi.httpstepid' . ' AND hi.type=' . zbx_dbstr(getRequest('http_item_type', HTTPSTEP_ITEM_TYPE_TIME)) . ' ORDER BY hs.no DESC');
    while ($item = DBfetch($dbItems)) {
        $itemColor = $color[$color['current'] = $color[$color['current']]['next']]['color'];
        $items[] = array('itemid' => $item['itemid'], 'color' => $itemColor);
    }
    $httpTest = get_httptest_by_httptestid($httptestid);
    $name = CMacrosResolverHelper::resolveHttpTestName($httpTest['hostid'], $httpTest['name']);
} elseif ($items = getRequest('items', array())) {
    asort_by_key($items, 'sortorder');
    $dbItems = API::Item()->get(array('itemids' => zbx_objectValues($items, 'itemid'), 'output' => array('itemid'), 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_CREATED)), 'webitems' => true, 'preservekeys' => true));
    foreach ($items as $item) {
        if (!isset($dbItems[$item['itemid']])) {
            access_deny();
        }
    }
    $name = getRequest('name', '');
} else {
    show_error_message(_('No items defined.'));
    exit;
}
/*
 * Display
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $this->dataId = 'httptest_details';
     $httptest = API::HttpTest()->get(['output' => ['httptestid', 'name', 'hostid'], 'selectSteps' => ['httpstepid', 'name', 'no'], 'httptestids' => $this->profileIdx2, 'preservekeys' => true]);
     $httptest = reset($httptest);
     if (!$httptest) {
         $messages = [['type' => 'error', 'message' => _('No permissions to referred object or it does not exist!')]];
         return $this->getOutput(makeMessageBox(false, $messages, null, false, false));
     }
     $httptest['lastfailedstep'] = 0;
     $httptest['error'] = '';
     // fetch http test execution data
     $httptest_data = Manager::HttpTest()->getLastData([$httptest['httptestid']]);
     if ($httptest_data) {
         $httptest_data = reset($httptest_data);
     }
     // fetch HTTP step items
     $items = DBfetchArray(DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httptest['httptestid'])));
     $step_items = [];
     foreach ($items as $item) {
         $step_items[$item['httpstepid']][$item['type']] = $item;
     }
     // fetch HTTP item history
     $item_history = Manager::History()->getLast($items);
     $table = (new CTableInfo())->setHeader([_('Step'), _('Speed'), _('Response time'), _('Response code'), _('Status')]);
     $total_time = ['value' => 0, 'value_type' => null, 'valuemapid' => null, 'units' => null];
     order_result($httptest['steps'], 'no');
     foreach ($httptest['steps'] as $step_data) {
         $items_by_type = $step_items[$step_data['httpstepid']];
         $status['msg'] = _('OK');
         $status['style'] = ZBX_STYLE_GREEN;
         $status['afterError'] = false;
         if (!array_key_exists('lastfailedstep', $httptest_data)) {
             $status['msg'] = _('Never executed');
             $status['style'] = ZBX_STYLE_GREY;
         } elseif ($httptest_data['lastfailedstep'] != 0) {
             if ($httptest_data['lastfailedstep'] == $step_data['no']) {
                 $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']);
                 $status['style'] = ZBX_STYLE_RED;
             } elseif ($httptest_data['lastfailedstep'] < $step_data['no']) {
                 $status['msg'] = _('Unknown');
                 $status['style'] = ZBX_STYLE_GREY;
                 $status['afterError'] = true;
             }
         }
         foreach ($items_by_type as &$item) {
             // Calculate the total time it took to execute the scenario.
             // Skip steps that come after a failed step.
             if (!$status['afterError'] && $item['type'] == HTTPSTEP_ITEM_TYPE_TIME) {
                 $total_time['value_type'] = $item['value_type'];
                 $total_time['valuemapid'] = $item['valuemapid'];
                 $total_time['units'] = $item['units'];
                 if (array_key_exists($item['itemid'], $item_history)) {
                     $history = $item_history[$item['itemid']][0];
                     $total_time['value'] += $history['value'];
                 }
             }
         }
         unset($item);
         // step speed
         $speed_item = $items_by_type[HTTPSTEP_ITEM_TYPE_IN];
         if (!$status['afterError'] && array_key_exists($speed_item['itemid'], $item_history) && $item_history[$speed_item['itemid']][0]['value'] > 0) {
             $speed = formatHistoryValue($item_history[$speed_item['itemid']][0]['value'], $speed_item);
         } else {
             $speed = UNKNOWN_VALUE;
         }
         // step response time
         $resptime_item = $items_by_type[HTTPSTEP_ITEM_TYPE_TIME];
         if (!$status['afterError'] && array_key_exists($resptime_item['itemid'], $item_history) && $item_history[$resptime_item['itemid']][0]['value'] > 0) {
             $resp_time = formatHistoryValue($item_history[$resptime_item['itemid']][0]['value'], $resptime_item);
         } else {
             $resp_time = UNKNOWN_VALUE;
         }
         // step response code
         $resp_item = $items_by_type[HTTPSTEP_ITEM_TYPE_RSPCODE];
         if (!$status['afterError'] && array_key_exists($resp_item['itemid'], $item_history) && $item_history[$resp_item['itemid']][0]['value'] > 0) {
             $resp = formatHistoryValue($item_history[$resp_item['itemid']][0]['value'], $resp_item);
         } else {
             $resp = UNKNOWN_VALUE;
         }
         $table->addRow([CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $step_data['name']), $speed, $resp_time, $resp, (new CSpan($status['msg']))->addClass($status['style'])]);
     }
     if (!array_key_exists('lastfailedstep', $httptest_data)) {
         $status['msg'] = _('Never executed');
         $status['style'] = ZBX_STYLE_GREY;
     } elseif ($httptest_data['lastfailedstep'] != 0) {
         $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']);
         $status['style'] = ZBX_STYLE_RED;
     } else {
         $status['msg'] = _('OK');
         $status['style'] = ZBX_STYLE_GREEN;
     }
     $table->addRow([bold(_('TOTAL')), '', bold($total_time['value'] ? formatHistoryValue($total_time['value'], $total_time) : UNKNOWN_VALUE), '', (new CSpan($status['msg']))->addClass($status['style'])]);
     return $this->getOutput($table);
 }