-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrename_device.php
executable file
·65 lines (55 loc) · 1.56 KB
/
rename_device.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage cli
* @copyright (C) Adam Armstrong
*
*/
chdir(dirname($argv[0]));
$options = getopt("dp");
if (isset($options['d'])) {
array_shift($argv);
} // for compatibility
include("includes/observium.inc.php");
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRename Device%n\n", 'color');
if (OBS_DEBUG) {
print_versions();
}
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
USAGE:
$scriptname <old hostname> <new hostname>
OPTIONS:
-p Skip icmp echo checks, device renamed only by SNMP checks
DEBUGGING OPTIONS:
-d Enable debugging output.
-dd More verbose debugging output.
%rInvalid arguments!%n", 'color', FALSE);
}
// EOF