function device_by_name($name, $refresh = 0) { // FIXME - cache name > id too. return device_by_id_cache(get_device_id_by_hostname($name), $refresh); }
include_once "includes/defaults.inc.php"; include_once "config.php"; $options = getopt("d"); if (isset($options['d'])) { array_shift($argv); } // for compatability include_once "includes/definitions.inc.php"; include "includes/functions.inc.php"; print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%W重命名设备%n\n", 'color'); // Remove a host and all related data from the system if ($argv[1] && $argv[2]) { $host = strtolower($argv[1]); $id = get_device_id_by_hostname($host); if ($id) { $tohost = strtolower($argv[2]); $toid = get_device_id_by_hostname($tohost); if ($toid) { print_error("没有重命名. 新的主机名 {$tohost} 已经存在."); } else { if (renamehost($id, $tohost, 'console')) { print_message("主机 {$host} 重命名为 {$tohost}."); } } } else { print_error("主机 {$host} 不存在."); } } else { print_message("%n\n使用方法:\n{$scriptname} <原主机名> <新主机名>\n\n%r无效的参数!%n", 'color', FALSE); } // EOF
* Observium Network Management and Monitoring System * Copyright (C) 2006-2015, Adam Armstrong - http://www.observium.org * * @package observium * @subpackage webui * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ // If we've been given a hostname, try to retrieve the device_id if (isset($vars['device']) && !is_numeric($vars['device'])) { $vars['hostname'] = $vars['device']; unset($vars['device']); } if (empty($vars['device']) && !empty($vars['hostname'])) { $vars['device'] = get_device_id_by_hostname($vars['hostname']); // If device lookup fails, generate an error. if (empty($vars['device'])) { print_error('<h4>Invalid Hostname</h4> A device matching the given hostname was not found. Please retype the hostname and try again.'); return; } } // If there is no device specified in the URL, generate an error. if (empty($vars['device'])) { print_error('<h4>No device specified</h4> A valid device was not specified in the URL. Please retype and try again.'); return; } // Allow people to see this page if they have permission to see one of the ports, but don't show them tabs. $permit_tabs = array();
function generate_entity_link($entity_type, $entity, $text = NULL, $graph_type = NULL, $escape = TRUE, $short = FALSE) { if (is_numeric($entity)) { $entity = get_entity_by_id_cache($entity_type, $entity); } entity_rewrite($entity_type, $entity); switch ($entity_type) { case "device": $link = generate_device_link($entity); break; case "mempool": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'mempool')); break; case "processor": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'processor')); break; case "status": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'status', 'id' => $entity['status_id'])); break; case "sensor": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => $entity['sensor_class'], 'id' => $entity['sensor_id'])); break; case "printersupply": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'printing', 'supply' => $entity['supply_type'])); break; case "port": $link = generate_port_link($entity, NULL, $graph_type, $escape, $short); break; case "storage": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage')); break; case "bgp_peer": $url = generate_url(array('page' => 'device', 'device' => $entity['peer_device_id'] ? $entity['peer_device_id'] : $entity['device_id'], 'tab' => 'routing', 'proto' => 'bgp')); break; case "netscalervsvr": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_vsvr', 'vsvr' => $entity['vsvr_id'])); break; case "netscalersvc": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_services', 'svc' => $entity['svc_id'])); break; case "netscalersvcgrpmem": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_servicegroupmembers', 'svc' => $entity['svc_id'])); break; case "sla": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'slas', 'id' => $entity['sla_id'])); break; case "pseudowire": $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'pseudowires', 'id' => $entity['pseudowire_id'])); break; case "maintenance": $url = generate_url(array('page' => 'alert_maintenance', 'maintenance' => $entity['maint_id'])); break; case "group": $url = generate_url(array('page' => 'group', 'group_id' => $entity['group_id'])); break; case "virtualmachine": // If we know this device by its vm name in our system, create a link to it, else just print the name. if (get_device_id_by_hostname($entity['vm_name'])) { $link = generate_device_link(device_by_name($entity['vm_name'])); } else { // Hardcode $link to just show the name, no actual link $link = $entity['vm_name']; } break; default: $url = NULL; } if (!isset($link)) { if (!isset($text)) { if ($short && $entity['entity_shortname']) { $text = $entity['entity_shortname']; } else { $text = $entity['entity_name']; } } if ($escape) { $text = escape_html($text); } $link = '<a href="' . $url . '" class="entity-popup ' . $entity['html_class'] . '" data-eid="' . $entity['entity_id'] . '" data-etype="' . $entity_type . '">' . $text . '</a>'; } return $link; }
function print_vm_row($vm, $device = NULL) { echo '<tr>'; echo '<td>'; if (get_device_id_by_hostname($vm['vmwVmDisplayName'])) { echo generate_device_link(device_by_name($vm['vmwVmDisplayName'])); } else { echo $vm['vmwVmDisplayName']; } echo "</td>"; echo '<td>' . $vm['vmwVmState'] . "</td>"; if ($vm['vmwVmGuestOS'] == "E: 工具未安装") { echo '<td class="small">未知 (VMware Tools 未安装)</td>'; } else { if ($vm['vmwVmGuestOS'] == "E: 工具未运行") { echo '<td class="small">未知 (VMware Tools 未运行)</td>'; } else { if ($vm['vmwVmGuestOS'] == "") { echo '<td class="small"><i>(未知)</i></td>'; } elseif (isset($config['vmware_guestid'][$vm['vmwVmGuestOS']])) { echo '<td>' . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . "</td>"; } else { echo '<td>' . $vm['vmwVmGuestOS'] . "</td>"; } } } if ($vm['vmwVmMemSize'] >= 1024) { echo "<td class=list>" . sprintf("%.2f", $vm['vmwVmMemSize'] / 1024) . " GB</td>"; } else { echo "<td class=list>" . sprintf("%.2f", $vm['vmwVmMemSize']) . " MB</td>"; } echo '<td>' . $vm['vmwVmCpus'] . " CPU</td>"; }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2014 Adam Armstrong * */ echo '<tr class="list">'; echo '<td class="list">'; if (get_device_id_by_hostname($vm['vmwVmDisplayName'])) { echo generate_device_link(device_by_name($vm['vmwVmDisplayName'])); } else { echo $vm['vmwVmDisplayName']; } echo "</td>"; echo '<td class="list">' . $vm['vmwVmState'] . "</td>"; if ($vm['vmwVmGuestOS'] == "E: 工具未安装") { echo '<td class="small">未知 (VMware Tools 未安装)</td>'; } else { if ($vm['vmwVmGuestOS'] == "") { echo '<td class="small"><i>(未知)</i></td>'; } elseif (isset($config['vmware_guestid'][$vm['vmwVmGuestOS']])) { echo '<td class="list">' . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . "</td>"; } else { echo '<td class="list">' . $vm['vmwVmGuestOS'] . "</td>"; }
* @copyright (C) 2006-2015 Adam Armstrong * */ chdir(dirname($argv[0])); $scriptname = basename($argv[0]); include_once "includes/defaults.inc.php"; include_once "config.php"; $options = getopt("d"); if (isset($options['d'])) { array_shift($argv); } // for compatability include_once "includes/definitions.inc.php"; include "includes/functions.inc.php"; print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%W删除设备%n\n", 'color'); // Remove a host and all related data from the system if ($argv[1]) { $host = strtolower($argv[1]); $id = get_device_id_by_hostname($host); $delete_rrd = isset($argv[2]) && strtolower($argv[2]) == 'rrd' ? TRUE : FALSE; // Test if a valid id was fetched from get_device_id_by_hostname() if (isset($id) && is_numeric($id)) { print_warning(delete_device($id, $delete_rrd)); print_success("设备 {$host} 已删除."); } else { print_error("设备 {$host} 不存在!"); } } else { print_message("%n\nUSAGE:\n{$scriptname} <hostname> [rrd]\n\nEXAMPLE:\n%WKeep RRDs%n: {$scriptname} <hostname>\n%WRemove RRDs%n: {$scriptname} <hostname> rrd\n\n%r无效的参数!%n", 'color', FALSE); } // EOF