本文整理汇总了PHP中API::Alert方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Alert方法的具体用法?PHP API::Alert怎么用?PHP API::Alert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Alert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array_unshift
$wd = $wd == 0 ? 6 : $wd - 1;
$minTime = $time - $wd * SEC_PER_DAY;
$dateFormat = DATE_TIME_FORMAT;
array_unshift($header, _('From'), _('Till'));
$max = $year == $currentYear ? date('W') - 1 : 52;
for ($i = 0; $i <= $max; $i++) {
$intervals[strtotime('+' . $i . ' week', $minTime)] = strtotime('+' . ($i + 1) . ' week', $minTime);
}
break;
}
// time till
$maxTime = $year == $currentYear ? time() : mktime(0, 0, 0, 1, 1, $year + 1);
// fetch alerts
$alerts = [];
foreach (eventSourceObjects() as $sourceObject) {
$alerts = array_merge($alerts, API::Alert()->get(['output' => ['mediatypeid', 'userid', 'clock'], 'eventsource' => $sourceObject['source'], 'eventobject' => $sourceObject['object'], 'mediatypeids' => getRequest('media_type') ? getRequest('media_type') : null, 'time_from' => $minTime, 'time_till' => $maxTime]));
}
// sort alerts in chronological order so we could easily iterate through them later
CArrayHelper::sort($alerts, ['clock']);
$table->setHeader($header);
foreach ($intervals as $from => $till) {
// interval start
$row = [zbx_date2str($dateFormat, $from)];
// interval end, displayed only for week intervals
if ($period == 'weekly') {
$row[] = zbx_date2str($dateFormat, min($till, time()));
}
// counting alert count for each user and media type
$summary = [];
foreach ($users as $userid) {
$summary[$userid] = [];
示例2: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$eventIds = array_keys($result);
// adding hosts
if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
// trigger events
if ($options['object'] == EVENT_OBJECT_TRIGGER) {
$query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,functions f,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source']));
} elseif ($options['object'] == EVENT_OBJECT_ITEM || $options['object'] == EVENT_OBJECT_LLDRULE) {
$query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source']));
}
$relationMap = new CRelationMap();
while ($relation = DBfetch($query)) {
$relationMap->addRelation($relation['eventid'], $relation['hostid']);
}
$hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $hosts, 'hosts');
}
// adding the related object
if ($options['selectRelatedObject'] !== null && $options['selectRelatedObject'] != API_OUTPUT_COUNT && $options['object'] != EVENT_OBJECT_AUTOREGHOST) {
$relationMap = new CRelationMap();
foreach ($result as $event) {
$relationMap->addRelation($event['eventid'], $event['objectid']);
}
switch ($options['object']) {
case EVENT_OBJECT_TRIGGER:
$api = API::Trigger();
break;
case EVENT_OBJECT_DHOST:
$api = API::DHost();
break;
case EVENT_OBJECT_DSERVICE:
$api = API::DService();
break;
case EVENT_OBJECT_ITEM:
$api = API::Item();
break;
case EVENT_OBJECT_LLDRULE:
$api = API::DiscoveryRule();
break;
}
$objects = $api->get(array('output' => $options['selectRelatedObject'], $api->pkOption() => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapOne($result, $objects, 'relatedObject');
}
// adding alerts
if ($options['select_alerts'] !== null && $options['select_alerts'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'eventid', 'alertid', 'alerts');
$alerts = API::Alert()->get(array('output' => $options['select_alerts'], 'selectMediatypes' => API_OUTPUT_EXTEND, 'alertids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN));
$result = $relationMap->mapMany($result, $alerts, 'alerts');
}
// adding acknowledges
if ($options['select_acknowledges'] !== null) {
if ($options['select_acknowledges'] != API_OUTPUT_COUNT) {
// create the base query
$sqlParts = API::getApiService()->createSelectQueryParts('acknowledges', 'a', array('output' => $this->outputExtend($options['select_acknowledges'], array('acknowledgeid', 'eventid', 'clock')), 'filter' => array('eventid' => $eventIds)));
$sqlParts['order'][] = 'a.clock DESC';
// if the user data is requested via extended output or specified fields, join the users table
$userFields = array('alias', 'name', 'surname');
$requestUserData = array();
foreach ($userFields as $userField) {
if ($this->outputIsRequested($userField, $options['select_acknowledges'])) {
$requestUserData[] = $userField;
}
}
if ($requestUserData) {
foreach ($requestUserData as $userField) {
$sqlParts = $this->addQuerySelect('u.' . $userField, $sqlParts);
}
$sqlParts['from'][] = 'users u';
$sqlParts['where'][] = 'a.userid=u.userid';
}
$acknowledges = DBFetchArrayAssoc(DBselect($this->createSelectQueryFromParts($sqlParts)), 'acknowledgeid');
$relationMap = $this->createRelationMap($acknowledges, 'eventid', 'acknowledgeid');
$acknowledges = $this->unsetExtraFields($acknowledges, array('eventid', 'acknowledgeid', 'clock'), $options['select_acknowledges']);
$result = $relationMap->mapMany($result, $acknowledges, 'acknowledges');
} else {
$acknowledges = DBFetchArrayAssoc(DBselect('SELECT COUNT(a.acknowledgeid) AS rowscount,a.eventid' . ' FROM acknowledges a' . ' WHERE ' . dbConditionInt('a.eventid', $eventIds) . ' GROUP BY a.eventid'), 'eventid');
foreach ($result as &$event) {
if (isset($acknowledges[$event['eventid']])) {
$event['acknowledges'] = $acknowledges[$event['eventid']]['rowscount'];
} else {
$event['acknowledges'] = 0;
}
}
unset($event);
}
}
return $result;
}
示例3: array
$till = $from + $effectivePeriod;
$user = null;
$queryData = true;
$firstAlert = null;
if ($data['alias']) {
$user = API::User()->get(array('output' => array('userid'), 'filter' => array('alias' => $data['alias'])));
if ($user) {
$user = reset($user);
} else {
$queryData = false;
}
}
// fetch alerts for different objects and sources and combine them in a single stream
if ($queryData) {
foreach (eventSourceObjects() as $eventSource) {
$data['alerts'] = array_merge($data['alerts'], API::Alert()->get(array('output' => API_OUTPUT_EXTEND, 'selectMediatypes' => API_OUTPUT_EXTEND, 'userids' => $data['alias'] ? $user['userid'] : null, 'time_from' => $from, 'time_till' => $till, 'eventsource' => $eventSource['source'], 'eventobject' => $eventSource['object'], 'limit' => $config['search_limit'] + 1)));
}
CArrayHelper::sort($data['alerts'], array(array('field' => 'alertid', 'order' => ZBX_SORT_DOWN)));
$data['alerts'] = array_slice($data['alerts'], 0, $config['search_limit'] + 1);
// get first alert
if ($user) {
$firstAlert = DBfetch(DBselect('SELECT MIN(a.clock) AS clock' . ' FROM alerts a' . ' WHERE a.userid=' . zbx_dbstr($user['userid'])));
}
}
// padding
$data['paging'] = getPagingLine($data['alerts']);
// timeline
$data['timeline'] = array('period' => $effectivePeriod, 'starttime' => date(TIMESTAMP_FORMAT, $firstAlert ? $firstAlert['clock'] : ZBX_MAX_PERIOD), 'usertime' => isset($data['stime']) ? date(TIMESTAMP_FORMAT, zbxDateToTime($data['stime']) + $effectivePeriod) : null);
// render view
$auditView = new CView('administration.auditacts.list', $data);
$auditView->render();
示例4: navigation_bar_calc
$effectivePeriod = navigation_bar_calc('web.auditacts.timeline', 0, true);
$data = array('stime' => getRequest('stime'), 'alias' => CProfile::get('web.auditacts.filter.alias', ''), 'users' => array(), 'alerts' => array(), 'paging' => null);
$userId = null;
if ($data['alias']) {
$data['users'] = API::User()->get(array('output' => array('userid', 'alias', 'name', 'surname'), 'filter' => array('alias' => $data['alias']), 'preservekeys' => true));
if ($data['users']) {
$user = reset($data['users']);
$userId = $user['userid'];
}
}
if (!$data['alias'] || $data['users']) {
$from = zbxDateToTime($data['stime']);
$till = $from + $effectivePeriod;
// fetch alerts for different objects and sources and combine them in a single stream
foreach (eventSourceObjects() as $eventSource) {
$data['alerts'] = array_merge($data['alerts'], API::Alert()->get(array('output' => array('alertid', 'actionid', 'userid', 'clock', 'sendto', 'subject', 'message', 'status', 'retries', 'error', 'alerttype'), 'selectMediatypes' => array('mediatypeid', 'description'), 'userids' => $userId, 'time_from' => $from, 'time_till' => $till, 'eventsource' => $eventSource['source'], 'eventobject' => $eventSource['object'], 'sortfield' => 'alertid', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $config['search_limit'] + 1)));
}
CArrayHelper::sort($data['alerts'], array(array('field' => 'alertid', 'order' => ZBX_SORT_DOWN)));
$data['alerts'] = array_slice($data['alerts'], 0, $config['search_limit'] + 1);
// paging
$data['paging'] = getPagingLine($data['alerts'], ZBX_SORT_DOWN);
// get users
if (!$data['alias']) {
$data['users'] = API::User()->get(array('output' => array('userid', 'alias', 'name', 'surname'), 'userids' => zbx_objectValues($data['alerts'], 'userid'), 'preservekeys' => true));
}
}
// get first alert clock
$firstAlert = null;
if ($userId) {
$firstAlert = DBfetch(DBselect('SELECT MIN(a.clock) AS clock' . ' FROM alerts a' . ' WHERE a.userid=' . zbx_dbstr($userId)));
} elseif ($data['alias'] === '') {
示例5: navigation_bar_calc
if (isset($_REQUEST['filter_set']) || isset($_REQUEST['filter_rst'])) {
CProfile::update('web.auditacts.filter.alias', $_REQUEST['alias'], PROFILE_TYPE_STR);
}
/*
* Display
*/
$effectivePeriod = navigation_bar_calc('web.auditacts.timeline', 0, true);
$data = array('stime' => get_request('stime'), 'alias' => get_request('alias'), 'alerts' => array());
$from = zbxDateToTime($data['stime']);
$till = $from + $effectivePeriod;
// get alerts
$options = array('time_from' => $from, 'time_till' => $till, 'output' => API_OUTPUT_EXTEND, 'selectMediatypes' => API_OUTPUT_EXTEND, 'sortfield' => 'alertid', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $config['search_limit'] + 1);
if (!empty($data['alias'])) {
$users = API::User()->get(array('filter' => array('alias' => $data['alias'])));
$options['userids'] = zbx_objectValues($users, 'userid');
}
$data['alerts'] = API::Alert()->get($options);
// get paging
$data['paging'] = getPagingLine($data['alerts']);
// get timeline
unset($options['userids'], $options['time_from'], $options['time_till'], $options['selectMediatypes']);
$options['limit'] = 1;
$options['sortorder'] = ZBX_SORT_UP;
$firstAlert = API::Alert()->get($options);
$firstAlert = reset($firstAlert);
$data['timeline'] = array('period' => $effectivePeriod, 'starttime' => date('YmdHis', !empty($firstAlert) ? $firstAlert['clock'] : time() - SEC_PER_HOUR), 'usertime' => isset($data['stime']) ? date('YmdHis', zbxDateToTime($data['stime']) + $effectivePeriod) : null);
// render view
$auditView = new CView('administration.auditacts.list', $data);
$auditView->render();
$auditView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
示例6: get
//.........这里部分代码省略.........
unset($event['itemid']);
}
$result[$event['eventid']] += $event;
}
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
/*
* Adding objects
*/
// adding hosts
if (!is_null($options['selectHosts']) && str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
$hosts = API::Host()->get(array('nodeids' => $nodeids, 'output' => $options['selectHosts'], 'triggerids' => $triggerids, 'nopermissions' => true, 'preservekeys' => true));
$triggers = array();
foreach ($hosts as $hostid => $host) {
$htriggers = $host['triggers'];
unset($host['triggers']);
foreach ($htriggers as $tnum => $trigger) {
$triggerid = $trigger['triggerid'];
if (!isset($triggers[$triggerid])) {
$triggers[$triggerid] = array('hosts' => array());
}
$triggers[$triggerid]['hosts'][] = $host;
}
}
foreach ($result as $eventid => $event) {
if (isset($triggers[$event['objectid']])) {
$result[$eventid]['hosts'] = $triggers[$event['objectid']]['hosts'];
} else {
$result[$eventid]['hosts'] = array();
}
}
}
// adding triggers
if (!is_null($options['selectTriggers']) && str_in_array($options['selectTriggers'], $subselectsAllowedOutputs)) {
$triggers = API::Trigger()->get(array('nodeids' => $nodeids, 'output' => $options['selectTriggers'], 'triggerids' => $triggerids, 'nopermissions' => true, 'preservekeys' => true));
foreach ($result as $eventid => $event) {
if (isset($triggers[$event['objectid']])) {
$result[$eventid]['triggers'][] = $triggers[$event['objectid']];
} else {
$result[$eventid]['triggers'] = array();
}
}
}
// adding items
if (!is_null($options['selectItems']) && str_in_array($options['selectItems'], $subselectsAllowedOutputs)) {
$dbItems = API::Item()->get(array('nodeids' => $nodeids, 'output' => $options['selectItems'], 'triggerids' => $triggerids, 'webitems' => true, 'nopermissions' => true, 'preservekeys' => true));
$items = array();
foreach ($dbItems as $itemid => $item) {
$itriggers = $item['triggers'];
unset($item['triggers']);
foreach ($itriggers as $trigger) {
if (!isset($items[$trigger['triggerid']])) {
$items[$trigger['triggerid']] = array();
}
$items[$trigger['triggerid']][] = $item;
}
}
foreach ($result as $eventid => $event) {
if (isset($items[$event['objectid']])) {
$result[$eventid]['items'] = $items[$event['objectid']];
} else {
$result[$eventid]['items'] = array();
}
}
}
// adding alerts
if (!is_null($options['select_alerts']) && str_in_array($options['select_alerts'], $subselectsAllowedOutputs)) {
$dbAlerts = API::Alert()->get(array('output' => $options['select_alerts'], 'selectMediatypes' => API_OUTPUT_EXTEND, 'nodeids' => $nodeids, 'eventids' => $eventids, 'nopermissions' => true, 'preservekeys' => true, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN));
foreach ($dbAlerts as $alert) {
$result[$alert['eventid']]['alerts'][] = $alert;
}
}
// adding acknowledges
if (!is_null($options['select_acknowledges'])) {
if (is_array($options['select_acknowledges']) || str_in_array($options['select_acknowledges'], $subselectsAllowedOutputs)) {
$res = DBselect('SELECT a.*,u.alias' . ' FROM acknowledges a' . ' LEFT JOIN users u ON u.userid=a.userid' . ' WHERE ' . dbConditionInt('a.eventid', $eventids) . ' ORDER BY a.clock DESC');
while ($ack = DBfetch($res)) {
$result[$ack['eventid']]['acknowledges'][] = $ack;
}
} elseif ($options['select_acknowledges'] == API_OUTPUT_COUNT) {
$res = DBselect('SELECT COUNT(a.acknowledgeid) AS rowscount,a.eventid' . ' FROM acknowledges a' . ' WHERE ' . dbConditionInt('a.eventid', $eventids) . ' GROUP BY a.eventid');
while ($ack = DBfetch($res)) {
$result[$ack['eventid']]['acknowledges'] = $ack['rowscount'];
}
} elseif ($options['select_acknowledges'] == API_OUTPUT_EXTEND) {
$res = DBselect('SELECT a.*' . ' FROM acknowledges a' . ' WHERE ' . dbConditionInt('a.eventid', $eventids) . ' ORDER BY a.clock DESC');
while ($ack = DBfetch($res)) {
$result[$ack['eventid']]['acknowledges'] = $ack['rowscount'];
}
}
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例7: time
for ($t = $from; $t <= $to; $t++) {
if (($start = get_time($t)) > time()) {
break;
}
if (($end = get_time($t + 1)) > time()) {
$end = time();
}
$table_row = array(format_time($start), format_time2($end));
// getting all alerts in this period of time
$options = array('output' => array('mediatypeid', 'userid'), 'time_from' => $start, 'time_till' => $end);
// if we must get only specific media type, no need to select the other ones
if ($media_type > 0) {
$options['mediatypeids'] = $media_type;
}
// getting data through API
$alert_info = API::Alert()->get($options);
// counting alert count for each user and media type
$summary = array();
foreach ($users as $userid => $alias) {
$summary[$userid] = array();
$summary[$userid]['total'] = 0;
$summary[$userid]['medias'] = array();
foreach ($media_types as $media_type_nr => $mt) {
$summary[$userid]['medias'][$media_type_nr] = 0;
}
}
foreach ($alert_info as $ai) {
if (!isset($summary[$ai['userid']])) {
continue;
}
$summary[$ai['userid']]['total']++;