public function addItem($itemid, $calc_fnc = CALC_FNC_AVG, $color = null, $type = null)
 {
     $this->items[$this->num] = get_item_by_itemid($itemid);
     $this->items[$this->num]['name'] = itemName($this->items[$this->num]);
     $host = get_host_by_hostid($this->items[$this->num]['hostid']);
     $this->items[$this->num]['host'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->num++;
 }
Beispiel #2
0
 public function addItem($itemid, $calc_fnc = CALC_FNC_AVG, $color = null, $type = null)
 {
     $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemid)));
     $this->items[$this->num] = reset($items);
     $host = get_host_by_hostid($this->items[$this->num]['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->num++;
 }
Beispiel #3
0
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_RIGHT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null, $periods_cnt = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $this->items[$this->num] = get_item_by_itemid($itemid);
     $this->items[$this->num]['description'] = item_description($this->items[$this->num]);
     $host = get_host_by_hostid($this->items[$this->num]['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_RIGHT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     //		SDI($this->items);
     $this->num++;
 }
Beispiel #4
0
function get_resource_name($permission, $id)
{
    $res = '-';
    if ($permission == 'Graph') {
        if (isset($id) && $id != 0) {
            if ($graph = get_graph_by_graphid($id)) {
                $res = $graph['name'];
            }
        } else {
            if (!isset($id) || $id == 0) {
                $res = 'All graphs';
            }
        }
    } else {
        if ($permission == 'Host') {
            if (isset($id) && $id != 0) {
                if ($host = get_host_by_hostid($id)) {
                    $res = $host['host'];
                }
            } else {
                if (!isset($id) || $id == 0) {
                    $res = 'All hosts';
                }
            }
        } else {
            if ($permission == 'Screen') {
                if (isset($id) && $id != 0) {
                    if ($screen = get_screen_by_screenid($id)) {
                        $res = $screen['name'];
                    }
                } else {
                    if (!isset($id) || $id == 0) {
                        $res = 'All screens';
                    }
                }
            } else {
                if ($permission == 'Item') {
                    if (isset($id) && $id != 0) {
                        if ($item = get_item_by_itemid($id)) {
                            if ($host = get_host_by_hostid($item['hostid'])) {
                                $res = $host['host'] . ':' . $item['description'];
                            }
                        }
                    } else {
                        if (!isset($id) || $id == 0) {
                            $res = 'All items';
                        }
                    }
                } else {
                    if ($permission == 'User') {
                        if (isset($id) && $id != 0) {
                            if ($user = get_user_by_userid($id)) {
                                $res = $user['alias'];
                            }
                        } else {
                            if (!isset($id) || $id == 0) {
                                $res = 'All users';
                            }
                        }
                    } else {
                        if ($permission == 'Network map') {
                            if (isset($id) && $id != 0) {
                                if ($user = get_sysmap_by_sysmapid($id)) {
                                    $res = $user['name'];
                                }
                            } else {
                                if (!isset($id) || $id == 0) {
                                    $res = 'All maps';
                                }
                            }
                        } else {
                            if ($permission == 'Application') {
                                if (isset($id) && $id > 0) {
                                    if ($app = get_application_by_applicationid($id)) {
                                        $res = $app['name'];
                                    }
                                } else {
                                    if (!isset($id) || $id == 0) {
                                        $res = 'All applications';
                                    }
                                }
                            } else {
                                if ($permission == 'Service') {
                                    if (isset($id) && $id > 0) {
                                        if ($service = get_service_by_serviceid($id)) {
                                            $res = $service['name'];
                                        }
                                    } else {
                                        if (!isset($id) || $id == 0) {
                                            $res = 'All services';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($res == '-' && isset($id) && $id > 0) {
        $res = $id;
    }
    return $res;
}
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Display
 */
$data = array('hostid' => getRequest('hostid', 0), 'fullscreen' => $_REQUEST['fullscreen'], 'screenid' => getRequest('screenid', CProfile::get('web.hostscreen.screenid', null)), 'period' => getRequest('period'), 'stime' => getRequest('stime'));
CProfile::update('web.hostscreen.screenid', $data['screenid'], PROFILE_TYPE_ID);
// get screen list
$data['screens'] = API::TemplateScreen()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND));
$data['screens'] = zbx_toHash($data['screens'], 'screenid');
order_result($data['screens'], 'name');
// get screen
$screenid = null;
if (!empty($data['screens'])) {
    $screen = !isset($data['screens'][$data['screenid']]) ? reset($data['screens']) : $data['screens'][$data['screenid']];
    if (!empty($screen['screenid'])) {
        $screenid = $screen['screenid'];
    }
}
$data['screen'] = API::TemplateScreen()->get(array('screenids' => $screenid, 'hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => API_OUTPUT_EXTEND));
$data['screen'] = reset($data['screen']);
// get host
if (!empty($data['screen']['hostid'])) {
    $data['host'] = get_host_by_hostid($data['screen']['hostid']);
}
// render view
$screenView = new CView('monitoring.hostscreen', $data);
$screenView->render();
$screenView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
            $httpTest['http_password'] = '';
        }
        if (isset($_REQUEST['httptestid'])) {
            $httpTest['httptestid'] = $httptestid = $_REQUEST['httptestid'];
            $result = API::WebCheck()->update($httpTest);
            if (!$result) {
                throw new Exception();
            }
        } else {
            $result = API::WebCheck()->create($httpTest);
            if (!$result) {
                throw new Exception();
            }
            $httptestid = reset($result['httptestids']);
        }
        $host = get_host_by_hostid($_REQUEST['hostid']);
        add_audit($action, AUDIT_RESOURCE_SCENARIO, _('Scenario') . ' [' . $_REQUEST['name'] . '] [' . $httptestid . '] ' . _('Host') . ' [' . $host['host'] . ']');
        unset($_REQUEST['httptestid'], $_REQUEST['form']);
        show_messages(true, $message_true);
        DBend(true);
    } catch (Exception $e) {
        DBend(false);
        show_messages(false, null, $message_false);
    }
} elseif ($_REQUEST['go'] == 'activate' && isset($_REQUEST['group_httptestid'])) {
    $go_result = false;
    $group_httptestid = $_REQUEST['group_httptestid'];
    foreach ($group_httptestid as $id) {
        if (!($httptest_data = get_httptest_by_httptestid($id))) {
            continue;
        }
Beispiel #7
0
                    				}*/
                }
                $result = DBend($result);
                show_messages(true, S_GROUP_DELETED, S_CANNOT_DELETE_GROUP);
            } else {
                if (str_in_array($_REQUEST['go'], array('activate', 'disable'))) {
                    $result = true;
                    $status = $_REQUEST['go'] == 'activate' ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
                    $groups = get_request('groups', array());
                    $db_hosts = DBselect('select h.hostid, hg.groupid ' . ' from hosts_groups hg, hosts h' . ' where h.hostid=hg.hostid ' . ' and h.status in (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' and ' . DBin_node('h.hostid'));
                    DBstart();
                    while ($db_host = DBfetch($db_hosts)) {
                        if (!uint_in_array($db_host['groupid'], $groups)) {
                            continue;
                        }
                        $host = get_host_by_hostid($db_host['hostid']);
                        $result &= update_host_status($db_host['hostid'], $status);
                        /*			add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,
                        				'Old status ['.$host['status'].'] '.'New status ['.$status.']');*/
                    }
                    $result = DBend($result);
                    show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST);
                    unset($_REQUEST['activate']);
                }
            }
        }
    }
}
/*** --->>> ACTIONS <<<--- ***/
$frmForm = new CForm();
$frmForm->setMethod('get');
        }
        show_messages($result, _('Application deleted'), _('Cannot delete application'));
    }
} elseif (hasRequest('action') && getRequest('action') == 'application.massdelete' && hasRequest('applications')) {
    $result = true;
    $applications = getRequest('applications');
    $deleted = 0;
    DBstart();
    $dbApplications = DBselect('SELECT a.applicationid,a.name,a.hostid' . ' FROM applications a' . ' WHERE ' . dbConditionInt('a.applicationid', $applications));
    while ($dbApplication = DBfetch($dbApplications)) {
        if (!isset($applications[$dbApplication['applicationid']])) {
            continue;
        }
        $result &= (bool) API::Application()->delete(array($dbApplication['applicationid']));
        if ($result) {
            $host = get_host_by_hostid($dbApplication['hostid']);
            add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $dbApplication['name'] . '] from host [' . $host['host'] . ']');
        }
        $deleted++;
    }
    $result = DBend($result);
    if ($result) {
        uncheckTableRows($pageFilter->hostid);
    }
    show_messages($result, _n('Application deleted', 'Applications deleted', $deleted), _n('Cannot delete application', 'Cannot delete applications', $deleted));
} elseif (hasRequest('applications') && str_in_array(getRequest('action'), array('application.massenable', 'application.massdisable'))) {
    $enableApplicationItems = getRequest('action') === 'application.massenable';
    $applications = API::Application()->get(array('output' => array(), 'applicationids' => getRequest('applications', array()), 'selectItems' => array('itemid'), 'hostids' => $pageFilter->hostid > 0 ? $pageFilter->hostid : null));
    $actionSuccessful = true;
    $updatedItemCount = 0;
    DBstart();
        $go_result = copyItemsToHosts($_REQUEST['group_itemid'], $hosts_ids);
        $go_result = DBend($go_result);
        show_messages($go_result, _('Items copied'), _('Cannot copy items'));
        $_REQUEST['go'] = 'none2';
    } else {
        show_error_message(_('No target selected.'));
    }
} elseif ($_REQUEST['go'] == 'clean_history' && isset($_REQUEST['group_itemid'])) {
    DBstart();
    $go_result = delete_history_by_itemid($_REQUEST['group_itemid']);
    DBexecute('UPDATE items SET lastvalue=null,lastclock=null,prevvalue=null WHERE ' . dbConditionInt('itemid', $_REQUEST['group_itemid']));
    foreach ($_REQUEST['group_itemid'] as $id) {
        if (!($item = get_item_by_itemid($id))) {
            continue;
        }
        $host = get_host_by_hostid($item['hostid']);
        add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, _('Item') . ' [' . $item['key_'] . '] [' . $id . '] ' . _('Host') . ' [' . $host['host'] . '] ' . _('History cleared'));
    }
    $go_result = DBend($go_result);
    show_messages($go_result, _('History cleared'), $go_result);
} elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_itemid'])) {
    DBstart();
    $group_itemid = $_REQUEST['group_itemid'];
    $itemsToDelete = API::Item()->get(array('output' => array('key_', 'itemid'), 'selectHosts' => array('name'), 'itemids' => $group_itemid, 'preservekeys' => true));
    $go_result = API::Item()->delete($group_itemid);
    if ($go_result) {
        foreach ($itemsToDelete as $item) {
            $host = reset($item['hosts']);
            add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM, _('Item') . ' [' . $item['key_'] . '] [' . $item['itemid'] . '] ' . _('Host') . ' [' . $host['name'] . ']');
        }
    }
Beispiel #10
0
 public function getItemListFormat($list = array())
 {
     $itemList = $list['list_item'];
     $parame = $list['parame'];
     $search_key = $parame['item_name_search'];
     $order_result_list = array();
     $search = 0;
     if (empty($search_key)) {
         $search_key_list = array();
     } else {
         $search_key_list = explode(",", $search_key);
     }
     if (count($search_key_list) >= 1) {
         $search = 1;
     }
     foreach ($itemList as $each_item) {
         $each_item = (array) $each_item;
         $item = get_item_by_itemid($each_item['itemid']);
         $newItem = $item;
         // $newItem['name'] = itemName($item);
         $newItem['name'] = $item['name'];
         $newItem['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
         $host = get_host_by_hostid($item['hostid']);
         $newItem['hostname'] = $host['name'];
         if (strpos($item['units'], ',') !== false) {
             list($newItem['units'], $newItem['unitsLong']) = explode(',', $item['units']);
         } else {
             $newItem['unitsLong'] = '';
         }
         if ($search == 0) {
             $newItem['graphid'] = $each_item['graphid'];
             $order_result_list[$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
         } else {
             foreach ($search_key_list as $each_search_key) {
                 $each_search_key = trim($each_search_key);
                 //按关键字进行筛选
                 if (strpos(strtolower($newItem['name']), strtolower($each_search_key)) === false) {
                     //echo "bupipei<br>";
                 } else {
                     $newItem['calc_fnc'] = is_null($each_item['calc_fnc']) ? CALC_FNC_AVG : $each_item->calc_fnc;
                     $newItem['calc_type'] = GRAPH_ITEM_SIMPLE;
                     $newItem['graphid'] = $each_item['graphid'];
                     $item_info_new = array_merge($newItem, $parame);
                     $data = self::GetItemValues($item_info_new);
                     if (isset($data) && isset($data['min'])) {
                         $lastvalue = convert_units(self::getLastValueBy($data), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $min = convert_units(min($data['min']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $avg = convert_units($data['avg_orig'], $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $max = convert_units(max($data['max']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         //return array("lastvalue"=>$lastvalue,'min'=>$min,'avg'=>$avg,'max'=>$max);
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => self::getLastValueBy($data), 'min' => min($data['min']), 'avg' => $data['avg_orig'], 'max' => max($data['max']), 'hostname' => $newItem['hostname'], 'chazhi' => max($data['max']) - min($data['min']));
                     } else {
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
                     }
                     break;
                 }
             }
         }
     }
     return $order_result_list;
 }
Beispiel #11
0
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemid)));
     $item = reset($items);
     $item['name'] = $item['name_expanded'];
     $this->items[$this->num] = $item;
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
     if (strpos($item['units'], ',') === false) {
         $this->items[$this->num]['unitsLong'] = '';
     } else {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = GRAPH_ITEM_SIMPLE;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
Beispiel #12
0
function copy_graph_to_host($graphid, $hostid, $copy_mode = false)
{
    $result = false;
    $gitems = array();
    $db_graph_items = get_graphitems_by_graphid($graphid);
    while ($db_gitem = DBfetch($db_graph_items)) {
        $gitems[] = array('itemid' => $db_gitem['itemid'], 'color' => $db_gitem['color'], 'drawtype' => $db_gitem['drawtype'], 'sortorder' => $db_gitem['sortorder'], 'yaxisside' => $db_gitem['yaxisside'], 'calc_fnc' => $db_gitem['calc_fnc'], 'type' => $db_gitem['type'], 'periods_cnt' => $db_gitem['periods_cnt']);
    }
    $db_graph = get_graph_by_graphid($graphid);
    if ($new_gitems = get_same_graphitems_for_host($gitems, $hostid)) {
        unset($chd_graphid);
        $chd_graphs = get_graphs_by_hostid($hostid);
        while (!isset($chd_graphid) && ($chd_graph = DBfetch($chd_graphs))) {
            /* compare graphs */
            if ($chd_graph['templateid'] != 0) {
                continue;
            }
            unset($equal);
            $chd_gitems = get_graphitems_by_graphid($chd_graph["graphid"]);
            while ($chd_gitem = DBfetch($chd_gitems)) {
                unset($gitem_equal);
                foreach ($new_gitems as $new_gitem) {
                    if (cmp_graphitems($new_gitem, $chd_gitem)) {
                        continue;
                    }
                    $gitem_equal = true;
                    break;
                }
                if (!isset($gitem_equal)) {
                    unset($equal);
                    break;
                }
                /* founded equal graph item */
                if (!isset($equal)) {
                    $equal = 0;
                }
                $equal++;
            }
            if (isset($equal) && count($new_gitems) == $equal) {
                /* founded equal graph */
                $chd_graphid = $chd_graph['graphid'];
                break;
            }
        }
        if (isset($chd_graphid)) {
            $result = update_graph_with_items($chd_graphid, $db_graph['name'], $db_graph['width'], $db_graph['height'], $db_graph['ymin_type'], $db_graph['ymax_type'], $db_graph['yaxismin'], $db_graph['yaxismax'], $db_graph['ymin_itemid'], $db_graph['ymax_itemid'], $db_graph['show_work_period'], $db_graph['show_triggers'], $db_graph['graphtype'], $db_graph['show_legend'], $db_graph['show_3d'], $db_graph['percent_left'], $db_graph['percent_right'], $new_gitems, $copy_mode ? 0 : $db_graph['graphid']);
        } else {
            $result = add_graph_with_items($db_graph['name'], $db_graph['width'], $db_graph['height'], $db_graph['ymin_type'], $db_graph['ymax_type'], $db_graph['yaxismin'], $db_graph['yaxismax'], $db_graph['ymin_itemid'], $db_graph['ymax_itemid'], $db_graph['show_work_period'], $db_graph['show_triggers'], $db_graph['graphtype'], $db_graph['show_legend'], $db_graph['show_3d'], $db_graph['percent_left'], $db_graph['percent_right'], $new_gitems, $copy_mode ? 0 : $db_graph['graphid']);
        }
    } else {
        $host = get_host_by_hostid($hostid);
        info('Skipped coping of graph "' . $db_graph["name"] . '" to host "' . $host['host'] . '"');
    }
    return $result;
}
Beispiel #13
0
function insert_map_link_form()
{
    $frmCnct = new CFormTable('New connector', 'sysmap.php');
    $frmCnct->SetHelp('web.sysmap.connector.php');
    $frmCnct->addVar('sysmapid', $_REQUEST['sysmapid']);
    if (isset($_REQUEST['linkid']) && !isset($_REQUEST['form_refresh'])) {
        $frmCnct->addVar('linkid', $_REQUEST['linkid']);
        $db_links = DBselect('SELECT * FROM sysmaps_links WHERE linkid=' . $_REQUEST['linkid']);
        $db_link = DBfetch($db_links);
        $selementid1 = $db_link['selementid1'];
        $selementid2 = $db_link['selementid2'];
        $triggers = array();
        $drawtype = $db_link['drawtype'];
        $color = $db_link['color'];
        $res = DBselect('SELECT * FROM sysmaps_link_triggers WHERE linkid=' . $_REQUEST['linkid']);
        while ($rows = DBfetch($res)) {
            $triggers[] = $rows;
        }
    } else {
        if (isset($_REQUEST['linkid'])) {
            $frmCnct->addVar('linkid', $_REQUEST['linkid']);
        }
        $selementid1 = get_request('selementid1', 0);
        $selementid2 = get_request('selementid2', 0);
        $triggers = get_request('triggers', array());
        $drawtype = get_request('drawtype', 0);
        $color = get_request('color', 0);
    }
    /* START comboboxes preparations */
    $cmbElements1 = new CComboBox('selementid1', $selementid1);
    $cmbElements2 = new CComboBox('selementid2', $selementid2);
    $db_selements = DBselect('SELECT selementid,label,elementid,elementtype ' . ' FROM sysmaps_elements ' . ' WHERE sysmapid=' . $_REQUEST['sysmapid']);
    while ($db_selement = DBfetch($db_selements)) {
        $label = $db_selement['label'];
        if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $db_host = get_host_by_hostid($db_selement['elementid']);
            $label .= ':' . $db_host['host'];
        } else {
            if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP) {
                $db_map = get_sysmap_by_sysmapid($db_selement['elementid']);
                $label .= ':' . $db_map['name'];
            } else {
                if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) {
                    if ($db_selement['elementid'] > 0) {
                        $label .= ':' . expand_trigger_description($db_selement['elementid']);
                    }
                } else {
                    if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) {
                        if ($db_selement['elementid'] > 0) {
                            $db_group = DBfetch(DBselect('SELECT name FROM groups WHERE groupid=' . $db_selement['elementid']));
                            $label .= ':' . $db_group['name'];
                        }
                    }
                }
            }
        }
        $cmbElements1->addItem($db_selement['selementid'], $label);
        $cmbElements2->addItem($db_selement['selementid'], $label);
    }
    $cmbType = new CComboBox('drawtype', $drawtype);
    foreach (map_link_drawtypes() as $i) {
        $value = map_link_drawtype2str($i);
        $cmbType->addItem($i, $value);
    }
    /* END preparation */
    $frmCnct->addRow(S_ELEMENT_1, $cmbElements1);
    $frmCnct->addRow(S_ELEMENT_2, $cmbElements2);
    //trigger links
    foreach ($triggers as $id => $trigger) {
        if (isset($trigger['triggerid'])) {
            $triggers[$id]['description'] = expand_trigger_description($trigger['triggerid']);
        }
    }
    $table = new CTable();
    $table->SetClass('tableinfo');
    $table->setOddRowClass('even_row');
    $table->setEvenRowClass('even_row');
    $table->options['cellpadding'] = 3;
    $table->options['cellspacing'] = 1;
    $table->headerClass = 'header';
    $table->footerClass = 'footer';
    $table->SetHeader(array(new CCheckBox('all_triggers', null, "CheckAll('" . $frmCnct->GetName() . "','all_triggers','triggers');"), S_TRIGGERS, S_TYPE, S_COLOR));
    $table->addOption('id', 'link_triggers');
    foreach ($triggers as $id => $trigger) {
        if (!isset($trigger['triggerid'])) {
            continue;
        }
        $colorbox = new CSpan(SPACE . SPACE . SPACE);
        $colorbox->addOption('style', 'text-decoration: none; outline-color: black; outline-style: solid; outline-width: 1px; background-color: #' . $trigger['color'] . ';');
        $table->addRow(array(array(new CCheckBox('triggers[' . $trigger['triggerid'] . '][triggerid]', null, null, $trigger['triggerid']), new CVar('triggers[' . $trigger['triggerid'] . '][triggerid]', $trigger['triggerid'])), array(new CLink($trigger['description'], "javascript: openWinCentered('popup_link_tr.php?form=1&dstfrm=" . $frmCnct->GetName() . "&triggerid=" . $trigger['triggerid'] . url_param('linkid') . "','ZBX_Link_Indicator',560,260,'scrollbars=1, toolbar=0, menubar=0, resizable=0');"), new CVar('triggers[' . $trigger['triggerid'] . '][description]', $trigger['description'])), array(map_link_drawtype2str($trigger['drawtype']), new CVar('triggers[' . $trigger['triggerid'] . '][drawtype]', $trigger['drawtype'])), array($colorbox, new CVar('triggers[' . $trigger['triggerid'] . '][color]', $trigger['color']))));
    }
    $btnadd = new CButton('btn1', S_ADD, "javascript: openWinCentered('popup_link_tr.php?form=1&dstfrm=" . $frmCnct->GetName() . url_param('linkid') . "','ZBX_Link_Indicator',560,180,'scrollbars=1, toolbar=0, menubar=0, resizable=0');", 'T');
    $btnRemove = new CButton('btn1', S_REMOVE, "javascript: remove_childs('" . $frmCnct->GetName() . "','triggers','tr');", 'T');
    $btnadd->SetType('button');
    $frmCnct->addRow(S_LINK_STATUS_INDICATORS, array($table, BR(), $btnadd, $btnRemove));
    //----------
    $frmCnct->addRow(S_TYPE . ' (' . S_OK_BIG . ')', $cmbType);
    $frmCnct->addRow(S_COLOR . ' (' . S_OK_BIG . ')', new CColor('color', $color));
    $frmCnct->addItemToBottomRow(new CButton("save_link", S_SAVE));
    if (isset($_REQUEST["linkid"])) {
        $frmCnct->addItemToBottomRow(SPACE);
        $frmCnct->addItemToBottomRow(new CButtonDelete("Delete link?", url_param("linkid") . url_param("sysmapid")));
    }
    $frmCnct->addItemToBottomRow(SPACE);
    $frmCnct->addItemToBottomRow(new CButtonCancel(url_param("sysmapid")));
    $frmCnct->Show();
}
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     // TODO: graphs shouldn't retrieve items and resolve macros themselves
     // all of the data must be passed as parameters
     $items = CMacrosResolverHelper::resolveItemNames([get_item_by_itemid($itemid)]);
     $item = reset($items);
     $item['name'] = $item['name_expanded'];
     $this->items[$this->num] = $item;
     $parser = new CItemDelayFlexParser($item['delay_flex']);
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $parser->getFlexibleIntervals());
     $this->items[$this->num]['intervals'] = $parser->getIntervals();
     if (strpos($item['units'], ',') === false) {
         $this->items[$this->num]['unitsLong'] = '';
     } else {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
Beispiel #15
0
$frmForm = new CForm();
$cmbConf = new CComboBox('config', 'proxies.php', 'javascript: redirect(this.options[this.selectedIndex].value);');
$cmbConf->addItem('nodes.php', S_NODES);
$cmbConf->addItem('proxies.php', S_PROXIES);
$frmForm->addItem($cmbConf);
if (!isset($_REQUEST['form'])) {
    $frmForm->addItem(new CButton('form', S_CREATE_PROXY));
}
$proxies_wdgt->addPageHeader(S_CONFIGURATION_OF_PROXIES, $frmForm);
if (isset($_REQUEST['form'])) {
    $_REQUEST['hostid'] = get_request('hostid', 0);
    $frm_title = S_PROXY;
    $frmHostG = new CFormTable($frm_title, 'proxies.php');
    $frmHostG->setHelp('web.proxy.php');
    if ($_REQUEST['hostid'] > 0) {
        $proxy = get_host_by_hostid($_REQUEST['hostid']);
        $frm_title = S_PROXY . ' [' . $proxy['host'] . ']';
        $frmHostG->addVar('hostid', $_REQUEST['hostid']);
    }
    if ($_REQUEST['hostid'] > 0 && !isset($_REQUEST['form_refresh'])) {
        $name = $proxy['host'];
        $status = $proxy['status'];
        if ($status == HOST_STATUS_PROXY_PASSIVE) {
            $useip = $proxy['useip'];
            $dns = $proxy['dns'];
            $ip = $proxy['ip'];
            $port = $proxy['port'];
        } else {
            $useip = get_request('useip', 1);
            $dns = get_request('dns', '');
            $ip = get_request('ip', '0.0.0.0');
Beispiel #16
0
 $data = array();
 // get drules
 $data['drules'] = API::DRule()->get(array('output' => API_OUTPUT_EXTEND, 'sortfield' => getPageSortField('name'), 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true));
 if (!empty($data['drules'])) {
     foreach ($data['drules'] as $druleid => $drule) {
         // checks
         $checks = array();
         foreach ($drule['dchecks'] as $check) {
             $checks[$check['type']] = discovery_check_type2str($check['type']);
         }
         order_result($checks);
         $data['drules'][$druleid]['checks'] = $checks;
         // description
         $data['drules'][$druleid]['description'] = array();
         if (!empty($drule['proxy_hostid'])) {
             $proxy = get_host_by_hostid($drule['proxy_hostid']);
             array_push($data['drules'][$druleid]['description'], $proxy['host'] . NAME_DELIMITER);
         }
     }
     order_result($data['drules'], getPageSortOrder());
 }
 // get paging
 $data['paging'] = getPagingLine($data['drules'], array('druleid'));
 // nodes
 if ($data['displayNodes'] = is_array(get_current_nodeid())) {
     foreach ($data['drules'] as &$drule) {
         $drule['nodename'] = get_node_name_by_elid($drule['druleid'], true);
     }
     unset($drule);
 }
 // render view
Beispiel #17
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $groups = API::HostGroup()->get(array('groupids' => $value, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($groups) {
                $group = reset($groups);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $group['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER:
            $trigs = API::Trigger()->get(array('triggerids' => $value, 'expandDescription' => true, 'output' => array('description'), 'selectHosts' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($trigs) {
                $trig = reset($trigs);
                $host = reset($trig['hosts']);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'] . NAME_DELIMITER . $trig['description'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_TEMPLATE:
            if ($host = get_host_by_hostid($value)) {
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
        case CONDITION_TYPE_HOST_METADATA:
        case CONDITION_TYPE_HOST_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = getSeverityCaption($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = _('maintenance');
            break;
        case CONDITION_TYPE_NODE:
            if ($node = get_node_by_nodeid($value)) {
                $str_val = $node['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DRULE:
            if ($drule = get_discovery_rule_by_druleid($value)) {
                $str_val = $drule['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DCHECK:
            $row = DBfetch(DBselect('SELECT dr.name,c.dcheckid,c.type,c.key_,c.ports' . ' FROM drules dr,dchecks c' . ' WHERE dr.druleid=c.druleid' . ' AND c.dcheckid=' . zbx_dbstr($value)));
            if ($row) {
                $str_val = $row['name'] . NAME_DELIMITER . discovery_check2str($row['type'], $row['key_'], $row['ports']);
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DOBJECT:
            $str_val = discovery_object2str($value);
            break;
        case CONDITION_TYPE_PROXY:
            if ($host = get_host_by_hostid($value)) {
                $str_val = $host['host'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? _('Ack') : _('Not Ack');
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_TYPE:
            $str_val = eventType($value);
            break;
        default:
            return _('Unknown');
    }
    return $str_val;
}
Beispiel #18
0
/**
 * Create CDiv with host/template information and references to it's elements
 *
 * @param string $currentElement
 * @param int $hostid
 * @param int $discoveryid
 *
 * @return object
 */
function get_header_host_table($currentElement, $hostid, $discoveryid = null)
{
    // LLD rule header
    if ($discoveryid) {
        $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'hosts' => 'hosts');
    } else {
        $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries', 'web' => 'web');
    }
    $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true, 'selectHostDiscovery' => array('ts_delete'));
    if (isset($elements['items'])) {
        $options['selectItems'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['triggers'])) {
        $options['selectTriggers'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['graphs'])) {
        $options['selectGraphs'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['applications'])) {
        $options['selectApplications'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['discoveries'])) {
        $options['selectDiscoveries'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['web'])) {
        $options['selectHttpTests'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['hosts'])) {
        $options['selectHostPrototypes'] = API_OUTPUT_COUNT;
    }
    // get hosts
    $dbHost = API::Host()->get($options);
    $dbHost = reset($dbHost);
    if (!$dbHost) {
        return null;
    }
    // get discoveries
    if (!empty($discoveryid)) {
        $options['itemids'] = $discoveryid;
        $options['output'] = array('name');
        unset($options['hostids'], $options['templated_hosts']);
        $dbDiscovery = API::DiscoveryRule()->get($options);
        $dbDiscovery = reset($dbDiscovery);
    }
    /*
     * Back
     */
    $list = new CList(null, 'objectlist');
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array('&laquo; ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid'))));
        $dbHost['screens'] = API::TemplateScreen()->get(array('editable' => true, 'countOutput' => true, 'groupCount' => true, 'templateids' => $dbHost['hostid']));
        $dbHost['screens'] = isset($dbHost['screens'][0]['rowscount']) ? $dbHost['screens'][0]['rowscount'] : 0;
    } else {
        $list->addItem(array('&laquo; ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
    }
    /*
     * Name
     */
    $proxyName = '';
    if ($dbHost['proxy_hostid']) {
        $proxy = get_host_by_hostid($dbHost['proxy_hostid']);
        $proxyName = CHtml::encode($proxy['host']) . NAME_DELIMITER;
    }
    $name = get_node_name_by_elid($dbHost['hostid'], true, NAME_DELIMITER) . $proxyName . CHtml::encode($dbHost['name']);
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array(bold(_('Template') . NAME_DELIMITER), new CLink($name, 'templates.php?form=update&templateid=' . $dbHost['hostid'])));
    } else {
        switch ($dbHost['status']) {
            case HOST_STATUS_MONITORED:
                if ($dbHost['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                    $status = new CSpan(_('In maintenance'), 'orange');
                } else {
                    $status = new CSpan(_('Monitored'), 'enabled');
                }
                break;
            case HOST_STATUS_NOT_MONITORED:
                $status = new CSpan(_('Not monitored'), 'on');
                break;
            default:
                $status = _('Unknown');
                break;
        }
        $list->addItem(array(bold(_('Host') . NAME_DELIMITER), new CLink($name, 'hosts.php?form=update&hostid=' . $dbHost['hostid'])));
        $list->addItem($status);
        $list->addItem(getAvailabilityTable($dbHost));
    }
    if (!empty($dbDiscovery)) {
        $list->addItem(array('&laquo; ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
        $list->addItem(array(bold(_('Discovery') . NAME_DELIMITER), new CLink(CHtml::encode($dbDiscovery['name']), 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid'])));
    }
    /*
     * Rowcount
     */
    if (isset($elements['applications'])) {
        if ($currentElement == 'applications') {
            $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')'));
        }
    }
    if (isset($elements['items'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'items') {
                $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')'));
            }
        } else {
            if ($currentElement == 'items') {
                $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')'));
            }
        }
    }
    if (isset($elements['triggers'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')'));
            }
        } else {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')'));
            }
        }
    }
    if (isset($elements['graphs'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')'));
            }
        } else {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')'));
            }
        }
    }
    if (isset($elements['hosts']) && $dbHost['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        if ($currentElement == 'hosts') {
            $list->addItem(_('Host prototypes') . ' (' . $dbDiscovery['hostPrototypes'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['hostPrototypes'] . ')'));
        }
    }
    if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) {
        if ($currentElement == 'screens') {
            $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')'));
        }
    }
    if (isset($elements['discoveries'])) {
        if ($currentElement == 'discoveries') {
            $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')'));
        }
    }
    if (isset($elements['web'])) {
        if ($currentElement == 'web') {
            $list->addItem(_('Web scenarios') . ' (' . $dbHost['httpTests'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Web scenarios'), 'httpconf.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['httpTests'] . ')'));
        }
    }
    return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all');
}
Beispiel #19
0
function get_operation_desc($type = SHORT_DESCRITION, $data)
{
    $result = null;
    switch ($type) {
        case SHORT_DESCRITION:
            switch ($data['operationtype']) {
                case OPERATION_TYPE_MESSAGE:
                    switch ($data['object']) {
                        case OPERATION_OBJECT_USER:
                            $obj_data = get_user_by_userid($data['objectid']);
                            $obj_data = S_USER . ' "' . $obj_data['alias'] . '"';
                            break;
                        case OPERATION_OBJECT_GROUP:
                            $obj_data = get_group_by_usrgrpid($data['objectid']);
                            $obj_data = S_GROUP . ' "' . $obj_data['name'] . '"';
                            break;
                    }
                    $result = S_SEND_MESSAGE_TO . ' ' . $obj_data;
                    break;
                case OPERATION_TYPE_COMMAND:
                    $result = S_RUN_REMOTE_COMMANDS;
                    break;
                case OPERATION_TYPE_HOST_ADD:
                    $result = S_ADD_HOST;
                    break;
                case OPERATION_TYPE_HOST_REMOVE:
                    $result = S_REMOVE_HOST;
                    break;
                case OPERATION_TYPE_GROUP_ADD:
                    $obj_data = get_hostgroup_by_groupid($data['objectid']);
                    $result = S_ADD_TO_GROUP . ' "' . $obj_data['name'] . '"';
                    break;
                case OPERATION_TYPE_GROUP_REMOVE:
                    $obj_data = get_hostgroup_by_groupid($data['objectid']);
                    $result = S_DELETE_FROM_GROUP . ' "' . $obj_data['name'] . '"';
                    break;
                case OPERATION_TYPE_TEMPLATE_ADD:
                    $obj_data = get_host_by_hostid($data['objectid']);
                    $result = S_LINK_TO_TEMPLATE . ' "' . $obj_data['host'] . '"';
                    break;
                case OPERATION_TYPE_TEMPLATE_REMOVE:
                    $obj_data = get_host_by_hostid($data['objectid']);
                    $result = S_UNLINK_FROM_TEMPLATE . ' "' . $obj_data['host'] . '"';
                    break;
                default:
                    break;
            }
            break;
        case LONG_DESCRITION:
            switch ($data['operationtype']) {
                case OPERATION_TYPE_MESSAGE:
                    // for PHP4
                    if (isset($data['default_msg']) && !empty($data['default_msg'])) {
                        if (isset($_REQUEST['def_shortdata']) && isset($_REQUEST['def_longdata'])) {
                            $temp = bold(S_SUBJECT . ': ');
                            $result = $temp->ToString() . $_REQUEST['def_shortdata'] . "\n";
                            $temp = bold(S_MESSAGE . ':');
                            $result .= $temp->ToString() . $_REQUEST['def_longdata'];
                        } else {
                            if (isset($data['operationid'])) {
                                $sql = 'SELECT a.def_shortdata,a.def_longdata ' . ' FROM actions a, operations o ' . ' WHERE a.actionid=o.actionid ' . ' AND o.operationid=' . $data['operationid'];
                                if ($rows = DBfetch(DBselect($sql, 1))) {
                                    $temp = bold(S_SUBJECT . ': ');
                                    $result = $temp->ToString() . $rows['def_shortdata'] . "\n";
                                    $temp = bold(S_MESSAGE . ':');
                                    $result .= $temp->ToString() . $rows['def_longdata'];
                                }
                            }
                        }
                    } else {
                        $temp = bold(S_SUBJECT . ': ');
                        $result = $temp->ToString() . $data['shortdata'] . "\n";
                        $temp = bold(S_MESSAGE . ':');
                        $result .= $temp->ToString() . $data['longdata'];
                    }
                    break;
                case OPERATION_TYPE_COMMAND:
                    $temp = bold(S_REMOTE_COMMANDS . ': ');
                    $result = $temp->ToString() . $data['longdata'];
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
    return $result;
}
Beispiel #20
0
 $table = new CTableInfo(_('No templates found.'));
 $table->setHeader(array(new CCheckBox('all_templates', null, "checkAll('" . $form->getName() . "', 'all_templates', 'templates');"), make_sorting_header(_('Templates'), 'name', $sortField, $sortOrder), _('Applications'), _('Items'), _('Triggers'), _('Graphs'), _('Screens'), _('Discovery'), _('Web'), _('Linked templates'), _('Linked to')));
 // get templates
 $templates = array();
 if ($pageFilter->groupsSelected) {
     $templates = API::Template()->get(array('output' => array('templateid', 'name'), 'groupids' => $pageFilter->groupid > 0 ? $pageFilter->groupid : null, 'editable' => true, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1));
 }
 // sorting && paging
 order_result($templates, $sortField, $sortOrder);
 $paging = getPagingLine($templates);
 $templates = API::Template()->get(array('templateids' => zbx_objectValues($templates, 'templateid'), 'editable' => true, 'output' => array('name', 'proxy_hostid'), 'selectHosts' => array('hostid', 'name', 'status'), 'selectTemplates' => array('hostid', 'name', 'status'), 'selectParentTemplates' => array('hostid', 'name', 'status'), 'selectItems' => API_OUTPUT_COUNT, 'selectTriggers' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT, 'selectApplications' => API_OUTPUT_COUNT, 'selectDiscoveries' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'selectHttpTests' => API_OUTPUT_COUNT, 'nopermissions' => true));
 order_result($templates, $sortField, $sortOrder);
 foreach ($templates as $template) {
     $templatesOutput = array();
     if ($template['proxy_hostid']) {
         $proxy = get_host_by_hostid($template['proxy_hostid']);
         $templatesOutput[] = $proxy['host'] . NAME_DELIMITER;
     }
     $templatesOutput[] = new CLink($template['name'], 'templates.php?form=update&templateid=' . $template['templateid'] . url_param('groupid'));
     $applications = array(new CLink(_('Applications'), 'applications.php?groupid=' . $_REQUEST['groupid'] . '&hostid=' . $template['templateid']), ' (' . $template['applications'] . ')');
     $items = array(new CLink(_('Items'), 'items.php?filter_set=1&groupid=' . $_REQUEST['groupid'] . '&hostid=' . $template['templateid']), ' (' . $template['items'] . ')');
     $triggers = array(new CLink(_('Triggers'), 'triggers.php?groupid=' . $_REQUEST['groupid'] . '&hostid=' . $template['templateid']), ' (' . $template['triggers'] . ')');
     $graphs = array(new CLink(_('Graphs'), 'graphs.php?groupid=' . $_REQUEST['groupid'] . '&hostid=' . $template['templateid']), ' (' . $template['graphs'] . ')');
     $screens = array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $template['templateid']), ' (' . $template['screens'] . ')');
     $discoveries = array(new CLink(_('Discovery'), 'host_discovery.php?&hostid=' . $template['templateid']), ' (' . $template['discoveries'] . ')');
     $httpTests = array(new CLink(_('Web'), 'httpconf.php?groupid=' . $_REQUEST['groupid'] . '&hostid=' . $template['templateid']), ' (' . $template['httpTests'] . ')');
     order_result($template['parentTemplates'], 'name');
     $linkedTemplatesOutput = $linkedToOutput = $linkedToObjects = array();
     $i = 0;
     foreach ($template['parentTemplates'] as $linkedTemplate) {
         $i++;
 // getting paging element
 $paging = getPagingLine($rules_arr);
 foreach ($rules_arr as $rule_data) {
     $checks = array();
     $sql = 'SELECT type FROM dchecks WHERE druleid=' . $rule_data['druleid'] . ' ORDER BY type, ports';
     $db_checks = DBselect($sql);
     while ($check_data = DBfetch($db_checks)) {
         if (!isset($checks[$check_data['type']])) {
             $checks[$check_data['type']] = discovery_check_type2str($check_data['type']);
         }
     }
     order_result($checks);
     $status = new CCol(new CLink(discovery_status2str($rule_data["status"]), '?g_druleid%5B%5D=' . $rule_data['druleid'] . ($rule_data["status"] == DRULE_STATUS_ACTIVE ? '&go=disable' : '&go=activate'), discovery_status2style($rule_data['status'])));
     $description = array();
     if ($rule_data["proxy_hostid"]) {
         $proxy = get_host_by_hostid($rule_data["proxy_hostid"]);
         array_push($description, $proxy["host"], ":");
     }
     array_push($description, new CLink($rule_data['name'], "?form=update&druleid=" . $rule_data['druleid']));
     $tblDiscovery->addRow(array(new CCheckBox('g_druleid[' . $rule_data["druleid"] . ']', null, null, $rule_data["druleid"]), $description, $rule_data['iprange'], $rule_data['delay'], implode(', ', $checks), $status));
 }
 // pagination at the top and the bottom of the page
 $tblDiscovery->addRow(new CCol($paging));
 $dscry_wdgt->addItem($paging);
 // gobox
 $goBox = new CComboBox('go');
 $goOption = new CComboItem('activate', S_ENABLE_SELECTED);
 $goOption->setAttribute('confirm', S_ENABLE_SELECTED_DISCOVERY_RULES);
 $goBox->addItem($goOption);
 $goOption = new CComboItem('disable', S_DISABLE_SELECTED);
 $goOption->setAttribute('confirm', S_DISABLE_SELECTED_DISCOVERY_RULES);
/**
 * Copy specified graph to specified host.
 *
 * @param $graphid
 * @param $hostid
 * @return array|bool
 */
function copy_graph_to_host($graphid, $hostid)
{
    $graphs = API::Graph()->get(array('graphids' => $graphid, 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND));
    $graph = reset($graphs);
    $new_gitems = get_same_graphitems_for_host($graph['gitems'], $hostid);
    if (!$new_gitems) {
        $host = get_host_by_hostid($hostid);
        info(_s('Skipped copying of graph "%1$s" to host "%2$s".', $graph['name'], $host['host']));
        return false;
    }
    // retrieve actual ymax_itemid and ymin_itemid
    if ($graph['ymax_itemid']) {
        if ($itemid = get_same_item_for_host($graph['ymax_itemid'], $hostid)) {
            $graph['ymax_itemid'] = $itemid;
        }
    }
    if ($graph['ymin_itemid']) {
        if ($itemid = get_same_item_for_host($graph['ymin_itemid'], $hostid)) {
            $graph['ymin_itemid'] = $itemid;
        }
    }
    $graph['gitems'] = $new_gitems;
    unset($graph['templateid']);
    $result = API::Graph()->create($graph);
    return $result;
}
Beispiel #23
0
 /**
  * Mass update hosts.
  *
  * @param array  $hosts								multidimensional array with Hosts data
  * @param array  $hosts['hosts']					Array of Host objects to update
  * @param string $hosts['fields']['host']			Host name.
  * @param array  $hosts['fields']['groupids']		HostGroup IDs add Host to.
  * @param int    $hosts['fields']['port']			Port. OPTIONAL
  * @param int    $hosts['fields']['status']			Host Status. OPTIONAL
  * @param int    $hosts['fields']['useip']			Use IP. OPTIONAL
  * @param string $hosts['fields']['dns']			DNS. OPTIONAL
  * @param string $hosts['fields']['ip']				IP. OPTIONAL
  * @param int    $hosts['fields']['bulk']			bulk. OPTIONAL
  * @param int    $hosts['fields']['proxy_hostid']	Proxy Host ID. OPTIONAL
  * @param int    $hosts['fields']['ipmi_authtype']	IPMI authentication type. OPTIONAL
  * @param int    $hosts['fields']['ipmi_privilege']	IPMI privilege. OPTIONAL
  * @param string $hosts['fields']['ipmi_username']	IPMI username. OPTIONAL
  * @param string $hosts['fields']['ipmi_password']	IPMI password. OPTIONAL
  *
  * @return boolean
  */
 public function massUpdate($data)
 {
     $hosts = zbx_toArray($data['hosts']);
     $inputHostIds = zbx_objectValues($hosts, 'hostid');
     $hostids = array_unique($inputHostIds);
     sort($hostids);
     $db_hosts = $this->get(['output' => ['hostid', 'tls_connect', 'tls_accept', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk'], 'hostids' => $hostids, 'editable' => true, 'preservekeys' => true]);
     foreach ($hosts as $host) {
         if (!array_key_exists($host['hostid'], $db_hosts)) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
         }
     }
     // Check connection fields only for massupdate action.
     if ((array_key_exists('tls_connect', $data) || array_key_exists('tls_accept', $data) || array_key_exists('tls_psk_identity', $data) || array_key_exists('tls_psk', $data) || array_key_exists('tls_issuer', $data) || array_key_exists('tls_subject', $data)) && (!array_key_exists('tls_connect', $data) || !array_key_exists('tls_accept', $data))) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('Cannot update host encryption settings. Connection settings for both directions should be specified.'));
     }
     $this->validateEncryption([$data]);
     // Clean PSK fields.
     if (array_key_exists('tls_connect', $data) && $data['tls_connect'] != HOST_ENCRYPTION_PSK && (array_key_exists('tls_accept', $data) && ($data['tls_accept'] & HOST_ENCRYPTION_PSK) != HOST_ENCRYPTION_PSK)) {
         $data['tls_psk_identity'] = '';
         $data['tls_psk'] = '';
     }
     // Clean certificate fields.
     if (array_key_exists('tls_connect', $data) && $data['tls_connect'] != HOST_ENCRYPTION_CERTIFICATE && (array_key_exists('tls_accept', $data) && ($data['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) != HOST_ENCRYPTION_CERTIFICATE)) {
         $data['tls_issuer'] = '';
         $data['tls_subject'] = '';
     }
     // check if hosts have at least 1 group
     if (isset($data['groups']) && empty($data['groups'])) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('No groups for hosts.'));
     }
     /*
      * Update hosts properties
      */
     if (isset($data['name'])) {
         if (count($hosts) > 1) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot mass update visible host name.'));
         }
     }
     if (isset($data['host'])) {
         if (!preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/', $data['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect characters used for host name "%s".', $data['host']));
         }
         if (count($hosts) > 1) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot mass update host name.'));
         }
         $curHost = reset($hosts);
         $sameHostnameHost = $this->get(['output' => ['hostid'], 'filter' => ['host' => $data['host']], 'nopermissions' => true, 'limit' => 1]);
         $sameHostnameHost = reset($sameHostnameHost);
         if ($sameHostnameHost && bccomp($sameHostnameHost['hostid'], $curHost['hostid']) != 0) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host "%1$s" already exists.', $data['host']));
         }
         // can't add host with the same name as existing template
         $sameHostnameTemplate = API::Template()->get(['output' => ['templateid'], 'filter' => ['host' => $data['host']], 'nopermissions' => true, 'limit' => 1]);
         if ($sameHostnameTemplate) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Template "%1$s" already exists.', $data['host']));
         }
     }
     if (isset($data['groups'])) {
         $updateGroups = $data['groups'];
     }
     if (isset($data['interfaces'])) {
         $updateInterfaces = $data['interfaces'];
     }
     if (array_key_exists('templates_clear', $data)) {
         $updateTemplatesClear = zbx_toArray($data['templates_clear']);
     }
     if (isset($data['templates'])) {
         $updateTemplates = $data['templates'];
     }
     if (isset($data['macros'])) {
         $updateMacros = $data['macros'];
     }
     // second check is necessary, because import incorrectly inputs unset 'inventory' as empty string rather than null
     if (isset($data['inventory']) && $data['inventory']) {
         if (isset($data['inventory_mode']) && $data['inventory_mode'] == HOST_INVENTORY_DISABLED) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set inventory fields for disabled inventory.'));
         }
         $updateInventory = $data['inventory'];
         $updateInventory['inventory_mode'] = null;
     }
     if (isset($data['inventory_mode'])) {
         if (!isset($updateInventory)) {
             $updateInventory = [];
         }
         $updateInventory['inventory_mode'] = $data['inventory_mode'];
     }
     if (isset($data['status'])) {
         $updateStatus = $data['status'];
     }
     unset($data['hosts'], $data['groups'], $data['interfaces'], $data['templates_clear'], $data['templates'], $data['macros'], $data['inventory'], $data['inventory_mode'], $data['status']);
     if (!zbx_empty($data)) {
         DB::update('hosts', ['values' => $data, 'where' => ['hostid' => $hostids]]);
     }
     if (isset($updateStatus)) {
         updateHostStatus($hostids, $updateStatus);
     }
     /*
      * Update template linkage
      */
     if (isset($updateTemplatesClear)) {
         $templateIdsClear = zbx_objectValues($updateTemplatesClear, 'templateid');
         if ($updateTemplatesClear) {
             $this->massRemove(['hostids' => $hostids, 'templateids_clear' => $templateIdsClear]);
         }
     } else {
         $templateIdsClear = [];
     }
     // unlink templates
     if (isset($updateTemplates)) {
         $hostTemplates = API::Template()->get(['hostids' => $hostids, 'output' => ['templateid'], 'preservekeys' => true]);
         $hostTemplateids = array_keys($hostTemplates);
         $newTemplateids = zbx_objectValues($updateTemplates, 'templateid');
         $templatesToDel = array_diff($hostTemplateids, $newTemplateids);
         $templatesToDel = array_diff($templatesToDel, $templateIdsClear);
         if ($templatesToDel) {
             $result = $this->massRemove(['hostids' => $hostids, 'templateids' => $templatesToDel]);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot unlink template'));
             }
         }
     }
     /*
      * update interfaces
      */
     if (isset($updateInterfaces)) {
         foreach ($hostids as $hostid) {
             API::HostInterface()->replaceHostInterfaces(['hostid' => $hostid, 'interfaces' => $updateInterfaces]);
         }
     }
     // link new templates
     if (isset($updateTemplates)) {
         $result = $this->massAdd(['hosts' => $hosts, 'templates' => $updateTemplates]);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot link template'));
         }
     }
     // macros
     if (isset($updateMacros)) {
         DB::delete('hostmacro', ['hostid' => $hostids]);
         $this->massAdd(['hosts' => $hosts, 'macros' => $updateMacros]);
     }
     /*
      * Inventory
      */
     if (isset($updateInventory)) {
         // disabling inventory
         if ($updateInventory['inventory_mode'] == HOST_INVENTORY_DISABLED) {
             $sql = 'DELETE FROM host_inventory WHERE ' . dbConditionInt('hostid', $hostids);
             if (!DBexecute($sql)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete inventory.'));
             }
         } else {
             $existingInventoriesDb = DBfetchArrayAssoc(DBselect('SELECT hostid,inventory_mode' . ' FROM host_inventory' . ' WHERE ' . dbConditionInt('hostid', $hostids)), 'hostid');
             // check existing host inventory data
             $automaticHostIds = [];
             if ($updateInventory['inventory_mode'] === null) {
                 foreach ($hostids as $hostid) {
                     // if inventory is disabled for one of the updated hosts, throw an exception
                     if (!isset($existingInventoriesDb[$hostid])) {
                         $host = get_host_by_hostid($hostid);
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Inventory disabled for host "%1$s".', $host['host']));
                     } elseif ($existingInventoriesDb[$hostid]['inventory_mode'] == HOST_INVENTORY_AUTOMATIC) {
                         $automaticHostIds[] = $hostid;
                     }
                 }
             }
             $inventoriesToSave = [];
             foreach ($hostids as $hostid) {
                 $hostInventory = $updateInventory;
                 $hostInventory['hostid'] = $hostid;
                 // if no 'inventory_mode' has been passed, set inventory 'inventory_mode' from DB
                 if ($updateInventory['inventory_mode'] === null) {
                     $hostInventory['inventory_mode'] = $existingInventoriesDb[$hostid]['inventory_mode'];
                 }
                 $inventoriesToSave[$hostid] = $hostInventory;
             }
             // when updating automatic inventory, ignore fields that have items linked to them
             if ($updateInventory['inventory_mode'] == HOST_INVENTORY_AUTOMATIC || $updateInventory['inventory_mode'] === null && $automaticHostIds) {
                 $itemsToInventories = API::item()->get(['output' => ['inventory_link', 'hostid'], 'hostids' => $automaticHostIds ? $automaticHostIds : $hostids, 'nopermissions' => true]);
                 $inventoryFields = getHostInventories();
                 foreach ($itemsToInventories as $hinv) {
                     // 0 means 'no link'
                     if ($hinv['inventory_link'] != 0) {
                         $inventoryName = $inventoryFields[$hinv['inventory_link']]['db_field'];
                         unset($inventoriesToSave[$hinv['hostid']][$inventoryName]);
                     }
                 }
             }
             // save inventory data
             foreach ($inventoriesToSave as $inventory) {
                 $hostid = $inventory['hostid'];
                 if (isset($existingInventoriesDb[$hostid])) {
                     DB::update('host_inventory', ['values' => $inventory, 'where' => ['hostid' => $hostid]]);
                 } else {
                     DB::insert('host_inventory', [$inventory], false);
                 }
             }
         }
     }
     /*
      * Update host and host group linkage. This procedure should be done the last because user can unlink
      * him self from a group with write permissions leaving only read premissions. Thus other procedures, like
      * host-template linkage, inventory update, macros update, must be done before this.
      */
     if (isset($updateGroups)) {
         $updateGroups = zbx_toArray($updateGroups);
         $hostGroups = API::HostGroup()->get(['output' => ['groupid'], 'hostids' => $hostids]);
         $hostGroupIds = zbx_objectValues($hostGroups, 'groupid');
         $newGroupIds = zbx_objectValues($updateGroups, 'groupid');
         $groupsToAdd = array_diff($newGroupIds, $hostGroupIds);
         if ($groupsToAdd) {
             $this->massAdd(['hosts' => $hosts, 'groups' => zbx_toObject($groupsToAdd, 'groupid')]);
         }
         $groupIdsToDelete = array_diff($hostGroupIds, $newGroupIds);
         if ($groupIdsToDelete) {
             $this->massRemove(['hostids' => $hostids, 'groupids' => $groupIdsToDelete]);
         }
     }
     return ['hostids' => $inputHostIds];
 }
Beispiel #24
0
function update_item_status($itemids, $status)
{
    zbx_value2array($itemids);
    $result = true;
    $db_items = DBselect('SELECT i.* FROM items i WHERE ' . dbConditionInt('i.itemid', $itemids));
    while ($item = DBfetch($db_items)) {
        $old_status = $item['status'];
        if ($status != $old_status) {
            $result &= DBexecute('UPDATE items SET status=' . zbx_dbstr($status) . ' WHERE itemid=' . zbx_dbstr($item['itemid']));
            if ($result) {
                $host = get_host_by_hostid($item['hostid']);
                $item_new = get_item_by_itemid($item['itemid']);
                add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, $item['itemid'], $host['host'] . NAME_DELIMITER . $item['name'], 'items', $item, $item_new);
            }
        }
    }
    return $result;
}
Beispiel #25
0
function copy_trigger_to_host($triggerid, $hostid, $copy_mode = false)
{
    $trigger = get_trigger_by_triggerid($triggerid);
    $deps = replace_template_dependencies(get_trigger_dependencies_by_triggerid($triggerid), $hostid);
    $sql = 'SELECT t2.triggerid, t2.expression ' . ' FROM triggers t2, functions f1, functions f2, items i1, items i2 ' . ' WHERE f1.triggerid=' . $triggerid . ' AND i1.itemid=f1.itemid ' . ' AND f2.function=f1.function ' . ' AND f2.parameter=f1.parameter ' . ' AND i2.itemid=f2.itemid ' . ' AND i2.key_=i1.key_ ' . ' AND i2.hostid=' . $hostid . ' AND t2.triggerid=f2.triggerid ' . ' AND t2.templateid=0 ';
    $host_triggers = DBSelect($sql);
    while ($host_trigger = DBfetch($host_triggers)) {
        if (cmp_triggers_exressions($triggerid, $host_trigger["triggerid"])) {
            continue;
        }
        // link not linked trigger with same expression
        return update_trigger($host_trigger["triggerid"], NULL, $trigger["description"], $trigger["type"], $trigger["priority"], NULL, $trigger["comments"], $trigger["url"], $deps, $copy_mode ? 0 : $triggerid);
    }
    $newtriggerid = get_dbid('triggers', 'triggerid');
    $result = DBexecute('INSERT INTO triggers ' . ' (triggerid,description,type,priority,status,comments,url,value,expression,templateid)' . ' VALUES (' . $newtriggerid . ',' . zbx_dbstr($trigger['description']) . ',' . $trigger['type'] . ',' . $trigger['priority'] . ',' . $trigger["status"] . ',' . zbx_dbstr($trigger["comments"]) . ',' . zbx_dbstr($trigger["url"]) . ",2,'0'," . ($copy_mode ? 0 : $triggerid) . ')');
    if (!$result) {
        return $result;
    }
    $host = get_host_by_hostid($hostid);
    $newexpression = $trigger["expression"];
    // Loop: functions
    $functions = get_functions_by_triggerid($triggerid);
    while ($function = DBfetch($functions)) {
        $item = get_item_by_itemid($function["itemid"]);
        $host_items = DBselect('SELECT * FROM items WHERE key_=' . zbx_dbstr($item['key_']) . ' AND hostid=' . $host['hostid']);
        $host_item = DBfetch($host_items);
        if (!$host_item) {
            error("Missing key '" . $item["key_"] . "' for host '" . $host["host"] . "'");
            return FALSE;
        }
        $newfunctionid = get_dbid("functions", "functionid");
        $result = DBexecute('INSERT INTO functions (functionid,itemid,triggerid,function,parameter) ' . " values ({$newfunctionid}," . $host_item["itemid"] . ",{$newtriggerid}," . zbx_dbstr($function["function"]) . "," . zbx_dbstr($function["parameter"]) . ")");
        $newexpression = str_replace("{" . $function["functionid"] . "}", "{" . $newfunctionid . "}", $newexpression);
    }
    DBexecute('UPDATE triggers SET expression=' . zbx_dbstr($newexpression) . ' WHERE triggerid=' . $newtriggerid);
    // copy dependencies
    delete_dependencies_by_triggerid($newtriggerid);
    foreach ($deps as $dep_id) {
        add_trigger_dependency($newtriggerid, $dep_id);
    }
    info("Added trigger '" . $trigger["description"] . "' to host '" . $host["host"] . "'");
    add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_TRIGGER, $newtriggerid, $trigger["description"], NULL, NULL, NULL);
    // Copy triggers to the child hosts
    $child_hosts = get_hosts_by_templateid($hostid);
    while ($child_host = DBfetch($child_hosts)) {
        // recursion
        $result = copy_trigger_to_host($newtriggerid, $child_host["hostid"]);
        if (!$result) {
            return result;
        }
    }
    return $newtriggerid;
}
Beispiel #26
0
 $form->setName('hosts');
 $form->addVar('config', get_request('config', 0));
 $table = new CTableInfo(S_NO_HOSTS_DEFINED);
 $table->setHeader(array(array(new CCheckBox('all_hosts', NULL, "CheckAll('" . $form->GetName() . "','all_hosts');"), SPACE, make_sorting_link(S_NAME, 'h.host')), $show_only_tmp ? NULL : make_sorting_link(S_DNS, 'h.dns'), $show_only_tmp ? NULL : make_sorting_link(S_IP, 'h.ip'), $show_only_tmp ? NULL : make_sorting_link(S_PORT, 'h.port'), S_TEMPLATES, $show_only_tmp ? NULL : make_sorting_link(S_STATUS, 'h.status'), $show_only_tmp ? NULL : make_sorting_link(S_AVAILABILITY, 'h.available'), $show_only_tmp ? NULL : S_ERROR, S_ACTIONS));
 $sql_from = '';
 $sql_where = '';
 if ($_REQUEST['groupid'] > 0) {
     $sql_from .= ',hosts_groups hg ';
     $sql_where .= ' AND hg.groupid=' . $_REQUEST['groupid'] . ' AND hg.hostid=h.hostid ';
 }
 $sql = 'SELECT DISTINCT h.* ' . ' FROM hosts h ' . $sql_from . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . $sql_where . order_by('h.host,h.port,h.ip,h.status,h.available,h.dns');
 $result = DBselect($sql);
 while ($row = DBfetch($result)) {
     $description = array();
     if ($row['proxy_hostid']) {
         $proxy = get_host_by_hostid($row['proxy_hostid']);
         array_push($description, $proxy['host'], ':');
     }
     array_push($description, new CLink($row['host'], 'hosts.php?form=update&hostid=' . $row['hostid'] . url_param('groupid') . url_param('config'), 'action'));
     $templates = get_templates_by_hostid($row['hostid']);
     $host = new CCol(array(new CCheckBox('hosts[' . $row['hostid'] . ']', NULL, NULL, $row['hostid']), SPACE, $description));
     if ($show_only_tmp) {
         $dns = NULL;
         $ip = NULL;
         $port = NULL;
         $status = NULL;
         $available = NULL;
         $error = NULL;
     } else {
         $dns = empty($row['dns']) ? '-' : $row['dns'];
         $ip = empty($row['ip']) ? '-' : $row['ip'];
Beispiel #27
0
function db_save_application($name, $hostid, $applicationid = null, $templateid = 0)
{
    if (!is_string($name)) {
        error('Incorrect parameters for "db_save_application"');
        return false;
    }
    $host = get_host_by_hostid($hostid);
    $hostids = array();
    $db_hosts = get_hosts_by_templateid($host['hostid']);
    while ($db_host = DBfetch($db_hosts)) {
        $hostids[] = $db_host['hostid'];
    }
    $sql = 'SELECT applicationid
			FROM applications
			WHERE name=' . zbx_dbstr($name) . '
				AND ' . DBcondition('hostid', $hostids);
    $lower_app = DBfetch(DBselect($sql));
    if ($lower_app) {
        error(S_APPLICATION . SPACE . "'{$name}'" . SPACE . S_ALREADY_EXISTS_IN_LINKED_HOSTS_SMALL);
        return false;
    }
    $sql = 'SELECT applicationid
			FROM applications
			WHERE name=' . zbx_dbstr($name) . '
				AND hostid=' . $hostid;
    if (!is_null($applicationid)) {
        $sql .= ' AND applicationid<>' . $applicationid;
    }
    $db_app = DBfetch(DBselect($sql));
    if ($db_app && $templateid == 0) {
        error(S_APPLICATION . SPACE . "'{$name}'" . SPACE . S_ALREADY_EXISTS_SMALL);
        return false;
    }
    if ($db_app && !is_null($applicationid)) {
        // delete old application with same name
        delete_application($db_app['applicationid']);
    }
    if ($db_app && is_null($applicationid)) {
        // if found application with same name update them, adding not needed
        $applicationid = $db_app['applicationid'];
    }
    if (is_null($applicationid)) {
        $applicationid_new = get_dbid('applications', 'applicationid');
        $sql = 'INSERT INTO applications (applicationid, name, hostid, templateid) ' . " VALUES ({$applicationid_new}, " . zbx_dbstr($name) . ", {$hostid}, {$templateid})";
        if ($result = DBexecute($sql)) {
            info(S_ADDED_NEW_APPLICATION . SPACE . $host['host'] . ':' . $name);
        }
    } else {
        $old_app = get_application_by_applicationid($applicationid);
        $result = DBexecute('UPDATE applications SET name=' . zbx_dbstr($name) . ', hostid=' . $hostid . ', templateid=' . $templateid . ' WHERE applicationid=' . $applicationid);
        if ($result) {
            info(S_UPDATED_APPLICATION . SPACE . $host['host'] . ':' . $old_app['name']);
        }
    }
    if (!$result) {
        return $result;
    }
    if (is_null($applicationid)) {
        // create application for childs
        $applicationid = $applicationid_new;
        $db_childs = get_hosts_by_templateid($hostid);
        while ($db_child = DBfetch($db_childs)) {
            // recursion
            $result = add_application($name, $db_child['hostid'], $applicationid);
            if (!$result) {
                break;
            }
        }
    } else {
        $db_applications = get_applications_by_templateid($applicationid);
        while ($db_app = DBfetch($db_applications)) {
            // recursion
            $result = update_application($db_app['applicationid'], $name, $db_app['hostid'], $applicationid);
            if (!$result) {
                break;
            }
        }
    }
    if ($result) {
        return $applicationid;
    }
    if ($templateid == 0) {
        delete_application($applicationid);
    }
    return false;
}
/**
 * Create CDiv with host/template information and references to it's elements
 *
 * @param string $currentElement
 * @param int $hostid
 * @param int $discoveryid
 *
 * @return object
 */
function get_header_host_table($currentElement, $hostid, $discoveryid = null)
{
    $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries');
    if (!empty($discoveryid)) {
        unset($elements['applications'], $elements['screens'], $elements['discoveries']);
    }
    $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true);
    if (isset($elements['items'])) {
        $options['selectItems'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['triggers'])) {
        $options['selectTriggers'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['graphs'])) {
        $options['selectGraphs'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['applications'])) {
        $options['selectApplications'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['screens'])) {
        $options['selectScreens'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['discoveries'])) {
        $options['selectDiscoveries'] = API_OUTPUT_COUNT;
    }
    // get hosts
    $dbHost = API::Host()->get($options);
    $dbHost = reset($dbHost);
    // get discoveries
    if (!empty($discoveryid)) {
        $options['itemids'] = $discoveryid;
        $options['output'] = array('name');
        unset($options['hostids'], $options['templated_hosts']);
        $dbDiscovery = API::DiscoveryRule()->get($options);
        $dbDiscovery = reset($dbDiscovery);
    }
    /*
     * Back
     */
    $list = new CList(null, 'objectlist');
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array('&laquo; ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid'))));
    } else {
        $list->addItem(array('&laquo; ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
    }
    /*
     * Name
     */
    $description = '';
    if ($dbHost['proxy_hostid']) {
        $proxy = get_host_by_hostid($dbHost['proxy_hostid']);
        $description .= $proxy['host'] . ': ';
    }
    $description .= $dbHost['name'];
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array(bold(_('Template') . ': '), new CLink($description, 'templates.php?form=update&templateid=' . $dbHost['hostid'])));
    } else {
        switch ($dbHost['status']) {
            case HOST_STATUS_MONITORED:
                $status = new CSpan(_('Monitored'), 'off');
                break;
            case HOST_STATUS_NOT_MONITORED:
                $status = new CSpan(_('Not monitored'), 'on');
                break;
            default:
                $status = _('Unknown');
                break;
        }
        $list->addItem(array(bold(_('Host') . ': '), new CLink($description, 'hosts.php?form=update&hostid=' . $dbHost['hostid'])));
        $list->addItem($status);
        $list->addItem(getAvailabilityTable($dbHost));
    }
    if (!empty($dbDiscovery)) {
        $list->addItem(array('&laquo; ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
        $list->addItem(array(bold(_('Discovery') . ': '), new CLink($dbDiscovery['name'], 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid'])));
    }
    /*
     * Rowcount
     */
    if (isset($elements['applications'])) {
        if ($currentElement == 'applications') {
            $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')'));
        }
    }
    if (isset($elements['items'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'items') {
                $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')'));
            }
        } else {
            if ($currentElement == 'items') {
                $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')'));
            }
        }
    }
    if (isset($elements['triggers'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')'));
            }
        } else {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')'));
            }
        }
    }
    if (isset($elements['graphs'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')'));
            }
        } else {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')'));
            }
        }
    }
    if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) {
        if ($currentElement == 'screens') {
            $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')'));
        }
    }
    if (isset($elements['discoveries'])) {
        if ($currentElement == 'discoveries') {
            $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')'));
        }
    }
    return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all');
}
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null, $periods_cnt = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $item = get_item_by_itemid($itemid);
     $this->items[$this->num] = $item;
     $this->items[$this->num]['description'] = item_description($item);
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
     if (strpos($item['units'], ',') !== false) {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     } else {
         $this->items[$this->num]['unitsLong'] = '';
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
$app_wdgt->addPageheader(S_CONFIGURATION_OF_APPLICATIONS, $frmForm);
if (isset($_REQUEST['form'])) {
    $frm_title = S_NEW_APPLICATION;
    if (isset($_REQUEST['applicationid'])) {
        $result = DBselect('SELECT * FROM applications WHERE applicationid=' . $_REQUEST['applicationid']);
        $row = DBfetch($result);
        $frm_title = S_APPLICATION . ': "' . $row['name'] . '"';
    }
    if (isset($_REQUEST["applicationid"]) && !isset($_REQUEST["form_refresh"])) {
        $appname = $row["name"];
        $apphostid = $row['hostid'];
    } else {
        $appname = get_request("appname", "");
        $apphostid = get_request("apphostid", get_request("hostid", 0));
    }
    $db_host = get_host_by_hostid($apphostid, 1);
    if ($db_host) {
        $apphost = $db_host["host"];
    } else {
        $apphost = '';
        $apphostid = 0;
    }
    $frmApp = new CFormTable($frm_title);
    $frmApp->setHelp("web.applications.php");
    if (isset($_REQUEST["applicationid"])) {
        $frmApp->addVar("applicationid", $_REQUEST["applicationid"]);
    }
    $frmApp->addRow(S_NAME, new CTextBox("appname", $appname, 32));
    $frmApp->addVar("apphostid", $apphostid);
    if (!isset($_REQUEST["applicationid"])) {
        // any new application can SELECT host