/usr/share/zabbix/discoveryconf.php is in zabbix-frontend-php 1:2.4.7+dfsg-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | <?php
/*
** Zabbix
** Copyright (C) 2001-2015 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** 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/forms.inc.php';
require_once dirname(__FILE__).'/include/discovery.inc.php';
$page['title'] = _('Configuration of discovery rules');
$page['file'] = 'discoveryconf.php';
$page['hist_arg'] = array();
$page['type'] = detect_page_type();
require_once dirname(__FILE__).'/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array(
'druleid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form}) && {form} == "update"'),
'name' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})'),
'proxy_hostid' => array(T_ZBX_INT, O_OPT, null, DB_ID, 'isset({add}) || isset({update})'),
'iprange' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'),
'delay' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, SEC_PER_WEEK), 'isset({add}) || isset({update})'),
'status' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null),
'uniqueness_criteria' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})', _('Device uniqueness criteria')),
'g_druleid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null),
'dchecks' => array(null, O_OPT, null, null, null),
// actions
'action' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT,
IN('"drule.massdelete","drule.massdisable","drule.massenable"'),
null
),
'add' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'update' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'delete' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null),
'output' => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
'ajaxaction' => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
'ajaxdata' => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
// sort and sortorder
'sort' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"name"'), null),
'sortorder' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null)
);
check_fields($fields);
$_REQUEST['status'] = isset($_REQUEST['status']) ? DRULE_STATUS_ACTIVE : DRULE_STATUS_DISABLED;
$_REQUEST['dchecks'] = getRequest('dchecks', array());
/*
* Permissions
*/
if (isset($_REQUEST['druleid'])) {
$dbDRule = API::DRule()->get(array(
'druleids' => getRequest('druleid'),
'output' => array('name', 'proxy_hostid', 'iprange', 'delay', 'status'),
'selectDChecks' => array(
'type', 'key_', 'snmp_community', 'ports', 'snmpv3_securityname', 'snmpv3_securitylevel',
'snmpv3_authpassphrase', 'snmpv3_privpassphrase', 'uniq', 'snmpv3_authprotocol', 'snmpv3_privprotocol',
'snmpv3_contextname'
),
'editable' => true
));
if (empty($dbDRule)) {
access_deny();
}
}
// ajax
if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'ajax') {
$ajaxResponse = new CAjaxResponse;
if (isset($_REQUEST['ajaxaction']) && $_REQUEST['ajaxaction'] == 'validate') {
$ajaxData = getRequest('ajaxdata', array());
foreach ($ajaxData as $check) {
switch ($check['field']) {
case 'port':
if (!validate_port_list($check['value'])) {
$ajaxResponse->error(_('Incorrect port range.'));
}
break;
case 'itemKey':
$itemKey = new CItemKey($check['value']);
if (!$itemKey->isValid()) {
$ajaxResponse->error(_s('Invalid key "%1$s": %2$s.', $check['value'], $itemKey->getError()));
}
break;
}
}
}
$ajaxResponse->send();
require_once dirname(__FILE__).'/include/page_footer.php';
exit;
}
/*
* Action
*/
if (hasRequest('add') || hasRequest('update')) {
$dChecks = getRequest('dchecks', array());
$uniq = getRequest('uniqueness_criteria', 0);
foreach ($dChecks as $dcnum => $check) {
if (substr($check['dcheckid'], 0, 3) === 'new') {
unset($dChecks[$dcnum]['dcheckid']);
}
$dChecks[$dcnum]['uniq'] = ($uniq == $dcnum) ? 1 : 0;
}
$discoveryRule = array(
'name' => getRequest('name'),
'proxy_hostid' => getRequest('proxy_hostid'),
'iprange' => getRequest('iprange'),
'delay' => getRequest('delay'),
'status' => getRequest('status'),
'dchecks' => $dChecks
);
DBStart();
if (hasRequest('update')) {
$discoveryRule['druleid'] = getRequest('druleid');
$result = API::DRule()->update($discoveryRule);
$messageSuccess = _('Discovery rule updated');
$messageFailed = _('Cannot update discovery rule');
$auditAction = AUDIT_ACTION_UPDATE;
}
else {
$result = API::DRule()->create($discoveryRule);
$messageSuccess = _('Discovery rule created');
$messageFailed = _('Cannot create discovery rule');
$auditAction = AUDIT_ACTION_ADD;
}
if ($result) {
$druleid = reset($result['druleids']);
add_audit($auditAction, AUDIT_RESOURCE_DISCOVERY_RULE, '['.$druleid.'] '.$discoveryRule['name']);
unset($_REQUEST['form']);
}
$result = DBend($result);
if ($result) {
uncheckTableRows();
}
show_messages($result, $messageSuccess, $messageFailed);
}
elseif (isset($_REQUEST['delete']) && isset($_REQUEST['druleid'])) {
$result = API::DRule()->delete(array($_REQUEST['druleid']));
if ($result) {
unset($_REQUEST['form'], $_REQUEST['druleid']);
uncheckTableRows();
}
show_messages($result, _('Discovery rule deleted'), _('Cannot delete discovery rule'));
}
elseif (hasRequest('action') && str_in_array(getRequest('action'), array('drule.massenable', 'drule.massdisable')) && hasRequest('g_druleid')) {
$result = true;
$enable = (getRequest('action') == 'drule.massenable');
$status = $enable ? DRULE_STATUS_ACTIVE : DRULE_STATUS_DISABLED;
$auditAction = $enable ? AUDIT_ACTION_ENABLE : AUDIT_ACTION_DISABLE;
$updated = 0;
DBStart();
foreach (getRequest('g_druleid') as $druleId) {
$result &= DBexecute('UPDATE drules SET status='.zbx_dbstr($status).' WHERE druleid='.zbx_dbstr($druleId));
if ($result) {
$druleData = get_discovery_rule_by_druleid($druleId);
add_audit($auditAction, AUDIT_RESOURCE_DISCOVERY_RULE, '['.$druleId.'] '.$druleData['name']);
}
$updated++;
}
$messageSuccess = $enable
? _n('Discovery rule enabled', 'Discovery rules enabled', $updated)
: _n('Discovery rule disabled', 'Discovery rules disabled', $updated);
$messageFailed = $enable
? _n('Cannot enable discovery rule', 'Cannot enable discovery rules', $updated)
: _n('Cannot disable discovery rule', 'Cannot disable discovery rules', $updated);
$result = DBend($result);
if ($result) {
uncheckTableRows();
}
show_messages($result, $messageSuccess, $messageFailed);
}
elseif (hasRequest('action') && getRequest('action') == 'drule.massdelete' && hasRequest('g_druleid')) {
$result = API::DRule()->delete(getRequest('g_druleid'));
if ($result) {
uncheckTableRows();
}
show_messages($result, _('Discovery rules deleted'), _('Cannot delete discovery rules'));
}
/*
* Display
*/
if (isset($_REQUEST['form'])) {
$data = array(
'druleid' => getRequest('druleid'),
'drule' => array(),
'form' => getRequest('form'),
'form_refresh' => getRequest('form_refresh', 0)
);
// get drule
if (isset($data['druleid']) && !isset($_REQUEST['form_refresh'])) {
$data['drule'] = reset($dbDRule);
$data['drule']['uniqueness_criteria'] = -1;
if (!empty($data['drule']['dchecks'])) {
foreach ($data['drule']['dchecks'] as $id => $dcheck) {
if ($dcheck['uniq']) {
$data['drule']['uniqueness_criteria'] = $dcheck['dcheckid'];
}
}
}
}
else {
$data['drule']['proxy_hostid'] = getRequest('proxy_hostid', 0);
$data['drule']['name'] = getRequest('name', '');
$data['drule']['iprange'] = getRequest('iprange', '192.168.0.1-254');
$data['drule']['delay'] = getRequest('delay', SEC_PER_HOUR);
$data['drule']['status'] = getRequest('status', DRULE_STATUS_ACTIVE);
$data['drule']['dchecks'] = getRequest('dchecks', array());
$data['drule']['nextcheck'] = getRequest('nextcheck', 0);
$data['drule']['uniqueness_criteria'] = getRequest('uniqueness_criteria', -1);
}
if (!empty($data['drule']['dchecks'])) {
foreach ($data['drule']['dchecks'] as $id => $dcheck) {
$data['drule']['dchecks'][$id]['name'] = discovery_check2str(
$dcheck['type'],
isset($dcheck['key_']) ? $dcheck['key_'] : '',
isset($dcheck['ports']) ? $dcheck['ports'] : ''
);
}
order_result($data['drule']['dchecks'], 'name');
}
// get proxies
$data['proxies'] = API::Proxy()->get(array(
'output' => API_OUTPUT_EXTEND
));
order_result($data['proxies'], 'host');
// render view
$discoveryView = new CView('configuration.discovery.edit', $data);
$discoveryView->render();
$discoveryView->show();
}
else {
$sortField = getRequest('sort', CProfile::get('web.'.$page['file'].'.sort', 'name'));
$sortOrder = getRequest('sortorder', CProfile::get('web.'.$page['file'].'.sortorder', ZBX_SORT_UP));
CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR);
$config = select_config();
$data = array(
'sort' => $sortField,
'sortorder' => $sortOrder
);
// get drules
$data['drules'] = API::DRule()->get(array(
'output' => array('proxy_hostid', 'name', 'status', 'iprange', 'delay'),
'selectDChecks' => array('type'),
'editable' => true,
'sortfield' => $sortField,
'limit' => $config['search_limit'] + 1
));
if ($data['drules']) {
foreach ($data['drules'] as $key => $drule) {
// checks
$checks = array();
foreach ($drule['dchecks'] as $check) {
$checks[$check['type']] = discovery_check_type2str($check['type']);
}
order_result($checks);
$data['drules'][$key]['checks'] = $checks;
// description
$data['drules'][$key]['description'] = array();
if ($drule['proxy_hostid']) {
$proxy = get_host_by_hostid($drule['proxy_hostid']);
array_push($data['drules'][$key]['description'], $proxy['host'].NAME_DELIMITER);
}
}
order_result($data['drules'], $sortField, $sortOrder);
}
// get paging
$data['paging'] = getPagingLine($data['drules'], $sortOrder);
// render view
$discoveryView = new CView('configuration.discovery.list', $data);
$discoveryView->render();
$discoveryView->show();
}
require_once dirname(__FILE__).'/include/page_footer.php';
|