function get_userid_by_usrgrpid($usrgrpids) { zbx_value2array($usrgrpids); $userids = array(); $db_users = DBselect('SELECT DISTINCT u.userid' . ' FROM users u,users_groups ug' . ' WHERE u.userid=ug.userid' . ' AND ' . dbConditionInt('ug.usrgrpid', $usrgrpids) . ' AND ' . DBin_node('ug.usrgrpid', false)); while ($user = DBFetch($db_users)) { $userids[$user['userid']] = $user['userid']; } return $userids; }
function get_userid_by_usrgrpid($usrgrpids) { zbx_value2array($usrgrpids); $userids = array(); $sql = 'SELECT DISTINCT u.userid ' . ' FROM users u,users_groups ug ' . ' WHERE u.userid=ug.userid ' . ' AND ' . DBcondition('ug.usrgrpid', $usrgrpids) . ' AND ' . DBin_node('ug.usrgrpid', get_current_nodeid(false)); $res = DBselect($sql); while ($user = DBFetch($res)) { $userids[$user['userid']] = $user['userid']; } return $userids; }
if ('hat' == $_REQUEST['favobj']) { update_profile('web.services.hats.' . $_REQUEST['favid'] . '.state', $_REQUEST['state'], PROFILE_TYPE_INT); } } if (PAGE_TYPE_JS == $page['type'] || PAGE_TYPE_HTML_BLOCK == $page['type']) { exit; } //-------- //-------------------------------------------------------------------------- $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY); $query = 'SELECT DISTINCT s.serviceid, sl.servicedownid, sl_p.serviceupid as serviceupid, s.triggerid, ' . ' s.name as caption, s.algorithm, t.description, t.expression, s.sortorder, sl.linkid, s.showsla, s.goodsla, s.status ' . ' FROM services s ' . ' LEFT JOIN triggers t ON s.triggerid = t.triggerid ' . ' LEFT JOIN services_links sl ON s.serviceid = sl.serviceupid and NOT(sl.soft=0) ' . ' LEFT JOIN services_links sl_p ON s.serviceid = sl_p.servicedownid and sl_p.soft=0 ' . ' WHERE ' . DBin_node('s.serviceid') . ' AND (t.triggerid IS NULL OR ' . DBcondition('t.triggerid', $available_triggers) . ') ' . ' ORDER BY s.sortorder, sl_p.serviceupid, s.serviceid'; $result = DBSelect($query); $services = array(); $row = array('id' => 0, 'serviceid' => 0, 'serviceupid' => 0, 'caption' => S_ROOT_SMALL, 'status' => SPACE, 'algorithm' => SPACE, 'description' => SPACE, 'soft' => 0, 'linkid' => ''); $services[0] = $row; while ($row = DBFetch($result)) { $row['id'] = $row['serviceid']; empty($row['serviceupid']) ? $row['serviceupid'] = '0' : ''; empty($row['triggerid']) ? $row['description'] = 'None' : ($row['description'] = expand_trigger_description($row['triggerid'])); if (isset($services[$row['serviceid']])) { $services[$row['serviceid']] = array_merge($services[$row['serviceid']], $row); } else { $services[$row['serviceid']] = $row; } if (isset($row['serviceupid'])) { $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0); } if (isset($row['servicedownid'])) { $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']); } }
function make_graph_submenu() { $graphids = array(); $fav_graphs = get_favorites('web.favorite.graphids'); foreach ($fav_graphs as $key => $favorite) { $source = $favorite['source']; $sourceid = $favorite['value']; if ('itemid' == $source) { if (!($item = get_item_by_itemid($sourceid))) { continue; } $item_added = true; $host = get_host_by_itemid($sourceid); $item["description"] = item_description($item); $graphids[] = array('name' => $host['host'] . ':' . $item['description'], 'favobj' => 'itemid', 'favid' => $sourceid, 'action' => 'remove'); } else { if (!($graph = get_graph_by_graphid($sourceid))) { continue; } $graph_added = true; $result = get_hosts_by_graphid($sourceid); $ghost = DBFetch($result); $graphids[] = array('name' => $ghost['host'] . ':' . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'action' => 'remove'); } } if (isset($graph_added)) { $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_GRAPHS, 'favobj' => 'graphid', 'favid' => 0, 'action' => 'remove'); } if (isset($item_added)) { $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_SIMPLE_GRAPHS, 'favobj' => 'itemid', 'favid' => 0, 'action' => 'remove'); } return $graphids; }
function get_user_actionmenu($userid) { $usr_grp_all_in = array(); $usr_grp_gui_in = array(); $usr_grp_status_in = array(); $sql = 'SELECT DISTINCT g.name, g.usrgrpid, g.gui_access, g.users_status ' . ' FROM users_groups ug, usrgrp g ' . ' WHERE ug.userid=' . $userid . ' AND g.usrgrpid=ug.usrgrpid ' . ' AND ' . DBin_node('g.usrgrpid', get_current_nodeid(false)); $res = DBselect($sql); while ($group = DBFetch($res)) { $group['name'] = htmlspecialchars($group['name']); $gui_access = $group['gui_access']; $users_status = $group['users_status']; unset($group['gui_access']); unset($group['users_status']); $usr_grp_all_in[] = $group; if ($gui_access != GROUP_GUI_ACCESS_SYSTEM) { $usr_grp_gui_in[] = $group; } if ($users_status == GROUP_STATUS_DISABLED) { $usr_grp_status_in[] = $group; } } $action = new CSpan(S_SELECT); $script = new CScript("javascript: create_user_menu(event," . $userid . "," . zbx_jsvalue($usr_grp_all_in) . "," . zbx_jsvalue($usr_grp_gui_in) . "," . zbx_jsvalue($usr_grp_status_in) . ");"); $action->AddAction('onclick', $script); $action->AddOption('onmouseover', 'javascript: this.style.cursor = "pointer";'); return $action; }
function delete_action($actionid) { $return = DBexecute('delete from conditions where actionid=' . $actionid); $opers = get_operations_by_actionid($actionid); while ($operation = DBFetch($opers)) { DBexecute('DELETE FROM opconditions WHERE operationid=' . $operation['operationid']); } if ($return) { $result = DBexecute('delete from operations where actionid=' . $actionid); } if ($return) { $result = DBexecute('delete from alerts where actionid=' . $actionid); } if ($return) { $result = DBexecute('delete from actions where actionid=' . $actionid); } return $result; }
function get_service_childs($serviceid, $soft = 0) { $childs = array(); $query = 'SELECT sl.servicedownid ' . ' FROM services_links sl ' . ' WHERE sl.serviceupid = ' . $serviceid . ($soft ? '' : ' AND sl.soft <> 1'); $res = DBSelect($query); while ($row = DBFetch($res)) { $childs[] = $row['servicedownid']; $childs = array_merge($childs, get_service_childs($row['servicedownid'])); } return $childs; }
/** * Delete host groups. * * @param array $groupids * @param bool $nopermissions * * @return boolean */ public function delete($groupids, $nopermissions = false) { if (empty($groupids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.')); } $groupids = zbx_toArray($groupids); sort($groupids); $delGroups = $this->get(array('groupids' => $groupids, 'editable' => true, 'output' => array('groupid', 'name', 'internal'), 'preservekeys' => true, 'nopermissions' => $nopermissions)); foreach ($groupids as $groupid) { if (!isset($delGroups[$groupid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); } if ($delGroups[$groupid]['internal'] == ZBX_INTERNAL_GROUP) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host group "%1$s" is internal and can not be deleted.', $delGroups[$groupid]['name'])); } } // check if a group is used in a group prototype $groupPrototype = DBFetch(DBselect('SELECT groupid' . ' FROM group_prototype gp' . ' WHERE ' . dbConditionInt('groupid', $groupids), 1)); if ($groupPrototype) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Group "%1$s" cannot be deleted, because it is used by a host prototype.', $delGroups[$groupPrototype['groupid']]['name'])); } $dltGroupids = getDeletableHostGroups($groupids); if (count($groupids) != count($dltGroupids)) { foreach ($groupids as $groupid) { if (isset($dltGroupids[$groupid])) { continue; } self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host group "%1$s" cannot be deleted, because some hosts depend on it.', $delGroups[$groupid]['name'])); } } $dbScripts = API::Script()->get(array('groupids' => $groupids, 'output' => array('scriptid', 'groupid'), 'nopermissions' => true)); if (!empty($dbScripts)) { foreach ($dbScripts as $script) { if ($script['groupid'] == 0) { continue; } self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host group "%1$s" cannot be deleted, because it is used in a global script.', $delGroups[$script['groupid']]['name'])); } } // delete screens items $resources = array(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW); DB::delete('screens_items', array('resourceid' => $groupids, 'resourcetype' => $resources)); // delete sysmap element if (!empty($groupids)) { DB::delete('sysmaps_elements', array('elementtype' => SYSMAP_ELEMENT_TYPE_HOST_GROUP, 'elementid' => $groupids)); } // disable actions // actions from conditions $actionids = array(); $dbActions = DBselect('SELECT DISTINCT c.actionid' . ' FROM conditions c' . ' WHERE c.conditiontype=' . CONDITION_TYPE_HOST_GROUP . ' AND ' . dbConditionString('c.value', $groupids)); while ($dbAction = DBfetch($dbActions)) { $actionids[$dbAction['actionid']] = $dbAction['actionid']; } // actions from operations $dbActions = DBselect('SELECT DISTINCT o.actionid' . ' FROM operations o,opgroup og' . ' WHERE o.operationid=og.operationid' . ' AND ' . dbConditionInt('og.groupid', $groupids)); while ($dbAction = DBfetch($dbActions)) { $actionids[$dbAction['actionid']] = $dbAction['actionid']; } if (!empty($actionids)) { $update = array(); $update[] = array('values' => array('status' => ACTION_STATUS_DISABLED), 'where' => array('actionid' => $actionids)); DB::update('actions', $update); } // delete action conditions DB::delete('conditions', array('conditiontype' => CONDITION_TYPE_HOST_GROUP, 'value' => $groupids)); // delete action operation commands $operationids = array(); $dbOperations = DBselect('SELECT DISTINCT og.operationid' . ' FROM opgroup og' . ' WHERE ' . dbConditionInt('og.groupid', $groupids)); while ($dbOperation = DBfetch($dbOperations)) { $operationids[$dbOperation['operationid']] = $dbOperation['operationid']; } DB::delete('opgroup', array('groupid' => $groupids)); // delete empty operations $delOperationids = array(); $dbOperations = DBselect('SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS (SELECT NULL FROM opgroup og WHERE o.operationid=og.operationid)'); while ($dbOperation = DBfetch($dbOperations)) { $delOperationids[$dbOperation['operationid']] = $dbOperation['operationid']; } DB::delete('operations', array('operationid' => $delOperationids)); DB::delete('groups', array('groupid' => $groupids)); DB::delete('profiles', array('idx' => 'web.dashconf.groups.groupids', 'value_id' => $groupids)); DB::delete('profiles', array('idx' => 'web.dashconf.groups.hide.groupids', 'value_id' => $groupids)); // TODO: remove audit foreach ($groupids as $groupid) { add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST_GROUP, $groupid, $delGroups[$groupid]['name'], 'groups', null, null); } return array('groupids' => $groupids); }
$triggerid = $service["triggerid"]; $linktrigger = isset($triggerid) ? 1 : 0; if (!isset($triggerid)) { $triggerid = 0; } $result = DBselect('select * from services_times where serviceid=' . $service['serviceid']); while ($db_stime = DBfetch($result)) { $stime = array('type' => $db_stime['type'], 'from' => $db_stime['ts_from'], 'to' => $db_stime['ts_to'], 'note' => $db_stime['note']); if (str_in_array($stime, $service_times)) { continue; } array_push($service_times, $stime); } //links $query = 'SELECT DISTINCT sl.linkid, sl.soft, sl.serviceupid, sl.servicedownid, ' . ' s1.name as serviceupname, s2.name as servicedownname ' . ' FROM services s1, services s2, services_links sl ' . ' WHERE sl.serviceupid=s1.serviceid ' . ' AND sl.servicedownid=s2.serviceid ' . ' AND NOT(sl.soft=1) ' . ' AND sl.servicedownid=' . $service['serviceid']; if ($link = DBFetch(DBSelect($query))) { $parentid = $link["serviceupid"]; $parentname = $link["serviceupname"]; } else { $parentid = 0; $parentname = 'root'; } $query = 'SELECT DISTINCT s.*, sl.soft ' . ' FROM services s1, services s2, services_links sl, services s ' . ' WHERE (s.triggerid IS NULL OR ' . DBcondition('s.triggerid', $available_triggers) . ') ' . ' AND ' . DBin_node('s.serviceid') . ' AND sl.serviceupid=s1.serviceid ' . ' AND sl.servicedownid=s2.serviceid ' . ' AND sl.serviceupid=' . $service['serviceid'] . ' AND s.serviceid=sl.servicedownid'; $db_services = DBselect($query); $childs = array(); while ($db_service_data = DBfetch($db_services)) { $child = array('name' => $db_service_data["name"], 'serviceid' => $db_service_data["serviceid"], 'triggerid' => $db_service_data["triggerid"], 'soft' => $db_service_data['soft']); if (str_in_array($child, $childs)) { continue; } array_push($childs, $child);