// 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');
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);
/* 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";
function insert_drule_form() { $frm_title = S_DISCOVERY_RULE; if (isset($_REQUEST['druleid'])) { if ($rule_data = DBfetch(DBselect('SELECT * FROM drules WHERE druleid=' . $_REQUEST['druleid']))) { $frm_title = S_DISCOVERY_RULE . ' "' . $rule_data['name'] . '"'; } } $form = new CFormTable($frm_title, null, 'post'); $form->SetHelp("web.discovery.rule.php"); if (isset($_REQUEST['druleid'])) { $form->addVar('druleid', $_REQUEST['druleid']); } if (isset($_REQUEST['druleid']) && $rule_data && (!isset($_REQUEST["form_refresh"]) || isset($_REQUEST["register"]))) { $proxy_hostid = $rule_data['proxy_hostid']; $name = $rule_data['name']; $iprange = $rule_data['iprange']; $delay = $rule_data['delay']; $status = $rule_data['status']; //TODO init checks $dchecks = array(); $db_checks = DBselect('SELECT type,ports,key_,snmp_community FROM dchecks WHERE druleid=' . $_REQUEST['druleid']); while ($check_data = DBfetch($db_checks)) { $dchecks[] = array('type' => $check_data['type'], 'ports' => $check_data['ports'], 'key' => $check_data['key_'], 'snmp_community' => $check_data['snmp_community']); } } else { $proxy_hostid = get_request("proxy_hostid", 0); $name = get_request('name', ''); $iprange = get_request('iprange', '192.168.0.1-255'); $delay = get_request('delay', 3600); $status = get_request('status', DRULE_STATUS_ACTIVE); $dchecks = get_request('dchecks', array()); } $new_check_type = get_request('new_check_type', SVC_HTTP); $new_check_ports = get_request('new_check_ports', '80'); $new_check_key = get_request('new_check_key', ''); $new_check_snmp_community = get_request('new_check_snmp_community', ''); $form->addRow(S_NAME, new CTextBox('name', $name, 40)); //Proxy $cmbProxy = new CComboBox("proxy_hostid", $proxy_hostid); $cmbProxy->addItem(0, S_NO_PROXY); $sql = 'SELECT hostid,host ' . ' FROM hosts' . ' WHERE status IN (' . HOST_STATUS_PROXY . ') ' . ' AND ' . DBin_node('hostid') . ' ORDER BY host'; $db_proxies = DBselect($sql); while ($db_proxy = DBfetch($db_proxies)) { $cmbProxy->addItem($db_proxy['hostid'], $db_proxy['host']); } $form->addRow(S_DISCOVERY_BY_PROXY, $cmbProxy); //---------- $form->addRow(S_IP_RANGE, new CTextBox('iprange', $iprange, 27)); $form->addRow(S_DELAY . ' (seconds)', new CNumericBox('delay', $delay, 8)); $form->addVar('dchecks', $dchecks); foreach ($dchecks as $id => $data) { switch ($data['type']) { case SVC_SNMPv1: case SVC_SNMPv2: $external_param = ' "' . $data['snmp_community'] . '":"' . $data['key'] . '"'; break; case SVC_AGENT: $external_param = ' "' . $data['key'] . '"'; break; default: $external_param = null; } $port_def = svc_default_port($data['type']); $dchecks[$id] = array(new CCheckBox('selected_checks[]', null, null, $id), discovery_check_type2str($data['type']), ($port_def == $data['ports'] ? '' : SPACE . '(' . $data['ports'] . ')') . $external_param, BR()); } if (count($dchecks)) { $dchecks[] = new CButton('delete_ckecks', S_DELETE_SELECTED); $form->addRow(S_CHECKS, $dchecks); } $cmbChkType = new CComboBox('new_check_type', $new_check_type, "if(add_variable(this, 'type_changed', 1)) submit()"); foreach (array(SVC_SSH, SVC_LDAP, SVC_SMTP, SVC_FTP, SVC_HTTP, SVC_POP, SVC_NNTP, SVC_IMAP, SVC_TCP, SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_ICMPPING) as $type_int) { $cmbChkType->addItem($type_int, discovery_check_type2str($type_int)); } if (isset($_REQUEST['type_changed'])) { $new_check_ports = svc_default_port($new_check_type); } $external_param = array(); switch ($new_check_type) { case SVC_SNMPv1: case SVC_SNMPv2: $external_param = array_merge($external_param, array(BR(), S_SNMP_COMMUNITY, SPACE, new CTextBox('new_check_snmp_community', $new_check_snmp_community))); $external_param = array_merge($external_param, array(BR(), S_SNMP_OID, new CTextBox('new_check_key', $new_check_key), BR())); break; case SVC_AGENT: $form->addVar('new_check_snmp_community', ''); $external_param = array_merge($external_param, array(BR(), S_KEY, new CTextBox('new_check_key', $new_check_key), BR())); break; case SVC_ICMPPING: $form->addVar('new_check_ports', '0'); default: $form->addVar('new_check_snmp_community', ''); $form->addVar('new_check_key', ''); } $ports_box = $new_check_type == SVC_ICMPPING ? NULL : array(S_PORTS_SMALL, SPACE, new CNumericBox('new_check_ports', $new_check_ports, 5)); $form->addRow(S_NEW_CHECK, array($cmbChkType, SPACE, $ports_box, $external_param, new CButton('add_check', S_ADD)), 'new'); $cmbStatus = new CComboBox("status", $status); foreach (array(DRULE_STATUS_ACTIVE, DRULE_STATUS_DISABLED) as $st) { $cmbStatus->addItem($st, discovery_status2str($st)); } $form->addRow(S_STATUS, $cmbStatus); $form->addItemToBottomRow(new CButton("save", S_SAVE)); if (isset($_REQUEST["druleid"])) { $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButton("clone", S_CLONE)); $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonDelete(S_DELETE_RULE_Q, url_param("form") . url_param("druleid"))); } $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonCancel()); $form->Show(); }
** 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;