|
23 | 23 | +-------------------------------------------------------------------------+ |
24 | 24 | */ |
25 | 25 |
|
| 26 | +ini_set('output_buffering', 'Off'); |
| 27 | + |
26 | 28 | require(__DIR__ . '/../include/cli_check.php'); |
| 29 | + |
27 | 30 | require_once($config['base_path'] . '/lib/utility.php'); |
28 | | -require_once($config['base_path'] . '/lib/api_data_source.php'); |
29 | | -require_once($config['base_path'] . '/lib/poller.php'); |
30 | 31 |
|
31 | | -/* switch to main database for cli's */ |
32 | | -if ($config['poller_id'] > 1) { |
33 | | - db_switch_remote_to_main(); |
34 | | -} |
| 32 | +ini_set('max_execution_time', '0'); |
| 33 | +ini_set('memory_limit', '-1'); |
35 | 34 |
|
36 | 35 | /* process calling arguments */ |
37 | 36 | $parms = $_SERVER['argv']; |
38 | 37 | array_shift($parms); |
39 | 38 |
|
40 | | -$debug = false; |
41 | | -$host_id = 0; |
42 | | -$host_template_id = 0; |
43 | | -$data_template_id = 0; |
44 | | - |
45 | | -foreach($parms as $parameter) { |
46 | | - if (strpos($parameter, '=')) { |
47 | | - list($arg, $value) = explode('=', $parameter); |
48 | | - } else { |
49 | | - $arg = $parameter; |
50 | | - $value = ''; |
51 | | - } |
52 | | - |
53 | | - switch ($arg) { |
54 | | - case '--host-id': |
55 | | - $host_id = trim($value); |
56 | | - |
57 | | - if (!is_numeric($host_id)) { |
58 | | - print 'ERROR: You must supply a valid Device Id to run this script!' . PHP_EOL; |
59 | | - exit(1); |
60 | | - } |
61 | | - |
62 | | - break; |
63 | | - case '--host-template-id': |
64 | | - $host_template_id = trim($value); |
65 | | - |
66 | | - if (!is_numeric($host_template_id)) { |
67 | | - print 'ERROR: You must supply a valid Device Template Id to run this script!' . PHP_EOL; |
68 | | - exit(1); |
69 | | - } |
| 39 | +$php_binary = read_config_option('path_php_binary'); |
70 | 40 |
|
71 | | - break; |
72 | | - case '--data-template-id': |
73 | | - $data_template_id = trim($value); |
| 41 | +$parameters = implode(' ', $parms); |
74 | 42 |
|
75 | | - if (!is_numeric($data_template_id)) { |
76 | | - print 'ERROR: You must supply a valid Data Template Id to run this script!' . PHP_EOL; |
77 | | - exit(1); |
78 | | - } |
| 43 | +cacti_log('WARNING: Deprecated script push_out_hosts.php. Please use rebuild_poller_cache.php.', false, 'PUSHOUT'); |
79 | 44 |
|
80 | | - break; |
81 | | - case '-d': |
82 | | - case '--debug': |
83 | | - $debug = true; |
84 | | - |
85 | | - break; |
86 | | - case '-h': |
87 | | - case '-H': |
88 | | - case '--help': |
89 | | - display_help(); |
90 | | - |
91 | | - exit; |
92 | | - case '-v': |
93 | | - case '-V': |
94 | | - case '--version': |
95 | | - display_version(); |
96 | | - |
97 | | - exit; |
98 | | - default: |
99 | | - print 'ERROR: Invalid Parameter ' . $parameter . PHP_EOL . PHP_EOL; |
100 | | - |
101 | | - display_help(); |
102 | | - exit; |
103 | | - } |
| 45 | +if (in_array('-v', $parms) || in_array('-V', $parms) || in_array('--version', $parms)) { |
| 46 | + // exception for github tests |
| 47 | + print 'Cacti Push out hosts/repopulate poller cache Tool, Version ' . get_cacti_cli_version() . ' ' . COPYRIGHT_YEARS . PHP_EOL; |
104 | 48 | } |
105 | | - |
106 | | -/* obtain timeout settings */ |
107 | | -$max_execution = ini_get('max_execution_time'); |
108 | | -$max_memory = ini_get('memory_limit'); |
109 | | - |
110 | | -/* set new timeout and memory settings */ |
111 | | -ini_set('max_execution_time', '0'); |
112 | | -ini_set('memory_limit', '-1'); |
113 | | - |
114 | | -$sql_where = ''; |
115 | | -$params = array(); |
116 | | - |
117 | | -if ($host_id > 0) { |
118 | | - $sql_where = ' AND h.id = ?'; |
119 | | - $params[] = $host_id; |
120 | | -} |
121 | | - |
122 | | -if ($host_template_id > 0) { |
123 | | - $sql_where .= ' AND h.host_template_id = ?'; |
124 | | - $params[] = $host_template_id; |
125 | | -} |
126 | | - |
127 | | -/* clear the poller cache first */ |
128 | | -$hosts = db_fetch_assoc_prepared("SELECT h.id |
129 | | - FROM host AS h |
130 | | - WHERE h.disabled = '' |
131 | | - $sql_where", |
132 | | - $params); |
133 | | - |
134 | | -/* initialize some variables */ |
135 | | -$current_host = 1; |
136 | | -$total_hosts = sizeof($hosts); |
137 | | - |
138 | | -/* issue warnings and start message if applicable */ |
139 | | -print 'WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time' . PHP_EOL; |
140 | | -debug("There are '$total_hosts' hosts to push out."); |
141 | | - |
142 | | -/* start rebuilding the poller cache */ |
143 | | -if (cacti_sizeof($hosts) > 0) { |
144 | | - foreach ($hosts as $host) { |
145 | | - if (!$debug) print '.'; |
146 | | - push_out_host($host['id'], 0, $data_template_id); |
147 | | - debug("Host ID '" . $host['id'] . "' or '$current_host' of '$total_hosts' updated"); |
148 | | - $current_host++; |
149 | | - } |
150 | | -} |
151 | | -if (!$debug) { |
152 | | - print PHP_EOL; |
153 | | -} |
154 | | - |
155 | | -/* display_version - displays version information */ |
156 | | -function display_version() { |
157 | | - $version = get_cacti_cli_version(); |
158 | | - print "Cacti Push Out Host Poller Cache Script, Version $version, " . COPYRIGHT_YEARS . PHP_EOL; |
159 | | -} |
160 | | - |
161 | | -/* display_help - displays the usage of the function */ |
162 | | -function display_help () { |
163 | | - display_version(); |
164 | | - |
165 | | - print PHP_EOL . 'usage: push_out_hosts.php [--host-id=N] [--host-template-id=N] [--debug]' . PHP_EOL . PHP_EOL; |
166 | | - |
167 | | - print 'Optional:' . PHP_EOL; |
168 | | - print ' --host-id=N - Run for a specific Device' . PHP_EOL; |
169 | | - print ' --host-template-id=N - Run for a specific Device Template' . PHP_EOL; |
170 | | - print ' --data-template-id=N - Run for a specific Data Template' . PHP_EOL; |
171 | | - print ' --debug - Display verbose output during execution' . PHP_EOL . PHP_EOL; |
172 | | -} |
173 | | - |
174 | | -function debug($message) { |
175 | | - global $debug; |
176 | | - |
177 | | - if ($debug) { |
178 | | - print('DEBUG: ' . trim($message) . PHP_EOL); |
179 | | - } |
| 49 | +else { |
| 50 | + print 'WARNING: Deprecated script push_out_hosts.php. Please use rebuild_poller_cache.php.' . PHP_EOL; |
| 51 | + passthru ($php_binary . ' ' . $config['base_path'] . '/cli/rebuild_poller_cache.php ' .$parameters); |
180 | 52 | } |
0 commit comments