Exemplo n.º 1
0
                }
            }
        }
    } else {
        $data['drule']['proxy_hostid'] = get_request('proxy_hostid', 0);
        $data['drule']['name'] = get_request('name', '');
        $data['drule']['iprange'] = get_request('iprange', '192.168.0.1-255');
        $data['drule']['delay'] = get_request('delay', SEC_PER_HOUR);
        $data['drule']['status'] = get_request('status', DRULE_STATUS_ACTIVE);
        $data['drule']['dchecks'] = get_request('dchecks', array());
        $data['drule']['nextcheck'] = get_request('nextcheck', 0);
        $data['drule']['uniqueness_criteria'] = get_request('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 {
    $data = array();
    // get drules
    $data['drules'] = API::DRule()->get(array('output' => API_OUTPUT_EXTEND, 'sortfield' => getPageSortField('name'), 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true));
    if (!empty($data['drules'])) {
Exemplo n.º 2
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $groups = API::HostGroup()->get(array('groupids' => $value, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($groups) {
                $group = reset($groups);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $group['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER:
            $trigs = API::Trigger()->get(array('triggerids' => $value, 'expandDescription' => true, 'output' => array('description'), 'selectHosts' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($trigs) {
                $trig = reset($trigs);
                $host = reset($trig['hosts']);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'] . NAME_DELIMITER . $trig['description'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_TEMPLATE:
            if ($host = get_host_by_hostid($value)) {
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
        case CONDITION_TYPE_HOST_METADATA:
        case CONDITION_TYPE_HOST_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = getSeverityCaption($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = _('maintenance');
            break;
        case CONDITION_TYPE_NODE:
            if ($node = get_node_by_nodeid($value)) {
                $str_val = $node['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DRULE:
            if ($drule = get_discovery_rule_by_druleid($value)) {
                $str_val = $drule['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DCHECK:
            $row = DBfetch(DBselect('SELECT dr.name,c.dcheckid,c.type,c.key_,c.ports' . ' FROM drules dr,dchecks c' . ' WHERE dr.druleid=c.druleid' . ' AND c.dcheckid=' . zbx_dbstr($value)));
            if ($row) {
                $str_val = $row['name'] . NAME_DELIMITER . discovery_check2str($row['type'], $row['key_'], $row['ports']);
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DOBJECT:
            $str_val = discovery_object2str($value);
            break;
        case CONDITION_TYPE_PROXY:
            if ($host = get_host_by_hostid($value)) {
                $str_val = $host['host'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? _('Ack') : _('Not Ack');
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_TYPE:
            $str_val = eventType($value);
            break;
        default:
            return _('Unknown');
    }
    return $str_val;
}
Exemplo n.º 3
0
/**
 * Converts numerical action condition values to their corresponding string values according to action condition type.
 *
 * For action condition types such as: hosts, host groups, templates, proxies, triggers, discovery rules
 * and discovery checks, action condition values contain IDs. All unique IDs are first collected and then queried.
 * For other action condition types values are returned as they are or converted using simple string convertion
 * functions according to action condition type.
 *
 * @param array $actions							array of actions
 * @param array $action['filter']					array containing arrays of action conditions and other data
 * @param array $action['filter']['conditions']		array of action conditions
 * @param array $config								array containing configuration parameters for getting trigger
 *													severity names
 *
 * @return array									returns an array of actions condition string values
 */
function actionConditionValueToString(array $actions, array $config)
{
    $result = [];
    $groupIds = [];
    $triggerIds = [];
    $hostIds = [];
    $templateIds = [];
    $proxyIds = [];
    $dRuleIds = [];
    $dCheckIds = [];
    foreach ($actions as $i => $action) {
        $result[$i] = [];
        foreach ($action['filter']['conditions'] as $j => $condition) {
            // unknown types and all of the default values for other types are 'Unknown'
            $result[$i][$j] = _('Unknown');
            switch ($condition['conditiontype']) {
                case CONDITION_TYPE_HOST_GROUP:
                    $groupIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TRIGGER:
                    $triggerIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_HOST:
                    $hostIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TEMPLATE:
                    $templateIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_PROXY:
                    $proxyIds[$condition['value']] = $condition['value'];
                    break;
                    // return values as is for following condition types
                // return values as is for following condition types
                case CONDITION_TYPE_TRIGGER_NAME:
                case CONDITION_TYPE_HOST_METADATA:
                case CONDITION_TYPE_HOST_NAME:
                case CONDITION_TYPE_TIME_PERIOD:
                case CONDITION_TYPE_DHOST_IP:
                case CONDITION_TYPE_DSERVICE_PORT:
                case CONDITION_TYPE_DUPTIME:
                case CONDITION_TYPE_DVALUE:
                case CONDITION_TYPE_APPLICATION:
                    $result[$i][$j] = $condition['value'];
                    break;
                case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
                    $result[$i][$j] = $condition['value'] ? _('Ack') : _('Not Ack');
                    break;
                case CONDITION_TYPE_MAINTENANCE:
                    $result[$i][$j] = _('maintenance');
                    break;
                case CONDITION_TYPE_TRIGGER_VALUE:
                    $result[$i][$j] = trigger_value2str($condition['value']);
                    break;
                case CONDITION_TYPE_TRIGGER_SEVERITY:
                    $result[$i][$j] = getSeverityName($condition['value'], $config);
                    break;
                case CONDITION_TYPE_DRULE:
                    $dRuleIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DCHECK:
                    $dCheckIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DOBJECT:
                    $result[$i][$j] = discovery_object2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSERVICE_TYPE:
                    $result[$i][$j] = discovery_check_type2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSTATUS:
                    $result[$i][$j] = discovery_object_status2str($condition['value']);
                    break;
                case CONDITION_TYPE_EVENT_TYPE:
                    $result[$i][$j] = eventType($condition['value']);
                    break;
            }
        }
    }
    $groups = [];
    $triggers = [];
    $hosts = [];
    $templates = [];
    $proxies = [];
    $dRules = [];
    $dChecks = [];
    if ($groupIds) {
        $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupIds, 'preservekeys' => true]);
    }
    if ($triggerIds) {
        $triggers = API::Trigger()->get(['output' => ['description'], 'triggerids' => $triggerIds, 'expandDescription' => true, 'selectHosts' => ['name'], 'preservekeys' => true]);
    }
    if ($hostIds) {
        $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]);
    }
    if ($templateIds) {
        $templates = API::Template()->get(['output' => ['name'], 'templateids' => $templateIds, 'preservekeys' => true]);
    }
    if ($proxyIds) {
        $proxies = API::Proxy()->get(['output' => ['host'], 'proxyids' => $proxyIds, 'preservekeys' => true]);
    }
    if ($dRuleIds) {
        $dRules = API::DRule()->get(['output' => ['name'], 'druleids' => $dRuleIds, 'preservekeys' => true]);
    }
    if ($dCheckIds) {
        $dChecks = API::DCheck()->get(['output' => ['type', 'key_', 'ports'], 'dcheckids' => $dCheckIds, 'selectDRules' => ['name'], 'preservekeys' => true]);
    }
    if ($groups || $triggers || $hosts || $templates || $proxies || $dRules || $dChecks) {
        foreach ($actions as $i => $action) {
            foreach ($action['filter']['conditions'] as $j => $condition) {
                $id = $condition['value'];
                switch ($condition['conditiontype']) {
                    case CONDITION_TYPE_HOST_GROUP:
                        if (isset($groups[$id])) {
                            $result[$i][$j] = $groups[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TRIGGER:
                        if (isset($triggers[$id])) {
                            $host = reset($triggers[$id]['hosts']);
                            $result[$i][$j] = $host['name'] . NAME_DELIMITER . $triggers[$id]['description'];
                        }
                        break;
                    case CONDITION_TYPE_HOST:
                        if (isset($hosts[$id])) {
                            $result[$i][$j] = $hosts[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TEMPLATE:
                        if (isset($templates[$id])) {
                            $result[$i][$j] = $templates[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_PROXY:
                        if (isset($proxies[$id])) {
                            $result[$i][$j] = $proxies[$id]['host'];
                        }
                        break;
                    case CONDITION_TYPE_DRULE:
                        if (isset($dRules[$id])) {
                            $result[$i][$j] = $dRules[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_DCHECK:
                        if (isset($dChecks[$id])) {
                            $drule = reset($dChecks[$id]['drules']);
                            $type = $dChecks[$id]['type'];
                            $key_ = $dChecks[$id]['key_'];
                            $ports = $dChecks[$id]['ports'];
                            $dCheck = discovery_check2str($type, $key_, $ports);
                            $result[$i][$j] = $drule['name'] . NAME_DELIMITER . $dCheck;
                        }
                        break;
                }
            }
        }
    }
    return $result;
}
Exemplo n.º 4
0
 $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_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ') ' . ' 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 . SPACE . S_SECOND_IN_PARENTHESES, new CNumericBox('delay', $delay, 8));
 $form->addVar('dchecks', $dchecks);
 $form->addVar('dchecks_deleted', $dchecks_deleted);
 $cmbUniquenessCriteria = new CComboBox('uniqueness_criteria', $uniqueness_criteria);
 $cmbUniquenessCriteria->addItem(-1, S_IP_ADDRESS);
 foreach ($dchecks as $id => $data) {
     $dchecks[$id]['name'] = discovery_check2str($data['type'], $data['snmp_community'], $data['key'], $data['ports']);
 }
 order_result($dchecks, 'name');
 foreach ($dchecks as $id => $data) {
     $label = new CLabel($data['name'], 'selected_checks[' . $id . ']');
     $dchecks[$id] = array(new CCheckBox('selected_checks[' . $id . ']', null, null, $id), $label, BR());
     if (in_array($data['type'], array(SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_SNMPv3))) {
         $cmbUniquenessCriteria->addItem($id, $data['name']);
     }
 }
 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()");
 $cmbChkType->addItems(discovery_check_type2str());
Exemplo n.º 5
0
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT d.*' . ' FROM drules d' . whereDbNode('d.druleid', $nodeId));
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'dchecks') {
    $table = new CTableInfo(_('No discovery rules found.'));
    $table->setHeader(_('Name'));
    $dRules = API::DRule()->get(array('selectDChecks' => array('dcheckid', 'type', 'key_', 'ports'), 'output' => array('name'), 'nodeids' => $nodeId));
    foreach ($dRules as $dRule) {
        foreach ($dRule['dchecks'] as $dCheck) {
            $name = $dRule['name'] . NAME_DELIMITER . discovery_check2str($dCheck['type'], $dCheck['key_'], $dCheck['ports']);
            $action = get_window_opener($dstfrm, $dstfld1, $dCheck[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $name) : '');
            $name = new CSpan($name, 'link');
            $name->setAttribute('onclick', $action . ' close_window(); return false;');
            $table->addRow($name);
        }
    }
    $table->show();
} elseif ($srctbl == 'proxies') {
    $table = new CTableInfo(_('No proxies found.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . andDbNode('h.hostid', $nodeId) . ' ORDER BY h.host,h.hostid');
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['host'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
Exemplo n.º 6
0
         if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') {
             $action = get_window_opener($dstfrm, $dstfld1, $srcfld2) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) . "window.opener.setTimeout('add2favorites();', 1000);";
         } else {
             $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
         }
         $name->SetAction($action . " close_window(); return false;");
         $table->addRow($name);
     }
     $table->Show();
 } else {
     if ($srctbl == "dchecks") {
         $table = new CTableInfo(S_NO_DISCOVERY_RULES_DEFINED);
         $table->SetHeader(S_NAME);
         $result = DBselect('SELECT DISTINCT r.name,c.dcheckid,c.type,c.key_,c.snmp_community,c.ports FROM drules r,dchecks c' . ' WHERE r.druleid=c.druleid and ' . DBin_node('r.druleid', $nodeid));
         while ($row = DBfetch($result)) {
             $row['name'] = $row['name'] . ':' . discovery_check2str($row['type'], $row['snmp_community'], $row['key_'], $row['ports']);
             $name = new CLink($row["name"], "#", "action");
             if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') {
                 $action = get_window_opener($dstfrm, $dstfld1, $srcfld2) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) . "window.opener.setTimeout('add2favorites();', 1000);";
             } else {
                 $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
             }
             $name->SetAction($action . " close_window(); return false;");
             $table->addRow($name);
         }
         $table->Show();
     } else {
         if ($srctbl == "proxies") {
             $table = new CTableInfo(S_NO_DISCOVERY_RULES_DEFINED);
             $table->SetHeader(S_NAME);
             $result = DBselect('SELECT DISTINCT hostid,host ' . ' FROM hosts' . ' WHERE ' . DBin_node('hostid', $nodeid) . ' AND status=' . HOST_STATUS_PROXY . ' ORDER BY host,hostid');
Exemplo n.º 7
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $group = get_hostgroup_by_groupid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $group['name'];
            break;
        case CONDITION_TYPE_TRIGGER:
            $trig = CTrigger::get(array('triggerids' => $value, 'expandTriggerDescriptions' => true, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true)));
            $trig = reset($trig);
            $host = reset($trig['hosts']);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $host['host'] . ':' . $trig['description'];
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_HOST_TEMPLATE:
            $host = get_host_by_hostid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $host['host'];
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
        case CONDITION_TYPE_HOST_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = get_severity_description($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = S_MAINTENANCE_SMALL;
            break;
        case CONDITION_TYPE_NODE:
            $node = get_node_by_nodeid($value);
            $str_val = $node['name'];
            break;
        case CONDITION_TYPE_DRULE:
            $drule = get_discovery_rule_by_druleid($value);
            $str_val = $drule['name'];
            break;
        case CONDITION_TYPE_DCHECK:
            $row = DBfetch(DBselect('SELECT DISTINCT r.name,c.dcheckid,c.type,c.key_,c.snmp_community,c.ports' . ' FROM drules r,dchecks c WHERE r.druleid=c.druleid AND c.dcheckid=' . $value));
            $str_val = $row['name'] . ':' . discovery_check2str($row['type'], $row['snmp_community'], $row['key_'], $row['ports']);
            break;
        case CONDITION_TYPE_DOBJECT:
            $str_val = discovery_object2str($value);
            break;
        case CONDITION_TYPE_PROXY:
            $host = get_host_by_hostid($value);
            $str_val = $host['host'];
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? S_ACK : S_NOT_ACK;
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        default:
            return S_UNKNOWN;
            break;
    }
    return '"' . $str_val . '"';
}
Exemplo n.º 8
0
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT d.* FROM drules d WHERE ' . DBin_node('d.druleid', $nodeid));
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'dchecks') {
    $table = new CTableInfo(_('No discovery checks defined.'));
    $table->setHeader(_('Name'));
    $dRules = API::DRule()->get(array('selectDChecks' => array('dcheckid', 'type', 'key_', 'ports'), 'output' => API_OUTPUT_EXTEND));
    foreach ($dRules as $dRule) {
        foreach ($dRule['dchecks'] as $dCheck) {
            $name = $dRule['name'] . ':' . discovery_check2str($dCheck['type'], $dCheck['key_'], $dCheck['ports']);
            $action = get_window_opener($dstfrm, $dstfld1, $dCheck[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $name) : '');
            $name = new CSpan($name, 'link');
            $name->setAttribute('onclick', $action . ' close_window(); return false;');
            $table->addRow($name);
        }
    }
    $table->show();
} elseif ($srctbl == 'proxies') {
    $table = new CTableInfo(_('No proxies defined.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT h.hostid,h.host' . ' FROM hosts h' . ' WHERE ' . DBin_node('h.hostid', $nodeid) . ' AND h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . ' ORDER BY h.host,h.hostid');
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['host'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
Exemplo n.º 9
0
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 dcheckid,type,ports,key_,snmp_community,snmpv3_securityname,' . 'snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase' . ' FROM dchecks' . ' WHERE druleid=' . $_REQUEST['druleid']);
        while ($check_data = DBfetch($db_checks)) {
            $dchecks[] = array('dcheckid' => $check_data['dcheckid'], 'type' => $check_data['type'], 'ports' => $check_data['ports'], 'key' => $check_data['key_'], 'snmp_community' => $check_data['snmp_community'], 'snmpv3_securityname' => $check_data['snmpv3_securityname'], 'snmpv3_securitylevel' => $check_data['snmpv3_securitylevel'], 'snmpv3_authpassphrase' => $check_data['snmpv3_authpassphrase'], 'snmpv3_privpassphrase' => $check_data['snmpv3_privpassphrase']);
        }
        $dchecks_deleted = get_request('dchecks_deleted', array());
    } 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());
        $dchecks_deleted = get_request('dchecks_deleted', 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', '');
    $new_check_snmpv3_securitylevel = get_request('new_check_snmpv3_securitylevel', ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV);
    $new_check_snmpv3_securityname = get_request('new_check_snmpv3_securityname', '');
    $new_check_snmpv3_authpassphrase = get_request('new_check_snmpv3_authpassphrase', '');
    $new_check_snmpv3_privpassphrase = get_request('new_check_snmpv3_privpassphrase', '');
    $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);
    $form->addVar('dchecks_deleted', $dchecks_deleted);
    foreach ($dchecks as $id => $data) {
        $dchecks[$id] = array(new CCheckBox('selected_checks[]', null, null, $id), discovery_check2str($data['type'], $data['snmp_community'], $data['key'], $data['ports']), 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_SNMPv3, 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, SPACE, new CTextBox('new_check_key', $new_check_key), BR()));
            $form->addVar('new_check_snmpv3_securitylevel', ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV);
            $form->addVar('new_check_snmpv3_securityname', '');
            $form->addVar('new_check_snmpv3_authpassphrase', '');
            $form->addVar('new_check_snmpv3_privpassphrase', '');
            break;
        case SVC_SNMPv3:
            $form->addVar('new_check_snmp_community', '');
            $external_param = array_merge($external_param, array(BR(), S_SNMP_OID, SPACE, new CTextBox('new_check_key', $new_check_key)));
            $external_param = array_merge($external_param, array(BR(), S_SNMPV3_SECURITY_NAME, SPACE, new CTextBox('new_check_snmpv3_securityname', $new_check_snmpv3_securityname)));
            $cmbSecLevel = new CComboBox('new_check_snmpv3_securitylevel', $new_check_snmpv3_securitylevel);
            $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, 'NoAuthPriv');
            $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'AuthNoPriv');
            $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'AuthPriv');
            $external_param = array_merge($external_param, array(BR(), S_SNMPV3_SECURITY_LEVEL, SPACE, $cmbSecLevel));
            $external_param = array_merge($external_param, array(BR(), S_SNMPV3_AUTH_PASSPHRASE, SPACE, new CTextBox('new_check_snmpv3_authpassphrase', $new_check_snmpv3_authpassphrase)));
            $external_param = array_merge($external_param, array(BR(), S_SNMPV3_PRIV_PASSPHRASE, SPACE, new CTextBox('new_check_snmpv3_privpassphrase', $new_check_snmpv3_privpassphrase), BR()));
            break;
        case SVC_AGENT:
            $form->addVar('new_check_snmp_community', '');
            $form->addVar('new_check_snmpv3_securitylevel', ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV);
            $form->addVar('new_check_snmpv3_securityname', '');
            $form->addVar('new_check_snmpv3_authpassphrase', '');
            $form->addVar('new_check_snmpv3_privpassphrase', '');
            $external_param = array_merge($external_param, array(BR(), S_KEY, SPACE, 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', '');
            $form->addVar('new_check_snmpv3_securitylevel', ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV);
            $form->addVar('new_check_snmpv3_securityname', '');
            $form->addVar('new_check_snmpv3_authpassphrase', '');
            $form->addVar('new_check_snmpv3_privpassphrase', '');
    }
    $ports_box = $new_check_type == SVC_ICMPPING ? NULL : array(S_PORTS_SMALL, SPACE, new CTextBox('new_check_ports', $new_check_ports, 20));
    $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();
}