作者:rennha
项目:zabbi
function get_script_by_scriptid($scriptid)
{
$sql = 'SELECT * FROM scripts WHERE scriptid=' . $scriptid;
$rows = false;
if ($res = DBSelect($sql)) {
$rows = DBfetch($res);
}
return $rows;
}
作者:edilqueirozdearauj
项目:mapa-municipio
function GetMun($GeoCod)
{
$Reg = array();
$Link = DBServerConnect();
if ($Link !== FALSE) {
DBSelect(cDBName);
$SQL = "SELECT * FROM Municipios WHERE Geocodigo = {$GeoCod} LIMIT 1;";
$ExeSQL = mysql_query($SQL);
// or die (mysql_error());;
$Total = MySQLResults($ExeSQL);
if ($Total > 0) {
$Reg = mysql_fetch_array($ExeSQL);
}
DBServerDisconnect($Link);
}
return $Reg;
}
作者:omidm
项目:zabbix-greenplu
// get items
$data['hostPrototypes'] = API::HostPrototype()->get(array('discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'selectTemplates' => array('templateid', 'name'), 'editable' => true, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1));
order_result($data['hostPrototypes'], $sortField, $sortOrder);
$data['paging'] = getPagingLine($data['hostPrototypes'], $sortOrder);
// fetch templates linked to the prototypes
$templateIds = array();
foreach ($data['hostPrototypes'] as $hostPrototype) {
$templateIds = array_merge($templateIds, zbx_objectValues($hostPrototype['templates'], 'templateid'));
}
$templateIds = array_unique($templateIds);
$linkedTemplates = API::Template()->get(array('output' => array('templateid', 'name'), 'templateids' => $templateIds, 'selectParentTemplates' => array('hostid', 'name')));
$data['linkedTemplates'] = zbx_toHash($linkedTemplates, 'templateid');
// fetch source templates and LLD rules
$hostPrototypeSourceIds = getHostPrototypeSourceParentIds(zbx_objectValues($data['hostPrototypes'], 'hostid'));
if ($hostPrototypeSourceIds) {
$hostPrototypeSourceTemplates = DBfetchArrayAssoc(DBSelect('SELECT h.hostid,h2.name,h2.hostid AS parent_hostid' . ' FROM hosts h,host_discovery hd,items i,hosts h2' . ' WHERE h.hostid=hd.hostid' . ' AND hd.parent_itemid=i.itemid' . ' AND i.hostid=h2.hostid' . ' AND ' . dbConditionInt('h.hostid', $hostPrototypeSourceIds)), 'hostid');
foreach ($data['hostPrototypes'] as &$hostPrototype) {
if ($hostPrototype['templateid']) {
$sourceTemplate = $hostPrototypeSourceTemplates[$hostPrototypeSourceIds[$hostPrototype['hostid']]];
$hostPrototype['sourceTemplate'] = array('hostid' => $sourceTemplate['parent_hostid'], 'name' => $sourceTemplate['name']);
$sourceDiscoveryRuleId = get_realrule_by_itemid_and_hostid($discoveryRule['itemid'], $sourceTemplate['hostid']);
$hostPrototype['sourceDiscoveryRuleId'] = $sourceDiscoveryRuleId;
}
}
unset($hostPrototype);
}
// render view
$itemView = new CView('configuration.host.prototype.list', $data);
$itemView->render();
$itemView->show();
}
作者:phedder
项目:zabbi
function make_webmon_overview()
{
global $USER_DETAILS;
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
$table = new CTableInfo();
$table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_OK, S_FAILED, S_IN_PROGRESS, S_UNKNOWN));
$sql = 'SELECT DISTINCT g.groupid, g.name ' . ' FROM httptest ht, applications a, groups g, hosts_groups hg ' . ' WHERE ' . DBcondition('hg.hostid', $available_hosts) . ' AND hg.hostid=a.hostid ' . ' AND g.groupid=hg.groupid ' . ' AND a.applicationid=ht.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ' ORDER BY g.name';
$host_groups = DBSelect($sql);
while ($group = DBFetch($host_groups)) {
$apps['ok'] = 0;
$apps['failed'] = 0;
$apps[HTTPTEST_STATE_BUSY] = 0;
$apps[HTTPTEST_STATE_UNKNOWN] = 0;
$sql = 'SELECT DISTINCT ht.httptestid, ht.curstate, ht.lastfailedstep ' . ' FROM httptest ht, applications a, hosts_groups hg, groups g ' . ' WHERE g.groupid=' . $group['groupid'] . ' AND hg.groupid=g.groupid ' . ' AND a.hostid=hg.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE;
$db_httptests = DBselect($sql);
while ($httptest_data = DBfetch($db_httptests)) {
if (HTTPTEST_STATE_BUSY == $httptest_data['curstate']) {
$apps[HTTPTEST_STATE_BUSY]++;
} else {
if (HTTPTEST_STATE_IDLE == $httptest_data['curstate']) {
if ($httptest_data['lastfailedstep'] > 0) {
$apps['failed']++;
} else {
$apps['ok']++;
}
} else {
$apps[HTTPTEST_STATE_UNKNOWN]++;
}
}
}
$table->addRow(array(is_show_all_nodes() ? get_node_name_by_elid($group['groupid']) : null, $group['name'], new CSpan($apps['ok'], 'off'), new CSpan($apps['failed'], $apps['failed'] ? 'on' : 'off'), new CSpan($apps[HTTPTEST_STATE_BUSY], $apps[HTTPTEST_STATE_BUSY] ? 'orange' : 'off'), new CSpan($apps[HTTPTEST_STATE_UNKNOWN], 'unknown')));
}
$table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time())));
return $table;
}
作者:TonywalkerC
项目:Zabbi
/**
* Inherit template graphs from template to host.
*
* @param array $data
*
* @return bool
*/
public function syncTemplates($data)
{
$data['templateids'] = zbx_toArray($data['templateids']);
$data['hostids'] = zbx_toArray($data['hostids']);
$dbLinks = DBSelect('SELECT ht.hostid,ht.templateid' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('ht.hostid', $data['hostids']) . ' AND ' . dbConditionInt('ht.templateid', $data['templateids']));
$linkage = array();
while ($link = DBfetch($dbLinks)) {
if (!isset($linkage[$link['templateid']])) {
$linkage[$link['templateid']] = array();
}
$linkage[$link['templateid']][$link['hostid']] = 1;
}
$graphs = $this->get(array('hostids' => $data['templateids'], 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'selectHosts' => array('hostid'), 'filter' => array('flags' => null)));
foreach ($graphs as $graph) {
foreach ($data['hostids'] as $hostid) {
if (isset($linkage[$graph['hosts'][0]['hostid']][$hostid])) {
$this->inherit($graph, $hostid);
}
}
}
return true;
}
作者:rennha
项目:zabbi
function get_row_for_nofalseforb($row, $sql)
{
$res_events = DBSelect($sql, 1);
if (!($e_row = DBfetch($res_events))) {
return false;
} else {
$row = array_merge($row, $e_row);
}
if ($row['value'] != TRIGGER_VALUE_TRUE && !event_initial_time($row)) {
if (!($eventid = first_initial_eventid($row, 0))) {
return false;
}
$sql = 'SELECT e.eventid, e.value' . ' FROM events e ' . ' WHERE e.eventid=' . $eventid . ' AND e.acknowledged=0';
$res_events = DBSelect($sql, 1);
if (!($e_row = DBfetch($res_events))) {
return false;
} else {
$row = array_merge($row, $e_row);
}
}
return $row;
}
作者:omidm
项目:zabbix-greenplu
/**
* Returns the farthest host prototype ancestor for each given host prototype.
*
* @param array $hostPrototypeIds
* @param array $templateHostPrototypeIds array with parent host prototype IDs as keys and arrays of child host
* prototype IDs as values
*
* @return array an array of child ID - ancestor ID pairs
*/
function getHostPrototypeSourceParentIds(array $hostPrototypeIds, array $templateHostPrototypeIds = array())
{
$query = DBSelect('SELECT h.hostid,h.templateid' . ' FROM hosts h' . ' WHERE ' . dbConditionInt('h.hostid', $hostPrototypeIds) . ' AND h.templateid>0');
$hostPrototypeIds = array();
while ($hostPrototype = DBfetch($query)) {
// check if we already have host prototype inherited from the current host prototype
// if we do - move all of its child prototypes to the parent template
if (isset($templateHostPrototypeIds[$hostPrototype['hostid']])) {
$templateHostPrototypeIds[$hostPrototype['templateid']] = $templateHostPrototypeIds[$hostPrototype['hostid']];
unset($templateHostPrototypeIds[$hostPrototype['hostid']]);
} else {
$templateHostPrototypeIds[$hostPrototype['templateid']][] = $hostPrototype['hostid'];
$hostPrototypeIds[] = $hostPrototype['templateid'];
}
}
// continue while we still have new host prototypes to check
if ($hostPrototypeIds) {
return getHostPrototypeSourceParentIds($hostPrototypeIds, $templateHostPrototypeIds);
} else {
// return an inverse hash with prototype IDs as keys and parent prototype IDs as values
$result = array();
foreach ($templateHostPrototypeIds as $templateId => $hostIds) {
foreach ($hostIds as $hostId) {
$result[$hostId] = $templateId;
}
}
return $result;
}
}
作者:omidm
项目:zabbix-greenplu
/**
* Returns the records that match the given criteria.
*
* @static
*
* @param string $tableName
* @param array $criteria An associative array of field-value pairs, where value can be either a single value
* or an array (IN)
*
* @return array
*/
public static function find($tableName, array $criteria = array())
{
// build the WHERE part
$sqlWhere = array();
foreach ($criteria as $field => $value) {
// check if the table has this field
if (!self::hasField($tableName, $field)) {
self::exception(self::DBEXECUTE_ERROR, _s('Table "%1$s" doesn\'t have a field named "%2$s".', $tableName, $field));
}
$sqlWhere[] = dbConditionString($field, zbx_toArray($value));
}
// build query
$sql = 'SELECT * FROM ' . $tableName;
if ($sqlWhere) {
$sql .= ' WHERE ' . implode(' AND ', $sqlWhere);
}
return DBfetchArray(DBSelect($sql));
}
作者:marku
项目:planetalinu
<caption>Resultados Concurso Planeta Linux 2007</caption>
<thead>
<tr>
<th scope="col">Correo de Denunciante</th>
<th scope="col">Puntos Acumulados</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row"></a></th>
<td colspan="2"></td>
</tr>
</tfoot>
<tbody>
<?php
$denunciantes = DBSelect("correo,puntos", "denunciantes", "", "Order by puntos DESC");
foreach ($denunciantes as $key => $denuncia) {
echo "<tr class='odd'><th scope='row' id=denunciantes>" . $denuncia['correo'] . "</th>";
echo " <td>" . $denuncia['puntos'] . "</td></tr>";
}
?>
</tbody>
</table>
</div>
<?php
require "footer.php";
?>
</body>
</html>
作者:itniha
项目:Zabbix
/**
* Check that none of the triggers have dependencies on their children. Checks only one level of inheritance, but
* since it is called on each inheritance step, also works for multiple inheritance levels.
*
* @throws APIException if at least one trigger is dependent on its child
*
* @param array $triggers
*/
protected function checkDependencyParents(array $triggers)
{
// fetch all templated dependency trigger parents
$depTriggerIds = array();
foreach ($triggers as $trigger) {
foreach ($trigger['dependencies'] as $depTriggerId) {
$depTriggerIds[$depTriggerId] = $depTriggerId;
}
}
$parentDepTriggers = DBfetchArray(DBSelect('SELECT templateid,triggerid' . ' FROM triggers' . ' WHERE templateid>0' . ' AND ' . dbConditionInt('triggerid', $depTriggerIds)));
if ($parentDepTriggers) {
$parentDepTriggers = zbx_toHash($parentDepTriggers, 'triggerid');
foreach ($triggers as $trigger) {
foreach ($trigger['dependencies'] as $depTriggerId) {
// check if the current trigger is the parent of the dependency trigger
if (isset($parentDepTriggers[$depTriggerId]) && $parentDepTriggers[$depTriggerId]['templateid'] == $trigger['triggerid']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger cannot be dependent on a trigger that is inherited from it.'));
}
}
}
}
}
作者:rennha
项目:zabbi
function get_regexp_form()
{
$frm_title = S_REGULAR_EXPRESSION;
if (isset($_REQUEST['regexpid']) && !isset($_REQUEST["form_refresh"])) {
$sql = 'SELECT re.* ' . ' FROM regexps re ' . ' WHERE ' . DBin_node('re.regexpid') . ' AND re.regexpid=' . $_REQUEST['regexpid'];
$regexp = DBfetch(DBSelect($sql));
$frm_title .= ' [' . $regexp['name'] . ']';
$rename = $regexp['name'];
$test_string = $regexp['test_string'];
$expressions = array();
$sql = 'SELECT e.* ' . ' FROM expressions e ' . ' WHERE ' . DBin_node('e.expressionid') . ' AND e.regexpid=' . $regexp['regexpid'] . ' ORDER BY e.expression_type';
$db_exps = DBselect($sql);
while ($exp = DBfetch($db_exps)) {
$expressions[] = $exp;
}
} else {
$rename = get_request('rename', '');
$test_string = get_request('test_string', '');
$expressions = get_request('expressions', array());
}
$tblRE = new CTable('', 'nowrap');
$tblRE->addStyle('border-left: 1px #AAA solid; border-right: 1px #AAA solid; background-color: #EEE; padding: 2px; padding-left: 6px; padding-right: 6px;');
$tblRE->addRow(array(S_NAME, new CTextBox('rename', $rename, 60)));
$tblRE->addRow(array(S_TEST_STRING, new CTextArea('test_string', $test_string, 66, 5)));
$tabExp = new CTableInfo();
$td1 = new CCol(S_EXPRESSION);
$td1->addStyle('background-color: #CCC;');
$td2 = new CCol(S_EXPECTED_RESULT);
$td2->addStyle('background-color: #CCC;');
$td3 = new CCol(S_RESULT);
$td3->addStyle('background-color: #CCC;');
$tabExp->setHeader(array($td1, $td2, $td3));
$final_result = !empty($test_string);
foreach ($expressions as $id => $expression) {
$results = array();
$paterns = array($expression['expression']);
if (!empty($test_string)) {
if ($expression['expression_type'] == EXPRESSION_TYPE_ANY_INCLUDED) {
$paterns = explode($expression['exp_delimiter'], $expression['expression']);
}
if (uint_in_array($expression['expression_type'], array(EXPRESSION_TYPE_TRUE, EXPRESSION_TYPE_FALSE))) {
if ($expression['case_sensitive']) {
$results[$id] = ereg($paterns[0], $test_string);
} else {
$results[$id] = eregi($paterns[0], $test_string);
}
if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE) {
$final_result &= $results[$id];
} else {
$final_result &= !$results[$id];
}
} else {
$results[$id] = true;
$tmp_result = false;
if ($expression['case_sensitive']) {
foreach ($paterns as $pid => $patern) {
$tmp_result |= zbx_stristr($test_string, $patern) !== false;
}
} else {
foreach ($paterns as $pid => $patern) {
$tmp_result |= zbx_strstr($test_string, $patern) !== false;
}
}
$results[$id] &= $tmp_result;
$final_result &= $results[$id];
}
}
if (isset($results[$id]) && $results[$id]) {
$exp_res = new CSpan(S_TRUE_BIG, 'green bold');
} else {
$exp_res = new CSpan(S_FALSE_BIG, 'red bold');
}
$expec_result = expression_type2str($expression['expression_type']);
if (EXPRESSION_TYPE_ANY_INCLUDED == $expression['expression_type']) {
$expec_result .= ' (' . S_DELIMITER . "='" . $expression['exp_delimiter'] . "')";
}
$tabExp->addRow(array($expression['expression'], $expec_result, $exp_res));
}
$td = new CCol(S_COMBINED_RESULT, 'bold');
$td->setColSpan(2);
if ($final_result) {
$final_result = new CSpan(S_TRUE_BIG, 'green bold');
} else {
$final_result = new CSpan(S_FALSE_BIG, 'red bold');
}
$tabExp->addRow(array($td, $final_result));
$tblRE->addRow(array(S_RESULT, $tabExp));
$tblFoot = new CTableInfo(null);
$td = new CCol(array(new CButton('save', S_SAVE)));
$td->setColSpan(2);
$td->addStyle('text-align: right;');
$td->addItem(SPACE);
$td->addItem(new CButton('test', S_TEST));
if (isset($_REQUEST['regexpid'])) {
$td->addItem(SPACE);
$td->addItem(new CButton('clone', S_CLONE));
$td->addItem(SPACE);
$td->addItem(new CButtonDelete(S_DELETE_REGULAR_EXPRESSION_Q, url_param('form') . url_param('config') . url_param('regexpid')));
}
$td->addItem(SPACE);
//.........这里部分代码省略.........
作者:omidm
项目:zabbix-greenplu
function addUserHistory($title, $url)
{
$userId = CWebUser::$data['userid'];
$history5 = DBfetch(DBSelect('SELECT uh.title5,uh.url5' . ' FROM user_history uh' . ' WHERE uh.userid=' . $userId));
if ($history5) {
if ($history5['title5'] === $title) {
if ($history5['url5'] === $url) {
return true;
} else {
$sql = 'UPDATE user_history SET url5=' . zbx_dbstr($url) . ' WHERE userid=' . $userId;
}
} else {
$sql = 'UPDATE user_history' . ' SET title1=title2,' . ' url1=url2,' . ' title2=title3,' . ' url2=url3,' . ' title3=title4,' . ' url3=url4,' . ' title4=title5,' . ' url4=url5,' . ' title5=' . zbx_dbstr($title) . ',' . ' url5=' . zbx_dbstr($url) . ' WHERE userid=' . $userId;
}
} else {
$userHistoryId = get_dbid('user_history', 'userhistoryid');
$sql = 'INSERT INTO user_history (userhistoryid, userid, title5, url5)' . ' VALUES(' . $userHistoryId . ', ' . $userId . ', ' . zbx_dbstr($title) . ', ' . zbx_dbstr($url) . ')';
}
return DBexecute($sql);
}
作者:quanta-computin
项目:debian-package
/**
* Returns the value of the latest service alarm before the given time.
*
* @param array $serviceIds
* @param int $beforeTime
*
* @return array
*/
protected function fetchLatestValues(array $serviceIds, $beforeTime)
{
// the query will return the alarms with the maximum timestamp for each service
// since multiple alarms can have the same timestamp, we only need to save the last one
$query = DBSelect('SELECT sa.serviceid,sa.value' . ' FROM (SELECT MAX(sa3.servicealarmid) AS servicealarmid' . ' FROM (SELECT sa2.serviceid,MAX(sa2.clock) AS clock' . ' FROM service_alarms sa2' . ' WHERE sa2.clock<' . zbx_dbstr($beforeTime) . ' AND ' . dbConditionInt('sa2.serviceid', $serviceIds) . ' GROUP BY sa2.serviceid) ss' . ' JOIN service_alarms sa3 ON sa3.serviceid = ss.serviceid and sa3.clock = ss.clock' . ' GROUP BY sa3.serviceid) ss2' . ' JOIN service_alarms sa ON sa.servicealarmid = ss2.servicealarmid');
$rs = array();
while ($alarm = DBfetch($query)) {
$rs[$alarm['serviceid']] = $alarm['value'];
}
return $rs;
}
作者:quanta-computin
项目:debian-package
$fields = array('regexpids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'regexpid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form})&&({form}=="update")'), 'rename' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({save})', _('Name')), 'test_string' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({save})', _('Test string')), 'delete_regexp' => array(T_ZBX_STR, O_OPT, null, null, null), 'g_expressionid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'expressions' => array(T_ZBX_STR, O_OPT, null, null, 'isset({save})'), 'new_expression' => array(T_ZBX_STR, O_OPT, null, null, null), 'cancel_new_expression' => array(T_ZBX_STR, O_OPT, null, null, null), 'add_expression' => array(T_ZBX_STR, O_OPT, null, null, null), 'edit_expressionid' => array(T_ZBX_STR, O_OPT, null, null, null), 'delete_expression' => array(T_ZBX_STR, O_OPT, null, null, null), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'clone' => array(T_ZBX_STR, O_OPT, null, null, null), 'go' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null));
check_fields($fields);
/*
* Permissions
*/
if (isset($_REQUEST['regexpid'])) {
$regExp = DBfetch(DBSelect('SELECT re.regexpid FROM regexps re WHERE re.regexpid=' . get_request('regexpid')));
if (empty($regExp)) {
access_deny();
}
}
if (isset($_REQUEST['go']) && !isset($_REQUEST['regexpid'])) {
if (!isset($_REQUEST['regexpids']) || !is_array($_REQUEST['regexpids'])) {
access_deny();
} else {
$regExpChk = DBfetch(DBSelect('SELECT COUNT(*) AS cnt FROM regexps re WHERE ' . dbConditionInt('re.regexpid', $_REQUEST['regexpids'])));
if ($regExpChk['cnt'] != count($_REQUEST['regexpids'])) {
access_deny();
}
}
}
/*
* Actions
*/
if (isset($_REQUEST['clone']) && isset($_REQUEST['regexpid'])) {
unset($_REQUEST['regexpid']);
$_REQUEST['form'] = 'clone';
} elseif (isset($_REQUEST['cancel_new_expression'])) {
unset($_REQUEST['new_expression']);
} elseif (isset($_REQUEST['save'])) {
$regExp = array('name' => $_REQUEST['rename'], 'test_string' => $_REQUEST['test_string']);
作者:songyuanji
项目:zabbix-stat
function get_screen($screenid, $editmode, $effectiveperiod = NULL)
{
global $USER_DETAILS;
if ($screenid == 0) {
return new CTableInfo(S_NO_SCREENS_DEFINED);
}
$r = CScreen::get(array('screenids' => $screenid, 'editable' => $editmode == 1 ? 1 : null, 'output' => API_OUTPUT_SHORTEN));
if (empty($r)) {
access_deny();
}
if (is_null($effectiveperiod)) {
$effectiveperiod = ZBX_MIN_PERIOD;
}
$result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid);
$row = DBfetch($result);
if (!$row) {
return new CTableInfo(S_NO_SCREENS_DEFINED);
}
$sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid;
$iresult = DBSelect($sql);
$skip_field = array();
$irows = array();
while ($irow = DBfetch($iresult)) {
$irows[] = $irow;
for ($i = 0; $i < $irow['rowspan'] || $i == 0; $i++) {
for ($j = 0; $j < $irow['colspan'] || $j == 0; $j++) {
if ($i != 0 || $j != 0) {
if (!isset($skip_field[$irow['y'] + $i])) {
$skip_field[$irow['y'] + $i] = array();
}
$skip_field[$irow['y'] + $i][$irow['x'] + $j] = 1;
}
}
}
}
$table = new CTable(new CLink(S_NO_ROWS_IN_SCREEN . SPACE . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit');
$table->setAttribute('id', 'iframe');
if ($editmode == 1) {
$new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1)));
for ($c = 0; $c < $row['hsize'] + 1; $c++) {
$add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer');
$add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_col={$c}';");
array_push($new_cols, new Ccol($add_icon));
}
$table->addRow($new_cols);
}
$empty_screen_col = array();
for ($r = 0; $r < $row['vsize']; $r++) {
$new_cols = array();
$empty_screen_row = true;
if ($editmode == 1) {
$add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer');
$add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$r}';");
array_push($new_cols, new Ccol($add_icon));
}
for ($c = 0; $c < $row['hsize']; $c++) {
$item = array();
if (isset($skip_field[$r][$c])) {
continue;
}
$item_form = false;
$irow = false;
foreach ($irows as $tmprow) {
if ($tmprow['x'] == $c && $tmprow['y'] == $r) {
$irow = $tmprow;
break;
}
}
if ($irow) {
$screenitemid = $irow['screenitemid'];
$resourcetype = $irow['resourcetype'];
$resourceid = $irow['resourceid'];
$width = $irow['width'];
$height = $irow['height'];
$colspan = $irow['colspan'];
$rowspan = $irow['rowspan'];
$elements = $irow['elements'];
$valign = $irow['valign'];
$halign = $irow['halign'];
$style = $irow['style'];
$url = $irow['url'];
$dynamic = $irow['dynamic'];
} else {
$screenitemid = 0;
$resourcetype = 0;
$resourceid = 0;
$width = 0;
$height = 0;
$colspan = 0;
$rowspan = 0;
$elements = 0;
$valign = VALIGN_DEFAULT;
$halign = HALIGN_DEFAULT;
$style = 0;
$url = '';
$dynamic = 0;
}
if ($screenitemid > 0) {
$empty_screen_row = false;
$empty_screen_col[$c] = 1;
//.........这里部分代码省略.........
作者:jbfavr
项目:debian-zabbi
/**
* Check that none of the triggers have dependencies on their children. Checks only one level of inheritance, but
* since it is called on each inheritance step, also works for multiple inheritance levels.
*
* @param array $triggerPrototypes
* @param string $triggerPrototypes[]['triggerid']
* @param array $triggerPrototypes[]['dependencies']
* @param string $triggerPrototypes[]['dependencies'][]['triggerid']
*
* @throws APIException if at least one trigger is dependent on its child.
*/
protected function checkDependencyParents(array $triggerPrototypes)
{
// fetch all templated dependency trigger parents
$depTriggerIds = [];
foreach ($triggerPrototypes as $triggerPrototype) {
if (!array_key_exists('dependencies', $triggerPrototype)) {
continue;
}
foreach ($triggerPrototype['dependencies'] as $dependency) {
$depTriggerIds[$dependency['triggerid']] = $dependency['triggerid'];
}
}
$parentDepTriggers = DBfetchArray(DBSelect('SELECT templateid,triggerid' . ' FROM triggers' . ' WHERE templateid>0' . ' AND ' . dbConditionInt('triggerid', $depTriggerIds)));
if ($parentDepTriggers) {
$parentDepTriggers = zbx_toHash($parentDepTriggers, 'triggerid');
foreach ($triggerPrototypes as $triggerPrototype) {
foreach ($triggerPrototype['dependencies'] as $dependency) {
// Check if the current trigger is the parent of the dependency trigger.
$depTriggerId = $dependency['triggerid'];
if (isset($parentDepTriggers[$depTriggerId]) && $parentDepTriggers[$depTriggerId]['templateid'] == $triggerPrototype['triggerid']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger prototype cannot be dependent on a trigger that is inherited from it.'));
}
}
}
}
}
作者:quanta-computin
项目:debian-package
/**
* Constructs an SQL SELECT query for a specific table from the given API options, executes it and returns
* the result.
*
* TODO: add global 'countOutput' support
*
* @param string $tableName
* @param array $options
*
* @return array
*/
protected function select($tableName, array $options)
{
$limit = isset($options['limit']) ? $options['limit'] : null;
$sql = $this->createSelectQuery($tableName, $options);
$query = DBSelect($sql, $limit);
$objects = DBfetchArray($query);
if (isset($options['preservekeys'])) {
$rs = array();
foreach ($objects as $object) {
$rs[$object[$this->pk($tableName)]] = $this->unsetExtraFields($tableName, $object, $options['output']);
}
return $rs;
} else {
return $objects;
}
}
作者:jbfavr
项目:debian-zabbi
/**
* Checks if the given host prototypes are not inherited from a template.
*
* @throws APIException if at least one host prototype is inherited
*
* @param array $hostPrototypeIds
*/
protected function checkNotInherited(array $hostPrototypeIds)
{
$query = DBSelect('SELECT hostid FROM hosts h WHERE h.templateid>0 AND ' . dbConditionInt('h.hostid', $hostPrototypeIds), 1);
if ($hostPrototype = DBfetch($query)) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('Cannot delete templated host prototype.'));
}
}
作者:jbfavr
项目:debian-zabbi
protected function applyPostSqlFiltering(array $triggers, array $options)
{
$triggers = zbx_toHash($triggers, 'triggerid');
// unset triggers which depend on at least one problem trigger upstream into dependency tree
if ($options['skipDependent'] !== null) {
// Result trigger IDs of all triggers in results.
$resultTriggerIds = zbx_objectValues($triggers, 'triggerid');
// Will contain IDs of all triggers on which some other trigger depends.
$allUpTriggerIds = [];
// Trigger dependency map.
$downToUpTriggerIds = [];
// Values (state) of each "up" trigger ID is stored in here.
$upTriggerValues = [];
// Will contain IDs of all triggers either disabled directly, or by having disabled item or disabled host.
$disabledTriggerIds = [];
// First loop uses result trigger IDs.
$triggerIds = $resultTriggerIds;
do {
// Fetch all dependency records where "down" trigger IDs are in current iteration trigger IDs.
$dbResult = DBselect('SELECT d.triggerid_down,d.triggerid_up,t.value' . ' FROM trigger_depends d,triggers t' . ' WHERE d.triggerid_up=t.triggerid' . ' AND ' . dbConditionInt('d.triggerid_down', $triggerIds));
// Add trigger IDs as keys and empty arrays as values.
$downToUpTriggerIds = $downToUpTriggerIds + array_fill_keys($triggerIds, []);
$triggerIds = [];
while ($dependency = DBfetch($dbResult)) {
// Trigger ID for "down" trigger, which has dependencies.
$downTriggerId = $dependency['triggerid_down'];
// Trigger ID for "up" trigger, on which the other ("up") trigger depends.
$upTriggerId = $dependency['triggerid_up'];
// Add "up" trigger ID to mapping. We also index by $upTrigger because later these arrays
// are combined with + and this way indexes and values do not break.
$downToUpTriggerIds[$downTriggerId][$upTriggerId] = $upTriggerId;
// Add ID of this "up" trigger to all known "up" triggers.
$allUpTriggerIds[] = $upTriggerId;
// Remember value of this "up" trigger.
$upTriggerValues[$upTriggerId] = $dependency['value'];
// Add ID of this "up" trigger to the list of trigger IDs which should be mapped.
$triggerIds[] = $upTriggerId;
}
} while ($triggerIds);
// Fetch trigger IDs for triggers that are disabled, have disabled items or disabled item hosts.
$dbResult = DBSelect('SELECT t.triggerid' . ' FROM triggers t,functions f,items i,hosts h' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND (' . 'i.status=' . ITEM_STATUS_DISABLED . ' OR h.status=' . HOST_STATUS_NOT_MONITORED . ' OR t.status=' . TRIGGER_STATUS_DISABLED . ')' . ' AND ' . dbConditionInt('t.triggerid', $allUpTriggerIds));
while ($row = DBfetch($dbResult)) {
$resultTriggerId = $row['triggerid'];
$disabledTriggerIds[$resultTriggerId] = $resultTriggerId;
}
// Now process all mapped dependencies and unset any disabled "up" triggers so they do not participate in
// decisions regarding nesting resolution in next step.
foreach ($downToUpTriggerIds as $downTriggerId => $upTriggerIds) {
$upTriggerIdsToUnset = [];
foreach ($upTriggerIds as $upTriggerId) {
if (isset($disabledTriggerIds[$upTriggerId])) {
unset($downToUpTriggerIds[$downTriggerId][$upTriggerId]);
}
}
}
// Resolve dependencies for all result set triggers.
foreach ($resultTriggerIds as $resultTriggerId) {
// We start with result trigger.
$triggerIds = [$resultTriggerId];
// This also is unrolled recursive function and is repeated until there are no more trigger IDs to
// check, add and resolve.
do {
$nextTriggerIds = [];
foreach ($triggerIds as $triggerId) {
// Loop through all "up" triggers.
foreach ($downToUpTriggerIds[$triggerId] as $upTriggerId) {
if ($downToUpTriggerIds[$upTriggerId]) {
// If there this "up" trigger has "up" triggers of it's own, merge them and proceed with recursion.
$downToUpTriggerIds[$resultTriggerId] += $downToUpTriggerIds[$upTriggerId];
// Add trigger ID to be processed in next loop iteration.
$nextTriggerIds[] = $upTriggerId;
}
}
}
$triggerIds = $nextTriggerIds;
} while ($triggerIds);
}
// Clean result set.
foreach ($resultTriggerIds as $resultTriggerId) {
foreach ($downToUpTriggerIds[$resultTriggerId] as $upTriggerId) {
// If "up" trigger is in problem state, dependent trigger should not be returned and is removed
// from results.
if ($upTriggerValues[$upTriggerId] == TRIGGER_VALUE_TRUE) {
unset($triggers[$resultTriggerId]);
}
}
// Check if result trigger is disabled and if so, remove from results.
if (isset($disabledTriggerIds[$resultTriggerId])) {
unset($triggers[$resultTriggerId]);
}
}
}
// withLastEventUnacknowledged
if (!is_null($options['withLastEventUnacknowledged'])) {
$triggerIds = zbx_objectValues($triggers, 'triggerid');
$eventIds = [];
$eventsDb = DBselect('SELECT MAX(e.eventid) AS eventid,e.objectid' . ' FROM events e' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND ' . dbConditionInt('e.objectid', $triggerIds) . ' AND ' . dbConditionInt('e.value', [TRIGGER_VALUE_TRUE]) . ' GROUP BY e.objectid');
while ($event = DBfetch($eventsDb)) {
$eventIds[] = $event['eventid'];
}
//.........这里部分代码省略.........
作者:phedder
项目:zabbi
$triggers_num++;
$row['events'] = array();
$row['items'] = array();
$triggers[$row['triggerid']] = $row;
$triggerids[$row['triggerid']] = $row['triggerid'];
}
$sql = 'SELECT f.triggerid, i.* ' . ' FROM functions f, items i ' . ' WHERE ' . DBcondition('f.triggerid', $triggerids) . ' AND i.itemid=f.itemid';
$result = DBselect($sql);
while ($row = DBfetch($result)) {
$item['itemid'] = $row['itemid'];
$item['action'] = str_in_array($row['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues';
$item['description'] = item_description($row);
$triggers[$row['triggerid']]['items'][$row['itemid']] = $item;
}
$event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type ' . ' FROM events e, triggers t ' . ' WHERE e.object=0 ' . ' AND ' . DBcondition('e.objectid', $triggerids) . ' AND t.triggerid=e.objectid ' . $event_cond . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
$res_events = DBSelect($event_sql, $config['event_show_max'] * 100);
while ($row_event = DBfetch($res_events)) {
if ($show_events == EVENTS_OPTION_NOFALSEFORB) {
if (EVENTS_NOFALSEFORB_STATUS_FALSE == $show_events_status && $row_event['value'] != TRIGGER_VALUE_FALSE) {
continue;
}
if (EVENTS_NOFALSEFORB_STATUS_TRUE == $show_events_status && $row_event['value'] != TRIGGER_VALUE_TRUE) {
continue;
}
if ($row_event['value'] == TRIGGER_VALUE_FALSE && !event_initial_time($row_event)) {
continue;
}
}
$triggers[$row_event['triggerid']]['events'][$row_event['eventid']] = $row_event;
}
foreach ($triggers as $triggerid => $row) {