Example #1
0
 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);
 }
Example #2
0
 $templates = get_request('templates', array());
 $_REQUEST['proxy_hostid'] = get_request('proxy_hostid', 0);
 $clone_hostid = false;
 if ($_REQUEST['form'] == 'full_clone') {
     $clone_hostid = $_REQUEST['hostid'];
     unset($_REQUEST['hostid']);
 }
 $result = true;
 DBstart();
 if (isset($_REQUEST['hostid'])) {
     if (isset($_REQUEST['clear_templates'])) {
         foreach ($_REQUEST['clear_templates'] as $id) {
             $result &= unlink_template($_REQUEST['hostid'], $id, false);
         }
     }
     $result = update_host($_REQUEST['hostid'], $_REQUEST['host'], $_REQUEST['port'], $_REQUEST['status'], $useip, $_REQUEST['dns'], $_REQUEST['ip'], $_REQUEST['proxy_hostid'], $templates, $useipmi, $_REQUEST['ipmi_ip'], $_REQUEST['ipmi_port'], $_REQUEST['ipmi_authtype'], $_REQUEST['ipmi_privilege'], $_REQUEST['ipmi_username'], $_REQUEST['ipmi_password'], $_REQUEST['newgroup'], $groups);
     $msg_ok = S_HOST_UPDATED;
     $msg_fail = S_CANNOT_UPDATE_HOST;
     /*			$audit_action 	= AUDIT_ACTION_UPDATE;*/
     $hostid = $_REQUEST['hostid'];
 } else {
     $hostid = $result = add_host($_REQUEST['host'], $_REQUEST['port'], $_REQUEST['status'], $useip, $_REQUEST['dns'], $_REQUEST['ip'], $_REQUEST['proxy_hostid'], $templates, $useipmi, $_REQUEST['ipmi_ip'], $_REQUEST['ipmi_port'], $_REQUEST['ipmi_authtype'], $_REQUEST['ipmi_privilege'], $_REQUEST['ipmi_username'], $_REQUEST['ipmi_password'], $_REQUEST['newgroup'], $groups);
     $msg_ok = S_HOST_ADDED;
     $msg_fail = S_CANNOT_ADD_HOST;
     /*			$audit_action 	= AUDIT_ACTION_ADD;*/
 }
 if (!zbx_empty($hostid) && $hostid && $clone_hostid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_hostid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
Example #3
0
<?php

$domain = "userhost.ffbin";
include 'inc/functions.inc';
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_REQUEST['hostname']) && isset($_REQUEST['token'])) {
    $hostname = strtolower($_REQUEST['hostname']);
    $token = $_REQUEST['token'];
    $hostip = $_SERVER['REMOTE_ADDR'];
    if (update_host($hostname, $token, $hostip)) {
        //OK
        http_response_code("200");
        syslog(LOG_INFO, "Renewed reservation for host '{$hostname}.{$domain}' on IP '{$hostip}'");
        echo "OK";
    }
} else {
    //Bad request
    http_response_code(400);
    echo "FAIL";
}
Example #4
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;
     }
 }
Example #5
0
$cpu_speed = (int) $xml->cpu->speed;
# connect to DB
$db = connect_db($mysqlserver, $mysqluser, $mysqlpassword, $mysqldatabase);
#print_result(query_db("SELECT host.id,host.hostname,network.macaddr FROM host,network WHERE host.hostname = '$xml->hostname' AND network.macaddr = '$xml->macaddr' AND host.id = network.host_id"));
# search for the hardware id to see if it's in the DB
$host = mysql_fetch_assoc(query_db("SELECT * FROM host WHERE host.hwid = '{$hwid}'"));
$os_id = insert_os($os_name, $os_arch, $os_basearch, $os_kernel);
if ($xml->cpu->unified_cache) {
    $cpu_unified_cache = (bool) $xml->cpu->unified_cache;
} else {
    $cpu_unified_cache = false;
}
$cpu_id = insert_cpu($cpu_cache, $cpu_name, $cpu_speed, $cpu_unified_cache);
if ($host["hwid"]) {
    echo "this host exists with hwid of : {$host['hwid']}\n";
    $host_id = update_host($hostname, $domain, $hwid, $os_id, $cpu_id, $cpu_count, $swaptotal, $memtotal);
} else {
    echo "this is new hardware\n";
    $host_id = insert_host($hostname, $domain, $hwid, $os_id, $cpu_id, $cpu_count, $swaptotal, $memtotal);
}
if ($xml->nic) {
    insert_network($host_id, $xml->nic);
}
if ($xml->disk) {
    machdb_disk($host_id, $xml->disk);
}
if ($xml->filesystem) {
    machdb_filesystem($host_id, $xml->filesystem);
}
if ($xml->package) {
    machdb_package($host_id, $xml->package);
Example #6
0
<?php

require_once './libraries/common.lib.php';
$action = isset($params['action']) ? $params['action'] : "";
$req_url = $cfg['sc_url'] . $_SERVER["REQUEST_URI"];
include_once './php-ofc-library-2.2/open-flash-chart.php';
switch ($action) {
    case 'edit':
        $u_info = check_login($req_url);
        $host_info = get_host_info($pdo, $params['host_id']);
        $template = 'host_edit';
        break;
    case 'do_edit':
        update_host($pdo, $params['host_id'], array('host_name' => $params['host_name'], 'host_ip' => $params['host_ip'], 'host_memory' => $params['host_memory']));
        msg_redirect("host.php");
        break;
    case 'detail':
        $host_info = get_host_info($pdo, $params['host_id']);
        $host_memory = round($host_info['host_memory'] / 1024, 2);
        /*某host上面的所有instance*/
        $host_instance_list = get_instance_list_complex($pdo, array('host_id' => $params['host_id'], 'with_unbind' => true));
        if ($host_instance_list) {
            /*取近期10min以内的最后一条数据*/
            foreach ($host_instance_list as &$instance) {
                $jvmmem_logs = get_status_log($pdo_log, $cfg['idc'], $cfg['default_host'], 'instance', 'jvmmem', $instance['instance_id'], 'status_log_instance_jvmmemory', 1, array('min' => date('Y-m-d H:i:00', time() - 10 * 60)));
                if ($jvmmem_logs) {
                    $instance['jvmmem'] = $jvmmem_logs[0]['log_value'];
                }
            }
        }
        $json_mem_instance = stacked_bar_chart($host_instance_list);
Example #7
0
         foreach ($unlink_hosts as $id => $value) {
             $result &= unlink_template($value, $templateid, false);
         }
         //-- link --
         $link_hosts = array_diff($hosts, $linked_hosts);
         $template_name = DBfetch(DBselect('SELECT host FROM hosts WHERE hostid=' . $templateid));
         foreach ($link_hosts as $id => $hostid) {
             $host_groups = array();
             $db_hosts_groups = DBselect('SELECT groupid FROM hosts_groups WHERE hostid=' . $hostid);
             while ($hg = DBfetch($db_hosts_groups)) {
                 $host_groups[] = $hg['groupid'];
             }
             $host = get_host_by_hostid($hostid);
             $templates_tmp = get_templates_by_hostid($hostid);
             $templates_tmp[$templateid] = $template_name['host'];
             $result &= update_host($hostid, $host['host'], $host['port'], $host['status'], $host['useip'], $host['dns'], $host['ip'], $host['proxy_hostid'], $templates_tmp, $host['useipmi'], $host['ipmi_ip'], $host['ipmi_port'], $host['ipmi_authtype'], $host['ipmi_privilege'], $host['ipmi_username'], $host['ipmi_password'], null, $host_groups);
         }
     }
     // --->>> <<<---
     $result = DBend($result);
     show_messages($result, $msg_ok, $msg_fail);
     if ($result) {
         unset($_REQUEST['form']);
         unset($_REQUEST['templateid']);
     }
     unset($_REQUEST['save']);
 } else {
     if ((isset($_REQUEST['delete']) || isset($_REQUEST['delete_and_clear'])) && isset($_REQUEST['templateid'])) {
         $unlink_mode = false;
         if (isset($_REQUEST['delete'])) {
             $unlink_mode = true;