function delete_script($scriptids) { zbx_value2array($scriptids); $sql = 'DELETE FROM scripts WHERE ' . DBcondition('scriptid', $scriptids); $result = DBexecute($sql); return $result; }
public function bodyToString() { global $USER_DETAILS; $this->cleanItems(); $total = 0; $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true)); $cond_from = ''; if (remove_nodes_from_id($this->groupid) > 0) { $cond_from = ', hosts_groups hg '; $cond_where = 'AND hg.hostid=h.hostid AND hg.groupid=' . $this->groupid; } else { $cond_where = ' AND ' . DBin_node('h.hostid', $this->nodeid); } $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $avail = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $notav = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $uncn = $host_cnt['cnt']; $total += $host_cnt['cnt']; $node = get_node_by_nodeid($this->nodeid); $header_str = S_HOSTS_INFO . SPACE; $header_str .= S_FOR_GROUP_SMALL . SPACE . '"'; if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= $group['name'] . '"'; } else { $header_str .= S_ALL_S . '"'; } $header = new CCol($header_str, "header"); if ($this->style == STYLE_HORISONTAL) { $header->SetColspan(4); } $this->addRow($header); $avail = new CCol($avail . ' ' . S_AVAILABLE, 'avail'); $notav = new CCol($notav . ' ' . S_NOT_AVAILABLE, 'notav'); $uncn = new CCol($uncn . ' ' . S_UNKNOWN, 'uncn'); $total = new CCol($total . ' ' . S_TOTAL, 'total'); if ($this->style == STYLE_HORISONTAL) { $this->addRow(array($avail, $notav, $uncn, $total)); } else { $this->addRow($avail); $this->addRow($notav); $this->addRow($uncn); $this->addRow($total); } return parent::bodyToString(); }
function updateMessageSettings($messages) { global $USER_DETAILS; if (!isset($messages['enabled'])) { $messages['enabled'] = 0; } if (isset($messages['triggers.severities'])) { $messages['triggers.severities'] = serialize($messages['triggers.severities']); } $sql = 'SELECT profileid, idx, source, value_str ' . ' FROM profiles ' . ' WHERE userid=' . $USER_DETAILS['userid'] . ' AND ' . DBcondition('idx', array('web.messages'), false, true); $db_profiles = DBselect($sql); while ($profile = DBfetch($db_profiles)) { $profile['value'] = $profile['value_str']; $dbMessages[$profile['source']] = $profile; } $inserts = array(); $updates = array(); foreach ($messages as $key => $value) { $values = array('userid' => $USER_DETAILS['userid'], 'idx' => 'web.messages', 'source' => $key, 'value_str' => $value, 'type' => PROFILE_TYPE_STR); if (!isset($dbMessages[$key])) { $inserts[] = $values; } else { if ($dbMessages[$key]['value'] != $value) { $updates[] = array('values' => $values, 'where' => array('profileid=' . $dbMessages[$key]['profileid'])); } } } try { DB::insert('profiles', $inserts); DB::update('profiles', $updates); } catch (APIException $e) { $errors = $e->getErrors(); $error = reset($errors); error($error); } return $messages; }
/** * Get history data * * {@source} * @access public * @static * @since 1.8.3 * @version 1.3 * * @param array $options * @param array $options['itemids'] * @param boolean $options['editable'] * @param string $options['pattern'] * @param int $options['limit'] * @param string $options['order'] * @return array|int item data as array or false if error */ public static function get($options = array()) { global $USER_DETAILS; $nodeCheck = false; $result = array(); $sort_columns = array('itemid', 'clock'); // allowed columns for sorting $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); // allowed output options for [ select_* ] params $sql_parts = array('select' => array('history' => 'h.itemid'), 'from' => array(), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null); $def_options = array('history' => ITEM_VALUE_TYPE_UINT64, 'nodeids' => null, 'hostids' => null, 'itemids' => null, 'triggerids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'time_from' => null, 'time_till' => null, 'output' => API_OUTPUT_REFER, 'countOutput' => null, 'groupCount' => null, 'groupOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($def_options, $options); switch ($options['history']) { case ITEM_VALUE_TYPE_LOG: $sql_parts['from']['history'] = 'history_log h'; $sort_columns[] = 'id'; break; case ITEM_VALUE_TYPE_TEXT: $sql_parts['from']['history'] = 'history_text h'; $sort_columns[] = 'id'; break; case ITEM_VALUE_TYPE_STR: $sql_parts['from']['history'] = 'history_str h'; break; case ITEM_VALUE_TYPE_UINT64: $sql_parts['from']['history'] = 'history_uint h'; break; case ITEM_VALUE_TYPE_FLOAT: default: $sql_parts['from']['history'] = 'history h'; } // editable + PERMISSION CHECK if (USER_TYPE_SUPER_ADMIN == $USER_DETAILS['type'] || $options['nopermissions']) { } else { $itemOptions = array('editable' => $options['editable'], 'preservekeys' => 1); if (!is_null($options['itemids'])) { $itemOptions['itemids'] = $options['itemids']; } $items = CItem::get($itemOptions); $options['itemids'] = array_keys($items); } // nodeids $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid(); // itemids if (!is_null($options['itemids'])) { zbx_value2array($options['itemids']); $sql_parts['where']['itemid'] = DBcondition('h.itemid', $options['itemids']); if (!$nodeCheck) { $nodeCheck = true; $sql_parts['where'][] = DBin_node('h.itemid', $nodeids); } } // hostids if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); if ($options['output'] != API_OUTPUT_SHORTEN) { $sql_parts['select']['hostid'] = 'i.hostid'; } $sql_parts['from']['items'] = 'items i'; $sql_parts['where']['i'] = DBcondition('i.hostid', $options['hostids']); $sql_parts['where']['hi'] = 'h.itemid=i.itemid'; if (!$nodeCheck) { $nodeCheck = true; $sql_parts['where'][] = DBin_node('i.hostid', $nodeids); } } // node check !!!!! // should be last, after all ****IDS checks if (!$nodeCheck) { $nodeCheck = true; $sql_parts['where'][] = DBin_node('h.itemid', $nodeids); } // time_from if (!is_null($options['time_from'])) { $sql_parts['select']['clock'] = 'h.clock'; $sql_parts['where']['clock_from'] = 'h.clock>=' . $options['time_from']; } // time_till if (!is_null($options['time_till'])) { $sql_parts['select']['clock'] = 'h.clock'; $sql_parts['where']['clock_till'] = 'h.clock<=' . $options['time_till']; } // filter if (is_array($options['filter'])) { zbx_db_filter($sql_parts['from']['history'], $options, $sql_parts); } // search if (is_array($options['search'])) { zbx_db_search($sql_parts['from']['history'], $options, $sql_parts); } // output if ($options['output'] == API_OUTPUT_EXTEND) { unset($sql_parts['select']['clock']); $sql_parts['select']['history'] = 'h.*'; } // countOutput if (!is_null($options['countOutput'])) { $options['sortfield'] = ''; $sql_parts['select'] = array('count(DISTINCT h.hostid) as rowscount'); //groupCount if (!is_null($options['groupCount'])) { foreach ($sql_parts['group'] as $key => $fields) { $sql_parts['select'][$key] = $fields; } } } // groupOutput $groupOutput = false; if (!is_null($options['groupOutput'])) { if (str_in_array('h.' . $options['groupOutput'], $sql_parts['select']) || str_in_array('h.*', $sql_parts['select'])) { $groupOutput = true; } } // order // restrict not allowed columns for sorting $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : ''; if (!zbx_empty($options['sortfield'])) { $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP; if ($options['sortfield'] == 'clock') { $sql_parts['order']['itemid'] = 'h.itemid ' . $sortorder; } $sql_parts['order'][$options['sortfield']] = 'h.' . $options['sortfield'] . ' ' . $sortorder; if (!str_in_array('h.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('h.*', $sql_parts['select'])) { $sql_parts['select'][$options['sortfield']] = 'h.' . $options['sortfield']; } } // limit if (zbx_ctype_digit($options['limit']) && $options['limit']) { $sql_parts['limit'] = $options['limit']; } //--------------- $itemids = array(); $triggerids = array(); $sql_parts['select'] = array_unique($sql_parts['select']); $sql_parts['from'] = array_unique($sql_parts['from']); $sql_parts['where'] = array_unique($sql_parts['where']); $sql_parts['order'] = array_unique($sql_parts['order']); $sql_select = ''; $sql_from = ''; $sql_where = ''; $sql_order = ''; if (!empty($sql_parts['select'])) { $sql_select .= implode(',', $sql_parts['select']); } if (!empty($sql_parts['from'])) { $sql_from .= implode(',', $sql_parts['from']); } if (!empty($sql_parts['where'])) { $sql_where .= implode(' AND ', $sql_parts['where']); } if (!empty($sql_parts['order'])) { $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']); } $sql_limit = $sql_parts['limit']; $sql = 'SELECT ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . $sql_where . $sql_order; $db_res = DBselect($sql, $sql_limit); //SDI($sql); $count = 0; $group = array(); while ($data = DBfetch($db_res)) { if ($options['countOutput']) { $result = $data; } else { $itemids[$data['itemid']] = $data['itemid']; if ($options['output'] == API_OUTPUT_SHORTEN) { $result[$count] = array('itemid' => $data['itemid']); } else { $result[$count] = array(); // hostids if (isset($data['hostid'])) { if (!isset($result[$count]['hosts'])) { $result[$count]['hosts'] = array(); } $result[$count]['hosts'][] = array('hostid' => $data['hostid']); unset($data['hostid']); } // triggerids if (isset($data['triggerid'])) { if (!isset($result[$count]['triggers'])) { $result[$count]['triggers'] = array(); } $result[$count]['triggers'][] = array('triggerid' => $data['triggerid']); unset($data['triggerid']); } // itemids // if(isset($data['itemid']) && !is_null($options['itemids'])){ // if(!isset($result[$count]['items'])) $result[$count]['items'] = array(); // $result[$count]['items'][] = array('itemid' => $data['itemid']); // } $result[$count] += $data; // grouping if ($groupOutput) { $dataid = $data[$options['groupOutput']]; if (!isset($group[$dataid])) { $group[$dataid] = array(); } $group[$dataid][] = $result[$count]; } $count++; } } } COpt::memoryPick(); if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; }
**/ require_once 'include/config.inc.php'; require_once 'include/triggers.inc.php'; $page['file'] = 'chart4.php'; $page['title'] = "S_CHART"; $page['type'] = PAGE_TYPE_IMAGE; include_once 'include/page_header.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('triggerid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, NULL)); check_fields($fields); $sql = 'SELECT DISTINCT i.hostid ' . ' FROM functions f, items i ' . ' WHERE f.triggerid=' . $_REQUEST['triggerid'] . ' AND i.itemid=f.itemid'; if (!($host = DBfetch(DBselect($sql)))) { fatal_error(S_NO_TRIGGER_DEFINED); } $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array($host['hostid'])); $sql = 'SELECT DISTINCT t.triggerid,t.description,t.expression, h.host,h.hostid ' . ' FROM hosts h, items i, functions f, triggers t' . ' WHERE h.hostid=i.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.triggerid=' . $_REQUEST['triggerid'] . ' AND ' . DBcondition('t.triggerid', $available_triggers); if (!($db_data = DBfetch(DBselect($sql)))) { access_deny(); } $start_time = time(NULL); $sizeX = 900; $sizeY = 300; $shiftX = 12; $shiftYup = 17; $shiftYdown = 25 + 15 * 3; $im = imagecreate($sizeX + $shiftX + 61, $sizeY + $shiftYup + $shiftYdown + 10); $red = imagecolorallocate($im, 255, 0, 0); $darkred = imagecolorallocate($im, 150, 0, 0); $green = imagecolorallocate($im, 0, 255, 0); $darkgreen = imagecolorallocate($im, 0, 150, 0); $bluei = imagecolorallocate($im, 0, 0, 255);
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array("msg" => array(T_ZBX_STR, O_OPT, null, null, NULL), 'favobj' => array(T_ZBX_STR, O_OPT, P_ACT, IN("'hat'"), NULL), 'favid' => array(T_ZBX_STR, O_OPT, P_ACT, NOT_EMPTY, 'isset({favobj})'), 'state' => array(T_ZBX_INT, O_OPT, P_ACT, NOT_EMPTY, 'isset({favobj})')); check_fields($fields); /* AJAX */ if (isset($_REQUEST['favobj'])) { 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);
function getDeletableHostGroups($groupids = null) { zbx_value2array($groupids); $dlt_groupids = array(); $hostids = getUnlinkableHosts($groupids); $sql_where = ''; if (!is_null($groupids)) { $sql_where .= ' AND ' . DBcondition('g.groupid', $groupids); } $sql = 'SELECT DISTINCT g.groupid ' . ' FROM groups g ' . ' WHERE g.internal=' . ZBX_NOT_INTERNAL_GROUP . $sql_where . ' AND NOT EXISTS (' . 'SELECT hg.groupid ' . ' FROM hosts_groups hg ' . ' WHERE g.groupid=hg.groupid ' . ' AND ' . DBcondition('hg.hostid', $hostids, true) . ')'; $res = DBselect($sql); while ($group = DBfetch($res)) { $dlt_groupids[$group['groupid']] = $group['groupid']; } return $dlt_groupids; }
function delete_expression($expressionids) { zbx_value2array($expressionids); $sql = 'DELETE FROM expressions WHERE ' . DBcondition('expressionid', $expressionids); return DBexecute($sql); }
function get_triggers_overview($hostids, $view_style = null) { $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids); if (is_null($view_style)) { $view_style = get_profile('web.overview.view.style', STYLE_TOP); } $table = new CTableInfo(S_NO_TRIGGERS_DEFINED); $result = DBselect('SELECT DISTINCT t.triggerid,t.description,t.expression,t.value,t.priority,t.lastchange,h.hostid,h.host' . ' FROM hosts h,items i,triggers t, functions f ' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid' . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' ORDER BY t.description'); unset($triggers); unset($hosts); $triggers = array(); while ($row = DBfetch($result)) { if (trigger_dependent($row['triggerid'])) { continue; } $row['host'] = get_node_name_by_elid($row['hostid']) . $row['host']; $row['description'] = expand_trigger_description_constants($row['description'], $row); $hosts[strtolower($row['host'])] = $row['host']; // A little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!isset($triggers[$row['description']][$row['host']]) || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE && $row['value'] == TRIGGER_VALUE_TRUE || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE || $row['value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $triggers[$row['description']][$row['host']]['priority'])) { $triggers[$row['description']][$row['host']] = array('hostid' => $row['hostid'], 'triggerid' => $row['triggerid'], 'value' => $row['value'], 'lastchange' => $row['lastchange'], 'priority' => $row['priority']); } } if (!isset($hosts)) { return $table; } ksort($hosts); if ($view_style == STYLE_TOP) { $header = array(new CCol(S_TRIGGERS, 'center')); foreach ($hosts as $hostname) { $header = array_merge($header, array(new CImg('vtext.php?text=' . $hostname))); } $table->setHeader($header, 'vertical_header'); foreach ($triggers as $descr => $trhosts) { $table_row = array(nbsp($descr)); foreach ($hosts as $hostname) { $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname); } $table->AddRow($table_row); } } else { $header = array(new CCol(S_HOSTS, 'center')); foreach ($triggers as $descr => $trhosts) { $descr = array(new CImg('vtext.php?text=' . $descr)); array_push($header, $descr); } $table->SetHeader($header, 'vertical_header'); foreach ($hosts as $hostname) { $table_row = array(nbsp($hostname)); foreach ($triggers as $descr => $trhosts) { $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname); } $table->AddRow($table_row); } } return $table; }
function delete_discovery_rule($druleid) { $result = true; $actionids = array(); // conditions $sql = 'SELECT DISTINCT actionid ' . ' FROM conditions ' . ' WHERE conditiontype=' . CONDITION_TYPE_DRULE . " AND value='{$druleid}'"; $db_actions = DBselect($sql); while ($db_action = DBfetch($db_actions)) { $actionids[] = $db_action['actionid']; } // disabling actions with deleted conditions if (!empty($actionids)) { DBexecute('UPDATE actions ' . ' SET status=' . ACTION_STATUS_DISABLED . ' WHERE ' . DBcondition('actionid', $actionids)); // delete action conditions DBexecute('DELETE FROM conditions ' . ' WHERE conditiontype=' . CONDITION_TYPE_DRULE . " AND value='{$druleid}'"); } if ($result) { $db_dhosts = DBselect('select dhostid from dhosts' . ' where druleid=' . $druleid . ' and ' . DBin_node('dhostid')); while ($result && ($db_dhost = DBfetch($db_dhosts))) { $result = DBexecute('delete from dservices where' . ' dhostid=' . $db_dhost['dhostid']); } } if ($result) { $result = DBexecute('delete from dhosts where druleid=' . $druleid); } if ($result) { $result = DBexecute('delete from dchecks where druleid=' . $druleid); } if ($result) { $result = DBexecute('delete from drules where druleid=' . $druleid); } return $result; }
/** * Delete graph items * * @static * @param array $items * @return boolean */ public static function deleteItems($item_list, $force = false) { $error = 'Unknown ZABBIX internal error'; $result = true; $graphid = $item_list['graphid']; $items = $item_list['items']; if (!$force) { // check if graph is templated graph, then items cannot be deleted $graph = CGraph::getById(array('graphid' => $graphid)); if ($graph['templateid'] != 0) { self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Cannot edit templated graph : ' . $graph['name']); return false; } } $chd_graphs = get_graphs_by_templateid($graphid); while ($chd_graph = DBfetch($chd_graphs)) { $item_list['graphid'] = $chd_graph['graphid']; $result = self::deleteItems($item_list, true); if (!$result) { return false; } } $sql = 'SELECT curr.itemid FROM graphs_items gi, items curr, items src WHERE gi.graphid=' . $graphid . ' AND gi.itemid=curr.itemid AND curr.key_=src.key_ AND ' . DBcondition('src.itemid', $items); $db_items = DBselect($sql); $gitems = array(); while ($curr_item = DBfetch($db_items)) { $gitems[$curr_item['itemid']] = $curr_item['itemid']; } $sql = 'DELETE FROM graphs_items WHERE graphid=' . $graphid . ' AND ' . DBcondition('itemid', $gitems); $result = DBselect($sql); return $result; }
/** * Delete alerts * * @param array $alertids * @return boolean */ public static function delete($alertids) { $alerts = zbx_toArray($alerts); $alertids = array(); $result = false; //------ $options = array('alertids' => zbx_objectValues($alerts, 'alertid'), 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $del_alerts = self::get($options); foreach ($alerts as $snum => $alert) { if (!isset($del_alerts[$alert['alertid']])) { self::setError(__METHOD__, ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); return false; } $alertids[] = $alert['alertid']; } if (!empty($alertids)) { $sql = 'DELETE FROM alerts WHERE ' . DBcondition('alertid', $alertids); $result = DBexecute($sql); } else { self::setError(__METHOD__, ZBX_API_ERROR_PARAMETERS, S_EMPTY_INPUT_PARAMETER . ' [ alertids ]'); $result = false; } if ($result) { return array('alertids' => $alertids); } else { self::setError(__METHOD__); return false; } }
$_REQUEST['paramtype'] = PARAM_TYPE_COUNTS; $_REQUEST['param'] = ltrim($_REQUEST['param'], '#'); } $operator = $expr_res[count($expr_res) - 2]; $_REQUEST['expr_type'] = $expr_res[ZBX_SIMPLE_EXPRESSION_FUNCTION_NAME_ID] . '[' . $operator . ']'; $_REQUEST['value'] = $expr_res[count($expr_res) - 1]; } } unset($expr_res); $dstfrm = get_request("dstfrm", 0); // destination form $dstfld1 = get_request("dstfld1", ''); // destination field $itemid = get_request("itemid", 0); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY); if ($item_data = DBfetch(DBselect('SELECT DISTINCT h.host,i.* ' . ' FROM hosts h,items i ' . ' WHERE h.hostid=i.hostid ' . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' AND i.itemid=' . $itemid))) { $description = $item_data['host'] . ':' . item_description($item_data); } else { $itemid = 0; $description = ''; } $expr_type = get_request("expr_type", 'last[=]'); if (eregi('^([a-z]{1,})\\[([' . implode('', array_keys($operators)) . '])\\]$', $expr_type, $expr_res)) { $function = $expr_res[1]; $operator = $expr_res[2]; if (!str_in_array($function, array_keys($functions))) { unset($function); } } unset($expr_res); if (!isset($function)) {
$access = $script['host_access']; } } $frmScr->addRow(S_NAME, new CTextBox('name', $name, 80)); $frmScr->addRow(S_COMMAND, new CTextBox('command', $command, 80)); $usr_groups = new CCombobox('usrgrpid', $usrgrpid); $usr_groups->addItem(0, S_ALL_S); $sql = 'SELECT DISTINCT ug.name, ug.usrgrpid ' . ' FROM usrgrp ug ' . ' WHERE ' . DBin_node('ug.usrgrpid') . ' ORDER BY ug.name'; $usrgrp_result = DBselect($sql); while ($usr_group = DBfetch($usrgrp_result)) { $usr_groups->addItem($usr_group['usrgrpid'], $usr_group['name']); } $frmScr->addRow(S_USER_GROUPS, $usr_groups); $host_groups = new CCombobox('groupid', $groupid); $host_groups->addItem(0, S_ALL_S); $sql = 'SELECT DISTINCT g.name, g.groupid ' . ' FROM groups g ' . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' ORDER BY g.name'; $grp_result = DBselect($sql); while ($group = DBfetch($grp_result)) { $host_groups->addItem($group['groupid'], $group['name']); } $frmScr->addRow(S_HOST_GROUPS, $host_groups); $select_acc = new CCombobox('access', $access); $select_acc->addItem(PERM_READ_ONLY, S_READ); $select_acc->addItem(PERM_READ_WRITE, S_WRITE); $frmScr->addRow(S_REQUIRED_HOST . SPACE . S_PERMISSIONS_SMALL, $select_acc); $frmScr->addItemToBottomRow(new CButton('save', S_SAVE, "javascript: document.getElementById('scripts').action+='?action=1'; ")); $frmScr->addItemToBottomRow(SPACE); if (isset($_REQUEST['scriptid'])) { $deleteButton = new CButtonDelete(S_DELETE_SCRIPTS_Q, '&action=1&scriptid=' . $_REQUEST['scriptid']); $frmScr->addItemToBottomRow($deleteButton); $frmScr->addItemToBottomRow(SPACE);
function get_report2_filter($config, &$PAGE_GROUPS, &$PAGE_HOSTS) { global $USER_DETAILS; $available_groups = $PAGE_GROUPS['groupids']; $available_hosts = $PAGE_HOSTS['hostids']; /************************* FILTER *************************/ /***********************************************************/ $filterForm = new CFormTable(); //,'events.php?filter_set=1','POST',null,'sform'); $filterForm->setAttribute('name', 'zbx_filter'); $filterForm->setAttribute('id', 'zbx_filter'); $filterForm->addVar('config', $config); $filterForm->addVar('filter_timesince', date('YmdHis', $_REQUEST['filter_timesince'])); $filterForm->addVar('filter_timetill', date('YmdHis', $_REQUEST['filter_timetill'])); $cmbGroups = new CComboBox('filter_groupid', $PAGE_GROUPS['selected'], 'javascript: submit();'); $cmbHosts = new CComboBox('filter_hostid', $PAGE_HOSTS['selected'], 'javascript: submit();'); foreach ($PAGE_GROUPS['groups'] as $groupid => $name) { $cmbGroups->addItem($groupid, get_node_name_by_elid($groupid, null, ': ') . $name); } foreach ($PAGE_HOSTS['hosts'] as $hostid => $name) { $cmbHosts->addItem($hostid, get_node_name_by_elid($hostid, null, ': ') . $name); } $filterForm->addRow(S_GROUP, $cmbGroups); $filterForm->addRow(S_HOST, $cmbHosts); if (1 == $config) { $cmbTrigs = new CComboBox('tpl_triggerid', get_request('tpl_triggerid', 0), 'submit()'); $cmbHGrps = new CComboBox('hostgroupid', get_request('hostgroupid', 0), 'submit()'); $cmbTrigs->addItem(0, S_ALL_SMALL); $cmbHGrps->addItem(0, S_ALL_SMALL); $sql_cond = ' AND h.hostid=ht.hostid '; if ($_REQUEST['hostid'] > 0) { $sql_cond .= ' AND ht.templateid=' . $_REQUEST['hostid']; } if (isset($_REQUEST['tpl_triggerid']) && $_REQUEST['tpl_triggerid'] > 0) { $sql_cond .= ' AND t.templateid=' . $_REQUEST['tpl_triggerid']; } $result = DBselect('SELECT DISTINCT g.groupid,g.name ' . ' FROM triggers t,hosts h,items i,functions f, hosts_templates ht, groups g, hosts_groups hg ' . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid' . ' AND g.groupid=hg.groupid ' . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND t.triggerid=f.triggerid ' . ' AND ' . DBin_node('t.triggerid') . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND h.status=' . HOST_STATUS_MONITORED . $sql_cond . ' ORDER BY g.name'); while ($row = DBfetch($result)) { $cmbHGrps->addItem($row['groupid'], get_node_name_by_elid($row['groupid'], null, ': ') . $row['name']); } $sql_cond = $_REQUEST['hostid'] > 0 ? ' AND h.hostid=' . $_REQUEST['hostid'] : ' AND ' . DBcondition('h.hostid', $available_hosts); $sql = 'SELECT DISTINCT t.triggerid,t.description ' . ' FROM triggers t,hosts h,items i,functions f ' . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND t.triggerid=f.triggerid ' . ' AND h.status=' . HOST_STATUS_TEMPLATE . ' AND ' . DBin_node('t.triggerid') . ' AND i.status=' . ITEM_STATUS_ACTIVE . $sql_cond . ' ORDER BY t.description'; $result = DBselect($sql); while ($row = DBfetch($result)) { $cmbTrigs->addItem($row['triggerid'], get_node_name_by_elid($row['triggerid'], null, ': ') . expand_trigger_description($row['triggerid'])); } $filterForm->addRow(S_TRIGGER, $cmbTrigs); $filterForm->addRow(S_FILTER . SPACE . S_HOST_GROUP, $cmbHGrps); } //* $clndr_icon = new CImg('images/general/bar/cal.gif', 'calendar', 16, 12, 'pointer'); $clndr_icon->addAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['avail_report_since'].clndr.clndrshow(pos.top,pos.left);"); $filtertimetab = new CTable(null, 'calendar'); $filtertimetab->setAttribute('width', '10%'); $filtertimetab->setCellPadding(0); $filtertimetab->setCellSpacing(0); $filtertimetab->addRow(array(S_FROM, new CNumericBox('filter_since_day', $_REQUEST['filter_timesince'] > 0 ? date('d', $_REQUEST['filter_timesince']) : '', 2), '/', new CNumericBox('filter_since_month', $_REQUEST['filter_timesince'] > 0 ? date('m', $_REQUEST['filter_timesince']) : '', 2), '/', new CNumericBox('filter_since_year', $_REQUEST['filter_timesince'] > 0 ? date('Y', $_REQUEST['filter_timesince']) : '', 4), SPACE, new CNumericBox('filter_since_hour', $_REQUEST['filter_timesince'] > 0 ? date('H', $_REQUEST['filter_timesince']) : '', 2), ':', new CNumericBox('filter_since_minute', $_REQUEST['filter_timesince'] > 0 ? date('i', $_REQUEST['filter_timesince']) : '', 2), $clndr_icon)); zbx_add_post_js('create_calendar(null,' . '["filter_since_day","filter_since_month","filter_since_year","filter_since_hour","filter_since_minute"],' . '"avail_report_since",' . '"filter_timesince");'); $clndr_icon->AddAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['avail_report_till'].clndr.clndrshow(pos.top,pos.left);"); $filtertimetab->AddRow(array(S_TILL, new CNumericBox('filter_till_day', $_REQUEST['filter_timetill'] > 0 ? date('d', $_REQUEST['filter_timetill']) : '', 2), '/', new CNumericBox('filter_till_month', $_REQUEST['filter_timetill'] > 0 ? date('m', $_REQUEST['filter_timetill']) : '', 2), '/', new CNumericBox('filter_till_year', $_REQUEST['filter_timetill'] > 0 ? date('Y', $_REQUEST['filter_timetill']) : '', 4), SPACE, new CNumericBox('filter_till_hour', $_REQUEST['filter_timetill'] > 0 ? date('H', $_REQUEST['filter_timetill']) : '', 2), ':', new CNumericBox('filter_till_minute', $_REQUEST['filter_timetill'] > 0 ? date('i', $_REQUEST['filter_timetill']) : '', 2), $clndr_icon)); zbx_add_post_js('create_calendar(null,' . '["filter_till_day","filter_till_month","filter_till_year","filter_till_hour","filter_till_minute"],' . '"avail_report_till",' . '"filter_timetill");'); zbx_add_post_js('addListener($("filter_icon"),"click",CLNDR[\'avail_report_since\'].clndr.clndrhide.bindAsEventListener(CLNDR[\'avail_report_since\'].clndr));' . 'addListener($("filter_icon"),"click",CLNDR[\'avail_report_till\'].clndr.clndrhide.bindAsEventListener(CLNDR[\'avail_report_till\'].clndr));'); $filterForm->addRow(S_PERIOD, $filtertimetab); //*/ $filterForm->addItemToBottomRow(new CButton('filter_set', S_FILTER)); $reset = new CButton("filter_rst", S_RESET); $reset->setType('button'); $reset->setAction('javascript: var url = new Curl(location.href); url.setArgument("filter_rst",1); location.href = url.getUrl();'); $filterForm->addItemToBottomRow($reset); return $filterForm; }
$dsc_events = CEvent::get($options); order_result($dsc_events, 'eventid', ZBX_SORT_DOWN); $objectids = array(); foreach ($dsc_events as $enum => $event_data) { $objectids[$event_data['objectid']] = $event_data['objectid']; } // OBJECT DHOST $dhosts = array(); $sql = 'SELECT s.dserviceid, s.dhostid, s.ip ' . ' FROM dservices s ' . ' WHERE ' . DBcondition('s.dhostid', $objectids); $res = DBselect($sql); while ($dservices = DBfetch($res)) { $dhosts[$dservices['dhostid']] = $dservices; } // OBJECT DSERVICE $dservices = array(); $sql = 'SELECT s.dserviceid,s.ip,s.type,s.port ' . ' FROM dservices s ' . ' WHERE ' . DBcondition('s.dserviceid', $objectids); $res = DBselect($sql); while ($dservice = DBfetch($res)) { $dservices[$dservice['dserviceid']] = $dservice; } // TABLE $table->setHeader(array(S_TIME, S_IP, S_DESCRIPTION, S_STATUS)); foreach ($dsc_events as $num => $event_data) { switch ($event_data['object']) { case EVENT_OBJECT_DHOST: if (isset($dhosts[$event_data['objectid']])) { $event_data['object_data'] = $dhosts[$event_data['objectid']]; } else { $event_data['object_data']['ip'] = S_UNKNOWN; } $event_data['description'] = S_HOST;
foreach ($app_rows as $row) { $table->AddRow($row); } } // OTHER ITEMS (which doesn't linked to application) $db_hosts = array(); $db_hostids = array(); $sql = 'SELECT DISTINCT h.host,h.hostid ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY h.host'; $db_host_res = DBselect($sql); while ($db_host = DBfetch($db_host_res)) { $db_host['item_cnt'] = 0; $db_hosts[$db_host['hostid']] = $db_host; $db_hostids[$db_host['hostid']] = $db_host['hostid']; } $tab_rows = array(); $sql = 'SELECT DISTINCT h.host,h.hostid,i.* ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('h.hostid', $db_hostids) . ' ORDER BY i.description,i.itemid'; $db_items = DBselect($sql); while ($db_item = DBfetch($db_items)) { $description = item_description($db_item); if (!empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) { continue; } $db_host =& $db_hosts[$db_item['hostid']]; if (!isset($tab_rows[$db_host['hostid']])) { $tab_rows[$db_host['hostid']] = array(); } $app_rows =& $tab_rows[$db_host['hostid']]; $db_host['item_cnt']++; if (!uint_in_array(0, $_REQUEST['applications']) && !isset($show_all_apps)) { continue; }
// ---- $available_maintenances = get_accessible_maintenance_by_user(PERM_READ_WRITE); $maintenances = array(); $maintenanceids = array(); $sql_from = ''; $sql_where = ''; if ($_REQUEST['hostid'] > 0) { $sql_from = ', maintenances_hosts mh, maintenances_groups mg, hosts_groups hg '; $sql_where = ' AND hg.hostid=' . $_REQUEST['hostid'] . ' AND (' . '(mh.hostid=hg.hostid AND m.maintenanceid=mh.maintenanceid) ' . ' OR (mg.groupid=hg.groupid AND m.maintenanceid=mg.maintenanceid))'; } else { if ($_REQUEST['groupid'] > 0) { $sql_from = ', maintenances_hosts mh, maintenances_groups mg, hosts_groups hg '; $sql_where = ' AND hg.groupid=' . $_REQUEST['groupid'] . ' AND (' . '(mg.groupid=hg.groupid AND m.maintenanceid=mg.maintenanceid) ' . ' OR (mh.hostid=hg.hostid AND m.maintenanceid=mh.maintenanceid))'; } } $sql = 'SELECT m.* ' . ' FROM maintenances m ' . $sql_from . ' WHERE ' . DBin_node('m.maintenanceid') . ' AND ' . DBcondition('m.maintenanceid', $available_maintenances) . $sql_where . order_by('m.name'); $db_maintenances = DBselect($sql); while ($maintenance = DBfetch($db_maintenances)) { $maintenances[$maintenance['maintenanceid']] = $maintenance; $maintenanceids[$maintenance['maintenanceid']] = $maintenance['maintenanceid']; } $form = new CForm(null, 'post'); $form->setName('maintenances'); $table = new CTableInfo(); $table->setHeader(array(array(new CCheckBox('all_maintenances', NULL, "CheckAll('" . $form->GetName() . "','all_maintenances','group_maintenanceid');"), make_sorting_link(S_NAME, 'm.name')), S_TYPE, S_STATUS, S_DESCRIPTION)); foreach ($maintenances as $maintenanceid => $maintenance) { if ($maintenance['active_till'] < time()) { $mnt_status = new CSpan(S_EXPIRED, 'red'); } else { $mnt_status = new CSpan(S_ACTIVE, 'green'); }
$admin_link = $admin ? new CLink(S_GO, 'hosts.php?config=1&groupid=' . $hostgroupid . '&hostid=0') : null; $table->addRow(array(get_node_name_by_elid($hostgroupid), $caption, new CLink(S_GO, 'latest.php?groupid=' . $hostgroupid . '&hostid=0'), new CLink(S_GO, 'tr_status.php?groupid=' . $hostgroupid . '&hostid=0'), new CLink(S_GO, 'events.php?groupid=' . $hostgroupid . '&hostid=0'), $admin_link)); } $table->setFooter(new CCol(S_DISPLAYING . SPACE . $viewCount . SPACE . S_OF_SMALL . SPACE . $overalCount . SPACE . S_FOUND_SMALL)); $wdgt_hgroups = new CWidget('search_hostgroup', $table); $wdgt_hgroups->addHeader(S_HOST_GROUPS, SPACE); $right_tab->addRow($wdgt_hgroups); //---------------- // FIND Templates if ($admin) { $params = array('nodeid' => get_current_nodeid(), 'extendoutput' => 1, 'pattern' => $search, 'limit' => $rows_per_page, 'order' => 'host', 'editable' => 1); $db_templates = CTemplate::get($params); $templates = selectByPattern($db_templates, 'host', $search, $rows_per_page); $templateids = array_keys($templates); $hostsgroups = array(); $sql = 'SELECT * FROM hosts_groups hg WHERE ' . DBcondition('hg.hostid', $templateids); $res = DBselect($sql); while ($templategroup = DBfetch($res)) { $hostsgroups[$templategroup['hostid']] = $templategroup['groupid']; } $params = array('nodeids' => get_current_nodeid(), 'pattern' => $search, 'count' => 1, 'editable' => 1); $hosts_count = CTemplate::get($params); $overalCount = $hosts_count['rowscount']; $viewCount = count($templates); $header = array(is_show_all_nodes() ? new CCol(S_NODE) : null, new CCol(S_TEMPLATES), new CCol(S_ITEMS), new CCol(S_TRIGGERS), new CCol(S_GRAPHS)); $table = new CTableInfo(); $table->setHeader($header); foreach ($templates as $num => $template) { $templateid = $template['hostid']; $groupid = isset($hostsgroups[$templateid]) ? $hostsgroups[$templateid] : 0; $link = 'groupid=' . $groupid . '&hostid=' . $templateid;
} $r_form->addItem(array(S_GROUP . SPACE, $cmbGroups)); $r_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); //---------------------------------------------_ $cmbGraphs = new CComboBox('graphid', $_REQUEST['graphid'], 'submit()'); $cmbGraphs->addItem(0, S_SELECT_GRAPH_DOT_DOT_DOT); $sql_from = ''; $sql_where = ''; if ($_REQUEST['groupid'] > 0) { $sql_from .= ',hosts_groups hg '; $sql_where .= ' AND hg.hostid=h.hostid AND hg.groupid=' . $_REQUEST['groupid']; } if ($_REQUEST['hostid'] > 0) { $sql_where .= ' AND h.hostid=' . $_REQUEST['hostid']; } $sql = 'SELECT DISTINCT g.graphid,g.name ' . ' FROM graphs g,graphs_items gi,items i,hosts h' . $sql_from . ' WHERE gi.graphid=g.graphid ' . ' AND i.itemid=gi.itemid ' . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . $sql_where . ' AND ' . DBin_node('g.graphid') . ' AND ' . DBcondition('g.graphid', $available_graphs) . ' ORDER BY g.name'; $result = DBselect($sql); while ($row = DBfetch($result)) { $cmbGraphs->addItem($row['graphid'], get_node_name_by_elid($row['graphid']) . $row['name']); } $r_form->addItem(array(SPACE . S_GRAPH . SPACE, $cmbGraphs)); $p_elements[] = get_table_header($h1, $r_form); $table = new CTableInfo('...', 'chart'); // $table->AddOption('border',1); if ($_REQUEST['graphid'] > 0) { $graphtype = GRAPH_TYPE_NORMAL; $yaxis = 0; // ZOOM featers $sql = 'SELECT MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider, MAX(g.height) as height' . ' FROM graphs g, graphs_items gi ' . ' WHERE g.graphid=' . $_REQUEST['graphid'] . ' AND gi.graphid=g.graphid '; $res = Dbselect($sql); while ($graph = DBfetch($res)) {
$services[0] = $row; $now = time(); while ($row = DBFetch($result)) { $row['id'] = $row['serviceid']; empty($row['serviceupid']) ? $row['serviceupid'] = '0' : ''; empty($row['description']) ? $row['description'] = 'None' : ''; $row['graph'] = new CLink(S_SHOW, "srv_status.php?serviceid=" . $row["serviceid"] . "&showgraph=1" . url_param('path'), "action"); if (isset($row["triggerid"]) && !empty($row["triggerid"])) { $url = new CLink(expand_trigger_description($row['triggerid']), 'events.php?triggerid=' . $row['triggerid']); $row['caption'] = array($row['caption'] . ' [', $url, ']'); } if ($row["status"] == 0 || isset($service) && bccomp($service["serviceid"], $row["serviceid"]) == 0) { $row['reason'] = '-'; } else { $row['reason'] = '-'; $result2 = DBselect('SELECT s.triggerid,s.serviceid ' . ' FROM services s, triggers t ' . ' WHERE s.status>0 ' . ' AND s.triggerid is not NULL ' . ' AND t.triggerid=s.triggerid ' . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND ' . DBin_node('s.serviceid') . ' ORDER BY s.status DESC, t.description'); while ($row2 = DBfetch($result2)) { if (is_string($row['reason']) && $row['reason'] == '-') { $row['reason'] = new CList(null, "itservices"); } if (does_service_depend_on_the_service($row["serviceid"], $row2["serviceid"])) { $row['reason']->AddItem(new CLink(expand_trigger_description($row2["triggerid"]), "events.php?triggerid=" . $row2["triggerid"])); } } } if ($row["showsla"] == 1) { $row['sla'] = new CLink(new CImg("chart_sla.php?serviceid=" . $row["serviceid"]), "report3.php?serviceid=" . $row["serviceid"] . "&year=" . date("Y")); $now = time(NULL); $period_start = $now - 7 * 24 * 3600; $period_end = $now; $stat = calculate_service_availability($row["serviceid"], $period_start, $period_end);
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ require_once 'include/config.inc.php'; require_once 'include/services.inc.php'; $page['file'] = 'chart5.php'; $page['title'] = "S_CHART"; $page['type'] = PAGE_TYPE_IMAGE; include_once 'include/page_header.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('serviceid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, NULL)); check_fields($fields); if (!DBfetch(DBselect('select serviceid from services where serviceid=' . $_REQUEST['serviceid']))) { fatal_error(S_NO_IT_SERVICE_DEFINED); } $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY); $sql = 'SELECT s.serviceid ' . ' FROM services s ' . ' WHERE (s.triggerid is NULL OR ' . DBcondition('s.triggerid', $available_triggers) . ') ' . ' AND s.serviceid=' . $_REQUEST['serviceid']; if (!($service = DBfetch(DBselect($sql, 1)))) { access_deny(); } $start_time = time(NULL); $sizeX = 900; $sizeY = 300; $shiftX = 12; $shiftYup = 17; $shiftYdown = 25 + 15 * 3; $im = imagecreate($sizeX + $shiftX + 61, $sizeY + $shiftYup + $shiftYdown + 10); $red = imagecolorallocate($im, 255, 0, 0); $darkred = imagecolorallocate($im, 150, 0, 0); $green = imagecolorallocate($im, 0, 255, 0); $darkgreen = imagecolorallocate($im, 0, 150, 0); $blue = imagecolorallocate($im, 0, 0, 255);
function make_webmon_overview() { global $USER_DETAILS; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY); $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_OK, S_FAILED, S_IN_PROGRESS, S_UNKNOWN)); $sql = 'SELECT DISTINCT g.groupid, g.name ' . ' FROM httptest ht, applications a, groups g, hosts_groups hg ' . ' WHERE ' . DBcondition('hg.hostid', $available_hosts) . ' AND hg.hostid=a.hostid ' . ' AND g.groupid=hg.groupid ' . ' AND a.applicationid=ht.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ' ORDER BY g.name'; $host_groups = DBSelect($sql); while ($group = DBFetch($host_groups)) { $apps['ok'] = 0; $apps['failed'] = 0; $apps[HTTPTEST_STATE_BUSY] = 0; $apps[HTTPTEST_STATE_UNKNOWN] = 0; $sql = 'SELECT DISTINCT ht.httptestid, ht.curstate, ht.lastfailedstep ' . ' FROM httptest ht, applications a, hosts_groups hg, groups g ' . ' WHERE g.groupid=' . $group['groupid'] . ' AND hg.groupid=g.groupid ' . ' AND a.hostid=hg.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE; $db_httptests = DBselect($sql); while ($httptest_data = DBfetch($db_httptests)) { if (HTTPTEST_STATE_BUSY == $httptest_data['curstate']) { $apps[HTTPTEST_STATE_BUSY]++; } else { if (HTTPTEST_STATE_IDLE == $httptest_data['curstate']) { if ($httptest_data['lastfailedstep'] > 0) { $apps['failed']++; } else { $apps['ok']++; } } else { $apps[HTTPTEST_STATE_UNKNOWN]++; } } } $table->addRow(array(is_show_all_nodes() ? get_node_name_by_elid($group['groupid']) : null, $group['name'], new CSpan($apps['ok'], 'off'), new CSpan($apps['failed'], $apps['failed'] ? 'on' : 'off'), new CSpan($apps[HTTPTEST_STATE_BUSY], $apps[HTTPTEST_STATE_BUSY] ? 'orange' : 'off'), new CSpan($apps[HTTPTEST_STATE_UNKNOWN], 'unknown'))); } $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time()))); return $table; }
/** * Delete User Medias * * <code> * $media_data = array( * *string 'userid => 'User ID', * array 'mediaids' => array('Media ID', 'Media ID', ...) * ); * </code> * * @static * @param array $media_data * @return boolean */ public static function deleteMedia($media_data) { $sql = 'DELETE FROM media WHERE userid=' . $media_data['userid'] . ' AND ' . DBcondition('mediaid', $media_data['mediaids']); $result = DBexecute($sql); if ($result) { return true; } else { self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error'); return false; } }
<?php $_REQUEST["show"] = get_request("show", 0); $form = new CForm(); $form->SetMethod('get'); $cmbMode = new CComboBox("show", $_REQUEST["show"], "submit();"); $cmbMode->AddItem(0, S_OVERVIEW); $cmbMode->AddItem(1, S_OVERVIEW_BY_PROXY); $cmbMode->AddItem(2, S_DETAILS); $form->AddItem($cmbMode); show_table_header(S_QUEUE_OF_ITEMS_TO_BE_UPDATED_BIG, $form); ?> <?php $now = time(); $item_types = array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_SIMPLE, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL); $result = DBselect('SELECT i.itemid,i.nextcheck,i.description,i.key_,i.type,h.host,h.hostid,h.proxy_hostid ' . ' FROM items i,hosts h ' . ' WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.type in (' . implode(',', $item_types) . ') ' . ' AND ((h.status=' . HOST_STATUS_MONITORED . ' AND h.available != ' . HOST_AVAILABLE_FALSE . ') ' . ' OR (h.status=' . HOST_STATUS_MONITORED . ' AND h.available=' . HOST_AVAILABLE_FALSE . ' AND h.disable_until<=' . $now . ')) ' . ' AND i.hostid=h.hostid ' . ' AND i.nextcheck + 5 <' . $now . ' AND i.key_ NOT IN (' . zbx_dbstr('status') . ',' . zbx_dbstr('icmpping') . ',' . zbx_dbstr('icmppingsec') . ',' . zbx_dbstr('zabbix[log]') . ') ' . ' AND i.value_type not in (' . ITEM_VALUE_TYPE_LOG . ') ' . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' AND ' . DBin_node('h.hostid', get_current_nodeid()) . ' ORDER BY i.nextcheck,h.host,i.description,i.key_'); $table = new CTableInfo(S_THE_QUEUE_IS_EMPTY); if ($_REQUEST["show"] == 0) { foreach ($item_types as $type) { $sec_10[$type] = 0; $sec_30[$type] = 0; $sec_60[$type] = 0; $sec_300[$type] = 0; $sec_600[$type] = 0; $sec_rest[$type] = 0; } while ($row = DBfetch($result)) { if ($now - $row["nextcheck"] <= 10) { $sec_10[$row["type"]]++; } else { if ($now - $row["nextcheck"] <= 30) {
function get_actions_hint_by_eventid($eventid, $status = NULL) { $hostids = array(); $sql = 'SELECT DISTINCT i.hostid ' . ' FROM events e, functions f, items i ' . ' WHERE e.eventid=' . $eventid . ' AND e.objectid=' . EVENT_SOURCE_TRIGGERS . ' AND f.triggerid=' . $_REQUEST['triggerid'] . ' AND i.itemid=f.itemid'; if ($host = DBfetch(DBselect($sql, 1))) { $hostids[$host['hostid']] = $host['hostid']; } $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids); $tab_hint = new CTableInfo(S_NO_ACTIONS_FOUND); $tab_hint->addOption('style', 'width: 300px;'); $tab_hint->SetHeader(array(is_show_subnodes() ? S_NODES : null, S_USER, S_DETAILS, S_STATUS)); /* $sql = 'SELECT DISTINCT a.alertid,mt.description,a.sendto,a.status,u.alias,a.retries '. ' FROM events e,users u,alerts a'. ' left join media_type mt on mt.mediatypeid=a.mediatypeid'. ' WHERE a.eventid='.$eventid. (is_null($status)?'':' AND a.status='.$status). ' AND e.eventid = a.eventid'. ' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'. ' AND '.DBcondition('e.objectid',$available_triggers). ' AND '.DBin_node('a.alertid'). ' AND u.userid=a.userid '. ' ORDER BY mt.description'; //*/ $sql = 'SELECT DISTINCT a.alertid,mt.description,u.alias,a.subject,a.message,a.sendto,a.status,a.retries,a.alerttype ' . ' FROM events e,alerts a ' . ' LEFT JOIN users u ON u.userid=a.userid ' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE a.eventid=' . $eventid . (is_null($status) ? '' : ' AND a.status=' . $status) . ' AND e.eventid = a.eventid' . ' AND a.alerttype IN (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND ' . DBcondition('e.objectid', $available_triggers) . ' AND ' . DBin_node('a.alertid') . ' ORDER BY a.alertid'; $result = DBselect($sql, 30); while ($row = DBfetch($result)) { if ($row["status"] == ALERT_STATUS_SENT) { $status = new CSpan(S_SENT, "green"); $retries = new CSpan(SPACE, "green"); } else { if ($row["status"] == ALERT_STATUS_NOT_SENT) { $status = new CSpan(S_IN_PROGRESS, "orange"); $retries = new CSpan(ALERT_MAX_RETRIES - $row["retries"], "orange"); } else { $status = new CSpan(S_NOT_SENT, "red"); $retries = new CSpan(0, "red"); } } switch ($row['alerttype']) { case ALERT_TYPE_MESSAGE: $message = empty($row['description']) ? '-' : $row['description']; break; case ALERT_TYPE_COMMAND: $message = array(bold(S_COMMAND . ':')); $msg = explode("\n", $row['message']); foreach ($msg as $m) { array_push($message, BR(), $m); } break; default: $message = '-'; } $tab_hint->addRow(array(get_node_name_by_elid($row['alertid']), empty($row['alias']) ? ' - ' : $row['alias'], $message, $status)); } return $tab_hint; }
function change_group_debug_mode($usrgrpids, $debug_mode) { zbx_value2array($usrgrpids); $res = false; $res = DBexecute('UPDATE usrgrp SET debug_mode=' . $debug_mode . ' WHERE ' . DBcondition('usrgrpid', $usrgrpids)); return $res; }
$header = get_table_header(array(S_MAINTENANCE_PERIODS, new CSpan(SPACE . SPACE . '|' . SPACE . SPACE, 'divider'), S_FOUND . ': ', $numrows)); show_table_header($header, $form); // ---- $available_maintenances = get_accessible_maintenance_by_user(PERM_READ_ONLY); $sqls = array(); $config = select_config(); $maintenances = array(); $maintenanceids = array(); if ($_REQUEST['groupid'] > 0) { $sqls[] = 'SELECT m.* ' . ' FROM maintenances m, maintenances_groups mg ' . ' WHERE ' . DBin_node('m.maintenanceid') . ' AND ' . DBcondition('m.maintenanceid', $available_maintenances) . ' AND mg.groupid=' . $_REQUEST['groupid'] . ' AND m.maintenanceid=mg.maintenanceid '; ' ORDER BY m.name'; $sqls[] = 'SELECT m.* ' . ' FROM maintenances m, maintenances_hosts mh, hosts_groups hg ' . ' WHERE ' . DBin_node('m.maintenanceid') . ' AND ' . DBcondition('m.maintenanceid', $available_maintenances) . ' AND hg.groupid=' . $_REQUEST['groupid'] . ' AND mh.hostid=hg.hostid ' . ' AND m.maintenanceid=mh.maintenanceid '; ' ORDER BY m.name'; } else { if ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_ALL) { $sqls[] = 'SELECT m.* ' . ' FROM maintenances m ' . ' WHERE ' . DBin_node('m.maintenanceid') . ' AND ' . DBcondition('m.maintenanceid', $available_maintenances) . ' ORDER BY m.name'; } } foreach ($sqls as $num => $sql) { $db_maintenances = DBselect($sql); while ($maintenance = DBfetch($db_maintenances)) { $maintenances[$maintenance['maintenanceid']] = $maintenance; $maintenanceids[$maintenance['maintenanceid']] = $maintenance['maintenanceid']; } } $form = new CForm(null, 'post'); $form->setName('maintenances'); $table = new CTableInfo(); $table->setHeader(array(new CCheckBox('all_maintenances', NULL, "checkAll('" . $form->GetName() . "','all_maintenances','maintenanceids');"), make_sorting_link(S_NAME, 'm.name'), S_TYPE, S_STATUS, S_DESCRIPTION)); foreach ($maintenances as $maintenanceid => $maintenance) { if ($maintenance['active_till'] < time()) {
/** * Mass update hosts * * @param _array $hosts multidimensional array with Hosts data * @param array $hosts['hosts'] Array of Host objects to update * @param string $hosts['fields']['host'] Host name. * @param array $hosts['fields']['groupids'] HostGroup IDs add Host to. * @param int $hosts['fields']['port'] Port. OPTIONAL * @param int $hosts['fields']['status'] Host Status. OPTIONAL * @param int $hosts['fields']['useip'] Use IP. OPTIONAL * @param string $hosts['fields']['dns'] DNS. OPTIONAL * @param string $hosts['fields']['ip'] IP. OPTIONAL * @param int $hosts['fields']['proxy_hostid'] Proxy Host ID. OPTIONAL * @param int $hosts['fields']['useipmi'] Use IPMI. OPTIONAL * @param string $hosts['fields']['ipmi_ip'] IPMAI IP. OPTIONAL * @param int $hosts['fields']['ipmi_port'] IPMI port. OPTIONAL * @param int $hosts['fields']['ipmi_authtype'] IPMI authentication type. OPTIONAL * @param int $hosts['fields']['ipmi_privilege'] IPMI privilege. OPTIONAL * @param string $hosts['fields']['ipmi_username'] IPMI username. OPTIONAL * @param string $hosts['fields']['ipmi_password'] IPMI password. OPTIONAL * @return boolean */ public static function massUpdate($data) { $hosts = zbx_toArray($data['hosts']); $hostids = zbx_objectValues($hosts, 'hostid'); try { self::BeginTransaction(__METHOD__); $options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $upd_hosts = self::get($options); foreach ($hosts as $hnum => $host) { if (!isset($upd_hosts[$host['hostid']])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } // CHECK IF HOSTS HAVE AT LEAST 1 GROUP {{{ if (isset($data['groups']) && empty($data['groups'])) { self::exception(ZBX_API_ERROR_PARAMETERS, 'No groups for hosts'); } // }}} CHECK IF HOSTS HAVE AT LEAST 1 GROUP // UPDATE HOSTS PROPERTIES {{{ if (isset($data['host'])) { if (count($hosts) > 1) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot mass update host name'); } $cur_host = reset($hosts); $options = array('filter' => array('host' => $cur_host['host']), 'output' => API_OUTPUT_SHORTEN, 'editable' => 1, 'nopermissions' => 1); $host_exists = self::get($options); $host_exist = reset($host_exists); if ($host_exist && $host_exist['hostid'] != $cur_host['hostid']) { self::exception(ZBX_API_ERROR_PARAMETERS, S_HOST . ' [ ' . $data['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL); } //can't add host with the same name as existing template if (CTemplate::exists(array('host' => $cur_host['host']))) { self::exception(ZBX_API_ERROR_PARAMETERS, S_TEMPLATE . ' [ ' . $cur_host['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL); } } if (isset($data['host']) && !preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/i', $data['host'])) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect characters used for Hostname [ ' . $data['host'] . ' ]'); } if (isset($data['dns']) && !empty($data['dns']) && !preg_match('/^' . ZBX_PREG_DNS_FORMAT . '$/i', $data['dns'])) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect characters used for DNS [ ' . $data['dns'] . ' ]'); } $sql_set = array(); if (isset($data['proxy_hostid'])) { $sql_set[] = 'proxy_hostid=' . $data['proxy_hostid']; } if (isset($data['host'])) { $sql_set[] = 'host=' . zbx_dbstr($data['host']); } if (isset($data['port'])) { $sql_set[] = 'port=' . $data['port']; } if (isset($data['status'])) { $sql_set[] = 'status=' . $data['status']; } if (isset($data['useip'])) { $sql_set[] = 'useip=' . $data['useip']; } if (isset($data['dns'])) { $sql_set[] = 'dns=' . zbx_dbstr($data['dns']); } if (isset($data['ip'])) { $sql_set[] = 'ip=' . zbx_dbstr($data['ip']); } if (isset($data['useipmi'])) { $sql_set[] = 'useipmi=' . $data['useipmi']; } if (isset($data['ipmi_port'])) { $sql_set[] = 'ipmi_port=' . $data['ipmi_port']; } if (isset($data['ipmi_authtype'])) { $sql_set[] = 'ipmi_authtype=' . $data['ipmi_authtype']; } if (isset($data['ipmi_privilege'])) { $sql_set[] = 'ipmi_privilege=' . $data['ipmi_privilege']; } if (isset($data['ipmi_username'])) { $sql_set[] = 'ipmi_username='******'ipmi_username']); } if (isset($data['ipmi_password'])) { $sql_set[] = 'ipmi_password='******'ipmi_password']); } if (isset($data['ipmi_ip'])) { $sql_set[] = 'ipmi_ip=' . zbx_dbstr($data['ipmi_ip']); } if (!empty($sql_set)) { $sql = 'UPDATE hosts SET ' . implode(', ', $sql_set) . ' WHERE ' . DBcondition('hostid', $hostids); $result = DBexecute($sql); if (isset($data['status'])) { update_host_status($hostids, $data['status']); } } // }}} UPDATE HOSTS PROPERTIES // UPDATE HOSTGROUPS LINKAGE {{{ if (isset($data['groups']) && !is_null($data['groups'])) { $data['groups'] = zbx_toArray($data['groups']); $host_groups = CHostGroup::get(array('hostids' => $hostids)); $host_groupids = zbx_objectValues($host_groups, 'groupid'); $new_groupids = zbx_objectValues($data['groups'], 'groupid'); $groups_to_add = array_diff($new_groupids, $host_groupids); if (!empty($groups_to_add)) { $result = self::massAdd(array('hosts' => $hosts, 'groups' => zbx_toObject($groups_to_add, 'groupid'))); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t add group'); } } $groupids_to_del = array_diff($host_groupids, $new_groupids); if (!empty($groupids_to_del)) { $result = self::massRemove(array('hostids' => $hostids, 'groupids' => $groupids_to_del)); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t remove group'); } } } // }}} UPDATE HOSTGROUPS LINKAGE $data['templates_clear'] = isset($data['templates_clear']) ? zbx_toArray($data['templates_clear']) : array(); $cleared_templateids = array(); foreach ($hostids as $hostid) { foreach ($data['templates_clear'] as $tpl) { $result = unlink_template($hostid, $tpl['templateid'], false); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot unlink template [ ' . $tpl['templateid'] . ' ]'); } $cleared_templateids[] = $tpl['templateid']; } } // UPDATE TEMPLATE LINKAGE {{{ if (isset($data['templates']) && !is_null($data['templates'])) { $opt = array('hostids' => $hostids, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true); $host_templates = CTemplate::get($opt); $host_templateids = array_keys($host_templates); $new_templateids = zbx_objectValues($data['templates'], 'templateid'); $templates_to_del = array_diff($host_templateids, $new_templateids); $templates_to_del = array_diff($templates_to_del, $cleared_templateids); if (!empty($templates_to_del)) { $result = self::massRemove(array('hostids' => $hostids, 'templateids' => $templates_to_del)); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, S_CANNOT_UNLINK_TEMPLATE); } } $result = self::massAdd(array('hosts' => $hosts, 'templates' => $data['templates'])); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, S_CANNOT_LINK_TEMPLATE); } } // }}} UPDATE TEMPLATE LINKAGE // UPDATE MACROS {{{ if (isset($data['macros']) && !is_null($data['macros'])) { $macrosToAdd = zbx_toHash($data['macros'], 'macro'); $hostMacros = CUserMacro::get(array('hostids' => $hostids, 'output' => API_OUTPUT_EXTEND)); $hostMacros = zbx_toHash($hostMacros, 'macro'); // Delete $macrosToDelete = array(); foreach ($hostMacros as $hmnum => $hmacro) { if (!isset($macrosToAdd[$hmacro['macro']])) { $macrosToDelete[] = $hmacro['macro']; } } // Update $macrosToUpdate = array(); foreach ($macrosToAdd as $nhmnum => $nhmacro) { if (isset($hostMacros[$nhmacro['macro']])) { $macrosToUpdate[] = $nhmacro; unset($macrosToAdd[$nhmnum]); } } //---- if (!empty($macrosToDelete)) { $result = self::massRemove(array('hostids' => $hostids, 'macros' => $macrosToDelete)); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t remove macro'); } } if (!empty($macrosToUpdate)) { $result = CUsermacro::massUpdate(array('hosts' => $hosts, 'macros' => $macrosToUpdate)); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot update macro'); } } if (!empty($macrosToAdd)) { $result = self::massAdd(array('hosts' => $hosts, 'macros' => $macrosToAdd)); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot add macro'); } } } // }}} UPDATE MACROS // PROFILE {{{ if (isset($data['profile']) && !is_null($data['profile'])) { if (empty($data['profile'])) { $sql = 'DELETE FROM hosts_profiles WHERE ' . DBcondition('hostid', $hostids); if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete profile'); } } else { $existing_profiles = array(); $existing_profiles_db = DBselect('SELECT hostid FROM hosts_profiles WHERE ' . DBcondition('hostid', $hostids)); while ($existing_profile = DBfetch($existing_profiles_db)) { $existing_profiles[] = $existing_profile['hostid']; } $hostids_without_profile = array_diff($hostids, $existing_profiles); $fields = array_keys($data['profile']); $fields = implode(', ', $fields); $values = array_map('zbx_dbstr', $data['profile']); $values = implode(', ', $values); foreach ($hostids_without_profile as $hostid) { $sql = 'INSERT INTO hosts_profiles (hostid, ' . $fields . ') VALUES (' . $hostid . ', ' . $values . ')'; if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot create profile'); } } if (!empty($existing_profiles)) { $host_profile_fields = array('devicetype', 'name', 'os', 'serialno', 'tag', 'macaddress', 'hardware', 'software', 'contact', 'location', 'notes'); $sql_set = array(); foreach ($host_profile_fields as $field) { if (isset($data['profile'][$field])) { $sql_set[] = $field . '=' . zbx_dbstr($data['profile'][$field]); } } $sql = 'UPDATE hosts_profiles SET ' . implode(', ', $sql_set) . ' WHERE ' . DBcondition('hostid', $existing_profiles); if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot update profile'); } } } } // }}} PROFILE // EXTENDED PROFILE {{{ if (isset($data['extendedProfile']) && !is_null($data['extendedProfile'])) { if (empty($data['extendedProfile'])) { $sql = 'DELETE FROM hosts_profiles_ext WHERE ' . DBcondition('hostid', $hostids); if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete extended profile'); } } else { $existing_profiles = array(); $existing_profiles_db = DBselect('SELECT hostid FROM hosts_profiles_ext WHERE ' . DBcondition('hostid', $hostids)); while ($existing_profile = DBfetch($existing_profiles_db)) { $existing_profiles[] = $existing_profile['hostid']; } $hostids_without_profile = array_diff($hostids, $existing_profiles); $fields = array_keys($data['extendedProfile']); $fields = implode(', ', $fields); $values = array_map('zbx_dbstr', $data['extendedProfile']); $values = implode(', ', $values); foreach ($hostids_without_profile as $hostid) { $sql = 'INSERT INTO hosts_profiles_ext (hostid, ' . $fields . ') VALUES (' . $hostid . ', ' . $values . ')'; if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot create extended profile'); } } if (!empty($existing_profiles)) { $host_profile_ext_fields = array('device_alias', 'device_type', 'device_chassis', 'device_os', 'device_os_short', 'device_hw_arch', 'device_serial', 'device_model', 'device_tag', 'device_vendor', 'device_contract', 'device_who', 'device_status', 'device_app_01', 'device_app_02', 'device_app_03', 'device_app_04', 'device_app_05', 'device_url_1', 'device_url_2', 'device_url_3', 'device_networks', 'device_notes', 'device_hardware', 'device_software', 'ip_subnet_mask', 'ip_router', 'ip_macaddress', 'oob_ip', 'oob_subnet_mask', 'oob_router', 'date_hw_buy', 'date_hw_install', 'date_hw_expiry', 'date_hw_decomm', 'site_street_1', 'site_street_2', 'site_street_3', 'site_city', 'site_state', 'site_country', 'site_zip', 'site_rack', 'site_notes', 'poc_1_name', 'poc_1_email', 'poc_1_phone_1', 'poc_1_phone_2', 'poc_1_cell', 'poc_1_screen', 'poc_1_notes', 'poc_2_name', 'poc_2_email', 'poc_2_phone_1', 'poc_2_phone_2', 'poc_2_cell', 'poc_2_screen', 'poc_2_notes'); $sql_set = array(); foreach ($host_profile_ext_fields as $field) { if (isset($data['extendedProfile'][$field])) { $sql_set[] = $field . '=' . zbx_dbstr($data['extendedProfile'][$field]); } } $sql = 'UPDATE hosts_profiles_ext SET ' . implode(', ', $sql_set) . ' WHERE ' . DBcondition('hostid', $existing_profiles); if (!DBexecute($sql)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot update extended profile'); } } } } // }}} EXTENDED PROFILE self::EndTransaction(true, __METHOD__); return array('hostids' => $hostids); } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }
$userids[$db_user['userid']] = $db_user['userid']; } $users_sessions = array(); $sql = 'SELECT s.userid, MAX(s.lastaccess) as lastaccess, s.status ' . ' FROM sessions s, users u' . ' WHERE ' . DBcondition('s.userid', $userids) . ' AND s.userid=u.userid ' . ' GROUP BY s.userid,s.status'; //SDI($sql); $db_sessions = DBselect($sql); while ($db_ses = DBfetch($db_sessions)) { if (!isset($users_sessions[$db_ses['userid']])) { $users_sessions[$db_ses['userid']] = $db_ses; } if (isset($users_sessions[$db_ses['userid']]) && $users_sessions[$db_ses['userid']]['lastaccess'] < $db_ses['lastaccess']) { $users_sessions[$db_ses['userid']] = $db_ses; } } $users_groups = array(); $sql = 'SELECT g.name, ug.usrgrpid, ug.userid ' . ' FROM usrgrp g, users_groups ug ' . ' WHERE g.usrgrpid=ug.usrgrpid ' . ' AND ' . DBcondition('ug.userid', $userids); $db_groups = DBselect($sql); while ($db_group = DBfetch($db_groups)) { if (!isset($users_groups[$db_group['userid']])) { $users_groups[$db_group['userid']] = array(); } if (!empty($users_groups[$db_group['userid']])) { $users_groups[$db_group['userid']][] = BR(); } $users_groups[$db_group['userid']][] = new CLink($db_group['name'], 'users.php?form=update&config=1&usrgrpid=' . $db_group['usrgrpid'] . '#form'); } foreach ($userids as $id => $userid) { $user =& $users[$userid]; //Log Out 10min or Autologout time $online_time = $user['autologout'] == 0 || ZBX_USER_ONLINE_TIME < $user['autologout'] ? ZBX_USER_ONLINE_TIME : $user['autologout']; $online = new CCol(S_NO, 'disabled');