예제 #1
0
파일: hosts.php 프로젝트: rennhak/zabbix
         if ($result) {
             add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $app['name'] . '] from host [' . $host['host'] . ']');
         }
         unset($_REQUEST['form']);
         unset($_REQUEST['applicationid']);
     } else {
         /* group operations */
         $result = true;
         $applications = get_request('applications', array());
         $db_applications = DBselect('SELECT applicationid, name, hostid ' . ' FROM applications ' . ' WHERE ' . DBin_node('applicationid'));
         DBstart();
         while ($db_app = DBfetch($db_applications)) {
             if (!uint_in_array($db_app['applicationid'], $applications)) {
                 continue;
             }
             $result &= delete_application($db_app['applicationid']);
             if ($result) {
                 $host = get_host_by_hostid($db_app['hostid']);
                 add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $db_app['name'] . '] from host [' . $host['host'] . ']');
             }
         }
         $result = DBend($result);
         show_messages(true, S_APPLICATION_DELETED, NULL);
     }
     unset($_REQUEST['delete']);
 } else {
     if ($_REQUEST['config'] == 4 && (isset($_REQUEST['activate']) || isset($_REQUEST['disable']))) {
         /* group operations */
         $result = true;
         $applications = get_request('applications', array());
         DBstart();
예제 #2
0
function delete_template_applications($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $db_apps = get_applications_by_hostid($hostid);
    while ($db_app = DBfetch($db_apps)) {
        if ($db_app["templateid"] == 0) {
            continue;
        }
        if (!is_null($templateids)) {
            unset($skip);
            if ($tmp_app_data = get_application_by_applicationid($db_app["templateid"])) {
                if (!uint_in_array($tmp_app_data["hostid"], $templateids)) {
                    $skip = true;
                    break;
                }
            }
            if (isset($skip)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute("update applications set templateid=0 where applicationid=" . $db_app["applicationid"])) {
                info(S_APPLICATION . SPACE . "'" . $db_app["name"] . "'" . SPACE . S_UNLINKED_SMALL);
            }
        } else {
            delete_application($db_app["applicationid"]);
        }
    }
}
 /**
  * Delete Applications
  *
  * @param _array $applications
  * @param array $applications[0,...]['applicationid']
  * @return boolean
  */
 public static function delete($applicationids)
 {
     $applicationids = zbx_toArray($applicationids);
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('applicationids' => $applicationids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
         $del_applications = self::get($options);
         foreach ($applicationids as $applicationid) {
             if (!isset($del_applications[$applicationid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSIONS);
             }
             if ($del_applications[$applicationid]['templateid'] != 0) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, 'Cannot delete templated application');
             }
         }
         $result = delete_application($applicationids);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, S_CANNOT_DELETE_APPLICATION);
         }
         self::EndTransaction(true, __METHOD__);
         return array('applicationids' => $applicationids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }