/** * Check if application exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('application.exists method is deprecated.'); $application = $this->get(array('output' => array('applicationid'), 'filter' => zbx_array_mintersect(array(array('hostid', 'host'), 'name'), $object), 'limit' => 1)); return (bool) $application; }
public function exists($data) { $keyFields = array(array('screenid', 'name'), 'templateid'); $options = array('filter' => zbx_array_mintersect($keyFields, $data), 'preservekeys' => true, 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true, 'limit' => 1); if (isset($data['node'])) { $options['nodeids'] = getNodeIdByNodeName($data['node']); } elseif (isset($data['nodeids'])) { $options['nodeids'] = $data['nodeids']; } $screens = $this->get($options); return !empty($screens); }
/** * Is interface exist. * * @param array $object * * @return bool */ public function exists(array $object) { $keyFields = array('interfaceid', 'hostid', 'ip', 'dns'); $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => array('interfaceid'), 'nopermissions' => true, 'limit' => 1); if (isset($object['node'])) { $options['nodeids'] = getNodeIdByNodeName($object['node']); } elseif (isset($object['nodeids'])) { $options['nodeids'] = $object['nodeids']; } $objs = $this->get($options); return !empty($objs); }
/** * @param $object * * @return bool */ public function exists(array $object) { $keyFields = array(array('hostid', 'host'), 'description'); $result = false; if (!isset($object['hostid']) && !isset($object['host'])) { $expressionData = new CTriggerExpression(); if (!$expressionData->parse($object['expression'])) { return false; } $expressionHosts = $expressionData->getHosts(); $object['host'] = reset($expressionHosts); } $options = array('filter' => array_merge(zbx_array_mintersect($keyFields, $object), array('flags' => null)), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => true); if (isset($object['node'])) { $options['nodeids'] = getNodeIdByNodeName($object['node']); } elseif (isset($object['nodeids'])) { $options['nodeids'] = $object['nodeids']; } $triggers = $this->get($options); foreach ($triggers as $trigger) { $tmpExp = explode_exp($trigger['expression']); if (strcmp($tmpExp, $object['expression']) == 0) { $result = true; break; } } return $result; }
/** * Updates the host prototypes and propagates the changes to linked hosts and templates. * * @param array $hostPrototypes * * @return array */ protected function updateReal(array $hostPrototypes) { // save the host prototypes foreach ($hostPrototypes as $hostPrototype) { DB::updateByPk($this->tableName(), $hostPrototype['hostid'], $hostPrototype); } $exHostPrototypes = $this->get(['output' => ['hostid'], 'selectGroupLinks' => API_OUTPUT_EXTEND, 'selectGroupPrototypes' => API_OUTPUT_EXTEND, 'selectTemplates' => ['templateid'], 'selectInventory' => API_OUTPUT_EXTEND, 'hostids' => zbx_objectValues($hostPrototypes, 'hostid'), 'preservekeys' => true]); // update related objects $inventoryCreate = []; $inventoryDeleteIds = []; foreach ($hostPrototypes as $key => $hostPrototype) { $exHostPrototype = $exHostPrototypes[$hostPrototype['hostid']]; // group prototypes if (isset($hostPrototype['groupPrototypes'])) { foreach ($hostPrototype['groupPrototypes'] as &$groupPrototype) { $groupPrototype['hostid'] = $hostPrototype['hostid']; } unset($groupPrototype); // save group prototypes $exGroupPrototypes = zbx_toHash(array_merge($exHostPrototype['groupLinks'], $exHostPrototype['groupPrototypes']), 'group_prototypeid'); $modifiedGroupPrototypes = []; foreach ($hostPrototype['groupPrototypes'] as $groupPrototype) { if (isset($groupPrototype['group_prototypeid'])) { unset($exGroupPrototypes[$groupPrototype['group_prototypeid']]); } $modifiedGroupPrototypes[] = $groupPrototype; } if ($exGroupPrototypes) { $this->deleteGroupPrototypes(array_keys($exGroupPrototypes)); } $hostPrototypes[$key]['groupPrototypes'] = DB::save('group_prototype', $modifiedGroupPrototypes); } // templates if (isset($hostPrototype['templates'])) { $existingTemplateIds = zbx_objectValues($exHostPrototype['templates'], 'templateid'); $newTemplateIds = zbx_objectValues($hostPrototype['templates'], 'templateid'); $this->unlink(array_diff($existingTemplateIds, $newTemplateIds), [$hostPrototype['hostid']]); $this->link(array_diff($newTemplateIds, $existingTemplateIds), [$hostPrototype['hostid']]); } // inventory if (isset($hostPrototype['inventory'])) { $inventory = zbx_array_mintersect(['inventory_mode'], $hostPrototype['inventory']); $inventory['hostid'] = $hostPrototype['hostid']; if ($hostPrototype['inventory'] && (!isset($hostPrototype['inventory']['inventory_mode']) || $hostPrototype['inventory']['inventory_mode'] != HOST_INVENTORY_DISABLED)) { if ($exHostPrototype['inventory']) { DB::update('host_inventory', ['values' => $inventory, 'where' => ['hostid' => $inventory['hostid']]]); } else { $inventoryCreate[] = $inventory; } } else { $inventoryDeleteIds[] = $hostPrototype['hostid']; } } } // save inventory DB::insert('host_inventory', $inventoryCreate, false); DB::delete('host_inventory', ['hostid' => $inventoryDeleteIds]); // TODO: REMOVE info $updatedHostPrototypes = $this->get(['hostids' => zbx_objectValues($hostPrototypes, 'hostid'), 'output' => ['host'], 'selectParentHost' => ['host'], 'nopermissions' => true]); foreach ($updatedHostPrototypes as $hostProtototype) { info(_s('Updated: Host prototype "%1$s" on "%2$s".', $hostProtototype['host'], $hostProtototype['parentHost']['host'])); } return $hostPrototypes; }
public function exists($object) { $keyFields = array(array('dserviceid')); $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1, 'limit' => 1); if (isset($object['node'])) { $options['nodeids'] = getNodeIdByNodeName($object['node']); } elseif (isset($object['nodeids'])) { $options['nodeids'] = $object['nodeids']; } $objs = $this->get($options); return !empty($objs); }
public static function exists($object) { $keyFields = array(array('hostid', 'host'), 'description'); $result = false; if (!isset($object['hostid']) && !isset($object['host'])) { $expr = new CTriggerExpression($object); $expression = $object['expression']; if (!empty($expr->errors)) { return false; } if (empty($expr->data['hosts'])) { return false; } $object['host'] = reset($expr->data['hosts']); } $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1); if (isset($object['node'])) { $options['nodeids'] = getNodeIdByNodeName($object['node']); } else { if (isset($object['nodeids'])) { $options['nodeids'] = $object['nodeids']; } } $triggers = self::get($options); foreach ($triggers as $tnum => $trigger) { $tmp_exp = explode_exp($trigger['expression'], false); if (strcmp($tmp_exp, $object['expression']) == 0) { $result = true; break; } } return $result; }
/** * Check if host group exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('hostgroup.exists method is deprecated.'); $hostGroup = $this->get(array('output' => array('groupid'), 'filter' => zbx_array_mintersect(array('name', 'groupid'), $object), 'limit' => 1)); return (bool) $hostGroup; }
public static function exists($object) { $keyFields = array('name', 'groupid'); $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1, 'limit' => 1); if (isset($object['node'])) { $options['nodeids'] = getNodeIdByNodeName($object['node']); } else { if (isset($object['nodeids'])) { $options['nodeids'] = $object['nodeids']; } } $objs = self::get($options); return !empty($objs); }
/** * Check if trigger exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('trigger.exists method is deprecated.'); $keyFields = array(array('hostid', 'host'), 'description'); $result = false; if (!isset($object['hostid']) && !isset($object['host'])) { $expressionData = new CTriggerExpression(); if (!$expressionData->parse($object['expression'])) { return false; } $expressionHosts = $expressionData->getHosts(); $object['host'] = reset($expressionHosts); } $triggers = $this->get(array('filter' => array_merge(zbx_array_mintersect($keyFields, $object), array('flags' => null)), 'output' => API_OUTPUT_EXTEND)); foreach ($triggers as $trigger) { $tmpExp = explode_exp($trigger['expression']); if (strcmp($tmpExp, $object['expression']) == 0) { $result = true; break; } } return $result; }
/** * Check if discovered host exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('dhost.exists method is deprecated.'); $dHost = $this->get(array('output' => array('dhostid'), 'filter' => zbx_array_mintersect(array(array('dhostid')), $object), 'limit' => 1)); return (bool) $dHost; }
/** * Check if template screen exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('templatescreen.exists method is deprecated.'); $templateScreen = $this->get(array('output' => array('screenid'), 'filter' => zbx_array_mintersect(array(array('screenid', 'name'), 'templateid'), $object), 'preservekeys' => true, 'limit' => 1)); return (bool) $templateScreen; }
public static function exists($data) { $keyFields = array(array('screenid', 'name')); $options = array('filter' => zbx_array_mintersect($keyFields, $data), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1, 'limit' => 1); if (isset($data['node'])) { $options['nodeids'] = getNodeIdByNodeName($data['node']); } else { if (isset($data['nodeids'])) { $options['nodeids'] = $data['nodeids']; } } $sysmaps = self::get($options); return !empty($sysmaps); }
/** * Check if host interface exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('hostinterface.exists method is deprecated.'); $hostInterface = $this->get(array('output' => array('interfaceid'), 'filter' => zbx_array_mintersect(array('interfaceid', 'hostid', 'ip', 'dns'), $object), 'limit' => 1)); return (bool) $hostInterface; }
/** * Check if maintenance exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('maintenance.exists method is deprecated.'); $keyFields = array(array('maintenanceid', 'name')); $maintenance = $this->get(array('output' => array('maintenanceid'), 'filter' => zbx_array_mintersect($keyFields, $object), 'limit' => 1)); return (bool) $maintenance; }
/** * Check if template exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('template.exists method is deprecated.'); $template = $this->get(array('output' => array('templateid'), 'filter' => zbx_array_mintersect(array(array('templateid', 'host', 'name')), $object), 'limit' => 1)); return (bool) $template; }
/** * Determine, whether an object already exists * * @param array $object * @return bool */ public function exists(array $object) { $keyFields = array(array('maintenanceid', 'name')); $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => array('maintenanceid'), 'nopermissions' => true, 'limit' => 1); $objs = $this->get($options); return !empty($objs); }
/** * Check if image exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('image.exists method is deprecated.'); $image = $this->get(array('output' => array('imageid'), 'filter' => zbx_array_mintersect(array(array('imageid', 'name'), 'imagetype'), $object), 'limit' => 1)); return (bool) $image; }
/** * Check if map exists. * * @deprecated As of version 2.4, use get method instead. * * @param array $object * * @return bool */ public function exists(array $object) { $this->deprecated('map.exists method is deprecated.'); $map = $this->get(array('output' => array('sysmapid'), 'filter' => zbx_array_mintersect(array(array('sysmapid', 'name')), $object), 'limit' => 1)); return (bool) $map; }
/** * Determine, whether an object already exists * * @param array $object * @return bool */ public static function exists($object) { $keyFields = array(array('maintenanceid', 'name')); $options = array('filter' => zbx_array_mintersect($keyFields, $object), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1, 'limit' => 1); $objs = self::get($options); return !empty($objs); }