// create new discovery rule button $createForm = new CForm('get'); $createForm->cleanItems(); $createForm->addItem(new CSubmit('form', _('Create discovery rule'))); $discoveryWidget->addPageHeader(_('CONFIGURATION OF DISCOVERY RULES'), $createForm); $discoveryWidget->addHeader(_('Discovery rules')); $discoveryWidget->addHeaderRowNumber(); // create form $discoveryForm = new CForm(); $discoveryForm->setName('druleForm'); // create table $discoveryTable = new CTableInfo(_('No discovery rules found.')); $discoveryTable->setHeader(array(new CCheckBox('all_drules', null, "checkAll('" . $discoveryForm->getName() . "', 'all_drules', 'g_druleid');"), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('IP range'), _('Delay'), _('Checks'), _('Status'))); foreach ($data['drules'] as $drule) { array_push($drule['description'], new CLink($drule['name'], '?form=update&druleid=' . $drule['druleid'])); $status = new CCol(new CLink(discovery_status2str($drule['status']), '?g_druleid[]=' . $drule['druleid'] . '&action=' . ($drule['status'] == DRULE_STATUS_ACTIVE ? 'drule.massdisable' : 'drule.massenable'), discovery_status2style($drule['status']))); $discoveryTable->addRow(array(new CCheckBox('g_druleid[' . $drule['druleid'] . ']', null, null, $drule['druleid']), $drule['description'], $drule['iprange'], $drule['delay'], !empty($drule['checks']) ? implode(', ', $drule['checks']) : '', $status)); } // create go buttons $goComboBox = new CComboBox('action'); $goOption = new CComboItem('drule.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected discovery rules?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('drule.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected discovery rules?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('drule.massdelete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected discovery rules?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');
// create new discovery rule button $createForm = new CForm('get'); $createForm->cleanItems(); $createForm->addItem(new CSubmit('form', _('Create discovery rule'))); $discoveryWidget->addPageHeader(_('CONFIGURATION OF DISCOVERY RULE'), $createForm); $discoveryWidget->addHeader(_('Discovery rules')); $discoveryWidget->addHeaderRowNumber(); // create form $discoveryForm = new CForm('get'); $discoveryForm->setName('druleForm'); // create table $discoveryTable = new CTableInfo(_('No discovery rules defined.')); $discoveryTable->setHeader(array(new CCheckBox('all_drules', null, "checkAll('" . $discoveryForm->getName() . "', 'all_drules', 'g_druleid');"), make_sorting_header(_('Name'), 'name'), _('IP range'), _('Delay'), _('Checks'), _('Status'))); foreach ($data['drules'] as $drule) { array_push($drule['description'], new CLink($drule['name'], '?form=update&druleid=' . $drule['druleid'])); $status = new CCol(new CLink(discovery_status2str($drule['status']), '?g_druleid' . SQUAREBRACKETS . '=' . $drule['druleid'] . ($drule['status'] == DRULE_STATUS_ACTIVE ? '&go=disable' : '&go=activate'), discovery_status2style($drule['status']))); $discoveryTable->addRow(array(new CCheckBox('g_druleid[' . $drule['druleid'] . ']', null, null, $drule['druleid']), $drule['description'], $drule['iprange'], $drule['delay'], !empty($drule['checks']) ? implode(', ', $drule['checks']) : '', $status)); } // create go buttons $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected discovery rules?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected discovery rules?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected discovery rules?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');
/* form */ insert_drule_form(); } else { show_table_header(S_DISCOVERY_BIG); /* table */ $form = new CForm(); $form->SetName('frmdrules'); $tblDiscovery = new CTableInfo(S_NO_DISCOVERY_RULES_DEFINED); $tblDiscovery->SetHeader(array(array(new CCheckBox('all_drules', null, "CheckAll('" . $form->GetName() . "','all_drules');"), make_sorting_link(S_NAME, 'd.name')), make_sorting_link(S_IP_RANGE, 'd.iprange'), make_sorting_link(S_DELAY, 'd.delay'), S_CHECKS, S_STATUS)); $db_rules = DBselect('SELECT d.* ' . ' FROM drules d' . ' WHERE ' . DBin_node('druleid') . order_by('d.name,d.iprange,d.delay', 'd.druleid')); while ($rule_data = DBfetch($db_rules)) { $cheks = array(); $db_checks = DBselect("select * from dchecks where druleid=" . $rule_data["druleid"] . " order by type,druleid"); while ($check_data = DBfetch($db_checks)) { $cheks[] = discovery_check_type2str($check_data['type']); } $status = new CCol(new CLink(discovery_status2str($rule_data["status"]), '?g_druleid%5B%5D=' . $rule_data['druleid'] . ($rule_data["status"] == DRULE_STATUS_ACTIVE ? '&group_disable=1' : '&group_enable=1'), discovery_status2style($rule_data["status"]))); $description = array(); if ($rule_data["proxy_hostid"]) { $proxy = get_host_by_hostid($rule_data["proxy_hostid"]); array_push($description, $proxy["host"], ":"); } array_push($description, new CLink($rule_data['name'], "?form=update&druleid=" . $rule_data['druleid'], 'action')); $drule = new CCol(array(new CCheckBox('g_druleid[' . $rule_data["druleid"] . ']', null, null, $rule_data["druleid"]), SPACE, $description)); $tblDiscovery->AddRow(array($drule, $rule_data['iprange'], $rule_data['delay'], implode(',', $cheks), $status)); } $tblDiscovery->SetFooter(new CCol(array(new CButtonQMessage('group_enable', S_ENABLE_SELECTED, S_ENABLE_SELECTED_RULES_Q), SPACE, new CButtonQMessage('group_disable', S_DISABLE_SELECTED, S_DISABLE_SELECTED_RULES_Q), SPACE, new CButtonQMessage('group_delete', S_DELETE_SELECTED, S_DELETE_SELECTED_RULES_Q)))); $form->AddItem($tblDiscovery); $form->Show(); } include_once "include/page_footer.php";
while ($rule_data = DBfetch($db_rules)) { $rules_arr[] = $rule_data; } // getting paging element $paging = getPagingLine($rules_arr); foreach ($rules_arr as $rule_data) { $checks = array(); $sql = 'SELECT type FROM dchecks WHERE druleid=' . $rule_data['druleid'] . ' ORDER BY type, ports'; $db_checks = DBselect($sql); while ($check_data = DBfetch($db_checks)) { if (!isset($checks[$check_data['type']])) { $checks[$check_data['type']] = discovery_check_type2str($check_data['type']); } } order_result($checks); $status = new CCol(new CLink(discovery_status2str($rule_data["status"]), '?g_druleid%5B%5D=' . $rule_data['druleid'] . ($rule_data["status"] == DRULE_STATUS_ACTIVE ? '&go=disable' : '&go=activate'), discovery_status2style($rule_data['status']))); $description = array(); if ($rule_data["proxy_hostid"]) { $proxy = get_host_by_hostid($rule_data["proxy_hostid"]); array_push($description, $proxy["host"], ":"); } array_push($description, new CLink($rule_data['name'], "?form=update&druleid=" . $rule_data['druleid'])); $tblDiscovery->addRow(array(new CCheckBox('g_druleid[' . $rule_data["druleid"] . ']', null, null, $rule_data["druleid"]), $description, $rule_data['iprange'], $rule_data['delay'], implode(', ', $checks), $status)); } // pagination at the top and the bottom of the page $tblDiscovery->addRow(new CCol($paging)); $dscry_wdgt->addItem($paging); // gobox $goBox = new CComboBox('go'); $goOption = new CComboItem('activate', S_ENABLE_SELECTED); $goOption->setAttribute('confirm', S_ENABLE_SELECTED_DISCOVERY_RULES);
** Copyright (C) 2001-2016 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. **/ $widget = (new CWidget())->setTitle(_('Discovery rules'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem(new CSubmit('form', _('Create discovery rule'))))); // create form $discoveryForm = (new CForm())->setName('druleForm'); // create table $discoveryTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_drules'))->onClick("checkAll('" . $discoveryForm->getName() . "', 'all_drules', 'g_druleid');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('IP range'), _('Delay'), _('Checks'), _('Status')]); foreach ($data['drules'] as $drule) { array_push($drule['description'], new CLink($drule['name'], '?form=update&druleid=' . $drule['druleid'])); $status = new CCol((new CLink(discovery_status2str($drule['status']), '?g_druleid[]=' . $drule['druleid'] . '&action=' . ($drule['status'] == DRULE_STATUS_ACTIVE ? 'drule.massdisable' : 'drule.massenable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(discovery_status2style($drule['status']))->addSID()); $discoveryTable->addRow([new CCheckBox('g_druleid[' . $drule['druleid'] . ']', $drule['druleid']), $drule['description'], $drule['iprange'], convertUnitsS($drule['delay']), !empty($drule['checks']) ? implode(', ', $drule['checks']) : '', $status]); } // append table to form $discoveryForm->addItem([$discoveryTable, $this->data['paging'], new CActionButtonList('action', 'g_druleid', ['drule.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected discovery rules?')], 'drule.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected discovery rules?')], 'drule.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected discovery rules?')]])]); // append form to widget $widget->addItem($discoveryForm); return $widget;