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


PHP CApplication::create方法代码示例

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


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

示例1: db_save_httptest

function db_save_httptest($httptestid, $hostid, $application, $name, $authentication, $http_user, $http_password, $delay, $status, $agent, $macros, $steps)
{
    $history = 30;
    // TODO !!! Allow user to set this parameter
    $trends = 90;
    // TODO !!! Allow user to set this parameter
    if (!preg_match('/^([' . ZBX_PREG_PRINT . '])+$/u', $name)) {
        error(S_ONLY_CHARACTERS_ARE_ALLOWED);
        return false;
    }
    DBstart();
    try {
        $sql = 'SELECT t.httptestid' . ' FROM httptest t, applications a' . ' WHERE t.applicationid=a.applicationid' . ' AND a.hostid=' . $hostid . ' AND t.name=' . zbx_dbstr($name);
        $t = DBfetch(DBselect($sql));
        if (isset($httptestid) && $t && $t['httptestid'] != $httptestid || $t && !isset($httptestid)) {
            throw new Exception(S_SCENARIO_WITH_NAME . ' [ ' . $name . ' ] ' . S_ALREADY_EXISTS_SMALL);
        }
        $sql = 'SELECT applicationid FROM applications WHERE name=' . zbx_dbstr($application) . ' AND hostid=' . $hostid;
        if ($applicationid = DBfetch(DBselect($sql))) {
            $applicationid = $applicationid['applicationid'];
        } else {
            $result = CApplication::create(array('name' => $application, 'hostid' => $hostid));
            if (!$result) {
                throw new Exception(S_CANNOT_ADD_NEW_APPLICATION . ' [ ' . $application . ' ]');
            } else {
                $applicationid = reset($result['applicationids']);
            }
        }
        if (isset($httptestid)) {
            $sql = 'UPDATE httptest SET ' . ' applicationid=' . $applicationid . ', ' . ' name=' . zbx_dbstr($name) . ', ' . ' authentication=' . $authentication . ', ' . ' http_user=' . zbx_dbstr($http_user) . ', ' . ' http_password=' . zbx_dbstr($http_password) . ', ' . ' delay=' . $delay . ', ' . ' status=' . $status . ', ' . ' agent=' . zbx_dbstr($agent) . ', ' . ' macros=' . zbx_dbstr($macros) . ', ' . ' error=' . zbx_dbstr('') . ', ' . ' curstate=' . HTTPTEST_STATE_UNKNOWN . ' WHERE httptestid=' . $httptestid;
            if (!DBexecute($sql)) {
                throw new Exception('DBerror');
            }
        } else {
            $httptestid = get_dbid('httptest', 'httptestid');
            $values = array('httptestid' => $httptestid, 'applicationid' => $applicationid, 'name' => zbx_dbstr($name), 'authentication' => $authentication, 'http_user' => zbx_dbstr($http_user), 'http_password' => zbx_dbstr($http_password), 'delay' => $delay, 'status' => $status, 'agent' => zbx_dbstr($agent), 'macros' => zbx_dbstr($macros), 'curstate' => HTTPTEST_STATE_UNKNOWN);
            $sql = 'INSERT INTO httptest (' . implode(', ', array_keys($values)) . ') VALUES (' . implode(', ', $values) . ')';
            if (!DBexecute($sql)) {
                throw new Exception('DBerror');
            }
        }
        $httpstepids = array();
        foreach ($steps as $sid => $s) {
            if (!isset($s['name'])) {
                $s['name'] = '';
            }
            if (!isset($s['timeout'])) {
                $s['timeout'] = 15;
            }
            if (!isset($s['url'])) {
                $s['url'] = '';
            }
            if (!isset($s['posts'])) {
                $s['posts'] = '';
            }
            if (!isset($s['required'])) {
                $s['required'] = '';
            }
            if (!isset($s['status_codes'])) {
                $s['status_codes'] = '';
            }
            $result = db_save_step($hostid, $applicationid, $httptestid, $name, $s['name'], $sid + 1, $s['timeout'], $s['url'], $s['posts'], $s['required'], $s['status_codes'], $delay, $history, $trends);
            if (!$result) {
                throw new Exception('Cannot create web step');
            }
            $httpstepids[$result] = $result;
        }
        /* clean unneeded steps */
        $sql = 'SELECT httpstepid FROM httpstep WHERE httptestid=' . $httptestid;
        $db_steps = DBselect($sql);
        while ($step_data = DBfetch($db_steps)) {
            if (!isset($httpstepids[$step_data['httpstepid']])) {
                delete_httpstep($step_data['httpstepid']);
            }
        }
        $monitored_items = array(array('description' => 'Download speed for scenario \'$1\'', 'key_' => 'web.test.in[' . $name . ',,bps]', 'type' => ITEM_VALUE_TYPE_FLOAT, 'units' => 'Bps', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_IN), array('description' => 'Failed step of scenario \'$1\'', 'key_' => 'web.test.fail[' . $name . ']', 'type' => ITEM_VALUE_TYPE_UINT64, 'units' => '', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_LASTSTEP));
        foreach ($monitored_items as $item) {
            $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i, httptestitem hi ' . ' where hi.httptestid=' . $httptestid . ' and hi.itemid=i.itemid ' . ' and hi.type=' . $item['httptestitemtype']));
            if (!$item_data) {
                $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i where i.key_=' . zbx_dbstr($item['key_']) . ' and i.hostid=' . $hostid));
            }
            $item_args = array('description' => $item['description'], 'key_' => $item['key_'], 'hostid' => $hostid, 'delay' => $delay, 'type' => ITEM_TYPE_HTTPTEST, 'snmp_community' => '', 'snmp_oid' => '', 'value_type' => $item['type'], 'data_type' => ITEM_DATA_TYPE_DECIMAL, 'trapper_hosts' => 'localhost', 'snmp_port' => 161, 'units' => $item['units'], 'multiplier' => 0, 'snmpv3_securityname' => '', 'snmpv3_securitylevel' => 0, 'snmpv3_authpassphrase' => '', 'snmpv3_privpassphrase' => '', 'formula' => 0, 'logtimefmt' => '', 'delay_flex' => '', 'authtype' => 0, 'username' => '', 'password' => '', 'publickey' => '', 'privatekey' => '', 'params' => '', 'ipmi_sensor' => '', 'applications' => array($applicationid));
            if (!$item_data) {
                $item_args['history'] = $history;
                $item_args['status'] = ITEM_STATUS_ACTIVE;
                $item_args['delta'] = 0;
                $item_args['trends'] = $trends;
                $item_args['valuemapid'] = 0;
                if (!($itemid = add_item($item_args))) {
                    throw new Exception('Cannot add item');
                }
            } else {
                $itemid = $item_data['itemid'];
                $item_args['history'] = $item_data['history'];
                $item_args['status'] = $item_data['status'];
                $item_args['delta'] = $item_data['delta'];
                $item_args['trends'] = $item_data['trends'];
                $item_args['valuemapid'] = $item_data['valuemapid'];
                if (!update_item($itemid, $item_args)) {
                    throw new Exception('Cannot update item');
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:httptest.inc.php

示例2: parseMain

 public static function parseMain($rules)
 {
     $triggers_for_dependencies = array();
     try {
         if (isset($rules['host']['exist']) || isset($rules['host']['missed'])) {
             $xpath = new DOMXPath(self::$xml);
             $hosts = $xpath->query('hosts/host');
             foreach ($hosts as $hnum => $host) {
                 $host_db = self::mapXML2arr($host, XML_TAG_HOST);
                 if (!isset($host_db['status'])) {
                     $host_db['status'] = HOST_STATUS_TEMPLATE;
                 }
                 $current_host = $host_db['status'] == HOST_STATUS_TEMPLATE ? CTemplate::exists($host_db) : CHost::exists($host_db);
                 if (!$current_host && !isset($rules['host']['missed'])) {
                     info('Host [' . $host_db['host'] . '] skipped - user rule');
                     continue;
                     // break if update nonexist
                 }
                 if ($current_host && !isset($rules['host']['exist'])) {
                     info('Host [' . $host_db['host'] . '] skipped - user rule');
                     continue;
                     // break if not update exist
                 }
                 if (isset($host_db['proxy_hostid'])) {
                     $proxy_exists = CProxy::get(array('proxyids' => $host_db['proxy_hostid']));
                     if (empty($proxy_exists)) {
                         $host_db['proxy_hostid'] = 0;
                     }
                 }
                 if ($current_host) {
                     $options = array('filter' => array('host' => $host_db['host']), 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                     if ($host_db['status'] == HOST_STATUS_TEMPLATE) {
                         $current_host = CTemplate::get($options);
                     } else {
                         $current_host = CHost::get($options);
                     }
                     if (empty($current_host)) {
                         throw new APIException(1, 'No permission for host [' . $host_db['host'] . ']');
                     } else {
                         $current_host = reset($current_host);
                     }
                 }
                 // HOST GROUPS {{{
                 $groups = $xpath->query('groups/group', $host);
                 $host_db['groups'] = array();
                 $groups_to_parse = array();
                 foreach ($groups as $gnum => $group) {
                     $groups_to_parse[] = array('name' => $group->nodeValue);
                 }
                 if (empty($groups_to_parse)) {
                     $groups_to_parse[] = array('name' => ZBX_DEFAULT_IMPORT_HOST_GROUP);
                 }
                 foreach ($groups_to_parse as $group) {
                     $current_group = CHostGroup::exists($group);
                     if ($current_group) {
                         $options = array('filter' => $group, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                         $current_group = CHostGroup::get($options);
                         if (empty($current_group)) {
                             throw new APIException(1, 'No permissions for group ' . $group['name']);
                         }
                         $host_db['groups'][] = reset($current_group);
                     } else {
                         $result = CHostGroup::create($group);
                         if (!$result) {
                             throw new APIException(1, CHostGroup::resetErrors());
                         }
                         $options = array('groupids' => $result['groupids'], 'output' => API_OUTPUT_EXTEND);
                         $new_group = CHostgroup::get($options);
                         $host_db['groups'][] = reset($new_group);
                     }
                 }
                 // }}} HOST GROUPS
                 // MACROS
                 $macros = $xpath->query('macros/macro', $host);
                 $host_db['macros'] = array();
                 if ($macros->length > 0) {
                     foreach ($macros as $macro) {
                         $host_db['macros'][] = self::mapXML2arr($macro, XML_TAG_MACRO);
                     }
                 }
                 // }}} MACROS
                 // TEMPLATES {{{
                 if (isset($rules['template']['exist'])) {
                     $templates = $xpath->query('templates/template', $host);
                     $host_db['templates'] = array();
                     foreach ($templates as $tnum => $template) {
                         $options = array('filter' => array('host' => $template->nodeValue), 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                         $current_template = CTemplate::get($options);
                         if (empty($current_template)) {
                             throw new APIException(1, 'No permission for Template [' . $template->nodeValue . ']');
                         }
                         $current_template = reset($current_template);
                         if (!$current_template && !isset($rules['template']['missed'])) {
                             info('Template [' . $template->nodeValue . '] skipped - user rule');
                             continue;
                             // break if update nonexist
                         }
                         if ($current_template && !isset($rules['template']['exist'])) {
                             info('Template [' . $template->nodeValue . '] skipped - user rule');
                             continue;
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:export.inc.php


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