if (!empty($this->data['eHTMLTree'])) {
     foreach ($this->data['eHTMLTree'] as $i => $e) {
         if (!isset($e['expression']['levelErrors'])) {
             $errorImg = '';
         } else {
             $allowedTesting = false;
             $errors = [];
             if (is_array($e['expression']['levelErrors'])) {
                 foreach ($e['expression']['levelErrors'] as $expVal => $errTxt) {
                     if ($errors) {
                         $errors[] = BR();
                     }
                     $errors[] = $expVal . ':' . $errTxt;
                 }
             }
             $errorImg = makeErrorIcon($errors);
         }
         // templated trigger
         if ($this->data['limited']) {
             // make all links inside inactive
             foreach ($e['list'] as &$obj) {
                 if (gettype($obj) == 'object' && get_class($obj) == 'CSpan' && $obj->getAttribute('class') == ZBX_STYLE_LINK_ACTION) {
                     $obj->removeAttribute('class');
                     $obj->onClick(null);
                 }
             }
             unset($obj);
         }
         $expressionTable->addRow(new CRow([!$this->data['limited'] ? (new CCheckBox('expr_target_single', $e['id']))->setChecked($i == 0)->onClick('check_target(this);') : null, $e['list'], !$this->data['limited'] ? (new CCol((new CButton(null, _('Remove')))->addClass(ZBX_STYLE_BTN_LINK)->onClick('javascript:' . ' if (confirm(' . CJs::encodeJson(_('Delete expression?')) . ')) {' . ' delete_expression("' . $e['id'] . '");' . ' document.forms["' . $triggersForm->getName() . '"].submit();' . ' }')))->addClass(ZBX_STYLE_NOWRAP) : null, $errorImg]));
     }
 } else {
         $depTrigger = $this->data['dependencyTriggers'][$dependency['triggerid']];
         $depTriggerDescription = CHtml::encode(implode(', ', zbx_objectValues($depTrigger['hosts'], 'name')) . NAME_DELIMITER . $depTrigger['description']);
         if ($depTrigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
             $triggerDependencies[] = (new CLink($depTriggerDescription, 'triggers.php?form=update&triggerid=' . $depTrigger['triggerid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(triggerIndicatorStyle($depTrigger['status']));
         } else {
             $triggerDependencies[] = $depTriggerDescription;
         }
         $triggerDependencies[] = BR();
     }
     array_pop($triggerDependencies);
     $description = array_merge($description, [(new CDiv($triggerDependencies))->addClass('dependencies')]);
 }
 // info
 if ($this->data['showInfoColumn']) {
     if ($trigger['status'] == TRIGGER_STATUS_ENABLED && $trigger['error']) {
         $info = makeErrorIcon($trigger['error']);
     } else {
         $info = '';
     }
 } else {
     $info = null;
 }
 // status
 $status = (new CLink(triggerIndicator($trigger['status'], $trigger['state']), 'triggers.php?' . 'action=' . ($trigger['status'] == TRIGGER_STATUS_DISABLED ? 'trigger.massenable' : 'trigger.massdisable') . '&hostid=' . $this->data['hostid'] . '&g_triggerid=' . $triggerid))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state']))->addSID();
 // hosts
 $hosts = null;
 if ($this->data['hostid'] == 0) {
     foreach ($trigger['hosts'] as $hostid => $host) {
         if (!empty($hosts)) {
             $hosts[] = ', ';
         }
Ejemplo n.º 3
0
function makeActionHints($alerts, $mediatypes, $users, $status)
{
    $table = (new CTableInfo())->setHeader([_('Time'), _('User'), _('Details'), _('Status'), _('Info')]);
    $popup_rows = 0;
    foreach ($alerts as $alert) {
        switch ($status) {
            case ALERT_STATUS_NOT_SENT:
                $status_str = (new CSpan(_('In progress')))->addClass(ZBX_STYLE_YELLOW);
                break;
            case ALERT_STATUS_SENT:
                $status_str = (new CSpan($alert['alerttype'] == ALERT_TYPE_COMMAND ? _('Executed') : _('Sent')))->addClass(ZBX_STYLE_GREEN);
                break;
            default:
                $status_str = (new CSpan(_('Not sent')))->addClass(ZBX_STYLE_RED);
        }
        switch ($alert['alerttype']) {
            case ALERT_TYPE_MESSAGE:
                $user = array_key_exists($alert['userid'], $users) ? getUserFullname($users[$alert['userid']]) : '';
                $message = array_key_exists($alert['mediatypeid'], $mediatypes) ? $mediatypes[$alert['mediatypeid']]['description'] : '';
                break;
            case ALERT_TYPE_COMMAND:
                $user = '';
                $message = [bold(_('Command') . NAME_DELIMITER), BR(), zbx_nl2br($alert['message'])];
                break;
            default:
                $user = '';
                $message = '';
        }
        $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']), $user, $message, $status_str, $alert['error'] === '' ? '' : makeErrorIcon($alert['error'])]);
        if (++$popup_rows == ZBX_WIDGET_ROWS) {
            break;
        }
    }
    return $table;
}
// create form
$auditForm = (new CForm('get'))->setName('auditForm');
// create table
$auditTable = (new CTableInfo())->setHeader([_('Time'), _('Action'), _('Type'), _('Recipient(s)'), _('Message'), _('Status'), _('Info')]);
foreach ($this->data['alerts'] as $alert) {
    $mediatype = array_pop($alert['mediatypes']);
    if ($alert['status'] == ALERT_STATUS_SENT) {
        $status = $alert['alerttype'] == ALERT_TYPE_MESSAGE ? (new CSpan(_('Sent')))->addClass(ZBX_STYLE_GREEN) : (new CSpan(_('Executed')))->addClass(ZBX_STYLE_GREEN);
    } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) {
        $status = (new CSpan([_('In progress') . ':', BR(), _n('%1$s retry left', '%1$s retries left', ALERT_MAX_RETRIES - $alert['retries'])]))->addClass(ZBX_STYLE_YELLOW);
    } else {
        $status = (new CSpan(_('Not sent')))->addClass(ZBX_STYLE_RED);
    }
    $message = $alert['alerttype'] == ALERT_TYPE_MESSAGE ? [bold(_('Subject') . ':'), BR(), $alert['subject'], BR(), BR(), bold(_('Message') . ':'), BR(), zbx_nl2br($alert['message'])] : [bold(_('Command') . ':'), BR(), zbx_nl2br($alert['message'])];
    if (zbx_empty($alert['error'])) {
        $info = '';
    } else {
        $info = makeErrorIcon($alert['error']);
    }
    $recipient = isset($alert['userid']) && $alert['userid'] ? [bold(getUserFullname($this->data['users'][$alert['userid']])), BR(), $alert['sendto']] : $alert['sendto'];
    $auditTable->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']), $this->data['actions'][$alert['actionid']]['name'], $mediatype ? $mediatype['description'] : '', $recipient, $message, $status, $info]);
}
// append table to form
$auditForm->addItem([$auditTable, $this->data['paging']]);
// append navigation bar js
$objData = ['id' => 'timeline_1', 'domid' => 'events', 'loadSBox' => 0, 'loadImage' => 0, 'loadScroll' => 1, 'dynamic' => 0, 'mainObject' => 1, 'periodFixed' => CProfile::get('web.auditacts.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD];
zbx_add_post_js('timeControl.addObject("events", ' . zbx_jsvalue($data['timeline']) . ', ' . zbx_jsvalue($objData) . ');');
zbx_add_post_js('timeControl.processObjects();');
// append form to widget
$auditWidget->addItem($auditForm);
return $auditWidget;
Ejemplo n.º 5
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $sortfield = 'clock';
     $sortorder = ZBX_SORT_DOWN;
     switch ($this->screenitem['sort_triggers']) {
         case SCREEN_SORT_TRIGGERS_TIME_ASC:
             $sortfield = 'clock';
             $sortorder = ZBX_SORT_UP;
             break;
         case SCREEN_SORT_TRIGGERS_TIME_DESC:
             $sortfield = 'clock';
             $sortorder = ZBX_SORT_DOWN;
             break;
         case SCREEN_SORT_TRIGGERS_TYPE_ASC:
             $sortfield = 'description';
             $sortorder = ZBX_SORT_UP;
             break;
         case SCREEN_SORT_TRIGGERS_TYPE_DESC:
             $sortfield = 'description';
             $sortorder = ZBX_SORT_DOWN;
             break;
         case SCREEN_SORT_TRIGGERS_STATUS_ASC:
             $sortfield = 'status';
             $sortorder = ZBX_SORT_UP;
             break;
         case SCREEN_SORT_TRIGGERS_STATUS_DESC:
             $sortfield = 'status';
             $sortorder = ZBX_SORT_DOWN;
             break;
         case SCREEN_SORT_TRIGGERS_RECIPIENT_ASC:
             $sortfield = 'sendto';
             $sortorder = ZBX_SORT_UP;
             break;
         case SCREEN_SORT_TRIGGERS_RECIPIENT_DESC:
             $sortfield = 'sendto';
             $sortorder = ZBX_SORT_DOWN;
             break;
     }
     $sql = 'SELECT a.alertid,a.clock,a.sendto,a.subject,a.message,a.status,a.retries,a.error,' . 'a.userid,a.actionid,a.mediatypeid,mt.description' . ' FROM events e,alerts a' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE e.eventid=a.eventid' . ' AND alerttype=' . ALERT_TYPE_MESSAGE;
     if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) {
         $userid = CWebUser::$data['userid'];
         $userGroups = getUserGroupsByUserId($userid);
         $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')';
     }
     $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder;
     $alerts = DBfetchArray(DBselect($sql, $this->screenitem['elements']));
     order_result($alerts, $sortfield, $sortorder);
     $userids = [];
     foreach ($alerts as $alert) {
         if ($alert['userid'] != 0) {
             $userids[$alert['userid']] = true;
         }
     }
     if ($userids) {
         $dbUsers = API::User()->get(['output' => ['userid', 'alias', 'name', 'surname'], 'userids' => array_keys($userids), 'preservekeys' => true]);
     }
     // indicator of sort field
     $sort_div = (new CSpan())->addClass($sortorder === ZBX_SORT_DOWN ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP);
     // create alert table
     $table = (new CTableInfo())->setHeader([$sortfield === 'clock' ? ['Time', $sort_div] : _('Time'), _('Action'), $sortfield === 'description' ? [_('Type'), $sort_div] : _('Type'), $sortfield === 'sendto' ? [_('Recipient(s)'), $sort_div] : _('Recipient(s)'), _('Message'), $sortfield === 'status' ? [_('Status'), $sort_div] : _('Status'), _('Info')]);
     $actions = API::Action()->get(['output' => ['actionid', 'name'], 'actionids' => array_unique(zbx_objectValues($alerts, 'actionid')), 'preservekeys' => true]);
     foreach ($alerts as $alert) {
         if ($alert['status'] == ALERT_STATUS_SENT) {
             $status = (new CSpan(_('Sent')))->addClass(ZBX_STYLE_GREEN);
         } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) {
             $status = (new CSpan([_('In progress') . ':', BR(), _n('%1$s retry left', '%1$s retries left', ALERT_MAX_RETRIES - $alert['retries'])]))->addClass(ZBX_STYLE_YELLOW);
         } else {
             $status = (new CSpan(_('Not sent')))->addClass(ZBX_STYLE_RED);
         }
         $recipient = $alert['userid'] != 0 ? [bold(getUserFullname($dbUsers[$alert['userid']])), BR(), $alert['sendto']] : $alert['sendto'];
         $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']), $actions[$alert['actionid']]['name'], $alert['mediatypeid'] == 0 ? '' : $alert['description'], $recipient, [bold($alert['subject']), BR(), BR(), zbx_nl2br($alert['message'])], $status, $alert['error'] === '' ? '' : makeErrorIcon($alert['error'])]);
     }
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput((new CUiWidget(uniqid(), [$table, $footer]))->setHeader(_('Action log')));
 }
$discoveryTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_items'))->onClick("checkAll('" . $discoveryForm->getName() . "', 'all_items', 'g_hostdruleid');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('Items'), _('Triggers'), _('Graphs'), $data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL ? _('Hosts') : null, make_sorting_header(_('Key'), 'key_', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Interval'), 'delay', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Type'), 'type', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder']), $data['showInfoColumn'] ? _('Info') : null]);
foreach ($data['discoveries'] as $discovery) {
    // description
    $description = [];
    if ($discovery['templateid']) {
        $dbTemplate = get_realhost_by_itemid($discovery['templateid']);
        $description[] = (new CLink($dbTemplate['name'], '?hostid=' . $dbTemplate['hostid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
        $description[] = NAME_DELIMITER;
    }
    $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']);
    // status
    $status = (new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&action=' . ($discovery['status'] == ITEM_STATUS_DISABLED ? 'discoveryrule.massenable' : 'discoveryrule.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($discovery['status'], $discovery['state']))->addSID();
    // info
    if ($data['showInfoColumn']) {
        if ($discovery['status'] == ITEM_STATUS_ACTIVE && !zbx_empty($discovery['error'])) {
            $info = makeErrorIcon($discovery['error']);
        } else {
            $info = '';
        }
    } else {
        $info = null;
    }
    // host prototype link
    $hostPrototypeLink = null;
    if ($data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        $hostPrototypeLink = [new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['hostPrototypes'])];
    }
    $discoveryTable->addRow([new CCheckBox('g_hostdruleid[' . $discovery['itemid'] . ']', $discovery['itemid']), $description, [new CLink(_('Item prototypes'), 'disc_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['items'])], [new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['triggers'])], [new CLink(_('Graph prototypes'), 'graphs.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['graphs'])], $hostPrototypeLink, $discovery['key_'], $discovery['delay'] === '' ? '' : convertUnitsS($discovery['delay']), item_type2str($discovery['type']), $status, $info]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
// append table to form
Ejemplo n.º 7
0
 $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'] . ']', $item['itemid']))->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);
 }
 $state_css = $item['state'] == ITEM_STATE_NOTSUPPORTED ? ZBX_STYLE_GREY : null;
 $host = $hosts[$item['hostid']];
 if ($filter['showDetails']) {
     // item key
     $itemKey = $item['type'] == ITEM_TYPE_HTTPTEST || $item['flags'] == ZBX_FLAG_DISCOVERY_CREATED ? (new CSpan($item['key_expanded']))->addClass(ZBX_STYLE_GREEN) : (new CLink($item['key_expanded'], 'items.php?form=update&itemid=' . $item['itemid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREEN);
     // info
     if ($item['status'] == ITEM_STATUS_ACTIVE && $item['error'] !== '') {
         $info = makeErrorIcon($item['error']);
     } else {
         $info = '';
     }
     // trend value
     if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
         $trendValue = $config['hk_trends_global'] ? $config['hk_trends'] : $item['trends'];
     } else {
         $trendValue = UNKNOWN_VALUE;
     }
     $row = new CRow(['', $checkbox, $hostColumn, (new CCol([$item['name_expanded'], BR(), $itemKey]))->addClass($state_css), (new CCol($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER ? UNKNOWN_VALUE : $item['delay']))->addClass($state_css), (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css), (new CCol($trendValue))->addClass($state_css), (new CCol(item_type2str($item['type'])))->addClass($state_css), (new CCol($lastClock))->addClass($state_css), (new CCol($lastValue))->addClass($state_css), (new CCol($change))->addClass($state_css), $actions, $info]);
 } else {
     $row = new CRow(['', $checkbox, $hostColumn, (new CCol($item['name_expanded']))->addClass($state_css), (new CCol($lastClock))->addClass($state_css), (new CCol($lastValue))->addClass($state_css), (new CCol($change))->addClass($state_css), $actions]);
 }
 $hosts[$item['hostid']]['item_cnt']++;
 $tab_rows[$item['hostid']][] = $row;
$httpTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_httptests'))->onClick("checkAll('" . $httpForm->getName() . "', 'all_httptests', 'group_httptestid');")))->addClass(ZBX_STYLE_CELL_WIDTH), $this->data['hostid'] == 0 ? make_sorting_header(_('Host'), 'hostname', $this->data['sort'], $this->data['sortorder']) : null, make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('Number of steps'), _('Update interval'), _('Attempts'), _('Authentication'), _('HTTP proxy'), _('Application'), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder']), $this->data['showInfoColumn'] ? _('Info') : null]);
$httpTestsLastData = $this->data['httpTestsLastData'];
$httpTests = $this->data['httpTests'];
foreach ($httpTests as $httpTestId => $httpTest) {
    $name = [];
    if (isset($this->data['parentTemplates'][$httpTestId])) {
        $template = $this->data['parentTemplates'][$httpTestId];
        $name[] = (new CLink($template['name'], '?groupid=0&hostid=' . $template['id']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
        $name[] = NAME_DELIMITER;
    }
    $name[] = new CLink($httpTest['name'], '?form=update' . '&httptestid=' . $httpTestId . '&hostid=' . $httpTest['hostid']);
    if ($this->data['showInfoColumn']) {
        if ($httpTest['status'] == HTTPTEST_STATUS_ACTIVE && isset($httpTestsLastData[$httpTestId]) && $httpTestsLastData[$httpTestId]['lastfailedstep']) {
            $lastData = $httpTestsLastData[$httpTestId];
            $failedStep = $lastData['failedstep'];
            $errorMessage = $failedStep ? _s('Step "%1$s" [%2$s of %3$s] failed: %4$s', $failedStep['name'], $failedStep['no'], $httpTest['stepscnt'], $lastData['error'] === null ? _('Unknown error') : $lastData['error']) : _s('Unknown step failed: %1$s', $lastData['error']);
            $infoIcon = makeErrorIcon($errorMessage);
        } else {
            $infoIcon = '';
        }
    } else {
        $infoIcon = null;
    }
    $httpTable->addRow([new CCheckBox('group_httptestid[' . $httpTest['httptestid'] . ']', $httpTest['httptestid']), $this->data['hostid'] > 0 ? null : $httpTest['hostname'], $name, $httpTest['stepscnt'], convertUnitsS($httpTest['delay']), $httpTest['retries'], httptest_authentications($httpTest['authentication']), $httpTest['http_proxy'] !== '' ? _('Yes') : _('No'), $httpTest['applicationid'] != 0 ? $httpTest['application_name'] : '', (new CLink(httptest_status2str($httpTest['status']), '?group_httptestid[]=' . $httpTest['httptestid'] . '&hostid=' . $httpTest['hostid'] . '&action=' . ($httpTest['status'] == HTTPTEST_STATUS_DISABLED ? 'httptest.massenable' : 'httptest.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(httptest_status2style($httpTest['status']))->addSID(), $infoIcon]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
// append table to form
$httpForm->addItem([$httpTable, $this->data['paging'], new CActionButtonList('action', 'group_httptestid', ['httptest.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected web scenarios?')], 'httptest.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected web scenarios?')], 'httptest.massclearhistory' => ['name' => _('Clear history'), 'confirm' => _('Delete history of selected web scenarios?')], 'httptest.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected web scenarios?')]], $this->data['hostid'])]);
// append form to widget
$widget->addItem($httpForm);
return $widget;