/** * Execute script. * * @param string $data['scriptid'] * @param string $data['hostid'] * * @return array */ public function execute(array $data) { global $ZBX_SERVER, $ZBX_SERVER_PORT; $scriptId = $data['scriptid']; $hostId = $data['hostid']; $scripts = $this->get(array('hostids' => $hostId, 'scriptids' => $scriptId, 'output' => array('scriptid'), 'preservekeys' => true)); if (!isset($scripts[$scriptId])) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } // execute script $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SCRIPT_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); $result = $zabbixServer->executeScript($scriptId, $hostId); if ($result !== false) { // return the result in a backwards-compatible format return array('response' => 'success', 'value' => $result); } else { self::exception(ZBX_API_ERROR_INTERNAL, $zabbixServer->getError()); } }
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ require_once dirname(__FILE__) . '/include/config.inc.php'; require_once dirname(__FILE__) . '/include/items.inc.php'; $page['title'] = _('Queue'); $page['file'] = 'queue.php'; define('ZBX_PAGE_DO_REFRESH', 1); require_once dirname(__FILE__) . '/include/page_header.php'; $queueModes = [QUEUE_OVERVIEW, QUEUE_OVERVIEW_BY_PROXY, QUEUE_DETAILS]; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = ['config' => [T_ZBX_INT, O_OPT, P_SYS, IN($queueModes), null]]; check_fields($fields); $config = getRequest('config', CProfile::get('web.queue.config', 0)); CProfile::update('web.queue.config', $config, PROFILE_TYPE_INT); // fetch data $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); $queueRequests = [QUEUE_OVERVIEW => CZabbixServer::QUEUE_OVERVIEW, QUEUE_OVERVIEW_BY_PROXY => CZabbixServer::QUEUE_OVERVIEW_BY_PROXY, QUEUE_DETAILS => CZabbixServer::QUEUE_DETAILS]; $queueData = $zabbixServer->getQueue($queueRequests[$config], get_cookie('zbx_sessionid')); // check for errors error if ($zabbixServer->getError()) { error($zabbixServer->getError()); show_error_message(_('Cannot display item queue.')); require_once dirname(__FILE__) . '/include/page_footer.php'; } $widget = (new CWidget())->setTitle(_('Queue of items to be updated'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem((new CComboBox('config', $config, 'submit();'))->addItem(QUEUE_OVERVIEW, _('Overview'))->addItem(QUEUE_OVERVIEW_BY_PROXY, _('Overview by proxy'))->addItem(QUEUE_DETAILS, _('Details'))))); $table = new CTableInfo(); $severityConfig = select_config(); // overview if ($config == QUEUE_OVERVIEW) { $itemTypes = [ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR, ITEM_TYPE_IPMI, ITEM_TYPE_SSH, ITEM_TYPE_TELNET, ITEM_TYPE_JMX, ITEM_TYPE_CALCULATED]; $table->setHeader([_('Items'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes')]);
} array_multisort($sortClock, SORT_ASC, $sortEvent, SORT_ASC, $result); break; case 'message.closeAll': $msgsettings = getMessageSettings(); switch (strtolower($data['params']['caption'])) { case 'events': $msgsettings['last.clock'] = (int) $data['params']['time'] + 1; updateMessageSettings($msgsettings); break; } break; case 'zabbix.status': $session = Z::getInstance()->getSession(); if (!isset($session['serverCheckResult']) || $session['serverCheckTime'] + SERVER_CHECK_INTERVAL <= time()) { $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); $session['serverCheckResult'] = $zabbixServer->isRunning(); $session['serverCheckTime'] = time(); } $result = array('result' => (bool) $session['serverCheckResult'], 'message' => $session['serverCheckResult'] ? '' : _('Zabbix server is not running: the information displayed may not be current.')); break; case 'screen.get': $options = array('pageFile' => !empty($data['pageFile']) ? $data['pageFile'] : null, 'mode' => !empty($data['mode']) ? $data['mode'] : null, 'timestamp' => !empty($data['timestamp']) ? $data['timestamp'] : time(), 'resourcetype' => !empty($data['resourcetype']) ? $data['resourcetype'] : null, 'screenid' => isset($data['screenid']) && $data['screenid'] != 0 ? $data['screenid'] : null, 'screenitemid' => !empty($data['screenitemid']) ? $data['screenitemid'] : null, 'groupid' => !empty($data['groupid']) ? $data['groupid'] : null, 'hostid' => !empty($data['hostid']) ? $data['hostid'] : null, 'period' => !empty($data['period']) ? $data['period'] : null, 'stime' => !empty($data['stime']) ? $data['stime'] : null, 'profileIdx' => !empty($data['profileIdx']) ? $data['profileIdx'] : null, 'profileIdx2' => !empty($data['profileIdx2']) ? $data['profileIdx2'] : null, 'updateProfile' => isset($data['updateProfile']) ? $data['updateProfile'] : null); if ($options['resourcetype'] == SCREEN_RESOURCE_HISTORY) { $options['itemids'] = !empty($data['itemids']) ? $data['itemids'] : null; $options['action'] = !empty($data['action']) ? $data['action'] : null; $options['filter'] = !empty($data['filter']) ? $data['filter'] : null; $options['filter_task'] = !empty($data['filter_task']) ? $data['filter_task'] : null; $options['mark_color'] = !empty($data['mark_color']) ? $data['mark_color'] : null; } elseif ($options['resourcetype'] == SCREEN_RESOURCE_CHART) { $options['graphid'] = !empty($data['graphid']) ? $data['graphid'] : null;
function get_status() { global $ZBX_SERVER, $ZBX_SERVER_PORT; $status = array('triggers_count' => 0, 'triggers_count_enabled' => 0, 'triggers_count_disabled' => 0, 'triggers_count_off' => 0, 'triggers_count_on' => 0, 'items_count' => 0, 'items_count_monitored' => 0, 'items_count_disabled' => 0, 'items_count_not_supported' => 0, 'hosts_count' => 0, 'hosts_count_monitored' => 0, 'hosts_count_not_monitored' => 0, 'hosts_count_template' => 0, 'users_online' => 0, 'qps_total' => 0); // server $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); $status['zabbix_server'] = $zabbixServer->isRunning() ? _('Yes') : _('No'); // triggers $dbTriggers = DBselect('SELECT COUNT(DISTINCT t.triggerid) AS cnt,t.status,t.value' . ' FROM triggers t' . ' WHERE NOT EXISTS (' . 'SELECT f.functionid FROM functions f' . ' JOIN items i ON f.itemid=i.itemid' . ' JOIN hosts h ON i.hostid=h.hostid' . ' WHERE f.triggerid=t.triggerid AND (i.status<>' . ITEM_STATUS_ACTIVE . ' OR h.status<>' . HOST_STATUS_MONITORED . ')' . ')' . ' AND t.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ' GROUP BY t.status,t.value'); while ($dbTrigger = DBfetch($dbTriggers)) { switch ($dbTrigger['status']) { case TRIGGER_STATUS_ENABLED: switch ($dbTrigger['value']) { case TRIGGER_VALUE_FALSE: $status['triggers_count_off'] = $dbTrigger['cnt']; break; case TRIGGER_VALUE_TRUE: $status['triggers_count_on'] = $dbTrigger['cnt']; break; } break; case TRIGGER_STATUS_DISABLED: $status['triggers_count_disabled'] += $dbTrigger['cnt']; break; } } $status['triggers_count_enabled'] = $status['triggers_count_off'] + $status['triggers_count_on']; $status['triggers_count'] = $status['triggers_count_enabled'] + $status['triggers_count_disabled']; // items $dbItems = DBselect('SELECT COUNT(i.itemid) AS cnt,i.status,i.state' . ' FROM items i' . ' INNER JOIN hosts h ON i.hostid=h.hostid' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND i.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ' AND i.type<>' . ITEM_TYPE_HTTPTEST . ' GROUP BY i.status,i.state'); while ($dbItem = DBfetch($dbItems)) { if ($dbItem['status'] == ITEM_STATUS_ACTIVE) { if ($dbItem['state'] == ITEM_STATE_NORMAL) { $status['items_count_monitored'] = $dbItem['cnt']; } else { $status['items_count_not_supported'] = $dbItem['cnt']; } } elseif ($dbItem['status'] == ITEM_STATUS_DISABLED) { $status['items_count_disabled'] += $dbItem['cnt']; } } $status['items_count'] = $status['items_count_monitored'] + $status['items_count_disabled'] + $status['items_count_not_supported']; // hosts $dbHosts = DBselect('SELECT COUNT(*) AS cnt,h.status' . ' FROM hosts h' . ' WHERE ' . dbConditionInt('h.status', array(HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED, HOST_STATUS_TEMPLATE)) . ' AND ' . dbConditionInt('h.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' GROUP BY h.status'); while ($dbHost = DBfetch($dbHosts)) { switch ($dbHost['status']) { case HOST_STATUS_MONITORED: $status['hosts_count_monitored'] = $dbHost['cnt']; break; case HOST_STATUS_NOT_MONITORED: $status['hosts_count_not_monitored'] = $dbHost['cnt']; break; case HOST_STATUS_TEMPLATE: $status['hosts_count_template'] = $dbHost['cnt']; break; } } $status['hosts_count'] = $status['hosts_count_monitored'] + $status['hosts_count_not_monitored'] + $status['hosts_count_template']; // users $row = DBfetch(DBselect('SELECT COUNT(*) AS usr_cnt FROM users u')); $status['users_count'] = $row['usr_cnt']; $status['users_online'] = 0; $db_sessions = DBselect('SELECT s.userid,s.status,MAX(s.lastaccess) AS lastaccess' . ' FROM sessions s' . ' WHERE s.status=' . ZBX_SESSION_ACTIVE . ' GROUP BY s.userid,s.status'); while ($session = DBfetch($db_sessions)) { if ($session['lastaccess'] + ZBX_USER_ONLINE_TIME >= time()) { $status['users_online']++; } } // comments: !!! Don't forget sync code with C !!! $row = DBfetch(DBselect('SELECT SUM(CAST(1.0/i.delay AS DECIMAL(20,10))) AS qps' . ' FROM items i,hosts h' . ' WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.hostid=h.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.delay<>0' . ' AND i.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE)); $status['qps_total'] = round($row['qps'], 2); return $status; }
} array_multisort($sortClock, SORT_ASC, $sortEvent, SORT_ASC, $result); break; case 'message.closeAll': $msgsettings = getMessageSettings(); switch (strtolower($data['params']['caption'])) { case 'events': $msgsettings['last.clock'] = (int) $data['params']['time'] + 1; updateMessageSettings($msgsettings); break; } break; case 'zabbix.status': CSession::start(); if (!CSession::keyExists('serverCheckResult') || CSession::getValue('serverCheckTime') + SERVER_CHECK_INTERVAL <= time()) { $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); CSession::setValue('serverCheckResult', $zabbixServer->isRunning()); CSession::setValue('serverCheckTime', time()); } $result = ['result' => (bool) CSession::getValue('serverCheckResult'), 'message' => CSession::getValue('serverCheckResult') ? '' : _('Zabbix server is not running: the information displayed may not be current.')]; break; case 'screen.get': $result = ''; $screenBase = CScreenBuilder::getScreen($data); if ($screenBase !== null) { $screen = $screenBase->get(); if ($data['mode'] == SCREEN_MODE_JS) { $result = $screen; } else { if (is_object($screen)) { $result = $screen->toString();