当前位置: 首页>>代码示例>>PHP>>正文


PHP API::DRule方法代码示例

本文整理汇总了PHP中API::DRule方法的典型用法代码示例。如果您正苦于以下问题:PHP API::DRule方法的具体用法?PHP API::DRule怎么用?PHP API::DRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API的用法示例。


在下文中一共展示了API::DRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doAction

 protected function doAction()
 {
     $show_discovery_widget = $this->getUserType() >= USER_TYPE_ZABBIX_ADMIN && (bool) API::DRule()->get(['output' => [], 'filter' => ['status' => DRULE_STATUS_ACTIVE], 'limit' => 1]);
     $data = ['fullscreen' => $this->getInput('fullscreen', 0), 'filter_enabled' => CProfile::get('web.dashconf.filter.enable', 0), 'favourite_graphs' => getFavouriteGraphs(), 'favourite_maps' => getFavouriteMaps(), 'favourite_screens' => getFavouriteScreens(), 'show_status_widget' => $this->getUserType() == USER_TYPE_SUPER_ADMIN, 'show_discovery_widget' => $show_discovery_widget];
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Dashboard'));
     $this->setResponse($response);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:8,代码来源:CControllerDashboardView.php

示例2: checkPermissions

 protected function checkPermissions()
 {
     if ($this->getUserType() < USER_TYPE_ZABBIX_ADMIN) {
         return false;
     }
     if ($this->hasInput('druleid') && $this->getInput('druleid') != 0) {
         $drules = API::DRule()->get(['output' => [], 'druleids' => [$this->getInput('druleid')], 'filter' => ['status' => DRULE_STATUS_ACTIVE]]);
         if (!$drules) {
             return false;
         }
     }
     return true;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:13,代码来源:CControllerDiscoveryView.php

示例3: validateConditions


//.........这里部分代码省略.........
                     if (!$timePeriodValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, $timePeriodValidator->getError());
                     }
                     break;
                 case CONDITION_TYPE_DHOST_IP:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } else {
                         if (!validate_ip_range($condition['value'])) {
                             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition ip "%1$s".', $condition['value']));
                         }
                     }
                     break;
                 case CONDITION_TYPE_DSERVICE_TYPE:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$discoveryCheckTypeValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check.'));
                     }
                     break;
                 case CONDITION_TYPE_DSERVICE_PORT:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!validate_port_list($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition port "%1$s".', $condition['value']));
                     }
                     break;
                 case CONDITION_TYPE_DSTATUS:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$discoveryObjectStatusValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery status.'));
                     }
                     break;
                 case CONDITION_TYPE_MAINTENANCE:
                     if (!zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Maintenance action condition value must be empty.'));
                     }
                     break;
                 case CONDITION_TYPE_TRIGGER_SEVERITY:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$triggerSeverityValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger severity.'));
                     }
                     break;
                 case CONDITION_TYPE_TRIGGER_VALUE:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$triggerValueValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger value.'));
                     }
                     break;
                 case CONDITION_TYPE_EVENT_TYPE:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$eventTypeValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition event type.'));
                     }
                     break;
                 case CONDITION_TYPE_TRIGGER_NAME:
                 case CONDITION_TYPE_NODE:
                 case CONDITION_TYPE_DUPTIME:
                 case CONDITION_TYPE_DVALUE:
                 case CONDITION_TYPE_APPLICATION:
                 case CONDITION_TYPE_HOST_NAME:
                 case CONDITION_TYPE_HOST_METADATA:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     break;
                 default:
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition type.'));
                     break;
             }
         }
     }
     if (!API::HostGroup()->isWritable($hostGroupIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host group. Host group does not exist or you have no access to it.'));
     }
     if (!API::Host()->isWritable($hostIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host. Host does not exist or you have no access to it.'));
     }
     if (!API::Template()->isWritable($templateIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition template. Template does not exist or you have no access to it.'));
     }
     if (!API::Trigger()->isWritable($triggerIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger. Trigger does not exist or you have no access to it.'));
     }
     if (!API::DRule()->isWritable($discoveryRuleIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery rule. Discovery rule does not exist or you have no access to it.'));
     }
     if (!API::DCheck()->isWritable($proxyIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check. Discovery check does not exist or you have no access to it.'));
     }
     if (!API::Proxy()->isWritable($proxyidsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition proxy. Proxy does not exist or you have no access to it.'));
     }
     return true;
 }
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:101,代码来源:CAction.php

示例4: actionConditionValueToString


//.........这里部分代码省略.........
                    $dRuleIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DCHECK:
                    $dCheckIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DOBJECT:
                    $result[$i][$j] = discovery_object2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSERVICE_TYPE:
                    $result[$i][$j] = discovery_check_type2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSTATUS:
                    $result[$i][$j] = discovery_object_status2str($condition['value']);
                    break;
                case CONDITION_TYPE_EVENT_TYPE:
                    $result[$i][$j] = eventType($condition['value']);
                    break;
            }
        }
    }
    $groups = [];
    $triggers = [];
    $hosts = [];
    $templates = [];
    $proxies = [];
    $dRules = [];
    $dChecks = [];
    if ($groupIds) {
        $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupIds, 'preservekeys' => true]);
    }
    if ($triggerIds) {
        $triggers = API::Trigger()->get(['output' => ['description'], 'triggerids' => $triggerIds, 'expandDescription' => true, 'selectHosts' => ['name'], 'preservekeys' => true]);
    }
    if ($hostIds) {
        $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]);
    }
    if ($templateIds) {
        $templates = API::Template()->get(['output' => ['name'], 'templateids' => $templateIds, 'preservekeys' => true]);
    }
    if ($proxyIds) {
        $proxies = API::Proxy()->get(['output' => ['host'], 'proxyids' => $proxyIds, 'preservekeys' => true]);
    }
    if ($dRuleIds) {
        $dRules = API::DRule()->get(['output' => ['name'], 'druleids' => $dRuleIds, 'preservekeys' => true]);
    }
    if ($dCheckIds) {
        $dChecks = API::DCheck()->get(['output' => ['type', 'key_', 'ports'], 'dcheckids' => $dCheckIds, 'selectDRules' => ['name'], 'preservekeys' => true]);
    }
    if ($groups || $triggers || $hosts || $templates || $proxies || $dRules || $dChecks) {
        foreach ($actions as $i => $action) {
            foreach ($action['filter']['conditions'] as $j => $condition) {
                $id = $condition['value'];
                switch ($condition['conditiontype']) {
                    case CONDITION_TYPE_HOST_GROUP:
                        if (isset($groups[$id])) {
                            $result[$i][$j] = $groups[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TRIGGER:
                        if (isset($triggers[$id])) {
                            $host = reset($triggers[$id]['hosts']);
                            $result[$i][$j] = $host['name'] . NAME_DELIMITER . $triggers[$id]['description'];
                        }
                        break;
                    case CONDITION_TYPE_HOST:
                        if (isset($hosts[$id])) {
                            $result[$i][$j] = $hosts[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TEMPLATE:
                        if (isset($templates[$id])) {
                            $result[$i][$j] = $templates[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_PROXY:
                        if (isset($proxies[$id])) {
                            $result[$i][$j] = $proxies[$id]['host'];
                        }
                        break;
                    case CONDITION_TYPE_DRULE:
                        if (isset($dRules[$id])) {
                            $result[$i][$j] = $dRules[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_DCHECK:
                        if (isset($dChecks[$id])) {
                            $drule = reset($dChecks[$id]['drules']);
                            $type = $dChecks[$id]['type'];
                            $key_ = $dChecks[$id]['key_'];
                            $ports = $dChecks[$id]['ports'];
                            $dCheck = discovery_check2str($type, $key_, $ports);
                            $result[$i][$j] = $drule['name'] . NAME_DELIMITER . $dCheck;
                        }
                        break;
                }
            }
        }
    }
    return $result;
}
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:101,代码来源:actions.inc.php

示例5: elseif

        $table->addRow($name);
    }
    $widget->addItem($table)->show();
} elseif ($srctbl === 'drules') {
    $table = (new CTableInfo())->setHeader(_('Name'));
    $dRules = API::DRule()->get(['output' => ['druleid', 'name']]);
    order_result($dRules, 'name');
    foreach ($dRules as $dRule) {
        $action = get_window_opener($dstfrm, $dstfld1, $dRule[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $dRule[$srcfld2]) : '');
        $name = (new CLink($dRule['name'], 'javascript:void(0);'))->onClick($action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $widget->addItem($table)->show();
} elseif ($srctbl === 'dchecks') {
    $table = (new CTableInfo())->setHeader(_('Name'));
    $dRules = API::DRule()->get(['selectDChecks' => ['dcheckid', 'type', 'key_', 'ports'], 'output' => ['druleid', 'name']]);
    order_result($dRules, 'name');
    foreach ($dRules as $dRule) {
        foreach ($dRule['dchecks'] as $dCheck) {
            $name = $dRule['name'] . NAME_DELIMITER . discovery_check2str($dCheck['type'], $dCheck['key_'], $dCheck['ports']);
            $action = get_window_opener($dstfrm, $dstfld1, $dCheck[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $name) : '');
            $name = (new CLink($name, 'javascript:void(0);'))->onClick($action . ' close_window(); return false;');
            $table->addRow($name);
        }
    }
    $widget->addItem($table)->show();
} elseif ($srctbl == 'proxies') {
    $table = (new CTableInfo())->setHeader(_('Name'));
    $result = DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . ' ORDER BY h.host,h.hostid');
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:popup.php

示例6: get

 /**
  * Get Service data
  *
  * @param _array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['groupids'] ServiceGroup IDs
  * @param array $options['hostids'] Service IDs
  * @param boolean $options['monitored_hosts'] only monitored Services
  * @param boolean $options['templated_hosts'] include templates in result
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['with_historical_items'] only with historical items
  * @param boolean $options['with_triggers'] only with triggers
  * @param boolean $options['with_httptests'] only with http tests
  * @param boolean $options['with_graphs'] only with graphs
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param boolean $options['selectGroups'] select ServiceGroups
  * @param boolean $options['selectTemplates'] select Templates
  * @param boolean $options['selectItems'] select Items
  * @param boolean $options['selectTriggers'] select Triggers
  * @param boolean $options['selectGraphs'] select Graphs
  * @param boolean $options['selectApplications'] select Applications
  * @param boolean $options['selectMacros'] select Macros
  * @param int $options['count'] count Services, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in Service name
  * @param string $options['extendPattern'] search hosts by pattern in Service name, ip and DNS
  * @param int $options['limit'] limit selection
  * @param string $options['sortfield'] field to sort by
  * @param string $options['sortorder'] sort order
  * @return array|boolean Service data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $nodeCheck = false;
     $userType = self::$userData['type'];
     // allowed columns for sorting
     $sortColumns = array('dserviceid', 'dhostid', 'ip');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     $sqlParts = array('select' => array('dservices' => 'ds.dserviceid'), 'from' => array('dservices' => 'dservices ds'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'dserviceids' => null, 'dhostids' => null, 'dcheckids' => null, 'druleids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectDRules' => null, 'selectDHosts' => null, 'selectDChecks' => null, 'selectHosts' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['dservices']);
         $dbTable = DB::getSchema('dservices');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $userType) {
     } elseif (is_null($options['editable']) && self::$userData['type'] == USER_TYPE_ZABBIX_ADMIN) {
     } elseif (!is_null($options['editable']) && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
         return array();
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // dserviceids
     if (!is_null($options['dserviceids'])) {
         zbx_value2array($options['dserviceids']);
         $sqlParts['where']['dserviceid'] = dbConditionInt('ds.dserviceid', $options['dserviceids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ds.dserviceid', $nodeids);
         }
     }
     // dhostids
     if (!is_null($options['dhostids'])) {
         zbx_value2array($options['dhostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['dhostid'] = 'ds.dhostid';
         }
         $sqlParts['where'][] = dbConditionInt('ds.dhostid', $options['dhostids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['dhostid'] = 'ds.dhostid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ds.dhostid', $nodeids);
         }
     }
     // dcheckids
     if (!is_null($options['dcheckids'])) {
         zbx_value2array($options['dcheckids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['dcheckid'] = 'dc.dcheckid';
         }
         $sqlParts['from']['dhosts'] = 'dhosts dh';
         $sqlParts['from']['dchecks'] = 'dchecks dc';
         $sqlParts['where'][] = dbConditionInt('dc.dcheckid', $options['dcheckids']);
         $sqlParts['where']['dhds'] = 'dh.hostid=ds.hostid';
         $sqlParts['where']['dcdh'] = 'dc.druleid=dh.druleid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['dcheckid'] = 'dc.dcheckid';
         }
     }
     // druleids
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CDService.php

示例7: update

 /**
  * Update existing drules
  *
  * @param array(
  * 	druleid => int,
  *  name => string,
  *  proxy_hostid => int,
  *  iprange => string,
  *  delay => string,
  *  status => int,
  *  dchecks => array(
  *  	array(
  * 			dcheckid => int,
  *  		type => int,
  *  		ports => string,
  *  		key_ => string,
  *  		snmp_community => string,
  *  		snmpv3_securityname => string,
  *  		snmpv3_securitylevel => int,
  *  		snmpv3_authpassphrase => string,
  *  		snmpv3_privpassphrase => string,
  *  		uniq => int,
  *  	), ...
  *  )
  * ) $drules
  * @return array
  */
 public function update(array $dRules)
 {
     $this->checkInput($dRules);
     $this->validateRequiredFields($dRules, __FUNCTION__);
     $dRuleids = zbx_objectValues($dRules, 'druleid');
     $dRulesDb = API::DRule()->get(array('druleids' => $dRuleids, 'output' => API_OUTPUT_EXTEND, 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true));
     $defaultValues = DB::getDefaults('dchecks');
     $dRulesUpdate = $dCheckidsDelete = $dChecksCreate = array();
     foreach ($dRules as $dRule) {
         // checking to the duplicate names
         if (strcmp($dRulesDb[$dRule['druleid']]['name'], $dRule['name']) != 0) {
             if ($this->exists($dRule)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule [%s] already exists', $dRule['name']));
             }
         }
         $dRulesUpdate[] = array('values' => $dRule, 'where' => array('druleid' => $dRule['druleid']));
         $dbChecks = $dRulesDb[$dRule['druleid']]['dchecks'];
         $newChecks = $dRule['dchecks'];
         foreach ($newChecks as &$dCheck) {
             $dCheck += $defaultValues;
         }
         unset($dCheck);
         foreach ($newChecks as $newnum => $newdCheck) {
             foreach ($dbChecks as $exnum => $exdCheck) {
                 $equal = true;
                 foreach ($exdCheck as $fieldName => $dCheckField) {
                     if (isset($newdCheck[$fieldName]) && strcmp($dCheckField, $newdCheck[$fieldName]) !== 0) {
                         $equal = false;
                         break;
                     }
                 }
                 if ($equal) {
                     unset($dRule['dchecks'][$newnum]);
                     unset($dbChecks[$exnum]);
                 }
             }
         }
         foreach ($dRule['dchecks'] as $dCheck) {
             $dCheck['druleid'] = $dRule['druleid'];
             $dChecksCreate[] = $dCheck;
         }
         $dCheckidsDelete = array_merge($dCheckidsDelete, zbx_objectValues($dbChecks, 'dcheckid'));
     }
     DB::update('drules', $dRulesUpdate);
     if (!empty($dCheckidsDelete)) {
         $this->deleteChecks($dCheckidsDelete);
     }
     DB::insert('dchecks', $dChecksCreate);
     return array('druleids' => $dRuleids);
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:77,代码来源:CDRule.php

示例8: access_deny

        access_deny();
    }
}
/*
 * Display
 */
$data = array('fullscreen' => $_REQUEST['fullscreen'], 'druleid' => getRequest('druleid', 0), 'sort' => $sortField, 'sortorder' => $sortOrder, 'services' => array(), 'drules' => array());
$data['pageFilter'] = new CPageFilter(array('drules' => array('filter' => array('status' => DRULE_STATUS_ACTIVE)), 'druleid' => getRequest('druleid')));
if ($data['pageFilter']->drulesSelected) {
    // discovery rules
    $options = array('filter' => array('status' => DRULE_STATUS_ACTIVE), 'selectDHosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND);
    if ($data['pageFilter']->druleid > 0) {
        $options['druleids'] = $data['pageFilter']->druleid;
        // set selected discovery rule id
    }
    $data['drules'] = API::DRule()->get($options);
    if (!empty($data['drules'])) {
        order_result($data['drules'], 'name');
    }
    // discovery services
    $options = array('selectHosts' => array('hostid', 'name', 'status'), 'output' => API_OUTPUT_EXTEND, 'sortfield' => $sortField, 'sortorder' => $sortOrder, 'limitSelects' => 1);
    if (!empty($data['druleid'])) {
        $options['druleids'] = $data['druleid'];
    } else {
        $options['druleids'] = zbx_objectValues($data['drules'], 'druleid');
    }
    $dservices = API::DService()->get($options);
    // user macros
    $data['macros'] = API::UserMacro()->get(array('output' => API_OUTPUT_EXTEND, 'globalmacro' => true));
    $data['macros'] = zbx_toHash($data['macros'], 'macro');
    // services
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:31,代码来源:discovery.php

示例9: update

 /**
  * Update existing drules.
  *
  * @param array(
  * 	druleid => int,
  *  name => string,
  *  proxy_hostid => int,
  *  iprange => string,
  *  delay => string,
  *  status => int,
  *  dchecks => array(
  *  	array(
  * 			dcheckid => int,
  *  		type => int,
  *  		ports => string,
  *  		key_ => string,
  *  		snmp_community => string,
  *  		snmpv3_securityname => string,
  *  		snmpv3_securitylevel => int,
  *  		snmpv3_authpassphrase => string,
  *  		snmpv3_privpassphrase => string,
  *  		uniq => int,
  *  	), ...
  *  )
  * ) $dRules
  *
  * @return array
  */
 public function update(array $dRules)
 {
     $this->checkInput($dRules);
     $this->validateRequiredFields($dRules, __FUNCTION__);
     $dRuleIds = zbx_objectValues($dRules, 'druleid');
     $dRulesDb = API::DRule()->get(array('druleids' => $dRuleIds, 'output' => API_OUTPUT_EXTEND, 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true));
     $defaultValues = DB::getDefaults('dchecks');
     $dRulesUpdate = array();
     $dCheckIdsDelete = array();
     $dChecksCreate = array();
     $dRuleNamesChanged = array();
     // validate drule duplicate names
     foreach ($dRules as $dRule) {
         if (!isset($dRulesDb[$dRule['druleid']])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
         }
         if ($dRulesDb[$dRule['druleid']]['name'] !== $dRule['name']) {
             if (isset($dRuleNamesChanged[$dRule['name']])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule "%1$s" already exists.', $dRule['name']));
             } else {
                 $dRuleNamesChanged[$dRule['name']] = $dRule['name'];
             }
         }
     }
     if ($dRuleNamesChanged) {
         $dbDRules = API::getApiService()->select($this->tableName(), array('output' => array('name'), 'filter' => array('name' => $dRuleNamesChanged), 'limit' => 1));
         if ($dbDRules) {
             $dbDRule = reset($dbDRules);
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule "%1$s" already exists.', $dbDRule['name']));
         }
     }
     foreach ($dRules as $dRule) {
         $dRulesUpdate[] = array('values' => $dRule, 'where' => array('druleid' => $dRule['druleid']));
         // update dchecks
         $dbChecks = $dRulesDb[$dRule['druleid']]['dchecks'];
         $newChecks = array();
         $oldChecks = array();
         foreach ($dRule['dchecks'] as $check) {
             $check['druleid'] = $dRule['druleid'];
             if (!isset($check['dcheckid'])) {
                 $newChecks[] = array_merge($defaultValues, $check);
             } else {
                 $oldChecks[] = $check;
             }
         }
         $delDCheckIds = array_diff(zbx_objectValues($dbChecks, 'dcheckid'), zbx_objectValues($oldChecks, 'dcheckid'));
         if ($delDCheckIds) {
             $this->deleteActionConditions($delDCheckIds);
         }
         DB::replace('dchecks', $dbChecks, array_merge($oldChecks, $newChecks));
     }
     DB::update('drules', $dRulesUpdate);
     return array('druleids' => $dRuleIds);
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:82,代码来源:CDRule.php

示例10: validateConditionsPermissions

 /**
  * Check permissions to DB entities referenced by action conditions.
  *
  * @param array $conditions   conditions for which permissions to referenced DB entities will be checked
  */
 protected function validateConditionsPermissions(array $conditions)
 {
     $hostGroupIdsAll = array();
     $templateIdsAll = array();
     $triggerIdsAll = array();
     $hostIdsAll = array();
     $discoveryRuleIdsAll = array();
     $discoveryCheckIdsAll = array();
     $proxyIdsAll = array();
     foreach ($conditions as $condition) {
         $conditionValue = $condition['value'];
         // validate condition values depending on condition type
         switch ($condition['conditiontype']) {
             case CONDITION_TYPE_HOST_GROUP:
                 $hostGroupIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_TEMPLATE:
                 $templateIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_TRIGGER:
                 $triggerIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_HOST:
                 $hostIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_DRULE:
                 $discoveryRuleIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_DCHECK:
                 $discoveryCheckIdsAll[$conditionValue] = $conditionValue;
                 break;
             case CONDITION_TYPE_PROXY:
                 $proxyIdsAll[$conditionValue] = $conditionValue;
                 break;
         }
     }
     if (!API::HostGroup()->isWritable($hostGroupIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host group. Host group does not exist or you have no access to it.'));
     }
     if (!API::Host()->isWritable($hostIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host. Host does not exist or you have no access to it.'));
     }
     if (!API::Template()->isWritable($templateIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition template. Template does not exist or you have no access to it.'));
     }
     if (!API::Trigger()->isWritable($triggerIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger. Trigger does not exist or you have no access to it.'));
     }
     if (!API::DRule()->isWritable($discoveryRuleIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery rule. Discovery rule does not exist or you have no access to it.'));
     }
     if (!API::DCheck()->isWritable($discoveryCheckIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check. Discovery check does not exist or you have no access to it.'));
     }
     if (!API::Proxy()->isWritable($proxyIdsAll)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition proxy. Proxy does not exist or you have no access to it.'));
     }
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:63,代码来源:CAction.php

示例11: _initDiscoveries

 /**
  * Load the available network discovery rules, choose the selected rule and remember the selection.
  *
  * @param int   $druleid
  * @param array $options
  */
 private function _initDiscoveries($druleid, array $options)
 {
     $def_options = array('nodeids' => $this->config['all_nodes'] ? get_current_nodeid() : null, 'output' => API_OUTPUT_EXTEND);
     $options = zbx_array_merge($def_options, $options);
     $drules = API::DRule()->get($options);
     order_result($drules, 'name');
     $this->data['drules'] = array();
     foreach ($drules as $drule) {
         $this->data['drules'][$drule['druleid']] = $drule;
     }
     if (is_null($druleid)) {
         $druleid = $this->_profileIds['druleid'];
     }
     if (!isset($this->data['drules'][$druleid]) && $druleid > 0 || is_null($druleid)) {
         if ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONE) {
             $druleid = 0;
         } elseif (is_null($this->_requestIds['druleid']) || $this->_requestIds['druleid'] > 0) {
             $druleids = array_keys($this->data['drules']);
             $druleid = empty($druleids) ? 0 : reset($druleids);
         }
     }
     CProfile::update($this->_profileIdx['drules'], $druleid, PROFILE_TYPE_ID);
     CProfile::update(self::DRULE_LATEST_IDX, $druleid, PROFILE_TYPE_ID);
     $this->isSelected['drulesSelected'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['drules']) || $druleid > 0;
     $this->isSelected['drulesAll'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['drules']) && $druleid == 0;
     $this->ids['druleid'] = $druleid;
 }
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:33,代码来源:class.cpagefilter.php

示例12: order_result

    }
    // get proxies
    $data['proxies'] = API::Proxy()->get(array('output' => API_OUTPUT_EXTEND));
    order_result($data['proxies'], 'host');
    // render view
    $discoveryView = new CView('configuration.discovery.edit', $data);
    $discoveryView->render();
    $discoveryView->show();
} else {
    $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
    $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
    CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
    CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
    $data = array('sort' => $sortField, 'sortorder' => $sortOrder);
    // get drules
    $data['drules'] = API::DRule()->get(array('output' => array('proxy_hostid', 'name', 'status', 'iprange', 'delay'), 'selectDChecks' => array('type'), 'editable' => true));
    if ($data['drules']) {
        foreach ($data['drules'] as $key => $drule) {
            // checks
            $checks = array();
            foreach ($drule['dchecks'] as $check) {
                $checks[$check['type']] = discovery_check_type2str($check['type']);
            }
            order_result($checks);
            $data['drules'][$key]['checks'] = $checks;
            // description
            $data['drules'][$key]['description'] = array();
            if ($drule['proxy_hostid']) {
                $proxy = get_host_by_hostid($drule['proxy_hostid']);
                array_push($data['drules'][$key]['description'], $proxy['host'] . NAME_DELIMITER);
            }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:31,代码来源:discoveryconf.php

示例13: update

 /**
  * Update existing drules.
  *
  * @param array(
  * 	druleid => int,
  *  name => string,
  *  proxy_hostid => int,
  *  iprange => string,
  *  delay => string,
  *  status => int,
  *  dchecks => array(
  *  	array(
  * 			dcheckid => int,
  *  		type => int,
  *  		ports => string,
  *  		key_ => string,
  *  		snmp_community => string,
  *  		snmpv3_securityname => string,
  *  		snmpv3_securitylevel => int,
  *  		snmpv3_authpassphrase => string,
  *  		snmpv3_privpassphrase => string,
  *  		uniq => int,
  *  	), ...
  *  )
  * ) $dRules
  *
  * @return array
  */
 public function update(array $dRules)
 {
     $this->checkInput($dRules);
     $this->validateRequiredFields($dRules, __FUNCTION__);
     $dRuleIds = zbx_objectValues($dRules, 'druleid');
     $dRulesDb = API::DRule()->get(array('druleids' => $dRuleIds, 'output' => API_OUTPUT_EXTEND, 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true));
     $defaultValues = DB::getDefaults('dchecks');
     $dRulesUpdate = $dCheckIdsDelete = $dChecksCreate = array();
     foreach ($dRules as $dRule) {
         // validate drule duplicate names
         if (strcmp($dRulesDb[$dRule['druleid']]['name'], $dRule['name']) != 0) {
             if ($this->exists($dRule)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule "%s" already exists.', $dRule['name']));
             }
         }
         $dRulesUpdate[] = array('values' => $dRule, 'where' => array('druleid' => $dRule['druleid']));
         // update dchecks
         $dbChecks = $dRulesDb[$dRule['druleid']]['dchecks'];
         $newChecks = array();
         foreach ($dRule['dchecks'] as $cnum => $check) {
             if (!isset($check['druleid'])) {
                 $check['druleid'] = $dRule['druleid'];
                 unset($check['dcheckid']);
                 $newChecks[] = array_merge($defaultValues, $check);
                 unset($dRule['dchecks'][$cnum]);
             }
         }
         $delDCheckIds = array_diff(zbx_objectValues($dbChecks, 'dcheckid'), zbx_objectValues($dRule['dchecks'], 'dcheckid'));
         if ($delDCheckIds) {
             $this->deleteActionConditions($delDCheckIds);
         }
         DB::replace('dchecks', $dbChecks, array_merge($dRule['dchecks'], $newChecks));
     }
     DB::update('drules', $dRulesUpdate);
     return array('druleids' => $dRuleIds);
 }
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:64,代码来源:CDRule.php

示例14: elseif

    $table->show();
} elseif ($srctbl == 'drules') {
    $table = new CTableInfo(_('No discovery rules defined.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT d.* FROM drules d WHERE ' . DBin_node('d.druleid', $nodeid));
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'dchecks') {
    $table = new CTableInfo(_('No discovery checks defined.'));
    $table->setHeader(_('Name'));
    $dRules = API::DRule()->get(array('selectDChecks' => array('dcheckid', 'type', 'key_', 'ports'), 'output' => API_OUTPUT_EXTEND));
    foreach ($dRules as $dRule) {
        foreach ($dRule['dchecks'] as $dCheck) {
            $name = $dRule['name'] . ':' . discovery_check2str($dCheck['type'], $dCheck['key_'], $dCheck['ports']);
            $action = get_window_opener($dstfrm, $dstfld1, $dCheck[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $name) : '');
            $name = new CSpan($name, 'link');
            $name->setAttribute('onclick', $action . ' close_window(); return false;');
            $table->addRow($name);
        }
    }
    $table->show();
} elseif ($srctbl == 'proxies') {
    $table = new CTableInfo(_('No proxies defined.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT h.hostid,h.host' . ' FROM hosts h' . ' WHERE ' . DBin_node('h.hostid', $nodeid) . ' AND h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . ' ORDER BY h.host,h.hostid');
    while ($row = DBfetch($result)) {
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:popup.php

示例15: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $dserviceIds = array_keys($result);
     // select_drules
     if ($options['selectDRules'] !== null && $options['selectDRules'] != API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         // discovered items
         $dbRules = DBselect('SELECT ds.dserviceid,dh.druleid' . ' FROM dservices ds,dhosts dh' . ' WHERE ' . dbConditionInt('ds.dserviceid', $dserviceIds) . ' AND ds.dhostid=dh.dhostid');
         while ($rule = DBfetch($dbRules)) {
             $relationMap->addRelation($rule['dserviceid'], $rule['druleid']);
         }
         $drules = API::DRule()->get(['output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         if (!is_null($options['limitSelects'])) {
             order_result($drules, 'name');
         }
         $result = $relationMap->mapMany($result, $drules, 'drules');
     }
     // selectDHosts
     if ($options['selectDHosts'] !== null && $options['selectDHosts'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'dserviceid', 'dhostid');
         $dhosts = API::DHost()->get(['output' => $options['selectDHosts'], 'dhosts' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         if (!is_null($options['limitSelects'])) {
             order_result($dhosts, 'dhostid');
         }
         $result = $relationMap->mapMany($result, $dhosts, 'dhosts', $options['limitSelects']);
     }
     // selectHosts
     if (!is_null($options['selectHosts'])) {
         if ($options['selectHosts'] != API_OUTPUT_COUNT) {
             $relationMap = new CRelationMap();
             // discovered items
             $dbRules = DBselect('SELECT ds.dserviceid,i.hostid' . ' FROM dservices ds,interface i' . ' WHERE ' . dbConditionInt('ds.dserviceid', $dserviceIds) . ' AND ds.ip=i.ip');
             while ($rule = DBfetch($dbRules)) {
                 $relationMap->addRelation($rule['dserviceid'], $rule['hostid']);
             }
             $hosts = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true, 'sortfield' => 'status']);
             if (!is_null($options['limitSelects'])) {
                 order_result($hosts, 'hostid');
             }
             $result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']);
         } else {
             $hosts = API::Host()->get(['dserviceids' => $dserviceIds, 'countOutput' => true, 'groupCount' => true]);
             $hosts = zbx_toHash($hosts, 'hostid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($hosts[$dserviceid])) {
                     $result[$dserviceid]['hosts'] = $hosts[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['hosts'] = 0;
                 }
             }
         }
     }
     return $result;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:55,代码来源:CDService.php


注:本文中的API::DRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。