Example #1
0
 function StartElement($parser, $name, $attrs)
 {
     $this->element_data = '';
     if (!isset($this->root)) {
         if ($name == XML_TAG_ZABBIX_EXPORT) {
             if (isset($attrs['version'])) {
                 if ($attrs['version'] == '1.0') {
                     $this->root = true;
                     return;
                 } else {
                     error(S_UNSUPPORTED_VERSION_OF_IMPORTED_DATA);
                 }
             }
         }
         error(S_UNSUPPORTED_FILE_FORMAT);
         $this->root = false;
     } else {
         if (!$this->root) {
             return false;
         }
     }
     $data =& $this->data[$name];
     foreach ($attrs as $id => $val) {
         $attrs[$id] = html_entity_decode($val);
     }
     switch ($name) {
         case XML_TAG_HOST:
             $this->main_node = array($name);
             $this->sub_node = null;
             $data = $attrs;
             $data['groups'] = array();
             $data['skip'] = false;
             $sql = 'SELECT hostid ' . ' FROM hosts' . ' WHERE host=' . zbx_dbstr($data['name']) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')' . ' AND ' . DBin_node('hostid', get_current_nodeid(false));
             if ($host_data = DBfetch(DBselect($sql))) {
                 /* exist */
                 if ($this->host['exist'] == 1) {
                     $data['skip'] = true;
                     info('Host [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!isset($this->available_hosts[$host_data['hostid']])) {
                     error('Host [' . $data['name'] . '] skipped - Access deny.');
                     break;
                     // case
                 }
                 $data['hostid'] = $host_data['hostid'];
                 $data['templates'] = get_templates_by_hostid($host_data['hostid']);
                 $data['groups'] = get_groupids_by_host($host_data['hostid']);
             } else {
                 /* missed */
                 if ($this->host['missed'] == 1) {
                     /* skip */
                     $data['skip'] = true;
                     info('Host [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!uint_in_array(get_current_nodeid(), $this->available_nodes)) {
                     error('Host [' . $data['name'] . '] skipped - access denied.');
                     break;
                     // case
                 }
                 $data['templates'] = array();
                 $data['hostid'] = add_host($data['name'], 10050, HOST_STATUS_TEMPLATE, 0, '', '', 0, array(), 'no', '', 623, -1, 2, '', '', null, array());
             }
             break;
             // case
         // case
         case XML_TAG_GRAPH:
             $data = $attrs;
             $data['items'] = array();
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
             // case
         // case
         case XML_TAG_DEPENDENCY:
             // checks if trigger has been skipped
             if (str_in_array($attrs['description'], $this->data[XML_TAG_DEPENDENCIES]['skip'])) {
                 info('Trigger [' . $attrs['description'] . '] dependency update skipped - user rule');
                 break;
             }
             // searches trigger by host name & trigger description
             if (!($trigger_down = get_trigger_by_description($attrs['description']))) {
                 error('Trigger [' . $attrs['description'] . '] dependency update skipped - trigger not found');
                 break;
             }
             $data['triggerid_down'] = $trigger_down['triggerid'];
             $data['triggerid_up'] = array();
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
         case XML_TAG_HOSTPROFILE:
         case XML_TAG_HOSTPROFILE_EXT:
         case XML_TAG_TEMPLATE:
         case XML_TAG_ITEM:
         case XML_TAG_TRIGGER:
         case XML_TAG_DEPENDS:
         case XML_TAG_GRAPH_ELEMENT:
             /*case XML_TAG_SCREEN:
             		case XML_TAG_SCREEN_ELEMENT:*/
             $data = $attrs;
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
             // case
         // case
         case XML_TAG_HOSTS:
             $this->data[XML_TAG_DEPENDENCIES]['skip'] = array();
             break;
         case XML_TAG_DEPENDENCIES:
         case XML_TAG_ZABBIX_EXPORT:
         case XML_TAG_GROUPS:
         case XML_TAG_APPLICATIONS:
         case XML_TAG_TEMPLATES:
         case XML_TAG_ITEMS:
         case XML_TAG_TRIGGERS:
         case XML_TAG_GRAPHS:
             /* case XML_TAG_SCREENS:*/
             $this->sub_node = null;
             break;
             // case
         // case
         case XML_TAG_GROUP:
         case XML_TAG_APPLICATION:
         default:
             $this->sub_node = $name;
             break;
             // case
     }
 }
Example #2
0
 foreach ($hosts as $id => $hostid) {
     $db_host = get_host_by_hostid($hostid);
     $db_templates = get_templates_by_hostid($hostid);
     foreach ($db_host as $key => $value) {
         if (isset($visible[$key])) {
             if ($key == 'useipmi') {
                 $db_host[$key] = get_request('useipmi', 'no');
             } else {
                 $db_host[$key] = $_REQUEST[$key];
             }
         }
     }
     if (isset($visible['groups'])) {
         $db_host['groups'] = $_REQUEST['groups'];
     } else {
         $db_host['groups'] = get_groupids_by_host($hostid);
     }
     if (isset($visible['template_table'])) {
         foreach ($db_templates as $templateid => $name) {
             $result &= unlink_template($hostid, $templateid, false);
         }
         $db_host['templates'] = $_REQUEST['templates'];
     } else {
         $db_host['templates'] = $db_templates;
     }
     $result = update_host($hostid, $db_host['host'], $db_host['port'], $db_host['status'], $db_host['useip'], $db_host['dns'], $db_host['ip'], $db_host['proxy_hostid'], $db_host['templates'], $db_host['useipmi'], $db_host['ipmi_ip'], $db_host['ipmi_port'], $db_host['ipmi_authtype'], $db_host['ipmi_privilege'], $db_host['ipmi_username'], $db_host['ipmi_password'], $_REQUEST['newgroup'], $db_host['groups']);
     if ($result && isset($visible['useprofile'])) {
         $host_profile = DBfetch(DBselect('SELECT * FROM hosts_profiles WHERE hostid=' . $hostid));
         $host_profile_fields = array('devicetype', 'name', 'os', 'serialno', 'tag', 'macaddress', 'hardware', 'software', 'contact', 'location', 'notes');
         delete_host_profile($hostid);
         if (get_request('useprofile', 'no') == 'yes') {
Example #3
0
 /**
  * Update Host
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $hosts multidimensional array with Hosts data
  * @param string $hosts['host'] Host name.
  * @param int $hosts['port'] Port. OPTIONAL
  * @param int $hosts['status'] Host Status. OPTIONAL
  * @param int $hosts['useip'] Use IP. OPTIONAL
  * @param string $hosts['dns'] DNS. OPTIONAL
  * @param string $hosts['ip'] IP. OPTIONAL
  * @param int $hosts['proxy_hostid'] Proxy Host ID. OPTIONAL
  * @param int $hosts['useipmi'] Use IPMI. OPTIONAL
  * @param string $hosts['ipmi_ip'] IPMAI IP. OPTIONAL
  * @param int $hosts['ipmi_port'] IPMI port. OPTIONAL
  * @param int $hosts['ipmi_authtype'] IPMI authentication type. OPTIONAL
  * @param int $hosts['ipmi_privilege'] IPMI privilege. OPTIONAL
  * @param string $hosts['ipmi_username'] IPMI username. OPTIONAL
  * @param string $hosts['ipmi_password'] IPMI password. OPTIONAL
  * @return boolean
  */
 public static function update($hosts)
 {
     $templates = null;
     $newgroup = '';
     $hostids = array();
     $result = false;
     DBstart(false);
     foreach ($hosts as $host) {
         $sql = 'SELECT DISTINCT * ' . ' FROM hosts ' . ' WHERE hostid=' . $host['hostid'];
         $host_db_fields = DBfetch(DBselect($sql));
         if (!isset($host_db_fields)) {
             $result = false;
             break;
         }
         if (!check_db_fields($host_db_fields, $host)) {
             $result = false;
             break;
         }
         $groups = get_groupids_by_host($host['hostid']);
         $result = update_host($host['hostid'], $host['host'], $host['port'], $host['status'], $host['useip'], $host['dns'], $host['ip'], $host['proxy_hostid'], $templates, $host['useipmi'], $host['ipmi_ip'], $host['ipmi_port'], $host['ipmi_authtype'], $host['ipmi_privilege'], $host['ipmi_username'], $host['ipmi_password'], $newgroup, $groups);
         if (!$result) {
             break;
         }
         $hostids[$result] = $result;
     }
     $result = DBend($result);
     if ($result) {
         return $hostids;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }