コード例 #1
0
 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);
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: CAction.php プロジェクト: itnihao/zatree-2.2
 /**
  * Validate conditions.
  *
  * @static
  *
  * @param array $conditions
  * @param int   $conditions['conditiontype']
  * @param array $conditions['value']
  *
  * @return bool
  */
 public static function validateConditions($conditions, $update = false)
 {
     $conditions = zbx_toArray($conditions);
     $hostGroupIdsAll = array();
     $templateIdsAll = array();
     $triggerIdsAll = array();
     $hostIdsAll = array();
     $discoveryRuleIdsAll = array();
     $proxyIdsAll = array();
     $proxyidsAll = array();
     // build validators
     $timePeriodValidator = new CTimePeriodValidator();
     $discoveryCheckTypeValidator = new CSetValidator(array('values' => array_keys(discovery_check_type2str())));
     $discoveryObjectStatusValidator = new CSetValidator(array('values' => array_keys(discovery_object_status2str())));
     $triggerSeverityValidator = new CSetValidator(array('values' => array_keys(getSeverityCaption())));
     $discoveryObjectValidator = new CSetValidator(array('values' => array_keys(discovery_object2str())));
     $triggerValueValidator = new CSetValidator(array('values' => array_keys(trigger_value2str())));
     $eventTypeValidator = new CSetValidator(array('values' => array_keys(eventType())));
     foreach ($conditions as $condition) {
         // on create operator is mandatory and needs validation, but on update it must be validated only if it's set
         if (!$update || $update && isset($condition['operator'])) {
             $operatorValidator = new CSetValidator(array('values' => get_operators_by_conditiontype($condition['conditiontype'])));
             if (!$operatorValidator->validate($condition['operator'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition operator.'));
             }
         }
         if (!$update || $update && isset($condition['value'])) {
             // validate condition values depending on condition type
             switch ($condition['conditiontype']) {
                 case CONDITION_TYPE_HOST_GROUP:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $hostGroupIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_TEMPLATE:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $templateIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_TRIGGER:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $triggerIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_HOST:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $hostIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_DRULE:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $discoveryRuleIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_DCHECK:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $proxyIdsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_PROXY:
                     if (!$condition['value']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     }
                     $proxyidsAll[$condition['value']] = $condition['value'];
                     break;
                 case CONDITION_TYPE_DOBJECT:
                     if (zbx_empty($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.'));
                     } elseif (!$discoveryObjectValidator->validate($condition['value'])) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery object.'));
                     }
                     break;
                 case CONDITION_TYPE_TIME_PERIOD:
                     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;
 }
コード例 #4
0
ファイル: actions.inc.php プロジェクト: jbfavre/debian-zabbix
/**
 * Converts numerical action condition values to their corresponding string values according to action condition type.
 *
 * For action condition types such as: hosts, host groups, templates, proxies, triggers, discovery rules
 * and discovery checks, action condition values contain IDs. All unique IDs are first collected and then queried.
 * For other action condition types values are returned as they are or converted using simple string convertion
 * functions according to action condition type.
 *
 * @param array $actions							array of actions
 * @param array $action['filter']					array containing arrays of action conditions and other data
 * @param array $action['filter']['conditions']		array of action conditions
 * @param array $config								array containing configuration parameters for getting trigger
 *													severity names
 *
 * @return array									returns an array of actions condition string values
 */
function actionConditionValueToString(array $actions, array $config)
{
    $result = [];
    $groupIds = [];
    $triggerIds = [];
    $hostIds = [];
    $templateIds = [];
    $proxyIds = [];
    $dRuleIds = [];
    $dCheckIds = [];
    foreach ($actions as $i => $action) {
        $result[$i] = [];
        foreach ($action['filter']['conditions'] as $j => $condition) {
            // unknown types and all of the default values for other types are 'Unknown'
            $result[$i][$j] = _('Unknown');
            switch ($condition['conditiontype']) {
                case CONDITION_TYPE_HOST_GROUP:
                    $groupIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TRIGGER:
                    $triggerIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_HOST:
                    $hostIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TEMPLATE:
                    $templateIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_PROXY:
                    $proxyIds[$condition['value']] = $condition['value'];
                    break;
                    // return values as is for following condition types
                // return values as is for following condition types
                case CONDITION_TYPE_TRIGGER_NAME:
                case CONDITION_TYPE_HOST_METADATA:
                case CONDITION_TYPE_HOST_NAME:
                case CONDITION_TYPE_TIME_PERIOD:
                case CONDITION_TYPE_DHOST_IP:
                case CONDITION_TYPE_DSERVICE_PORT:
                case CONDITION_TYPE_DUPTIME:
                case CONDITION_TYPE_DVALUE:
                case CONDITION_TYPE_APPLICATION:
                    $result[$i][$j] = $condition['value'];
                    break;
                case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
                    $result[$i][$j] = $condition['value'] ? _('Ack') : _('Not Ack');
                    break;
                case CONDITION_TYPE_MAINTENANCE:
                    $result[$i][$j] = _('maintenance');
                    break;
                case CONDITION_TYPE_TRIGGER_VALUE:
                    $result[$i][$j] = trigger_value2str($condition['value']);
                    break;
                case CONDITION_TYPE_TRIGGER_SEVERITY:
                    $result[$i][$j] = getSeverityName($condition['value'], $config);
                    break;
                case CONDITION_TYPE_DRULE:
                    $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;
}
コード例 #5
0
ファイル: popup.php プロジェクト: jbfavre/debian-zabbix
        $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]) : '');
コード例 #6
0
 /**
  * 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
     if (!is_null($options['druleids'])) {
         zbx_value2array($options['druleids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['druleid'] = 'dh.druleid';
         }
         $sqlParts['from']['dhosts'] = 'dhosts dh';
         $sqlParts['where']['druleid'] = dbConditionInt('dh.druleid', $options['druleids']);
         $sqlParts['where']['dhds'] = 'dh.dhostid=ds.dhostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['druleid'] = 'dh.druleid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('dh.druleid', $nodeids);
         }
     }
     // node check !!!!!
     // should last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sqlParts['where'][] = DBin_node('ds.dserviceid', $nodeids);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['dservices'] = 'ds.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT ds.dserviceid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sqlParts['group'] as $key => $fields) {
                 $sqlParts['select'][$key] = $fields;
             }
         }
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('dservices ds', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('dservices ds', $options, $sqlParts);
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'ds');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     //-------
     $dserviceids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['group'])) {
         $sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sqlParts) . ' ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere . $sqlGroup . $sqlOrder;
     //SDI($sql);
     $res = DBselect($sql, $sqlLimit);
     while ($dservice = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $dservice;
             } else {
                 $result = $dservice['rowscount'];
             }
         } else {
             $dserviceids[$dservice['dserviceid']] = $dservice['dserviceid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$dservice['dserviceid']] = array('dserviceid' => $dservice['dserviceid']);
             } else {
                 if (!isset($result[$dservice['dserviceid']])) {
                     $result[$dservice['dserviceid']] = array();
                 }
                 if (!is_null($options['selectDRules']) && !isset($result[$dservice['dserviceid']]['drules'])) {
                     $result[$dservice['dserviceid']]['drules'] = array();
                 }
                 if (!is_null($options['selectDHosts']) && !isset($result[$dservice['dserviceid']]['dhosts'])) {
                     $result[$dservice['dserviceid']]['dhosts'] = array();
                 }
                 if (!is_null($options['selectDChecks']) && !isset($result[$dservice['dserviceid']]['dchecks'])) {
                     $result[$dservice['dserviceid']]['dchecks'] = array();
                 }
                 if (!is_null($options['selectHosts']) && !isset($result[$dservice['dserviceid']]['hosts'])) {
                     $result[$dservice['dserviceid']]['hosts'] = array();
                 }
                 // druleids
                 if (isset($dservice['druleid']) && is_null($options['selectDRules'])) {
                     if (!isset($result[$dservice['dserviceid']]['drules'])) {
                         $result[$dservice['dserviceid']]['drules'] = array();
                     }
                     $result[$dservice['dserviceid']]['drules'][] = array('druleid' => $dservice['druleid']);
                 }
                 // dhostids
                 if (isset($dservice['dhostid']) && is_null($options['selectDHosts'])) {
                     if (!isset($result[$dservice['dserviceid']]['dhosts'])) {
                         $result[$dservice['dserviceid']]['dhosts'] = array();
                     }
                     $result[$dservice['dserviceid']]['dhosts'][] = array('dhostid' => $dservice['dhostid']);
                 }
                 // dcheckids
                 if (isset($dservice['dcheckid']) && is_null($options['selectDChecks'])) {
                     if (!isset($result[$dservice['dserviceid']]['dchecks'])) {
                         $result[$dservice['dserviceid']]['dchecks'] = array();
                     }
                     $result[$dservice['dserviceid']]['dchecks'][] = array('dcheckid' => $dservice['dcheckid']);
                 }
                 $result[$dservice['dserviceid']] += $dservice;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // Adding Objects
     // select_drules
     if (!is_null($options['selectDRules'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1);
         if (is_array($options['selectDRules']) || str_in_array($options['selectDRules'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDRules'];
             $drules = API::DRule()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($drules, 'name');
             }
             foreach ($drules as $druleid => $drule) {
                 unset($drules[$druleid]['dservices']);
                 $count = array();
                 foreach ($drule['dservices'] as $dnum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['drules'][] =& $drules[$druleid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectDRules']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $drules = API::DRule()->get($objParams);
             $drules = zbx_toHash($drules, 'dserviceid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($drules[$dserviceid])) {
                     $result[$dserviceid]['drules'] = $drules[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['drules'] = 0;
                 }
             }
         }
     }
     // selectDHosts
     if (!is_null($options['selectDHosts'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1);
         if (is_array($options['selectDHosts']) || str_in_array($options['selectDHosts'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDHosts'];
             $dhosts = API::DHost()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($dhosts, 'dhostid');
             }
             foreach ($dhosts as $dhostid => $dhost) {
                 unset($dhosts[$dhostid]['dservices']);
                 foreach ($dhost['dservices'] as $snum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['dhosts'][] =& $dhosts[$dhostid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectDHosts']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $dhosts = API::DHost()->get($objParams);
             $dhosts = zbx_toHash($dhosts, 'dhostid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($dhosts[$dserviceid])) {
                     $result[$dserviceid]['dhosts'] = $dhosts[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['dhosts'] = 0;
                 }
             }
         }
     }
     // selectHosts
     if (!is_null($options['selectHosts'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1, 'sortfield' => 'status');
         if (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectHosts'];
             $hosts = API::Host()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($hosts, 'hostid');
             }
             foreach ($hosts as $hostid => $host) {
                 unset($hosts[$hostid]['dservices']);
                 foreach ($host['dservices'] as $dnum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['hosts'][] =& $hosts[$hostid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectHosts']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $hosts = API::Host()->get($objParams);
             $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;
                 }
             }
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
ファイル: discovery.php プロジェクト: omidmt/zabbix-greenplum
        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
コード例 #9
0
ファイル: CDRule.php プロジェクト: omidmt/zabbix-greenplum
 /**
  * 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);
 }
コード例 #10
0
ファイル: CAction.php プロジェクト: omidmt/zabbix-greenplum
 /**
  * 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.'));
     }
 }
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
ファイル: discoveryconf.php プロジェクト: TonywalkerCN/Zabbix
    }
    // 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);
            }
コード例 #13
0
ファイル: CDRule.php プロジェクト: itnihao/zatree-2.2
 /**
  * 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);
 }
コード例 #14
0
    $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)) {
コード例 #15
0
ファイル: CDService.php プロジェクト: jbfavre/debian-zabbix
 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;
 }
コード例 #16
0
function make_discovery_status()
{
    $options = array('filter' => array('status' => DHOST_STATUS_ACTIVE), 'selectDHosts' => array('druleid', 'dhostid', 'status'), 'output' => API_OUTPUT_EXTEND);
    $drules = API::DRule()->get($options);
    CArrayHelper::sort($drules, array(array('field' => 'name', 'order' => ZBX_SORT_UP)));
    foreach ($drules as $drnum => $drule) {
        $drules[$drnum]['up'] = 0;
        $drules[$drnum]['down'] = 0;
        foreach ($drule['dhosts'] as $dhost) {
            if (DRULE_STATUS_DISABLED == $dhost['status']) {
                $drules[$drnum]['down']++;
            } else {
                $drules[$drnum]['up']++;
            }
        }
    }
    $header = array(new CCol(_('Discovery rule'), 'center'), new CCol(_x('Up', 'discovery results in dashboard')), new CCol(_x('Down', 'discovery results in dashboard')));
    $table = new CTableInfo();
    $table->setHeader($header, 'header');
    foreach ($drules as $drule) {
        $table->addRow(array(new CLink($drule['name'], 'discovery.php?druleid=' . $drule['druleid']), new CSpan($drule['up'], 'green'), new CSpan($drule['down'], $drule['down'] > 0 ? 'red' : 'green')));
    }
    $script = new CJsScript(get_js('jQuery("#' . WIDGET_DISCOVERY_STATUS . '_footer").html("' . _s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)) . '");'));
    return new CDiv(array($table, $script));
}
コード例 #17
0
ファイル: discoveryconf.php プロジェクト: itnihao/zatree-2.2
        }
        order_result($data['drule']['dchecks'], 'name');
    }
    // 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 {
    $data = array();
    $config = select_config();
    $sortfield = getPageSortField('name');
    // get drules
    $data['drules'] = API::DRule()->get(array('output' => array('proxy_hostid', 'name', 'status', 'iprange', 'delay'), 'selectDChecks' => array('type'), 'editable' => true, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1));
    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);
            }
コード例 #18
0
        foreach ($data['drule']['dchecks'] as $id => $dcheck) {
            $data['drule']['dchecks'][$id]['name'] = discovery_check2str($dcheck['type'], isset($dcheck['key_']) ? $dcheck['key_'] : '', isset($dcheck['ports']) ? $dcheck['ports'] : '');
        }
        order_result($data['drule']['dchecks'], 'name');
    }
    // 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 {
    $data = array();
    // get drules
    $data['drules'] = API::DRule()->get(array('output' => API_OUTPUT_EXTEND, 'sortfield' => getPageSortField('name'), 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true));
    if (!empty($data['drules'])) {
        foreach ($data['drules'] as $druleid => $drule) {
            // checks
            $checks = array();
            foreach ($drule['dchecks'] as $check) {
                $checks[$check['type']] = discovery_check_type2str($check['type']);
            }
            order_result($checks);
            $data['drules'][$druleid]['checks'] = $checks;
            // description
            $data['drules'][$druleid]['description'] = array();
            if (!empty($drule['proxy_hostid'])) {
                $proxy = get_host_by_hostid($drule['proxy_hostid']);
                array_push($data['drules'][$druleid]['description'], $proxy['host'] . NAME_DELIMITER);
            }
コード例 #19
0
ファイル: CDHost.php プロジェクト: TonywalkerCN/Zabbix
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $dhostIds = array_keys($result);
     // select_drules
     if ($options['selectDRules'] !== null && $options['selectDRules'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'dhostid', 'druleid');
         $drules = API::DRule()->get(array('output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         if (!is_null($options['limitSelects'])) {
             order_result($drules, 'name');
         }
         $result = $relationMap->mapMany($result, $drules, 'drules', $options['limitSelects']);
     }
     // selectDServices
     if (!is_null($options['selectDServices'])) {
         if ($options['selectDServices'] != API_OUTPUT_COUNT) {
             $dservices = API::DService()->get(array('output' => $this->outputExtend($options['selectDServices'], array('dserviceid', 'dhostid')), 'dhostids' => $dhostIds, 'preservekeys' => true));
             $relationMap = $this->createRelationMap($dservices, 'dhostid', 'dserviceid');
             $dservices = $this->unsetExtraFields($dservices, array('dserviceid', 'dhostid'), $options['selectDServices']);
             if (!is_null($options['limitSelects'])) {
                 order_result($dservices, 'name');
             }
             $result = $relationMap->mapMany($result, $dservices, 'dservices', $options['limitSelects']);
         } else {
             $dservices = API::DService()->get(array('output' => $options['selectDServices'], 'dhostids' => $dhostIds, 'countOutput' => true, 'groupCount' => true));
             $dservices = zbx_toHash($dservices, 'dhostid');
             foreach ($result as $dhostid => $dhost) {
                 if (isset($dservices[$dhostid])) {
                     $result[$dhostid]['dservices'] = $dservices[$dhostid]['rowscount'];
                 } else {
                     $result[$dhostid]['dservices'] = 0;
                 }
             }
         }
     }
     return $result;
 }
コード例 #20
0
ファイル: CDCheck.php プロジェクト: TonywalkerCN/Zabbix
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     // select_drules
     if ($options['selectDRules'] !== null && $options['selectDRules'] !== API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'dcheckid', 'druleid');
         $drules = API::DRule()->get(array('output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         if (!is_null($options['limitSelects'])) {
             order_result($drules, 'name');
         }
         $result = $relationMap->mapMany($result, $drules, 'drules', $options['limitSelects']);
     }
     return $result;
 }
コード例 #21
0
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
$drules = API::DRule()->get(['output' => ['druleid', 'name'], 'selectDHosts' => ['status'], 'filter' => ['status' => DHOST_STATUS_ACTIVE]]);
CArrayHelper::sort($drules, ['name']);
foreach ($drules as &$drule) {
    $drule['up'] = 0;
    $drule['down'] = 0;
    foreach ($drule['dhosts'] as $dhost) {
        if (DRULE_STATUS_DISABLED == $dhost['status']) {
            $drule['down']++;
        } else {
            $drule['up']++;
        }
    }
}
unset($drule);
$table = (new CTableInfo())->setHeader([_('Discovery rule'), _x('Up', 'discovery results in dashboard'), _x('Down', 'discovery results in dashboard')]);
foreach ($drules as $drule) {
コード例 #22
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $this->dataId = 'discovery';
     $sort_field = $this->data['sort'];
     $sort_order = $this->data['sortorder'];
     $druleid = $this->data['druleid'];
     // discovery rules
     $options = ['output' => ['druleid', 'name'], 'selectDHosts' => ['dhostid', 'status', 'lastup', 'lastdown'], 'filter' => ['status' => DRULE_STATUS_ACTIVE]];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
         // set selected discovery rule id
     }
     $drules = API::DRule()->get($options);
     if ($drules) {
         order_result($drules, 'name');
     }
     // discovery services
     $options = ['selectHosts' => ['hostid', 'name', 'status'], 'output' => ['dserviceid', 'type', 'key_', 'port', 'status', 'lastup', 'lastdown', 'ip', 'dns'], 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limitSelects' => 1];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
     } else {
         $options['druleids'] = zbx_objectValues($drules, 'druleid');
     }
     $dservices = API::DService()->get($options);
     // user macros
     $macros = API::UserMacro()->get(['output' => ['macro', 'value'], 'globalmacro' => true]);
     $macros = zbx_toHash($macros, 'macro');
     // services
     $services = [];
     foreach ($dservices as $dservice) {
         $key_ = $dservice['key_'];
         if ($key_ !== '') {
             if (array_key_exists($key_, $macros)) {
                 $key_ = $macros[$key_]['value'];
             }
             $key_ = ': ' . $key_;
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $services[$service_name] = 1;
     }
     ksort($services);
     // discovery services to hash
     $dservices = zbx_toHash($dservices, 'dserviceid');
     // discovery hosts
     $dhosts = API::DHost()->get(['druleids' => zbx_objectValues($drules, 'druleid'), 'selectDServices' => ['dserviceid', 'ip', 'dns', 'type', 'status', 'key_'], 'output' => ['dhostid', 'lastdown', 'lastup', 'druleid']]);
     $dhosts = zbx_toHash($dhosts, 'dhostid');
     $header = [make_sorting_header(_('Discovered device'), 'ip', $sort_field, $sort_order, 'zabbix.php?action=discovery.view'), _('Monitored host'), _('Uptime') . '/' . _('Downtime')];
     foreach ($services as $name => $foo) {
         $header[] = (new CColHeader($name))->addClass('vertical_rotation');
     }
     // create table
     $table = (new CTableInfo())->makeVerticalRotation()->setHeader($header);
     foreach ($drules as $drule) {
         $discovery_info = [];
         foreach ($drule['dhosts'] as $dhost) {
             if ($dhost['status'] == DHOST_STATUS_DISABLED) {
                 $hclass = 'disabled';
                 $htime = $dhost['lastdown'];
             } else {
                 $hclass = 'enabled';
                 $htime = $dhost['lastup'];
             }
             // $primary_ip stores the primary host ip of the dhost
             $primary_ip = '';
             foreach ($dhosts[$dhost['dhostid']]['dservices'] as $dservice) {
                 $dservice = $dservices[$dservice['dserviceid']];
                 $hostName = '';
                 $host = reset($dservices[$dservice['dserviceid']]['hosts']);
                 if (!is_null($host)) {
                     $hostName = $host['name'];
                 }
                 if ($primary_ip !== '') {
                     if ($primary_ip === $dservice['ip']) {
                         $htype = 'primary';
                     } else {
                         $htype = 'slave';
                     }
                 } else {
                     $primary_ip = $dservice['ip'];
                     $htype = 'primary';
                 }
                 if (!array_key_exists($dservice['ip'], $discovery_info)) {
                     $discovery_info[$dservice['ip']] = ['ip' => $dservice['ip'], 'dns' => $dservice['dns'], 'type' => $htype, 'class' => $hclass, 'host' => $hostName, 'time' => $htime];
                 }
                 if ($dservice['status'] == DSVC_STATUS_DISABLED) {
                     $class = ZBX_STYLE_INACTIVE_BG;
                     $time = 'lastdown';
                 } else {
                     $class = ZBX_STYLE_ACTIVE_BG;
                     $time = 'lastup';
                 }
                 $key_ = $dservice['key_'];
                 if ($key_ !== '') {
                     if (array_key_exists($key_, $macros)) {
                         $key_ = $macros[$key_]['value'];
                     }
                     $key_ = NAME_DELIMITER . $key_;
                 }
                 $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
                 $discovery_info[$dservice['ip']]['services'][$service_name] = ['class' => $class, 'time' => $dservice[$time]];
             }
         }
         if ($druleid == 0 && $discovery_info) {
             $col = new CCol([bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')']);
             $col->setColSpan(count($services) + 3);
             $table->addRow($col);
         }
         order_result($discovery_info, $sort_field, $sort_order);
         foreach ($discovery_info as $ip => $h_data) {
             $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
             $row = [$h_data['type'] == 'primary' ? (new CSpan($ip . $dns))->addClass($h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(array_key_exists('host', $h_data) ? $h_data['host'] : ''), (new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(['value' => time() - $h_data['time'], 'units' => 'uptime'])))->addClass($h_data['class'])];
             foreach ($services as $name => $foo) {
                 $class = null;
                 $time = SPACE;
                 $hint = (new CDiv(SPACE))->addClass($class);
                 $hint_table = null;
                 if (array_key_exists($name, $h_data['services'])) {
                     $class = $h_data['services'][$name]['class'];
                     $time = $h_data['services'][$name]['time'];
                     $hint_table = (new CTableInfo())->setAttribute('style', 'width: auto;');
                     if ($class == ZBX_STYLE_ACTIVE_BG) {
                         $hint_table->setHeader(_('Uptime'));
                     } else {
                         $hint_table->setHeader(_('Downtime'));
                     }
                     $hint_table->addRow((new CCol(zbx_date2age($h_data['services'][$name]['time'])))->addClass($class));
                 }
                 $column = (new CCol($hint))->addClass($class);
                 if (!is_null($hint_table)) {
                     $column->setHint($hint_table);
                 }
                 $row[] = $column;
             }
             $table->addRow($row);
         }
     }
     return $this->getOutput($table, true, $this->data);
 }
コード例 #23
0
ファイル: popup.php プロジェクト: itnihao/zatree-2.2
    $table->show();
} elseif ($srctbl == 'drules') {
    $table = new CTableInfo(_('No discovery rules found.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT d.*' . ' FROM drules d' . whereDbNode('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 rules found.'));
    $table->setHeader(_('Name'));
    $dRules = API::DRule()->get(array('selectDChecks' => array('dcheckid', 'type', 'key_', 'ports'), 'output' => array('name'), 'nodeids' => $nodeId));
    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 CSpan($name, 'link');
            $name->setAttribute('onclick', $action . ' close_window(); return false;');
            $table->addRow($name);
        }
    }
    $table->show();
} elseif ($srctbl == 'proxies') {
    $table = new CTableInfo(_('No proxies found.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . andDbNode('h.hostid', $nodeId) . ' ORDER BY h.host,h.hostid');
    while ($row = DBfetch($result)) {
コード例 #24
0
ファイル: blocks.inc.php プロジェクト: SandipSingh14/Zabbix_
function make_discovery_status()
{
    $options = array('filter' => array('status' => DHOST_STATUS_ACTIVE), 'selectDHosts' => array('druleid', 'dhostid', 'status'), 'output' => API_OUTPUT_EXTEND);
    $drules = API::DRule()->get($options);
    foreach ($drules as &$drule) {
        $drule['nodename'] = get_node_name_by_elid($drule['druleid']);
    }
    unset($drule);
    // we need natural sort
    $sortFields = array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP));
    CArrayHelper::sort($drules, $sortFields);
    foreach ($drules as $drnum => $drule) {
        $drules[$drnum]['up'] = 0;
        $drules[$drnum]['down'] = 0;
        foreach ($drule['dhosts'] as $dhost) {
            if (DRULE_STATUS_DISABLED == $dhost['status']) {
                $drules[$drnum]['down']++;
            } else {
                $drules[$drnum]['up']++;
            }
        }
    }
    $header = array(is_show_all_nodes() ? new CCol(_('Node'), 'center') : null, new CCol(_('Discovery rule'), 'center'), new CCol(_x('Up', 'discovery results in dashboard')), new CCol(_x('Down', 'discovery results in dashboard')));
    $table = new CTableInfo();
    $table->setHeader($header, 'header');
    foreach ($drules as $drule) {
        $table->addRow(array($drule['nodename'], new CLink($drule['nodename'] . ($drule['nodename'] ? NAME_DELIMITER : '') . $drule['name'], 'discovery.php?druleid=' . $drule['druleid']), new CSpan($drule['up'], 'green'), new CSpan($drule['down'], $drule['down'] > 0 ? 'red' : 'green')));
    }
    $script = new CJSScript(get_js("jQuery('#hat_dscvry_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($table, $script));
}
コード例 #25
0
 /**
  * Validate conditions.
  *
  * @static
  * @param $conditions
  * @return bool
  */
 public static function validateConditions($conditions)
 {
     $conditions = zbx_toArray($conditions);
     $hostGroupidsAll = array();
     $templateidsAll = array();
     $triggeridsAll = array();
     $hostidsAll = array();
     $discoveryRuleidsAll = array();
     $discoveryCheckidsAll = array();
     $proxyidsAll = array();
     $discoveryCheckTypes = discovery_check_type2str();
     $discoveryObjectStatuses = discovery_object_status2str();
     $timePeriodValidator = new CTimePeriodValidator();
     foreach ($conditions as $condition) {
         switch ($condition['conditiontype']) {
             case CONDITION_TYPE_HOST_GROUP:
                 $hostGroupidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_HOST_TEMPLATE:
                 $templateidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_TRIGGER:
                 $triggeridsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_HOST:
                 $hostidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_DRULE:
                 $discoveryRuleidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_DCHECK:
                 $discoveryCheckidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_PROXY:
                 $proxyidsAll[$condition['value']] = $condition['value'];
                 break;
             case CONDITION_TYPE_TIME_PERIOD:
                 if (!$timePeriodValidator->validate($condition['value'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition period "%s".', $condition['value']));
                 }
                 break;
             case CONDITION_TYPE_DHOST_IP:
                 if (!validate_ip_range($condition['value'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition ip "%s".', $condition['value']));
                 }
                 break;
             case CONDITION_TYPE_DSERVICE_TYPE:
                 if (!isset($discoveryCheckTypes[$condition['value']])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check.'));
                 }
                 break;
             case CONDITION_TYPE_DSERVICE_PORT:
                 if (!validate_port_list($condition['value'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition port "%s".', $condition['value']));
                 }
                 break;
             case CONDITION_TYPE_DSTATUS:
                 if (!isset($discoveryObjectStatuses[$condition['value']])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery status.'));
                 }
                 break;
             case CONDITION_TYPE_MAINTENANCE:
                 // maintenance condition has no value...
                 break;
             case CONDITION_TYPE_TRIGGER_NAME:
             case CONDITION_TYPE_TRIGGER_VALUE:
             case CONDITION_TYPE_TRIGGER_SEVERITY:
             case CONDITION_TYPE_NODE:
             case CONDITION_TYPE_DOBJECT:
             case CONDITION_TYPE_DUPTIME:
             case CONDITION_TYPE_DVALUE:
             case CONDITION_TYPE_APPLICATION:
             case CONDITION_TYPE_HOST_NAME:
                 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($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.'));
     }
     return true;
 }