Exemplo n.º 1
0
 private static function template($action, $params)
 {
     CTemplate::$error = array();
     switch ($action) {
         case 'add':
             $result = CTemplate::add($params);
             break;
         case 'get':
             $result = CTemplate::get($params);
             break;
         case 'getById':
             $result = CTemplate::getById($params);
             break;
         case 'getId':
             $result = CTemplate::getId($params);
             break;
         case 'update':
             $result = CTemplate::update($params);
             break;
         case 'linkHosts':
             $result = CTemplate::linkHosts($params);
             break;
         case 'unlinkHosts':
             $result = CTemplate::unlinkHosts($params);
             break;
         case 'linkTemplates':
             $result = CTemplate::linkTemplates($params);
             break;
         case 'unlinkTemplates':
             $result = CTemplate::unlinkTemplates($params);
             break;
         case 'delete':
             $result = CTemplate::delete($params);
             break;
         default:
             self::$result = array('error' => ZBX_API_ERROR_NO_METHOD, 'data' => 'Method: "' . $action . '" doesn\'t exist.');
             return;
             //exit function
     }
     if ($result !== false) {
         self::$result = array('result' => $result);
     } else {
         self::$result = CTemplate::$error;
     }
 }
Exemplo n.º 2
0
     $msg_ok = S_TEMPLATE_UPDATED;
     $msg_fail = S_CANNOT_UPDATE_TEMPLATE;
 } else {
     if ($result = CTemplate::add(array(array('host' => $template_name, 'groupids' => $groups)))) {
         $templateid = reset($result);
     } else {
         $result = false;
     }
     $msg_ok = S_TEMPLATE_ADDED;
     $msg_fail = S_CANNOT_ADD_TEMPLATE;
 }
 if ($result) {
     $original_templates = get_templates_by_hostid($templateid);
     $original_templates = array_keys($original_templates);
     $templates_to_link = array_diff($templates, $original_templates);
     $result &= CTemplate::linkTemplates(array('hostid' => $templateid, 'templateids' => $templates_to_link));
 }
 // --->>> <<<---
 // <<<--- FULL_CLONE --->>>
 if (!zbx_empty($templateid) && $templateid && $clone_templateid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_templateid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $templateid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_templateid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         $result &= copy_item_to_host($db_item['itemid'], $templateid, true);