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
include "includes/sql-config.inc.php"; print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRename Device%n\n", 'color'); if (OBS_DEBUG) { print_versions(); } $options = array(); if (isset($options['p'])) { $options['ping_skip'] = 1; array_shift($argv); } // 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("NOT renamed. New hostname {$tohost} already exists."); } else { if (renamehost($id, $tohost, 'console', $options)) { print_message("Host {$host} renamed to {$tohost}."); } } } else { print_error("Host {$host} doesn't exist."); } } else { print_message("%n\nUSAGE:\n{$scriptname} <old hostname> <new hostname>\n\nOPTIONS:\n -p Skip icmp echo checks, device renamed only by SNMP checks\n\nDEBUGGING OPTIONS:\n -d Enable debugging output.\n -dd More verbose debugging output.\n\n%rInvalid arguments!%n", 'color', FALSE); } // EOF
#FIXME needs more sanity checking! and better feedback $param = array('purpose' => $vars['descr'], 'type' => $vars['type'], 'ignore' => $vars['ignore'], 'disabled' => $vars['disabled']); $rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id'])); if ($rows_updated > 0 || $updated) { $update_message = "Device record updated."; $updated = 1; $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); } elseif ($rows_updated = '-1') { $update_message = "Device record unchanged. No update necessary."; $updated = -1; } else { $update_message = "Device record update error."; } if (isset($_POST['hostname']) && $_POST['hostname'] !== '' && $_POST['hostname'] !== $device['hostname']) { if (is_admin()) { $result = renamehost($device['device_id'], $_POST['hostname'], 'webui'); if ($result == "") { print_message("Hostname updated from {$device['hostname']} to {$_POST['hostname']}"); echo ' <script> var loc = window.location; window.location.replace(loc.protocol + "//" + loc.host + loc.pathname + loc.search); </script> '; } else { print_error($result . ". Does your web server have permission to modify the rrd files?"); } } else { print_error('Only administrative users may update the device hostname'); } }
#!/usr/bin/php <?php include "includes/defaults.inc.php"; include "config.php"; include "includes/functions.php"; # Remove a host and all related data from the system if ($argv[1] && $argv[2]) { $host = strtolower($argv[1]); $id = getidbyname($host); if ($id) { renamehost($id, $argv[2]); echo "Renamed {$host}\n"; } else { echo "Host doesn't exist!\n"; } } else { echo "Host Rename Tool\nUsage: ./renamehost.php <old hostname> <new hostname>\n"; }