/** * Get data for item edit page. * * @param array $item item, item prototype or LLD rule to take the data from * @param bool $options['is_discovery_rule'] * * @return array */ function getItemFormData(array $item = array(), array $options = array()) { $data = array('form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'is_discovery_rule' => !empty($options['is_discovery_rule']), 'parent_discoveryid' => getRequest('parent_discoveryid', !empty($options['is_discovery_rule']) ? getRequest('itemid') : null), 'itemid' => getRequest('itemid'), 'limited' => false, 'interfaceid' => getRequest('interfaceid', 0), 'name' => getRequest('name', ''), 'description' => getRequest('description', ''), 'key' => getRequest('key', ''), 'hostname' => getRequest('hostname'), 'delay' => getRequest('delay', ZBX_ITEM_DELAY_DEFAULT), 'history' => getRequest('history', 90), 'status' => getRequest('status', isset($_REQUEST['form_refresh']) ? 1 : 0), 'type' => getRequest('type', 0), 'snmp_community' => getRequest('snmp_community', 'public'), 'snmp_oid' => getRequest('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'), 'port' => getRequest('port', ''), 'value_type' => getRequest('value_type', ITEM_VALUE_TYPE_UINT64), 'data_type' => getRequest('data_type', ITEM_DATA_TYPE_DECIMAL), 'trapper_hosts' => getRequest('trapper_hosts', ''), 'units' => getRequest('units', ''), 'valuemapid' => getRequest('valuemapid', 0), 'params' => getRequest('params', ''), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta', 0), 'trends' => getRequest('trends', DAY_IN_YEAR), 'new_application' => getRequest('new_application', ''), 'applications' => getRequest('applications', array()), 'delay_flex' => getRequest('delay_flex', array()), 'new_delay_flex' => getRequest('new_delay_flex', array('delay' => 50, 'period' => ZBX_DEFAULT_INTERVAL)), 'snmpv3_contextname' => getRequest('snmpv3_contextname', ''), 'snmpv3_securityname' => getRequest('snmpv3_securityname', ''), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel', 0), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol', ITEM_AUTHPROTOCOL_MD5), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase', ''), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol', ITEM_PRIVPROTOCOL_DES), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase', ''), 'ipmi_sensor' => getRequest('ipmi_sensor', ''), 'authtype' => getRequest('authtype', 0), 'username' => getRequest('username', ''), 'password' => getRequest('password', ''), 'publickey' => getRequest('publickey', ''), 'privatekey' => getRequest('privatekey', ''), 'formula' => getRequest('formula', 1), 'logtimefmt' => getRequest('logtimefmt', ''), 'add_groupid' => getRequest('add_groupid', getRequest('groupid', 0)), 'valuemaps' => null, 'possibleHostInventories' => null, 'alreadyPopulated' => null, 'initial_item_type' => null, 'templates' => array()); // hostid if (!empty($data['parent_discoveryid'])) { $discoveryRule = API::DiscoveryRule()->get(array('itemids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true)); $discoveryRule = reset($discoveryRule); $data['hostid'] = $discoveryRule['hostid']; } else { $data['hostid'] = getRequest('hostid', 0); } // types, http items only for internal processes $data['types'] = item_type2str(); unset($data['types'][ITEM_TYPE_HTTPTEST]); if (!empty($options['is_discovery_rule'])) { unset($data['types'][ITEM_TYPE_AGGREGATE], $data['types'][ITEM_TYPE_CALCULATED], $data['types'][ITEM_TYPE_SNMPTRAP]); } // item if ($item) { $data['item'] = $item; $data['hostid'] = !empty($data['hostid']) ? $data['hostid'] : $data['item']['hostid']; $data['limited'] = $data['item']['templateid'] != 0; // get templates $itemid = $item['itemid']; do { $params = array('itemids' => $itemid, 'output' => array('itemid', 'templateid'), 'selectHosts' => array('name')); if ($data['is_discovery_rule']) { $item = API::DiscoveryRule()->get($params); } else { $params['selectDiscoveryRule'] = array('itemid'); $params['filter'] = array('flags' => null); $item = API::Item()->get($params); } $item = reset($item); if (!empty($item)) { $host = reset($item['hosts']); if (!empty($item['hosts'])) { $host['name'] = CHtml::encode($host['name']); if (bccomp($data['itemid'], $itemid) == 0) { } elseif ($data['is_discovery_rule']) { $data['templates'][] = new CLink($host['name'], 'host_discovery.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } elseif ($item['discoveryRule']) { $data['templates'][] = new CLink($host['name'], 'disc_prototypes.php?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $item['discoveryRule']['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } else { $data['templates'][] = new CLink($host['name'], 'items.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } } $itemid = $item['templateid']; } else { break; } } while ($itemid != 0); $data['templates'] = array_reverse($data['templates']); array_shift($data['templates']); } // caption if (!empty($data['is_discovery_rule'])) { $data['caption'] = _('Discovery rule'); } else { $data['caption'] = !empty($data['parent_discoveryid']) ? _('Item prototype') : _('Item'); } // hostname if (empty($data['is_discovery_rule']) && empty($data['hostname'])) { if (!empty($data['hostid'])) { $hostInfo = API::Host()->get(array('hostids' => $data['hostid'], 'output' => array('name'), 'templated_hosts' => true)); $hostInfo = reset($hostInfo); $data['hostname'] = $hostInfo['name']; } else { $data['hostname'] = _('not selected'); } } // fill data from item if (!hasRequest('form_refresh') && ($item || $data['limited'])) { $data['name'] = $data['item']['name']; $data['description'] = $data['item']['description']; $data['key'] = $data['item']['key_']; $data['interfaceid'] = $data['item']['interfaceid']; $data['type'] = $data['item']['type']; $data['snmp_community'] = $data['item']['snmp_community']; $data['snmp_oid'] = $data['item']['snmp_oid']; $data['port'] = $data['item']['port']; $data['value_type'] = $data['item']['value_type']; $data['data_type'] = $data['item']['data_type']; $data['trapper_hosts'] = $data['item']['trapper_hosts']; $data['units'] = $data['item']['units']; $data['valuemapid'] = $data['item']['valuemapid']; $data['multiplier'] = $data['item']['multiplier']; $data['hostid'] = $data['item']['hostid']; $data['params'] = $data['item']['params']; $data['snmpv3_contextname'] = $data['item']['snmpv3_contextname']; $data['snmpv3_securityname'] = $data['item']['snmpv3_securityname']; $data['snmpv3_securitylevel'] = $data['item']['snmpv3_securitylevel']; $data['snmpv3_authprotocol'] = $data['item']['snmpv3_authprotocol']; $data['snmpv3_authpassphrase'] = $data['item']['snmpv3_authpassphrase']; $data['snmpv3_privprotocol'] = $data['item']['snmpv3_privprotocol']; $data['snmpv3_privpassphrase'] = $data['item']['snmpv3_privpassphrase']; $data['ipmi_sensor'] = $data['item']['ipmi_sensor']; $data['authtype'] = $data['item']['authtype']; $data['username'] = $data['item']['username']; $data['password'] = $data['item']['password']; $data['publickey'] = $data['item']['publickey']; $data['privatekey'] = $data['item']['privatekey']; $data['logtimefmt'] = $data['item']['logtimefmt']; $data['new_application'] = getRequest('new_application', ''); if (!$data['is_discovery_rule']) { $data['formula'] = $data['item']['formula']; } if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) { $data['delay'] = $data['item']['delay']; if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) { $data['delay'] = ZBX_ITEM_DELAY_DEFAULT; } $data['history'] = $data['item']['history']; $data['status'] = $data['item']['status']; $data['delta'] = $data['item']['delta']; $data['trends'] = $data['item']['trends']; $db_delay_flex = $data['item']['delay_flex']; if (isset($db_delay_flex)) { $arr_of_dellays = explode(';', $db_delay_flex); foreach ($arr_of_dellays as $one_db_delay) { $arr_of_delay = explode('/', $one_db_delay); if (!isset($arr_of_delay[0]) || !isset($arr_of_delay[1])) { continue; } array_push($data['delay_flex'], array('delay' => $arr_of_delay[0], 'period' => $arr_of_delay[1])); } } $data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid']))); } } // applications if (count($data['applications']) == 0) { array_push($data['applications'], 0); } $data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']))); order_result($data['db_applications'], 'name'); // interfaces $data['interfaces'] = API::HostInterface()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND)); // valuemapid if ($data['limited']) { if (!empty($data['valuemapid'])) { if ($map_data = DBfetch(DBselect('SELECT v.name FROM valuemaps v WHERE v.valuemapid=' . zbx_dbstr($data['valuemapid'])))) { $data['valuemaps'] = $map_data['name']; } } } else { $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.* FROM valuemaps v')); order_result($data['valuemaps'], 'name'); } // possible host inventories if (empty($data['parent_discoveryid'])) { $data['possibleHostInventories'] = getHostInventories(); // get already populated fields by other items $data['alreadyPopulated'] = API::item()->get(array('output' => array('inventory_link'), 'filter' => array('hostid' => $data['hostid']), 'nopermissions' => true)); $data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link'); } // template $data['is_template'] = isTemplate($data['hostid']); // unset snmpv3 fields if ($data['type'] != ITEM_TYPE_SNMPV3) { $data['snmpv3_contextname'] = ''; $data['snmpv3_securityname'] = ''; $data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV; $data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $data['snmpv3_authpassphrase'] = ''; $data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; $data['snmpv3_privpassphrase'] = ''; } // unset ssh auth fields if ($data['type'] != ITEM_TYPE_SSH) { $data['authtype'] = ITEM_AUTHTYPE_PASSWORD; $data['publickey'] = ''; $data['privatekey'] = ''; } return $data; }
} if ($application_prototypes) { foreach ($application_prototypes as &$application_prototype) { $application_prototype = ['name' => $application_prototype]; } unset($application_prototype); } $new_application_prototype = getRequest('new_application_prototype', ''); if ($new_application_prototype !== '') { $application_prototypes[] = ['name' => $new_application_prototype]; } $item = ['name' => getRequest('name'), 'description' => getRequest('description'), 'key_' => getRequest('key'), 'hostid' => $discoveryRule['hostid'], 'interfaceid' => getRequest('interfaceid'), 'delay' => getRequest('delay'), 'status' => getRequest('status', ITEM_STATUS_DISABLED), 'type' => getRequest('type'), 'snmp_community' => getRequest('snmp_community'), 'snmp_oid' => getRequest('snmp_oid'), 'value_type' => getRequest('value_type'), 'trapper_hosts' => getRequest('trapper_hosts'), 'port' => getRequest('port'), 'history' => getRequest('history'), 'trends' => getRequest('trends'), 'units' => getRequest('units'), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta'), 'snmpv3_contextname' => getRequest('snmpv3_contextname'), 'snmpv3_securityname' => getRequest('snmpv3_securityname'), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel'), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol'), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase'), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol'), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase'), 'formula' => getRequest('formula', '1'), 'logtimefmt' => getRequest('logtimefmt'), 'valuemapid' => getRequest('valuemapid'), 'authtype' => getRequest('authtype'), 'username' => getRequest('username'), 'password' => getRequest('password'), 'publickey' => getRequest('publickey'), 'privatekey' => getRequest('privatekey'), 'params' => getRequest('params'), 'ipmi_sensor' => getRequest('ipmi_sensor'), 'data_type' => getRequest('data_type'), 'ruleid' => getRequest('parent_discoveryid'), 'delay_flex' => $delay_flex, 'applications' => $applications, 'applicationPrototypes' => $application_prototypes]; if (hasRequest('update')) { $itemId = getRequest('itemid'); $dbItem = get_item_by_itemid_limited($itemId); $dbItem['applications'] = get_applications_by_itemid($itemId); // unset snmpv3 fields if ($item['snmpv3_securitylevel'] == ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV) { $item['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $item['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; } elseif ($item['snmpv3_securitylevel'] == ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV) { $item['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; } $item = CArrayHelper::unsetEqualValues($item, $dbItem); $item['itemid'] = $itemId; $result = API::Itemprototype()->update($item); } else { $result = API::Itemprototype()->create($item); } } $result = DBend($result);
function insert_item_form() { global $USER_DETAILS; $frmItem = new CFormTable(S_ITEM, 'items.php', 'post'); $frmItem->SetHelp('web.items.item.php'); $frmItem->addVar('config', get_request('config', 0)); if ($_REQUEST['groupid'] > 0) { $frmItem->addVar('groupid', $_REQUEST['groupid']); } $frmItem->addVar('hostid', $_REQUEST['hostid']); $frmItem->addVar('applications_visible', 1); $description = get_request('description', ''); $key = get_request('key', ''); $host = get_request('host', null); $delay = get_request('delay', 30); $history = get_request('history', 90); $status = get_request('status', 0); $type = get_request('type', 0); $snmp_community = get_request('snmp_community', 'public'); $snmp_oid = get_request('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'); $snmp_port = get_request('snmp_port', 161); $value_type = get_request('value_type', ITEM_VALUE_TYPE_UINT64); $data_type = get_request('data_type', ITEM_DATA_TYPE_DECIMAL); $trapper_hosts = get_request('trapper_hosts', ''); $units = get_request('units', ''); $valuemapid = get_request('valuemapid', 0); $params = get_request('params', 'DSN=<database source name>\\n' . 'user=<user name>\\n' . 'password=<password>\\n' . 'sql=<query>'); $multiplier = get_request('multiplier', 0); $delta = get_request('delta', 0); $trends = get_request('trends', 365); $new_application = get_request('new_application', ''); $applications = get_request('applications', array()); $delay_flex = get_request('delay_flex', array()); $snmpv3_securityname = get_request('snmpv3_securityname', ''); $snmpv3_securitylevel = get_request('snmpv3_securitylevel', 0); $snmpv3_authpassphrase = get_request('snmpv3_authpassphrase', ''); $snmpv3_privpassphrase = get_request('snmpv3_privpassphrase', ''); $ipmi_sensor = get_request('ipmi_sensor', ''); $formula = get_request('formula', '1'); $logtimefmt = get_request('logtimefmt', ''); $add_groupid = get_request('add_groupid', get_request('groupid', 0)); $limited = null; if ('' == $key && $type == ITEM_TYPE_DB_MONITOR) { $key = 'db.odbc.select[<unique short description>]'; } if (is_null($host)) { $host_info = get_host_by_hostid($_REQUEST['hostid']); $host = $host_info['host']; } if (isset($_REQUEST['itemid'])) { $frmItem->addVar('itemid', $_REQUEST['itemid']); $item_data = DBfetch(DBselect('SELECT i.*, h.host, h.hostid ' . ' FROM items i,hosts h ' . ' WHERE i.itemid=' . $_REQUEST['itemid'] . ' AND h.hostid=i.hostid')); $limited = $item_data['templateid'] == 0 && $item_data['type'] != ITEM_TYPE_HTTPTEST ? null : 'yes'; } if (isset($_REQUEST['itemid']) && !isset($_REQUEST['form_refresh']) || isset($limited)) { $description = $item_data['description']; $key = $item_data['key_']; $host = $item_data['host']; $type = $item_data['type']; $snmp_community = $item_data['snmp_community']; $snmp_oid = $item_data['snmp_oid']; $snmp_port = $item_data['snmp_port']; $value_type = $item_data['value_type']; $data_type = $item_data['data_type']; $trapper_hosts = $item_data['trapper_hosts']; $units = $item_data['units']; $valuemapid = $item_data['valuemapid']; $multiplier = $item_data['multiplier']; $hostid = $item_data['hostid']; $params = $item_data['params']; $snmpv3_securityname = $item_data['snmpv3_securityname']; $snmpv3_securitylevel = $item_data['snmpv3_securitylevel']; $snmpv3_authpassphrase = $item_data['snmpv3_authpassphrase']; $snmpv3_privpassphrase = $item_data['snmpv3_privpassphrase']; $ipmi_sensor = $item_data['ipmi_sensor']; $formula = $item_data['formula']; $logtimefmt = $item_data['logtimefmt']; $new_application = get_request('new_application', ''); if (!isset($limited) || !isset($_REQUEST['form_refresh'])) { $delay = $item_data['delay']; $history = $item_data['history']; $status = $item_data['status']; $delta = $item_data['delta']; $trends = $item_data['trends']; $db_delay_flex = $item_data['delay_flex']; if (isset($db_delay_flex)) { $arr_of_dellays = explode(';', $db_delay_flex); foreach ($arr_of_dellays as $one_db_delay) { $arr_of_delay = explode('/', $one_db_delay); if (!isset($arr_of_delay[0]) || !isset($arr_of_delay[1])) { continue; } array_push($delay_flex, array('delay' => $arr_of_delay[0], 'period' => $arr_of_delay[1])); } } $applications = array_unique(array_merge($applications, get_applications_by_itemid($_REQUEST['itemid']))); } } $delay_flex_el = array(); if ($type != ITEM_TYPE_TRAPPER && $type != ITEM_TYPE_HTTPTEST) { $i = 0; foreach ($delay_flex as $val) { if (!isset($val['delay']) && !isset($val['period'])) { continue; } array_push($delay_flex_el, array(new CCheckBox('rem_delay_flex[]', 'no', null, $i), $val['delay'], ' sec at ', $val['period']), BR()); $frmItem->addVar('delay_flex[' . $i . '][delay]', $val['delay']); $frmItem->addVar('delay_flex[' . $i . '][period]', $val['period']); $i++; if ($i >= 7) { break; } /* limit count of intervals * 7 intervals by 30 symbols = 210 characters * db storage field is 256 */ } } if (count($delay_flex_el) == 0) { array_push($delay_flex_el, S_NO_FLEXIBLE_INTERVALS); } else { array_push($delay_flex_el, new CButton('del_delay_flex', 'delete selected')); } if (count($applications) == 0) { array_push($applications, 0); } if (isset($_REQUEST['itemid'])) { $frmItem->SetTitle(S_ITEM . " '{$host}:" . $item_data["description"] . "'"); } else { $frmItem->SetTitle(S_ITEM . " '{$host}:{$description}'"); } $frmItem->addRow(S_DESCRIPTION, new CTextBox('description', $description, 40, $limited)); if (isset($limited)) { $frmItem->addRow(S_TYPE, new CTextBox('typename', item_type2str($type), 40, 'yes')); $frmItem->addVar('type', $type); } else { $cmbType = new CComboBox('type', $type, 'submit()'); foreach (array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_TRAPPER, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR, ITEM_TYPE_IPMI) as $it) { $cmbType->addItem($it, item_type2str($it)); } $frmItem->addRow(S_TYPE, $cmbType); } if ($type == ITEM_TYPE_SNMPV1 || $type == ITEM_TYPE_SNMPV2C) { $frmItem->addVar('snmpv3_securityname', $snmpv3_securityname); $frmItem->addVar('snmpv3_securitylevel', $snmpv3_securitylevel); $frmItem->addVar('snmpv3_authpassphrase', $snmpv3_authpassphrase); $frmItem->addVar('snmpv3_privpassphrase', $snmpv3_privpassphrase); $frmItem->addRow(S_SNMP_COMMUNITY, new CTextBox('snmp_community', $snmp_community, 16, $limited)); $frmItem->addRow(S_SNMP_OID, new CTextBox('snmp_oid', $snmp_oid, 40, $limited)); $frmItem->addRow(S_SNMP_PORT, new CNumericBox('snmp_port', $snmp_port, 5, $limited)); } else { if ($type == ITEM_TYPE_SNMPV3) { $frmItem->addVar('snmp_community', $snmp_community); $frmItem->addRow(S_SNMP_OID, new CTextBox('snmp_oid', $snmp_oid, 40, $limited)); $frmItem->addRow(S_SNMPV3_SECURITY_NAME, new CTextBox('snmpv3_securityname', $snmpv3_securityname, 64, $limited)); if (isset($limited)) { $frmItem->addVar('snmpv3_securitylevel', $snmpv3_securitylevel); switch ($snmpv3_securitylevel) { case ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV: $snmpv3_securitylevel = 'NoAuthPriv'; break; case ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV: $snmpv3_securitylevel = 'AuthNoPriv'; break; case ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV: $snmpv3_securitylevel = 'AuthPriv'; break; } $frmItem->addRow(S_SNMPV3_SECURITY_LEVEL, new CTextBox('snmpv3_securitylevel_desc', $snmpv3_securitylevel, $limited)); } else { $cmbSecLevel = new CComboBox('snmpv3_securitylevel', $snmpv3_securitylevel); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, 'NoAuthPriv'); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'AuthNoPriv'); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'AuthPriv'); $frmItem->addRow(S_SNMPV3_SECURITY_LEVEL, $cmbSecLevel); } $frmItem->addRow(S_SNMPV3_AUTH_PASSPHRASE, new CTextBox('snmpv3_authpassphrase', $snmpv3_authpassphrase, 64, $limited)); $frmItem->addRow(S_SNMPV3_PRIV_PASSPHRASE, new CTextBox('snmpv3_privpassphrase', $snmpv3_privpassphrase, 64, $limited)); $frmItem->addRow(S_SNMP_PORT, new CNumericBox('snmp_port', $snmp_port, 5, $limited)); } else { $frmItem->addVar('snmp_community', $snmp_community); $frmItem->addVar('snmp_oid', $snmp_oid); $frmItem->addVar('snmp_port', $snmp_port); $frmItem->addVar('snmpv3_securityname', $snmpv3_securityname); $frmItem->addVar('snmpv3_securitylevel', $snmpv3_securitylevel); $frmItem->addVar('snmpv3_authpassphrase', $snmpv3_authpassphrase); $frmItem->addVar('snmpv3_privpassphrase', $snmpv3_privpassphrase); } } if ($type == ITEM_TYPE_IPMI) { $frmItem->addRow(S_IPMI_SENSOR, new CTextBox('ipmi_sensor', $ipmi_sensor, 64, $limited)); } else { $frmItem->addVar('ipmi_sensor', $ipmi_sensor); } if (isset($limited)) { $btnSelect = null; } else { $btnSelect = new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmItem->GetName() . "&dstfld1=key&srctbl=help_items&srcfld1=key_&itemtype=" . $type . "');", 'T'); } $frmItem->addRow(S_KEY, array(new CTextBox('key', $key, 40, $limited), $btnSelect)); if (ITEM_TYPE_DB_MONITOR == $type) { $frmItem->addRow(S_PARAMS, new CTextArea('params', $params, 60, 4)); } else { $frmItem->addVar('params', $params); } if (isset($limited)) { $frmItem->addVar('value_type', $value_type); $cmbValType = new CTextBox('value_type_name', item_value_type2str($value_type), 40, 'yes'); } else { $cmbValType = new CComboBox('value_type', $value_type, 'submit()'); $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UNSIGNED); $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG); $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); } $frmItem->addRow(S_TYPE_OF_INFORMATION, $cmbValType); if ($value_type == ITEM_VALUE_TYPE_UINT64) { if (isset($limited)) { $frmItem->addVar('data_type', $data_type); $cmbDataType = new CTextBox('data_type_name', item_data_type2str($data_type), 20, 'yes'); } else { $cmbDataType = new CComboBox('data_type', $data_type, 'submit()'); $cmbDataType->addItem(ITEM_DATA_TYPE_DECIMAL, item_data_type2str(ITEM_DATA_TYPE_DECIMAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_OCTAL, item_data_type2str(ITEM_DATA_TYPE_OCTAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_HEXADECIMAL, item_data_type2str(ITEM_DATA_TYPE_HEXADECIMAL)); } $frmItem->addRow(S_DATA_TYPE, $cmbDataType); } else { $frmItem->addVar('data_type', $data_type); } if ($value_type == ITEM_VALUE_TYPE_FLOAT || $value_type == ITEM_VALUE_TYPE_UINT64) { $frmItem->addRow(S_UNITS, new CTextBox('units', $units, 40, $limited)); if (isset($limited)) { $frmItem->addVar('multiplier', $multiplier); $cmbMultipler = new CTextBox('multiplier_name', $multiplier ? S_CUSTOM_MULTIPLIER : S_DO_NOT_USE, 20, 'yes'); } else { $cmbMultipler = new CComboBox('multiplier', $multiplier, 'submit()'); $cmbMultipler->addItem(0, S_DO_NOT_USE); $cmbMultipler->addItem(1, S_CUSTOM_MULTIPLIER); } $frmItem->addRow(S_USE_MULTIPLIER, $cmbMultipler); } else { $frmItem->addVar('units', $units); $frmItem->addVar('multiplier', $multiplier); } if (!is_numeric($formula)) { $formula = 1; } if ($multiplier == 1) { $frmItem->addRow(S_CUSTOM_MULTIPLIER, new CTextBox('formula', $formula, 40, $limited)); } else { $frmItem->addVar('formula', $formula); } if ($type != ITEM_TYPE_TRAPPER && $type != ITEM_TYPE_HTTPTEST) { $frmItem->addRow(S_UPDATE_INTERVAL_IN_SEC, new CNumericBox('delay', $delay, 5)); $frmItem->addRow(S_FLEXIBLE_INTERVALS, $delay_flex_el); $frmItem->addRow(S_NEW_FLEXIBLE_INTERVAL, array(S_DELAY, SPACE, new CNumericBox('new_delay_flex[delay]', '50', 5), S_PERIOD, SPACE, new CTextBox('new_delay_flex[period]', '1-7,00:00-23:59', 27), BR(), new CButton('add_delay_flex', S_ADD)), 'new'); } else { $frmItem->addVar('delay', $delay); $frmItem->addVar('delay_flex', null); } $frmItem->addRow(S_KEEP_HISTORY_IN_DAYS, array(new CNumericBox('history', $history, 8), !isset($_REQUEST['itemid']) ? null : new CButtonQMessage('del_history', S_CLEAN_HISTORY, S_HISTORY_CLEANING_CAN_TAKE_A_LONG_TIME_CONTINUE_Q))); if (uint_in_array($value_type, array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64))) { $frmItem->addRow(S_KEEP_TRENDS_IN_DAYS, new CNumericBox('trends', $trends, 8)); } else { $frmItem->addVar('trends', 0); } $cmbStatus = new CComboBox('status', $status); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED) as $st) { $cmbStatus->addItem($st, item_status2str($st)); } $frmItem->addRow(S_STATUS, $cmbStatus); if ($value_type == ITEM_VALUE_TYPE_LOG) { $frmItem->addRow(S_LOG_TIME_FORMAT, new CTextBox('logtimefmt', $logtimefmt, 16, $limited)); } else { $frmItem->addVar('logtimefmt', $logtimefmt); } if ($value_type == ITEM_VALUE_TYPE_FLOAT || $value_type == ITEM_VALUE_TYPE_UINT64) { $cmbDelta = new CComboBox('delta', $delta); $cmbDelta->addItem(0, S_AS_IS); $cmbDelta->addItem(1, S_DELTA_SPEED_PER_SECOND); $cmbDelta->addItem(2, S_DELTA_SIMPLE_CHANGE); $frmItem->addRow(S_STORE_VALUE, $cmbDelta); } else { $frmItem->addVar('delta', 0); } if ($value_type == ITEM_VALUE_TYPE_UINT64 || $value_type == ITEM_VALUE_TYPE_STR) { if (isset($limited) && $type != ITEM_TYPE_HTTPTEST) { $frmItem->addVar('valuemapid', $valuemapid); $map_name = S_AS_IS; if ($map_data = DBfetch(DBselect('SELECT name FROM valuemaps WHERE valuemapid=' . $valuemapid))) { $map_name = $map_data['name']; } $cmbMap = new CTextBox('valuemap_name', $map_name, 20, 'yes'); } else { $cmbMap = new CComboBox('valuemapid', $valuemapid); $cmbMap->addItem(0, S_AS_IS); $db_valuemaps = DBselect('SELECT * FROM valuemaps WHERE ' . DBin_node('valuemapid')); while ($db_valuemap = DBfetch($db_valuemaps)) { $cmbMap->addItem($db_valuemap['valuemapid'], get_node_name_by_elid($db_valuemap['valuemapid']) . $db_valuemap['name']); } } $link = new CLink('throw map', 'config.php?config=6', 'action'); $link->addOption('target', '_blank'); $frmItem->addRow(array(S_SHOW_VALUE . SPACE, $link), $cmbMap); } else { $frmItem->addVar('valuemapid', 0); } if ($type == ITEM_TYPE_TRAPPER) { $frmItem->addRow(S_ALLOWED_HOSTS, new CTextBox('trapper_hosts', $trapper_hosts, 40, $limited)); } else { $frmItem->addVar('trapper_hosts', $trapper_hosts); } if ($type == ITEM_TYPE_HTTPTEST) { $app_names = get_applications_by_itemid($_REQUEST['itemid'], 'name'); $frmItem->addRow(S_APPLICATIONS, new CTextBox('application_name', isset($app_names[0]) ? $app_names[0] : '', 20, $limited)); $frmItem->addVar('applications', $applications, 6); } else { $new_app = new CTextBox('new_application', $new_application, 40); $frmItem->addRow(S_NEW_APPLICATION, $new_app); $cmbApps = new CListBox('applications[]', $applications, 6); $cmbApps->addItem(0, '-' . S_NONE . '-'); $db_applications = DBselect('SELECT DISTINCT applicationid,name ' . ' FROM applications ' . ' WHERE hostid=' . $_REQUEST['hostid'] . ' ORDER BY name'); while ($db_app = DBfetch($db_applications)) { $cmbApps->addItem($db_app['applicationid'], $db_app['name']); } $frmItem->addRow(S_APPLICATIONS, $cmbApps); } $frmRow = array(new CButton('save', S_SAVE)); if (isset($_REQUEST['itemid'])) { array_push($frmRow, SPACE, new CButton('clone', S_CLONE)); if (!isset($limited)) { array_push($frmRow, SPACE, new CButtonDelete('Delete selected item?', url_param('form') . url_param('groupid') . url_param('hostid') . url_param('config') . url_param('itemid'))); } } array_push($frmRow, SPACE, new CButtonCancel(url_param('groupid') . url_param('hostid') . url_param('config'))); $frmItem->addSpanRow($frmRow, 'form_row_last'); $cmbGroups = new CComboBox('add_groupid', $add_groupid); $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); $groups = DBselect('SELECT DISTINCT groupid,name ' . ' FROM groups ' . ' WHERE ' . DBcondition('groupid', $available_groups) . ' ORDER BY name'); while ($group = DBfetch($groups)) { $cmbGroups->addItem($group['groupid'], get_node_name_by_elid($group['groupid']) . $group['name']); } $frmItem->addRow(S_GROUP, $cmbGroups); $cmbAction = new CComboBox('action'); $cmbAction->addItem('add to group', S_ADD_TO_GROUP); if (isset($_REQUEST['itemid'])) { $cmbAction->addItem('update in group', S_UPDATE_IN_GROUP); $cmbAction->addItem('delete FROM group', S_DELETE_FROM_GROUP); } $frmItem->addItemToBottomRow($cmbAction); $frmItem->addItemToBottomRow(SPACE); $frmItem->addItemToBottomRow(new CButton('register', 'do')); $frmItem->Show(); }
DBstart(); $result = true; if (!zbx_empty($_REQUEST['new_application'])) { $new_appid = API::Application()->create(array('name' => $_REQUEST['new_application'], 'hostid' => $_REQUEST['form_hostid'])); if ($new_appid) { $new_appid = reset($new_appid['applicationids']); $applications[$new_appid] = $new_appid; } else { $result = false; } } if ($result) { $item = array('name' => get_request('name'), 'description' => get_request('description'), 'key_' => get_request('key'), 'hostid' => get_request('form_hostid'), 'interfaceid' => get_request('interfaceid', 0), 'delay' => get_request('delay'), 'history' => get_request('history'), 'status' => get_request('status'), 'type' => get_request('type'), 'snmp_community' => get_request('snmp_community'), 'snmp_oid' => get_request('snmp_oid'), 'value_type' => get_request('value_type'), 'trapper_hosts' => get_request('trapper_hosts'), 'port' => get_request('port'), 'units' => get_request('units'), 'multiplier' => get_request('multiplier', 0), 'delta' => get_request('delta'), 'snmpv3_securityname' => get_request('snmpv3_securityname'), 'snmpv3_securitylevel' => get_request('snmpv3_securitylevel'), 'snmpv3_authpassphrase' => get_request('snmpv3_authpassphrase'), 'snmpv3_privpassphrase' => get_request('snmpv3_privpassphrase'), 'formula' => get_request('formula'), 'trends' => get_request('trends'), 'logtimefmt' => get_request('logtimefmt'), 'valuemapid' => get_request('valuemapid'), 'delay_flex' => $db_delay_flex, 'authtype' => get_request('authtype'), 'username' => get_request('username'), 'password' => get_request('password'), 'publickey' => get_request('publickey'), 'privatekey' => get_request('privatekey'), 'params' => get_request('params'), 'ipmi_sensor' => get_request('ipmi_sensor'), 'data_type' => get_request('data_type'), 'applications' => $applications, 'inventory_link' => get_request('inventory_link')); if (isset($_REQUEST['itemid'])) { $db_item = get_item_by_itemid_limited($_REQUEST['itemid']); $db_item['applications'] = get_applications_by_itemid($_REQUEST['itemid']); foreach ($item as $field => $value) { if ($item[$field] == $db_item[$field]) { unset($item[$field]); } } $item['itemid'] = $_REQUEST['itemid']; $result = API::Item()->update($item); } else { $result = API::Item()->create($item); } } $result = DBend($result); if (isset($_REQUEST['itemid'])) { show_messages($result, _('Item updated'), _('Cannot update item')); } else {
function EndElement($parser, $name) { if (!$this->root) { return false; } global $USER_DETAILS; $data =& $this->data[$name]; switch ($name) { case XML_TAG_HOST: if ($data['skip'] || !isset($data['hostid']) || !$data['hostid']) { break; } // case if (!isset($data['port'])) { $data['port'] = 10050; } if (!isset($data['status'])) { $data['status'] = 0; } if (!isset($data['useip'])) { $data['useip'] = 0; } if (!isset($data['dns'])) { $data['dns'] = ''; } if (!isset($data['ip'])) { $data['ip'] = ''; } if (!isset($data['proxy'])) { $data['proxy'] = ''; } if (!zbx_empty($data['proxy'])) { $sql = 'SELECT hostid ' . ' FROM hosts ' . ' WHERE host=' . zbx_dbstr($data['proxy']) . ' AND status=' . HOST_STATUS_PROXY . ' AND ' . DBin_node('hostid', get_current_nodeid(false)); if ($host_data = DBfetch(DBselect($sql))) { $data['proxy'] = $host_data['hostid']; } else { $data['proxy'] = 0; } } else { $data['proxy'] = 0; } if (update_host($data['hostid'], $data['name'], $data['port'], $data['status'], $data['useip'], $data['dns'], $data['ip'], $data['proxy'], $data['templates'], 'no', '', 623, -1, 2, '', '', null, $data['groups'])) { info('Host [' . $data['name'] . '] updated'); } break; // case // based on mod by scricca // case // based on mod by scricca case XML_TAG_HOSTPROFILE: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { break; } //case if (!isset($data['devicetype'])) { $data['devicetype'] = ''; } if (!isset($data['name'])) { $data['name'] = ''; } if (!isset($data['os'])) { $data['os'] = ''; } if (!isset($data['serialno'])) { $data['serialno'] = ''; } if (!isset($data['tag'])) { $data['tag'] = ''; } if (!isset($data['macaddress'])) { $data['macaddress'] = ''; } if (!isset($data['hardware'])) { $data['hardware'] = ''; } if (!isset($data['software'])) { $data['software'] = ''; } if (!isset($data['contact'])) { $data['contact'] = ''; } if (!isset($data['location'])) { $data['location'] = ''; } if (!isset($data['notes'])) { $data['notes'] = ''; } delete_host_profile($this->data[XML_TAG_HOST]['hostid']); if (add_host_profile($this->data[XML_TAG_HOST]['hostid'], $data['devicetype'], $data['name'], $data['os'], $data['serialno'], $data['tag'], $data['macaddress'], $data['hardware'], $data['software'], $data['contact'], $data['location'], $data['notes'])) { info('Host Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated'); } break; // case //--- // Extended profiles // case //--- // Extended profiles case XML_TAG_HOSTPROFILE_EXT: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { break; } //case if (!isset($data['device_alias'])) { $data['device_alias'] = ''; } if (!isset($data['device_type'])) { $data['device_type'] = ''; } if (!isset($data['device_chassis'])) { $data['device_chassis'] = ''; } if (!isset($data['device_os'])) { $data['device_os'] = ''; } if (!isset($data['device_os_short'])) { $data['device_os_short'] = ''; } if (!isset($data['device_hw_arch'])) { $data['device_hw_arch'] = ''; } if (!isset($data['device_serial'])) { $data['device_serial'] = ''; } if (!isset($data['device_model'])) { $data['device_model'] = ''; } if (!isset($data['device_tag'])) { $data['device_tag'] = ''; } if (!isset($data['device_vendor'])) { $data['device_vendor'] = ''; } if (!isset($data['device_contract'])) { $data['device_contract'] = ''; } if (!isset($data['device_who'])) { $data['device_who'] = ''; } if (!isset($data['device_status'])) { $data['device_status'] = ''; } if (!isset($data['device_app_01'])) { $data['device_app_01'] = ''; } if (!isset($data['device_app_02'])) { $data['device_app_02'] = ''; } if (!isset($data['device_app_03'])) { $data['device_app_03'] = ''; } if (!isset($data['device_app_04'])) { $data['device_app_04'] = ''; } if (!isset($data['device_app_05'])) { $data['device_app_05'] = ''; } if (!isset($data['device_url_1'])) { $data['device_url_1'] = ''; } if (!isset($data['device_url_2'])) { $data['device_url_2'] = ''; } if (!isset($data['device_url_3'])) { $data['device_url_3'] = ''; } if (!isset($data['device_networks'])) { $data['device_networks'] = ''; } if (!isset($data['device_notes'])) { $data['device_notes'] = ''; } if (!isset($data['device_hardware'])) { $data['device_hardware'] = ''; } if (!isset($data['device_software'])) { $data['device_software'] = ''; } if (!isset($data['ip_subnet_mask'])) { $data['ip_subnet_mask'] = ''; } if (!isset($data['ip_router'])) { $data['ip_router'] = ''; } if (!isset($data['ip_macaddress'])) { $data['ip_macaddress'] = ''; } if (!isset($data['oob_ip'])) { $data['oob_ip'] = ''; } if (!isset($data['oob_subnet_mask'])) { $data['oob_subnet_mask'] = ''; } if (!isset($data['oob_router'])) { $data['oob_router'] = ''; } if (!isset($data['date_hw_buy'])) { $data['date_hw_buy'] = ''; } if (!isset($data['date_hw_install'])) { $data['date_hw_install'] = ''; } if (!isset($data['date_hw_expiry'])) { $data['date_hw_expiry'] = ''; } if (!isset($data['date_hw_decomm'])) { $data['date_hw_decomm'] = ''; } if (!isset($data['site_street_1'])) { $data['site_street_1'] = ''; } if (!isset($data['site_street_2'])) { $data['site_street_2'] = ''; } if (!isset($data['site_street_3'])) { $data['site_street_3'] = ''; } if (!isset($data['site_city'])) { $data['site_city'] = ''; } if (!isset($data['site_state'])) { $data['site_state'] = ''; } if (!isset($data['site_country'])) { $data['site_country'] = ''; } if (!isset($data['site_zip'])) { $data['site_zip'] = ''; } if (!isset($data['site_rack'])) { $data['site_rack'] = ''; } if (!isset($data['site_notes'])) { $data['site_notes'] = ''; } if (!isset($data['poc_1_name'])) { $data['poc_1_name'] = ''; } if (!isset($data['poc_1_email'])) { $data['poc_1_email'] = ''; } if (!isset($data['poc_1_phone_1'])) { $data['poc_1_phone_1'] = ''; } if (!isset($data['poc_1_phone_2'])) { $data['poc_1_phone_2'] = ''; } if (!isset($data['poc_1_cell'])) { $data['poc_1_cell'] = ''; } if (!isset($data['poc_1_screen'])) { $data['poc_1_screen'] = ''; } if (!isset($data['poc_1_notes'])) { $data['poc_1_notes'] = ''; } if (!isset($data['poc_2_name'])) { $data['poc_2_name'] = ''; } if (!isset($data['poc_2_email'])) { $data['poc_2_email'] = ''; } if (!isset($data['poc_2_phone_1'])) { $data['poc_2_phone_1'] = ''; } if (!isset($data['poc_2_phone_2'])) { $data['poc_2_phone_2'] = ''; } if (!isset($data['poc_2_cell'])) { $data['poc_2_cell'] = ''; } if (!isset($data['poc_2_screen'])) { $data['poc_2_screen'] = ''; } if (!isset($data['poc_2_notes'])) { $data['poc_2_notes'] = ''; } delete_host_profile_ext($this->data[XML_TAG_HOST]['hostid']); if (add_host_profile_ext($this->data[XML_TAG_HOST]['hostid'], $data)) { info('Host Extended Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated'); } break; // case //--- // case //--- case XML_TAG_GROUP: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { break; } //case $sql = 'SELECT groupid, name ' . ' FROM groups' . ' WHERE ' . DBin_node('groupid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data); if (!($group = DBfetch(DBselect($sql)))) { error('Missing group [' . $this->element_data . ']'); break; // case } if (!isset($this->available_groups[$group['groupid']])) { error('Group [' . $this->element_data . '] skipped - Access deny.'); break; // case } $this->data[XML_TAG_HOST]['groups'][$group['groupid']] = $group['groupid']; break; // case // case case XML_TAG_DEPENDENCY: if (!isset($data['triggerid_down']) || !$data['triggerid_down']) { break; } // case update_trigger($data['triggerid_down'], null, null, null, null, null, null, null, $data['triggerid_up'], null); break; // case // case case XML_TAG_DEPENDS: if (!isset($this->data[XML_TAG_DEPENDENCY]['triggerid_down']) || !$this->data[XML_TAG_DEPENDENCY]['triggerid_down']) { break; } //case if (!($trigger_up = get_trigger_by_description($this->element_data))) { break; } array_push($this->data[XML_TAG_DEPENDENCY]['triggerid_up'], $trigger_up['triggerid']); break; // case // case case XML_TAG_APPLICATION: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { break; } //case if (!isset($this->data[XML_TAG_ITEM])) { break; } //case $sql = 'SELECT applicationid ' . ' FROM applications' . ' WHERE ' . DBin_node('applicationid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid']; if (!($application = DBfetch(DBselect($sql)))) { $applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']); } else { $applicationid = $application['applicationid']; } $this->data[XML_TAG_ITEM]['applications'][] = $applicationid; break; // case // case case XML_TAG_TEMPLATE: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { break; } //case $sql = 'SELECT DISTINCT host, hostid ' . ' FROM hosts' . ' WHERE ' . DBin_node('hostid') . ' AND host=' . zbx_dbstr($this->element_data) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')'; if (!($template = DBfetch(DBselect($sql)))) { error('Missing template [' . $this->element_data . ']'); break; // case } if (!isset($this->available_hosts[$template['hostid']])) { error('Template [' . $this->element_data . '] skipped - Access deny.'); break; // case } $this->data[XML_TAG_HOST]['templates'][$template["hostid"]] = $template['host']; break; // case // case case XML_TAG_ITEM: if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) { info('Item [' . $data['description'] . '] skipped - user rule for host'); break; // case } error('Item [' . $data['description'] . '] skipped - missing host'); break; // case } if (!isset($data['description'])) { $data['description'] = ''; } if (!isset($data['delay'])) { $data['delay'] = 30; } if (!isset($data['history'])) { $data['history'] = 90; } if (!isset($data['trends'])) { $data['trends'] = 365; } if (!isset($data['status'])) { $data['status'] = 0; } if (!isset($data['units'])) { $data['units'] = ''; } if (!isset($data['multiplier'])) { $data['multiplier'] = 0; } if (!isset($data['delta'])) { $data['delta'] = 0; } if (!isset($data['formula'])) { $data['formula'] = ''; } if (!isset($data['lastlogsize'])) { $data['lastlogsize'] = 0; } if (!isset($data['logtimefmt'])) { $data['logtimefmt'] = ''; } if (!isset($data['delay_flex'])) { $data['delay_flex'] = ''; } if (!isset($data['trapper_hosts'])) { $data['trapper_hosts'] = ''; } if (!isset($data['snmp_community'])) { $data['snmp_community'] = ''; } if (!isset($data['snmp_oid'])) { $data['snmp_oid'] = ''; } if (!isset($data['snmp_port'])) { $data['snmp_port'] = 161; } if (!isset($data['snmpv3_securityname'])) { $data['snmpv3_securityname'] = ''; } if (!isset($data['snmpv3_securitylevel'])) { $data['snmpv3_securitylevel'] = 0; } if (!isset($data['snmpv3_authpassphrase'])) { $data['snmpv3_authpassphrase'] = ''; } if (!isset($data['snmpv3_privpassphrase'])) { $data['snmpv3_privpassphrase'] = ''; } if (!isset($data['valuemap'])) { $data['valuemap'] = ''; } if (!isset($data['params'])) { $data['params'] = ''; } if (!isset($data['ipmi_sensor'])) { $data['ipmi_sensor'] = ''; } if (!isset($data['applications'])) { $data['applications'] = array(); } if (!empty($data['valuemap'])) { $sql = 'SELECT valuemapid ' . ' FROM valuemaps ' . ' WHERE ' . DBin_node('valuemapid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($data['valuemap']); if ($valuemap = DBfetch(DBselect($sql))) { $data['valuemapid'] = $valuemap['valuemapid']; } else { $data['valuemapid'] = add_valuemap($data['valuemap'], array()); } } $sql = 'SELECT itemid,valuemapid,templateid ' . ' FROM items ' . ' WHERE key_=' . zbx_dbstr($data['key']) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND ' . DBin_node('itemid', get_current_nodeid(false)); if ($item = DBfetch(DBselect($sql))) { /* exist */ if ($this->item['exist'] == 1) { info('Item [' . $data['description'] . '] skipped - user rule'); break; } if (!isset($data['valuemapid'])) { $data['valuemapid'] = $item['valuemapid']; } $data['key_'] = $data['key']; $data['hostid'] = $this->data[XML_TAG_HOST]['hostid']; $data['applications'] = array_unique(array_merge($data['applications'], get_applications_by_itemid($item['itemid']))); $data['templateid'] = $item['templateid']; check_db_fields($item, $data); update_item($item['itemid'], $data); } else { /* missed */ if ($this->item['missed'] == 1) { info('Item [' . $data['description'] . '] skipped - user rule'); break; // case } if (!isset($data['valuemapid'])) { $data['valuemapid'] = 0; } $data['hostid'] = $this->data[XML_TAG_HOST]['hostid']; $data['key_'] = $data['key']; add_item($data); } break; // case // case case XML_TAG_TRIGGER: if (!isset($data['expression'])) { $data['expression'] = ''; } if (!isset($data['description'])) { $data['description'] = ''; } if (!isset($data['type'])) { $data['type'] = 0; } if (!isset($data['priority'])) { $data['priority'] = 0; } if (!isset($data['status'])) { $data['status'] = 0; } if (!isset($data['comments'])) { $data['comments'] = ''; } if (!isset($data['url'])) { $data['url'] = ''; } if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) { // remember skipped triggers for dependencies $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description']; info('Trigger [' . $data['description'] . '] skipped - user rule for host'); break; // case } if (zbx_strstr($data['expression'], '{HOSTNAME}')) { // remember skipped triggers for dependencies $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description']; error('Trigger [' . $data['description'] . '] skipped - missing host'); break; // case } } else { $data['expression'] = str_replace('{{HOSTNAME}:', '{' . $this->data[XML_TAG_HOST]['name'] . ':', $data['expression']); $result = DBselect('SELECT DISTINCT t.triggerid,t.templateid,t.expression ' . ' FROM triggers t,functions f,items i ' . ' WHERE t.triggerid=f.triggerid ' . ' AND f.itemid=i.itemid' . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND t.description=' . zbx_dbstr($data['description'])); while ($trigger = DBfetch($result)) { if (explode_exp($trigger['expression'], 0) == $data['expression']) { break; // while } } if (!empty($trigger)) { /* exist */ if ($this->trigger['exist'] == 1) { /* skip */ // remember skipped triggers for dependencies $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description']; info('Trigger [' . $data['description'] . '] skipped - user rule'); break; // case } update_trigger($trigger['triggerid'], $data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url'], get_trigger_dependencies_by_triggerid($trigger['triggerid']), $trigger['templateid']); break; // case } else { /* missed */ // continue [add_trigger] } } if ($this->trigger['missed'] == 1) { // remember skipped triggers for dependencies $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description']; info('Trigger [' . $data['description'] . '] skipped - user rule'); break; // case } add_trigger($data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url']); break; // case // case case XML_TAG_GRAPH: if (isset($data['error'])) { error('Graph [' . $data['name'] . '] skipped - error occured'); break; // case } if (!isset($data['ymin_type'])) { $data['ymin_type'] = 0; } if (!isset($data['ymax_type'])) { $data['ymax_type'] = 0; } if (!isset($data['ymin_item_key'])) { $data['ymin_item_key'] = ''; } if (!isset($data['ymax_item_key'])) { $data['ymax_item_key'] = ''; } if (!isset($data['ymin_itemid'])) { $data['ymin_itemid'] = 0; } if (!isset($data['ymax_itemid'])) { $data['ymax_itemid'] = 0; } if (!isset($data['show_work_period'])) { $data['show_work_period'] = 1; } if (!isset($data['show_triggers'])) { $data['show_triggers'] = 1; } if (!isset($data['graphtype'])) { $data['graphtype'] = 0; } if (!isset($data['yaxismin'])) { $data['yaxismin'] = 0; } if (!isset($data['yaxismax'])) { $data['yaxismax'] = 0; } if (!isset($data['show_legend'])) { $data['show_legend'] = 0; } if (!isset($data['show_3d'])) { $data['show_3d'] = 0; } if (!isset($data['percent_left'])) { $data['percent_left'] = 0; } if (!isset($data['percent_right'])) { $data['percent_right'] = 0; } if (!isset($data['items'])) { $data['items'] = array(); } if (!empty($data['ymin_item_key'])) { $data['ymin_item_key'] = explode(':', $data['ymin_item_key']); if (count($data['ymin_item_key']) < 2) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Incorrect y min item for graph [' . $data['name'] . ']'); break; // case } $data['host'] = array_shift($data['ymin_item_key']); $data['ymin_item_key'] = implode(':', $data['ymin_item_key']); if (!($item = get_item_by_key($data['ymin_item_key'], $data['host']))) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Missed item [' . $data['ymin_item_key'] . '] for host [' . $data['host'] . ']'); break; // case } $data['ymin_itemid'] = $item['itemid']; } if (!empty($data['ymax_item_key'])) { $data['ymax_item_key'] = explode(':', $data['ymax_item_key']); if (count($data['ymax_item_key']) < 2) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Incorrect y max item for graph [' . $data['name'] . ']'); break; // case } $data['host'] = array_shift($data['ymax_item_key']); $data['ymax_item_key'] = implode(':', $data['ymax_item_key']); if (!($item = get_item_by_key($data['ymax_item_key'], $data['host']))) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Missed item [' . $data['ymax_item_key'] . '] for host [' . $data['host'] . ']'); break; // case } $data['ymax_itemid'] = $item['itemid']; } if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) { if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) { info('Graph [' . $data['name'] . '] skipped - user rule for host'); break; // case } foreach ($data['items'] as $id) { if (zbx_strstr($data['name'], '{HOSTNAME}')) { error('Graph [' . $data['name'] . '] skipped - missing host'); break; // case } } } else { if ($graph = DBfetch(DBselect('SELECT DISTINCT g.graphid, g.templateid' . ' FROM graphs g, graphs_items gi, items i' . ' WHERE g.graphid=gi.graphid ' . ' AND gi.itemid=i.itemid' . ' AND g.name=' . zbx_dbstr($data['name']) . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid']))) { /* exist */ if ($this->graph['exist'] == 1) { /* skip */ info('Graph [' . $data['name'] . '] skipped - user rule'); break; // case } $data['graphid'] = $graph['graphid']; update_graph_with_items($data['graphid'], $data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items'], $graph['templateid']); } else { /* missed */ // continue [add_group] } } if (!isset($data['graphid'])) { if ($this->graph['missed'] == 1) { /* skip */ info('Graph [' . $data['name'] . '] skipped - user rule'); break; // case } $data['graphid'] = add_graph_with_items($data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items']); } break; // case // case case XML_TAG_GRAPH_ELEMENT: if (!isset($this->data[XML_TAG_GRAPH])) { break; } // case $data['key'] = explode(':', $data['item']); if (count($data['key']) < 2) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Incorrect element for graph [' . $data['name'] . ']'); break; // case } $data['host'] = array_shift($data['key']); $data['key'] = implode(':', $data['key']); if (isset($this->data[XML_TAG_HOST]['name'])) { $data['host'] = str_replace('{HOSTNAME}', $this->data[XML_TAG_HOST]['name'], $data['host']); } if (!isset($data['drawtype'])) { $data['drawtype'] = 0; } if (!isset($data['sortorder'])) { $data['sortorder'] = 0; } if (!isset($data['color'])) { $data['color'] = 'Dark Green'; } if (!isset($data['yaxisside'])) { $data['yaxisside'] = 1; } if (!isset($data['calc_fnc'])) { $data['calc_fnc'] = 2; } if (!isset($data['type'])) { $data['type'] = 0; } if (!isset($data['periods_cnt'])) { $data['periods_cnt'] = 5; } if (!($item = get_item_by_key($data['key'], $data['host']))) { $this->data[XML_TAG_GRAPH]['error'] = true; error('Missing item [' . $data['key'] . '] for host [' . $data['host'] . ']'); break; // case } $data['itemid'] = $item['itemid']; array_push($this->data[XML_TAG_GRAPH]['items'], $data); break; // case /*case XML_TAG_SCREEN: case XML_TAG_SCREEN_ELEMENT: break; // case*/ // case /*case XML_TAG_SCREEN: case XML_TAG_SCREEN_ELEMENT: break; // case*/ default: if (isset($this->sub_node) && isset($this->main_node)) { $main_node = array_pop($this->main_node); $this->data[$main_node][$this->sub_node] = $this->element_data; array_push($this->main_node, $main_node); } $this->sub_node = null; return; } unset($this->data[$name], $data); array_pop($this->main_node); }
/** * Get data for item edit page. * * @param array $item item, item prototype or LLD rule to take the data from * @param bool $options['is_discovery_rule'] * * @return array */ function getItemFormData(array $item = [], array $options = []) { $data = ['form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'is_discovery_rule' => !empty($options['is_discovery_rule']), 'parent_discoveryid' => getRequest('parent_discoveryid', !empty($options['is_discovery_rule']) ? getRequest('itemid') : null), 'itemid' => getRequest('itemid'), 'limited' => false, 'interfaceid' => getRequest('interfaceid', 0), 'name' => getRequest('name', ''), 'description' => getRequest('description', ''), 'key' => getRequest('key', ''), 'hostname' => getRequest('hostname'), 'delay' => getRequest('delay', ZBX_ITEM_DELAY_DEFAULT), 'history' => getRequest('history', 90), 'status' => getRequest('status', isset($_REQUEST['form_refresh']) ? 1 : 0), 'type' => getRequest('type', 0), 'snmp_community' => getRequest('snmp_community', 'public'), 'snmp_oid' => getRequest('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'), 'port' => getRequest('port', ''), 'value_type' => getRequest('value_type', ITEM_VALUE_TYPE_UINT64), 'data_type' => getRequest('data_type', ITEM_DATA_TYPE_DECIMAL), 'trapper_hosts' => getRequest('trapper_hosts', ''), 'units' => getRequest('units', ''), 'valuemapid' => getRequest('valuemapid', 0), 'params' => getRequest('params', ''), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta', 0), 'trends' => getRequest('trends', DAY_IN_YEAR), 'new_application' => getRequest('new_application', ''), 'applications' => getRequest('applications', []), 'delay_flex' => getRequest('delay_flex', []), 'snmpv3_contextname' => getRequest('snmpv3_contextname', ''), 'snmpv3_securityname' => getRequest('snmpv3_securityname', ''), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel', 0), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol', ITEM_AUTHPROTOCOL_MD5), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase', ''), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol', ITEM_PRIVPROTOCOL_DES), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase', ''), 'ipmi_sensor' => getRequest('ipmi_sensor', ''), 'authtype' => getRequest('authtype', 0), 'username' => getRequest('username', ''), 'password' => getRequest('password', ''), 'publickey' => getRequest('publickey', ''), 'privatekey' => getRequest('privatekey', ''), 'formula' => getRequest('formula', 1), 'logtimefmt' => getRequest('logtimefmt', ''), 'add_groupid' => getRequest('add_groupid', getRequest('groupid', 0)), 'valuemaps' => null, 'possibleHostInventories' => null, 'alreadyPopulated' => null, 'initial_item_type' => null, 'templates' => []]; // hostid if (!empty($data['parent_discoveryid'])) { $discoveryRule = API::DiscoveryRule()->get(['itemids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true]); $discoveryRule = reset($discoveryRule); $data['hostid'] = $discoveryRule['hostid']; $data['new_application_prototype'] = getRequest('new_application_prototype', ''); $data['application_prototypes'] = getRequest('application_prototypes', array()); } else { $data['hostid'] = getRequest('hostid', 0); } // types, http items only for internal processes $data['types'] = item_type2str(); unset($data['types'][ITEM_TYPE_HTTPTEST]); if (!empty($options['is_discovery_rule'])) { unset($data['types'][ITEM_TYPE_AGGREGATE], $data['types'][ITEM_TYPE_CALCULATED], $data['types'][ITEM_TYPE_SNMPTRAP]); } // item if ($item) { $data['item'] = $item; $data['hostid'] = !empty($data['hostid']) ? $data['hostid'] : $data['item']['hostid']; $data['limited'] = $data['item']['templateid'] != 0; // get templates $itemid = $item['itemid']; do { $params = ['itemids' => $itemid, 'output' => ['itemid', 'templateid'], 'selectHosts' => ['name']]; if ($data['is_discovery_rule']) { $item = API::DiscoveryRule()->get($params); } else { $params['selectDiscoveryRule'] = ['itemid']; $params['filter'] = ['flags' => null]; $item = API::Item()->get($params); } $item = reset($item); if (!empty($item)) { $host = reset($item['hosts']); if (!empty($item['hosts'])) { $host['name'] = CHtml::encode($host['name']); if (bccomp($data['itemid'], $itemid) == 0) { } elseif ($data['is_discovery_rule']) { $data['templates'][] = new CLink($host['name'], 'host_discovery.php?form=update&itemid=' . $item['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } elseif ($item['discoveryRule']) { $data['templates'][] = new CLink($host['name'], 'disc_prototypes.php?form=update' . '&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $item['discoveryRule']['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } else { $data['templates'][] = new CLink($host['name'], 'items.php?form=update&itemid=' . $item['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } } $itemid = $item['templateid']; } else { break; } } while ($itemid != 0); $data['templates'] = array_reverse($data['templates']); array_shift($data['templates']); } // caption if (!empty($data['is_discovery_rule'])) { $data['caption'] = _('Discovery rule'); } else { $data['caption'] = !empty($data['parent_discoveryid']) ? _('Item prototype') : _('Item'); } // hostname if (empty($data['is_discovery_rule']) && empty($data['hostname'])) { if (!empty($data['hostid'])) { $hostInfo = API::Host()->get(['hostids' => $data['hostid'], 'output' => ['name'], 'templated_hosts' => true]); $hostInfo = reset($hostInfo); $data['hostname'] = $hostInfo['name']; } else { $data['hostname'] = _('not selected'); } } // fill data from item if (!hasRequest('form_refresh') && ($item || $data['limited'])) { $data['name'] = $data['item']['name']; $data['description'] = $data['item']['description']; $data['key'] = $data['item']['key_']; $data['interfaceid'] = $data['item']['interfaceid']; $data['type'] = $data['item']['type']; $data['snmp_community'] = $data['item']['snmp_community']; $data['snmp_oid'] = $data['item']['snmp_oid']; $data['port'] = $data['item']['port']; $data['value_type'] = $data['item']['value_type']; $data['data_type'] = $data['item']['data_type']; $data['trapper_hosts'] = $data['item']['trapper_hosts']; $data['units'] = $data['item']['units']; $data['valuemapid'] = $data['item']['valuemapid']; $data['multiplier'] = $data['item']['multiplier']; $data['hostid'] = $data['item']['hostid']; $data['params'] = $data['item']['params']; $data['snmpv3_contextname'] = $data['item']['snmpv3_contextname']; $data['snmpv3_securityname'] = $data['item']['snmpv3_securityname']; $data['snmpv3_securitylevel'] = $data['item']['snmpv3_securitylevel']; $data['snmpv3_authprotocol'] = $data['item']['snmpv3_authprotocol']; $data['snmpv3_authpassphrase'] = $data['item']['snmpv3_authpassphrase']; $data['snmpv3_privprotocol'] = $data['item']['snmpv3_privprotocol']; $data['snmpv3_privpassphrase'] = $data['item']['snmpv3_privpassphrase']; $data['ipmi_sensor'] = $data['item']['ipmi_sensor']; $data['authtype'] = $data['item']['authtype']; $data['username'] = $data['item']['username']; $data['password'] = $data['item']['password']; $data['publickey'] = $data['item']['publickey']; $data['privatekey'] = $data['item']['privatekey']; $data['logtimefmt'] = $data['item']['logtimefmt']; $data['new_application'] = getRequest('new_application', ''); if ($data['parent_discoveryid'] != 0) { $data['new_application_prototype'] = getRequest('new_application_prototype', ''); } if (!$data['is_discovery_rule']) { $data['formula'] = $data['item']['formula']; } if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) { $data['delay'] = $data['item']['delay']; if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) { $data['delay'] = ZBX_ITEM_DELAY_DEFAULT; } $data['history'] = $data['item']['history']; $data['status'] = $data['item']['status']; $data['delta'] = $data['item']['delta']; $data['trends'] = $data['item']['trends']; $parser = new CItemDelayFlexParser($data['item']['delay_flex']); if ($parser->isValid()) { foreach ($parser->getIntervals() as $interval) { if ($interval['type'] == ITEM_DELAY_FLEX_TYPE_FLEXIBLE) { $interval_parts = explode('/', $interval['interval']); $data['delay_flex'][] = ['delay' => $interval_parts[0], 'period' => $interval_parts[1], 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE]; } else { $data['delay_flex'][] = ['schedule' => $interval['interval'], 'type' => ITEM_DELAY_FLEX_TYPE_SCHEDULING]; } } } $data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid']))); if ($data['parent_discoveryid'] != 0) { /* * Get a list of application prototypes assigned to item prototype. Don't select distinct names, * since database can be accidentally created case insensitive. */ $application_prototypes = DBfetchArray(DBselect('SELECT ap.name' . ' FROM application_prototype ap,item_application_prototype iap' . ' WHERE ap.application_prototypeid=iap.application_prototypeid' . ' AND ap.itemid=' . zbx_dbstr($data['parent_discoveryid']) . ' AND iap.itemid=' . zbx_dbstr($data['itemid']))); // Merge form submitted data with data existing in DB to find diff and correctly display ListBox. $data['application_prototypes'] = array_unique(zbx_array_merge($data['application_prototypes'], zbx_objectValues($application_prototypes, 'name'))); } } } if (!$data['delay_flex']) { $data['delay_flex'][] = ['delay' => '', 'period' => '', 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE]; } // applications if (count($data['applications']) == 0) { array_push($data['applications'], 0); } $data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']) . ($data['parent_discoveryid'] ? ' AND a.flags=' . ZBX_FLAG_DISCOVERY_NORMAL : ''))); order_result($data['db_applications'], 'name'); if ($data['parent_discoveryid'] != 0) { // Make the application prototype list no appearing empty, but filling it with "-None-" as first element. if (count($data['application_prototypes']) == 0) { $data['application_prototypes'][] = 0; } // Get a list of application prototypes by discovery rule. $data['db_application_prototypes'] = DBfetchArray(DBselect('SELECT ap.application_prototypeid,ap.name' . ' FROM application_prototype ap' . ' WHERE ap.itemid=' . zbx_dbstr($data['parent_discoveryid']))); order_result($data['db_application_prototypes'], 'name'); } // interfaces $data['interfaces'] = API::HostInterface()->get(['hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND]); // valuemapid if ($data['limited']) { if ($data['valuemapid'] != 0) { $valuemaps = API::ValueMap()->get(['output' => ['name'], 'valuemapids' => [$data['valuemapid']]]); if ($valuemaps) { $data['valuemaps'] = $valuemaps[0]['name']; } } } else { $data['valuemaps'] = API::ValueMap()->get(['output' => ['valemapid', 'name']]); CArrayHelper::sort($data['valuemaps'], ['name']); } // possible host inventories if (empty($data['parent_discoveryid'])) { $data['possibleHostInventories'] = getHostInventories(); // get already populated fields by other items $data['alreadyPopulated'] = API::item()->get(['output' => ['inventory_link'], 'filter' => ['hostid' => $data['hostid']], 'nopermissions' => true]); $data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link'); } // unset snmpv3 fields if ($data['type'] != ITEM_TYPE_SNMPV3) { $data['snmpv3_contextname'] = ''; $data['snmpv3_securityname'] = ''; $data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV; $data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $data['snmpv3_authpassphrase'] = ''; $data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; $data['snmpv3_privpassphrase'] = ''; } // unset ssh auth fields if ($data['type'] != ITEM_TYPE_SSH) { $data['authtype'] = ITEM_AUTHTYPE_PASSWORD; $data['publickey'] = ''; $data['privatekey'] = ''; } return $data; }
function copy_template_items($hostid, $templateid = null, $copy_mode = false) { if ($templateid == null) { $templateid = array_keys(get_templates_by_hostid($hostid)); } if (is_array($templateid)) { foreach ($templateid as $id) { copy_template_items($hostid, $id, $copy_mode); } // attention recursion return; } $db_tmp_items = get_items_by_hostid($templateid); while ($db_tmp_item = DBfetch($db_tmp_items)) { $db_tmp_item['hostid'] = $hostid; $db_tmp_item['applications'] = get_same_applications_for_host(get_applications_by_itemid($db_tmp_item['itemid']), $hostid); $db_tmp_item['templateid'] = $copy_mode ? 0 : $db_tmp_item['itemid']; add_item($db_tmp_item); } }
function insert_item_form() { global $USER_DETAILS; $frmItem = new CFormTable(S_ITEM, 'items.php', 'post'); $frmItem->setAttribute('style', 'visibility: hidden;'); $frmItem->setHelp('web.items.item.php'); $hostid = get_request('form_hostid', 0); $description = get_request('description', ''); $key = get_request('key', ''); $host = get_request('host', null); $delay = get_request('delay', 30); $history = get_request('history', 90); $status = get_request('status', 0); $type = get_request('type', 0); $snmp_community = get_request('snmp_community', 'public'); $snmp_oid = get_request('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'); $snmp_port = get_request('snmp_port', 161); $value_type = get_request('value_type', ITEM_VALUE_TYPE_UINT64); $data_type = get_request('data_type', ITEM_DATA_TYPE_DECIMAL); $trapper_hosts = get_request('trapper_hosts', ''); $units = get_request('units', ''); $valuemapid = get_request('valuemapid', 0); $params = get_request('params', ''); $multiplier = get_request('multiplier', 0); $delta = get_request('delta', 0); $trends = get_request('trends', 365); $new_application = get_request('new_application', ''); $applications = get_request('applications', array()); $delay_flex = get_request('delay_flex', array()); $snmpv3_securityname = get_request('snmpv3_securityname', ''); $snmpv3_securitylevel = get_request('snmpv3_securitylevel', 0); $snmpv3_authpassphrase = get_request('snmpv3_authpassphrase', ''); $snmpv3_privpassphrase = get_request('snmpv3_privpassphrase', ''); $ipmi_sensor = get_request('ipmi_sensor', ''); $authtype = get_request('authtype', 0); $username = get_request('username', ''); $password = get_request('password', ''); $publickey = get_request('publickey', ''); $privatekey = get_request('privatekey', ''); $formula = get_request('formula', '1'); $logtimefmt = get_request('logtimefmt', ''); $add_groupid = get_request('add_groupid', get_request('groupid', 0)); $limited = null; $types = item_type2str(); // http items only for internal processes unset($types[ITEM_TYPE_HTTPTEST]); if (isset($_REQUEST['itemid'])) { $frmItem->addVar('itemid', $_REQUEST['itemid']); $options = array('itemids' => $_REQUEST['itemid'], 'output' => API_OUTPUT_EXTEND); $item_data = CItem::get($options); $item_data = reset($item_data); $hostid = $hostid > 0 ? $hostid : $item_data['hostid']; $limited = $item_data['templateid'] == 0 && $item_data['type'] != ITEM_TYPE_HTTPTEST ? null : 'yes'; $item_data['snmp_port'] = $item_data['snmp_port'] == '0' ? 161 : $item_data['snmp_port']; } if (is_null($host)) { if ($hostid > 0) { $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => 1); $host_info = CHost::get($options); $host_info = reset($host_info); $host = $host_info['host']; } else { $host = S_NOT_SELECTED_SMALL; } } if (isset($_REQUEST['itemid']) && !isset($_REQUEST['form_refresh']) || isset($limited)) { $description = $item_data['description']; $key = $item_data['key_']; // $host = $item_data['host']; $type = $item_data['type']; $snmp_community = $item_data['snmp_community']; $snmp_oid = $item_data['snmp_oid']; $snmp_port = $item_data['snmp_port']; $value_type = $item_data['value_type']; $data_type = $item_data['data_type']; $trapper_hosts = $item_data['trapper_hosts']; $units = $item_data['units']; $valuemapid = $item_data['valuemapid']; $multiplier = $item_data['multiplier']; $hostid = $item_data['hostid']; $params = $item_data['params']; $snmpv3_securityname = $item_data['snmpv3_securityname']; $snmpv3_securitylevel = $item_data['snmpv3_securitylevel']; $snmpv3_authpassphrase = $item_data['snmpv3_authpassphrase']; $snmpv3_privpassphrase = $item_data['snmpv3_privpassphrase']; $ipmi_sensor = $item_data['ipmi_sensor']; $authtype = $item_data['authtype']; $username = $item_data['username']; $password = $item_data['password']; $publickey = $item_data['publickey']; $privatekey = $item_data['privatekey']; $formula = $item_data['formula']; $logtimefmt = $item_data['logtimefmt']; $new_application = get_request('new_application', ''); if (!isset($limited) || !isset($_REQUEST['form_refresh'])) { $delay = $item_data['delay']; $history = $item_data['history']; $status = $item_data['status']; $delta = $item_data['delta']; $trends = $item_data['trends']; $db_delay_flex = $item_data['delay_flex']; if (isset($db_delay_flex)) { $arr_of_dellays = explode(';', $db_delay_flex); foreach ($arr_of_dellays as $one_db_delay) { $arr_of_delay = explode('/', $one_db_delay); if (!isset($arr_of_delay[0]) || !isset($arr_of_delay[1])) { continue; } array_push($delay_flex, array('delay' => $arr_of_delay[0], 'period' => $arr_of_delay[1])); } } $applications = array_unique(zbx_array_merge($applications, get_applications_by_itemid($_REQUEST['itemid']))); } } $securityLevelVisibility = array(); $valueTypeVisibility = array(); $authTypeVisibility = array(); $typeVisibility = array(); $delay_flex_el = array(); //if($type != ITEM_TYPE_TRAPPER){ $i = 0; foreach ($delay_flex as $val) { if (!isset($val['delay']) && !isset($val['period'])) { continue; } array_push($delay_flex_el, array(new CCheckBox('rem_delay_flex[' . $i . ']', 'no', null, $i), $val['delay'], SPACE . S_SEC_AT . SPACE, $val['period']), BR()); $frmItem->addVar('delay_flex[' . $i . '][delay]', $val['delay']); $frmItem->addVar('delay_flex[' . $i . '][period]', $val['period']); foreach ($types as $it => $caption) { if ($it == ITEM_TYPE_TRAPPER || $it == ITEM_TYPE_ZABBIX_ACTIVE) { continue; } zbx_subarray_push($typeVisibility, $it, 'delay_flex[' . $i . '][delay]'); zbx_subarray_push($typeVisibility, $it, 'delay_flex[' . $i . '][period]'); zbx_subarray_push($typeVisibility, $it, 'rem_delay_flex[' . $i . ']'); } $i++; if ($i >= 7) { break; } /* limit count of intervals * 7 intervals by 30 symbols = 210 characters * db storage field is 256 */ } //} array_push($delay_flex_el, count($delay_flex_el) == 0 ? S_NO_FLEXIBLE_INTERVALS : new CButton('del_delay_flex', S_DELETE_SELECTED)); if (count($applications) == 0) { array_push($applications, 0); } if (isset($_REQUEST['itemid'])) { $caption = array(); $itemid = $_REQUEST['itemid']; do { $sql = 'SELECT i.itemid, i.templateid, h.host' . ' FROM items i, hosts h' . ' WHERE i.itemid=' . $itemid . ' AND h.hostid=i.hostid'; $itemFromDb = DBfetch(DBselect($sql)); if ($itemFromDb) { if ($_REQUEST['itemid'] == $itemid) { $caption[] = SPACE; $caption[] = $itemFromDb['host']; } else { $caption[] = ' : '; $caption[] = new CLink($itemFromDb['host'], 'items.php?form=update&itemid=' . $itemFromDb['itemid'], 'highlight underline'); } $itemid = $itemFromDb['templateid']; } else { break; } } while ($itemid != 0); $caption[] = S_ITEM . ' "'; $caption = array_reverse($caption); $caption[] = ': '; $caption[] = $item_data['description']; $caption[] = '"'; $frmItem->setTitle($caption); } else { $frmItem->setTitle(S_ITEM . " {$host} : {$description}"); } $frmItem->addVar('form_hostid', $hostid); $frmItem->addRow(S_HOST, array(new CTextBox('host', $host, 32, true), new CButton('btn_host', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmItem->getName() . "&dstfld1=host&dstfld2=form_hostid&srctbl=hosts_and_templates&srcfld1=host&srcfld2=hostid',450,450);", 'H'))); $frmItem->addRow(S_DESCRIPTION, new CTextBox('description', $description, 40, $limited)); if (isset($limited)) { $frmItem->addRow(S_TYPE, new CTextBox('typename', item_type2str($type), 40, 'yes')); $frmItem->addVar('type', $type); } else { $cmbType = new CComboBox('type', $type); $cmbType->addItems($types); $frmItem->addRow(S_TYPE, $cmbType); } $row = new CRow(array(new CCol(S_SNMP_OID, 'form_row_l'), new CCol(new CTextBox('snmp_oid', $snmp_oid, 40, $limited), 'form_row_r'))); $row->setAttribute('id', 'row_snmp_oid'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'snmp_oid'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'snmp_oid'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'snmp_oid'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'row_snmp_oid'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'row_snmp_oid'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'row_snmp_oid'); $row = new CRow(array(new CCol(S_SNMP_COMMUNITY, 'form_row_l'), new CCol(new CTextBox('snmp_community', $snmp_community, 16), 'form_row_r'))); $row->setAttribute('id', 'row_snmp_community'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'snmp_community'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'snmp_community'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'row_snmp_community'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'row_snmp_community'); $row = new CRow(array(new CCol(S_SNMPV3_SECURITY_NAME, 'form_row_l'), new CCol(new CTextBox('snmpv3_securityname', $snmpv3_securityname, 64), 'form_row_r'))); $row->setAttribute('id', 'row_snmpv3_securityname'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'snmpv3_securityname'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'row_snmpv3_securityname'); $cmbSecLevel = new CComboBox('snmpv3_securitylevel', $snmpv3_securitylevel); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, 'noAuthNoPriv'); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'authNoPriv'); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'authPriv'); $row = new CRow(array(new CCol(S_SNMPV3_SECURITY_LEVEL, 'form_row_l'), new CCol($cmbSecLevel, 'form_row_r'))); $row->setAttribute('id', 'row_snmpv3_securitylevel'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'snmpv3_securitylevel'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'row_snmpv3_securitylevel'); $row = new CRow(array(new CCol(S_SNMPV3_AUTH_PASSPHRASE, 'form_row_l'), new CCol(new CTextBox('snmpv3_authpassphrase', $snmpv3_authpassphrase, 64), 'form_row_r'))); $row->setAttribute('id', 'row_snmpv3_authpassphrase'); $frmItem->addRow($row); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'snmpv3_authpassphrase'); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'row_snmpv3_authpassphrase'); $row = new CRow(array(new CCol(S_SNMPV3_PRIV_PASSPHRASE, 'form_row_l'), new CCol(new CTextBox('snmpv3_privpassphrase', $snmpv3_privpassphrase, 64), 'form_row_r'))); $row->setAttribute('id', 'row_snmpv3_privpassphrase'); $frmItem->addRow($row); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'snmpv3_privpassphrase'); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'row_snmpv3_privpassphrase'); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'snmpv3_authpassphrase'); zbx_subarray_push($securityLevelVisibility, ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'row_snmpv3_authpassphrase'); $row = new CRow(array(new CCol(S_SNMP_PORT, 'form_row_l'), new CCol(new CNumericBox('snmp_port', $snmp_port, 5), 'form_row_r'))); $row->setAttribute('id', 'row_snmp_port'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'snmp_port'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'snmp_port'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'snmp_port'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV1, 'row_snmp_port'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV2C, 'row_snmp_port'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SNMPV3, 'row_snmp_port'); $row = new CRow(array(new CCol(S_IPMI_SENSOR, 'form_row_l'), new CCol(new CTextBox('ipmi_sensor', $ipmi_sensor, 64, $limited), 'form_row_r'))); $row->setAttribute('id', 'row_ipmi_sensor'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_IPMI, 'ipmi_sensor'); zbx_subarray_push($typeVisibility, ITEM_TYPE_IPMI, 'row_ipmi_sensor'); if (isset($limited)) { $btnSelect = null; } else { $btnSelect = new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmItem->getName() . "&dstfld1=key&srctbl=help_items&srcfld1=key_&itemtype=" . $type . "');", 'T'); } $frmItem->addRow(S_KEY, array(new CTextBox('key', $key, 40, $limited), $btnSelect)); foreach ($types as $it => $ilabel) { switch ($it) { case ITEM_TYPE_DB_MONITOR: zbx_subarray_push($typeVisibility, $it, array('id' => 'key', 'defaultValue' => 'db.odbc.select[<unique short description>]')); zbx_subarray_push($typeVisibility, $it, array('id' => 'params_dbmonitor', 'defaultValue' => "DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>")); break; case ITEM_TYPE_SSH: zbx_subarray_push($typeVisibility, $it, array('id' => 'key', 'defaultValue' => 'ssh.run[<unique short description>,<ip>,<port>,<encoding>]')); break; case ITEM_TYPE_TELNET: zbx_subarray_push($typeVisibility, $it, array('id' => 'key', 'defaultValue' => 'telnet.run[<unique short description>,<ip>,<port>,<encoding>]')); break; default: zbx_subarray_push($typeVisibility, $it, array('id' => 'key', 'defaultValue' => '')); } } /* ITEM_TYPE_DB_MONITOR $key = 'db.odbc.select[<unique short description>]'; $params = "DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>"; ITEM_TYPE_SSH $key = 'ssh.run[<unique short description>,<ip>,<port>,<encoding>]'; $params = ''; ITEM_TYPE_TELNET $key = 'telnet.run[<unique short description>,<ip>,<port>,<encoding>]'; $params = ''; ITEM_TYPE_CALCULATED $key = ''; $params = ''; //*/ $cmbAuthType = new CComboBox('authtype', $authtype); $cmbAuthType->addItem(ITEM_AUTHTYPE_PASSWORD, S_PASSWORD); $cmbAuthType->addItem(ITEM_AUTHTYPE_PUBLICKEY, S_PUBLIC_KEY); $row = new CRow(array(new CCol(S_AUTHENTICATION_METHOD, 'form_row_l'), new CCol($cmbAuthType, 'form_row_r'))); $row->setAttribute('id', 'row_authtype'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'authtype'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'row_authtype'); $row = new CRow(array(new CCol(S_USER_NAME, 'form_row_l'), new CCol(new CTextBox('username', $username, 16), 'form_row_r'))); $row->setAttribute('id', 'row_username'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'username'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'row_username'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'username'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'row_username'); $row = new CRow(array(new CCol(S_PUBLIC_KEY_FILE, 'form_row_l'), new CCol(new CTextBox('publickey', $publickey, 16), 'form_row_r'))); $row->setAttribute('id', 'row_publickey'); $frmItem->addRow($row); zbx_subarray_push($authTypeVisibility, ITEM_AUTHTYPE_PUBLICKEY, 'publickey'); zbx_subarray_push($authTypeVisibility, ITEM_AUTHTYPE_PUBLICKEY, 'row_publickey'); $row = new CRow(array(new CCol(S_PRIVATE_KEY_FILE, 'form_row_l'), new CCol(new CTextBox('privatekey', $privatekey, 16), 'form_row_r'))); $row->setAttribute('id', 'row_privatekey'); $frmItem->addRow($row); zbx_subarray_push($authTypeVisibility, ITEM_AUTHTYPE_PUBLICKEY, 'privatekey'); zbx_subarray_push($authTypeVisibility, ITEM_AUTHTYPE_PUBLICKEY, 'row_privatekey'); $row = new CRow(array(new CCol(S_PASSWORD, 'form_row_l'), new CCol(new CTextBox('password', $password, 16), 'form_row_r'))); $row->setAttribute('id', 'row_password'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'password'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'row_password'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'password'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'row_password'); $spanEC = new CSpan(S_EXECUTED_SCRIPT); $spanEC->setAttribute('id', 'label_executed_script'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'label_executed_script'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'label_executed_script'); $spanP = new CSpan(S_PARAMS); $spanP->setAttribute('id', 'label_params'); zbx_subarray_push($typeVisibility, ITEM_TYPE_DB_MONITOR, 'label_params'); $spanF = new CSpan(S_FORMULA); $spanF->setAttribute('id', 'label_formula'); zbx_subarray_push($typeVisibility, ITEM_TYPE_CALCULATED, 'label_formula'); $params_script = new CTextArea('params', $params, 60, 4); $params_script->setAttribute('id', 'params_script'); $params_dbmonitor = new CTextArea('params', $params, 60, 4); $params_dbmonitor->setAttribute('id', 'params_dbmonitor'); $params_calculted = new CTextArea('params', $params, 60, 4); $params_calculted->setAttribute('id', 'params_calculted'); $row = new CRow(array(new CCol(array($spanEC, $spanP, $spanF), 'form_row_l'), new CCol(array($params_script, $params_dbmonitor, $params_calculted), 'form_row_r'))); $row->setAttribute('id', 'row_params'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'params_script'); zbx_subarray_push($typeVisibility, ITEM_TYPE_SSH, 'row_params'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'params_script'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TELNET, 'row_params'); zbx_subarray_push($typeVisibility, ITEM_TYPE_DB_MONITOR, 'params_dbmonitor'); zbx_subarray_push($typeVisibility, ITEM_TYPE_DB_MONITOR, 'row_params'); zbx_subarray_push($typeVisibility, ITEM_TYPE_CALCULATED, 'params_calculted'); zbx_subarray_push($typeVisibility, ITEM_TYPE_CALCULATED, 'row_params'); /* ITEM_TYPE_DB_MONITOR $key = 'db.odbc.select[<unique short description>]'; $params = "DSN=<database source name>\nuser=<user name>\npassword=<password>\nsql=<query>"; ITEM_TYPE_SSH $key = 'ssh.run[<unique short description>,<ip>,<port>,<encoding>]'; $params = ''; ITEM_TYPE_TELNET $key = 'telnet.run[<unique short description>,<ip>,<port>,<encoding>]'; $params = ''; ITEM_TYPE_CALCULATED $key = ''; $params = ''; //*/ if (isset($limited)) { $frmItem->addVar('value_type', $value_type); $cmbValType = new CTextBox('value_type_name', item_value_type2str($value_type), 40, 'yes'); } else { $cmbValType = new CComboBox('value_type', $value_type); $cmbValType->addItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UNSIGNED); $cmbValType->addItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); $cmbValType->addItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); $cmbValType->addItem(ITEM_VALUE_TYPE_LOG, S_LOG); $cmbValType->addItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); } $frmItem->addRow(S_TYPE_OF_INFORMATION, $cmbValType); if (isset($limited)) { $frmItem->addVar('data_type', $data_type); $cmbDataType = new CTextBox('data_type_name', item_data_type2str($data_type), 20, 'yes'); } else { $cmbDataType = new CComboBox('data_type', $data_type); $cmbDataType->addItem(ITEM_DATA_TYPE_DECIMAL, item_data_type2str(ITEM_DATA_TYPE_DECIMAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_OCTAL, item_data_type2str(ITEM_DATA_TYPE_OCTAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_HEXADECIMAL, item_data_type2str(ITEM_DATA_TYPE_HEXADECIMAL)); } $row = new CRow(array(new CCol(S_DATA_TYPE, 'form_row_l'), new CCol($cmbDataType, 'form_row_r'))); $row->setAttribute('id', 'row_data_type'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'data_type'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_data_type'); $row = new CRow(array(new CCol(S_UNITS, 'form_row_l'), new CCol(new CTextBox('units', $units, 40, $limited), 'form_row_r'))); $row->setAttribute('id', 'row_units'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'units'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'row_units'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'units'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_units'); $mltpbox = array(); if (isset($limited)) { $frmItem->addVar('multiplier', $multiplier); $mcb = new CCheckBox('multiplier', $multiplier == 1 ? 'yes' : 'no'); $mcb->setAttribute('disabled', 'disabled'); $mltpbox[] = $mcb; if ($multiplier) { $mltpbox[] = SPACE; $ctb = new CTextBox('formula', $formula, 10, 1); $ctb->setAttribute('style', 'text-align: right;'); $mltpbox[] = $ctb; } else { $frmItem->addVar('formula', $formula); } } else { $mltpbox[] = new CCheckBox('multiplier', $multiplier == 1 ? 'yes' : 'no', 'var editbx = document.getElementById(\'formula\'); if(editbx) editbx.disabled = !this.checked;', 1); $mltpbox[] = SPACE; $ctb = new CTextBox('formula', $formula, 10); $ctb->setAttribute('style', 'text-align: right;'); $mltpbox[] = $ctb; } $row = new CRow(array(new CCol(S_USE_CUSTOM_MULTIPLIER, 'form_row_l'), new CCol($mltpbox, 'form_row_r'))); $row->setAttribute('id', 'row_multiplier'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'multiplier'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'row_multiplier'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'multiplier'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_multiplier'); $row = new CRow(array(new CCol(S_UPDATE_INTERVAL_IN_SEC, 'form_row_l'), new CCol(new CNumericBox('delay', $delay, 5), 'form_row_r'))); $row->setAttribute('id', 'row_delay'); $frmItem->addRow($row); foreach ($types as $it => $ilabel) { if ($it == ITEM_TYPE_TRAPPER) { continue; } zbx_subarray_push($typeVisibility, $it, 'delay'); zbx_subarray_push($typeVisibility, $it, 'row_delay'); } $row = new CRow(array(new CCol(S_FLEXIBLE_INTERVALS, 'form_row_l'), new CCol($delay_flex_el, 'form_row_r'))); $row->setAttribute('id', 'row_flex_intervals'); $frmItem->addRow($row); $row = new CRow(array(new CCol(S_NEW_FLEXIBLE_INTERVAL, 'form_row_l'), new CCol(array(S_DELAY, SPACE, new CNumericBox('new_delay_flex[delay]', '50', 5), S_PERIOD, SPACE, new CTextBox('new_delay_flex[period]', '1-7,00:00-23:59', 27), BR(), new CButton('add_delay_flex', S_ADD)), 'form_row_r')), 'new'); $row->setAttribute('id', 'row_new_delay_flex'); $frmItem->addRow($row); foreach ($types as $it => $ilabel) { if ($it == ITEM_TYPE_TRAPPER || $it == ITEM_TYPE_ZABBIX_ACTIVE) { continue; } zbx_subarray_push($typeVisibility, $it, 'row_flex_intervals'); zbx_subarray_push($typeVisibility, $it, 'row_new_delay_flex'); zbx_subarray_push($typeVisibility, $it, 'new_delay_flex[delay]'); zbx_subarray_push($typeVisibility, $it, 'new_delay_flex[period]'); zbx_subarray_push($typeVisibility, $it, 'add_delay_flex'); } $frmItem->addRow(S_KEEP_HISTORY_IN_DAYS, array(new CNumericBox('history', $history, 8), !isset($_REQUEST['itemid']) ? null : new CButtonQMessage('del_history', S_CLEAR_HISTORY, S_HISTORY_CLEARING_CAN_TAKE_A_LONG_TIME_CONTINUE_Q))); $row = new CRow(array(new CCol(S_KEEP_TRENDS_IN_DAYS, 'form_row_l'), new CCol(new CNumericBox('trends', $trends, 8), 'form_row_r'))); $row->setAttribute('id', 'row_trends'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'trends'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'row_trends'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'trends'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_trends'); $cmbStatus = new CComboBox('status', $status); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED) as $st) { $cmbStatus->addItem($st, item_status2str($st)); } $frmItem->addRow(S_STATUS, $cmbStatus); $row = new CRow(array(new CCol(S_LOG_TIME_FORMAT, 'form_row_l'), new CCol(new CTextBox('logtimefmt', $logtimefmt, 16, $limited), 'form_row_r'))); $row->setAttribute('id', 'row_logtimefmt'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_LOG, 'logtimefmt'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_LOG, 'row_logtimefmt'); $cmbDelta = new CComboBox('delta', $delta); $cmbDelta->addItem(0, S_AS_IS); $cmbDelta->addItem(1, S_DELTA_SPEED_PER_SECOND); $cmbDelta->addItem(2, S_DELTA_SIMPLE_CHANGE); $row = new CRow(array(new CCol(S_STORE_VALUE, 'form_row_l'), new CCol($cmbDelta, 'form_row_r'))); $row->setAttribute('id', 'row_delta'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'delta'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'row_delta'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'delta'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_delta'); if (isset($limited)) { $frmItem->addVar('valuemapid', $valuemapid); $map_name = S_AS_IS; if ($map_data = DBfetch(DBselect('SELECT name FROM valuemaps WHERE valuemapid=' . $valuemapid))) { $map_name = $map_data['name']; } $cmbMap = new CTextBox('valuemap_name', $map_name, 20, 'yes'); } else { $cmbMap = new CComboBox('valuemapid', $valuemapid); $cmbMap->addItem(0, S_AS_IS); $db_valuemaps = DBselect('SELECT * FROM valuemaps WHERE ' . DBin_node('valuemapid')); while ($db_valuemap = DBfetch($db_valuemaps)) { $cmbMap->addItem($db_valuemap['valuemapid'], get_node_name_by_elid($db_valuemap['valuemapid'], null, ': ') . $db_valuemap['name']); } } $link = new CLink(S_SHOW_VALUE_MAPPINGS, 'config.php?config=6'); $link->setAttribute('target', '_blank'); $row = new CRow(array(new CCol(S_SHOW_VALUE), new CCol(array($cmbMap, SPACE, $link)))); $row->setAttribute('id', 'row_valuemap'); $frmItem->addRow($row); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'valuemapid'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'row_valuemap'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_FLOAT, 'valuemap_name'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'valuemapid'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'row_valuemap'); zbx_subarray_push($valueTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'valuemap_name'); $row = new CRow(array(new CCol(S_ALLOWED_HOSTS, 'form_row_l'), new CCol(new CTextBox('trapper_hosts', $trapper_hosts, 40), 'form_row_r'))); $row->setAttribute('id', 'row_trapper_hosts'); $frmItem->addRow($row); zbx_subarray_push($typeVisibility, ITEM_TYPE_TRAPPER, 'trapper_hosts'); zbx_subarray_push($typeVisibility, ITEM_TYPE_TRAPPER, 'row_trapper_hosts'); $new_app = new CTextBox('new_application', $new_application, 40); $frmItem->addRow(S_NEW_APPLICATION, $new_app, 'new'); $cmbApps = new CListBox('applications[]', $applications, 6); $cmbApps->addItem(0, '-' . S_NONE . '-'); $sql = 'SELECT DISTINCT applicationid,name ' . ' FROM applications ' . ' WHERE hostid=' . $hostid . ' ORDER BY name'; $db_applications = DBselect($sql); while ($db_app = DBfetch($db_applications)) { $cmbApps->addItem($db_app['applicationid'], $db_app['name']); } $frmItem->addRow(S_APPLICATIONS, $cmbApps); $frmRow = array(new CButton('save', S_SAVE)); if (isset($_REQUEST['itemid'])) { array_push($frmRow, SPACE, new CButton('clone', S_CLONE)); if (!isset($limited)) { array_push($frmRow, SPACE, new CButtonDelete(S_DELETE_SELECTED_ITEM_Q, url_param('form') . url_param('groupid') . url_param('itemid'))); } } array_push($frmRow, SPACE, new CButtonCancel(url_param('groupid'))); $frmItem->addSpanRow($frmRow, 'form_row_last'); // GROUP OPERATIONS $cmbGroups = new CComboBox('add_groupid', $add_groupid); $groups = CHostGroup::get(array('editable' => 1, 'output' => API_OUTPUT_EXTEND)); order_result($groups, 'name'); foreach ($groups as $group) { $cmbGroups->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } $frmItem->addRow(S_GROUP, $cmbGroups); $cmbAction = new CComboBox('action'); $cmbAction->addItem('add to group', S_ADD_TO_GROUP); if (isset($_REQUEST['itemid'])) { $cmbAction->addItem('update in group', S_UPDATE_IN_GROUP); $cmbAction->addItem('delete FROM group', S_DELETE_FROM_GROUP); } $frmItem->addItemToBottomRow(array($cmbAction, SPACE, new CButton('register', S_DO))); $json = new CJSON(); zbx_add_post_js("var valueTypeSwitcher = new CViewSwitcher('value_type', 'change', " . zbx_jsvalue($valueTypeVisibility, true) . ");"); zbx_add_post_js("var authTypeSwitcher = new CViewSwitcher('authtype', 'change', " . zbx_jsvalue($authTypeVisibility, true) . ");"); zbx_add_post_js("var typeSwitcher = new CViewSwitcher('type', 'change', " . zbx_jsvalue($typeVisibility, true) . (isset($_REQUEST['itemid']) ? ', true' : '') . ');'); zbx_add_post_js("var securityLevelSwitcher = new CViewSwitcher('snmpv3_securitylevel', 'change', " . zbx_jsvalue($securityLevelVisibility, true) . ");"); zbx_add_post_js("var multpStat = document.getElementById('multiplier'); if(multpStat && multpStat.onclick) multpStat.onclick();"); zbx_add_post_js("var mnFrmTbl = document.getElementById('web.items.item.php'); if(mnFrmTbl) mnFrmTbl.style.visibility = 'visible';"); return $frmItem; }
if (isset($_REQUEST['filter_description']) && !zbx_stristr($item_description, $_REQUEST['filter_description'])) { continue; } if ($db_item['templateid']) { $template_host = get_realhost_by_itemid($db_item['templateid']); array_push($description, new CLink($template_host['host'], '?' . 'hostid=' . $template_host['hostid'], 'unknown'), ':'); } array_push($description, new CLink(item_description($db_item), '?form=update&itemid=' . $db_item['itemid'] . '&hostid=' . $db_item['hostid'])); $status = new CCol(new CLink(item_status2str($db_item['status']), '?group_itemid%5B%5D=' . $db_item['itemid'] . '&go=' . ($db_item['status'] ? 'activate' : 'disable'), item_status2style($db_item['status']))); if (!zbx_empty($db_item['error'])) { $error = new CDiv(SPACE, 'error_icon'); $error->setHint($db_item['error'], '', 'on'); } else { $error = new CDiv(SPACE, 'ok_icon'); } $applications = $show_applications ? implode(', ', get_applications_by_itemid($db_item['itemid'], 'name')) : null; if (!is_null($applications) && empty($applications)) { $applications = ' - '; } $applications = new CCol($applications, 'wraptext'); $table->addRow(array(new CCheckBox('group_itemid[' . $db_item['itemid'] . ']', null, null, $db_item['itemid']), $show_host ? $db_item['host'] : null, $description, $db_item['key_'], $db_item['delay'], $db_item['history'], $db_item['trends'], item_type2str($db_item['type']), $status, $applications, $error)); $row_count++; } //----- GO ------ $goBox = new CComboBox('go'); $goBox->addItem('activate', S_ACTIVATE_SELECTED); $goBox->addItem('disable', S_DISABLE_SELECTED); $goBox->addItem('massupdate', S_MASS_UPDATE); $goBox->addItem('copy_to', S_COPY_SELECTED_TO); $goBox->addItem('clean_history', S_CLEAN_HISTORY_SELECTED_ITEMS); $goBox->addItem('delete', S_DELETE_SELECTED);