mirror of
https://github.com/Cacti/cacti.git
synced 2026-11-08 21:16:17 +09:00
* spelling: about Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: accommodates Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: account Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: acquire Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: across Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: actual Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: addition Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: administrative Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: agent Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: algorithms Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: amongst Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: anchor Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: appropriate Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: archive Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: arguments Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: assuming Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: asynchronously Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: attachments Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: attribute Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: availability Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: behaves Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: being Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: branch Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: calculate Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: callback Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: case of Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: certainly Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: changes Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: characters Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: coalition Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: column Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: configuration Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: confirm Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: connect to Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: consistently Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: containing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: convert Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: corrected Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: current Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: data Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: datasource Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: default Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: delimited Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: delimiter Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: deprecated Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: description Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: destination Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: determines Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: device Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: devices Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: diagnosing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: dimensional Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: directory Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: disabling Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: distribution Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: documentation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: dynamically Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: embedded Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: enough Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: especially Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: everything is Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: everything Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: example Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: exceeds Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: exclude Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: existence Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: explicitly Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: exported Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: extract Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: extraneous Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: failed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: fails Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: fallback Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: fashioned Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: field values Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: foreground Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: format Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: function Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: functions Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: gauge Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: get Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: github Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: global Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: graph Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: gzipped Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: hierarchy Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: identify Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: immediately Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: increase Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: increment Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: indexes Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: inefficient Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: inherited Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: initialize Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: installation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: insufficient Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: irrelevant Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: label Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: latest Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: leaves Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: local Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: location Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: lockout Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: logging Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: manually Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: menus Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: minimum Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: modifiable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: multi Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: multiple Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: mutually Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: naturally Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: navigation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: necessary Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: network Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: number Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: occurrences Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: only Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: output Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: overridable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: overridden Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: override Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: package Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: parameters Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: perform Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: performing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: permanently Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: permission Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: piece Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: plugin Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: prevent Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: programmatically Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: propagated Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: purpose Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: purposes Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: push Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: queries Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: refresh Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: relevant Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: remainder Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: repetitions Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: representing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: reserved Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: resetting Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: response Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: responsible Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: results Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: retrieve Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: routines Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: running Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: section Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: separate Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: sequences Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: session Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: settings Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: setup Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: snmp Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: some Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: specific Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: specification Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: specified Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: stacked Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: statistics Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: string Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: structure Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: structured Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: successful Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: successfully Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: suggested Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: suppress Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: suppresses Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: switches Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: synchronization Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: synchronize Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: table Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: temperature Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: template Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: temporary Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: textarea Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: the Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: themselves Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: therefore Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: thoroughly Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: through Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: time Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: timed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: timespan Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: tries Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: true Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: uninstall Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unless Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unlocks Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: up to Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: update Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: updating Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: useful Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: utility Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: variable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: version Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: visibility Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: what is Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: when Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: whether Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: written Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
340 lines
9.6 KiB
PHP
Executable File
340 lines
9.6 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2022 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU General Public License |
|
|
| as published by the Free Software Foundation; either version 2 |
|
|
| of the License, or (at your option) any later version. |
|
|
| |
|
|
| This program is distributed in the hope that it will be useful, |
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
| GNU General Public License for more details. |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
| This code is designed, written, and maintained by the Cacti Group. See |
|
|
| about.php and/or the AUTHORS file for specific developer information. |
|
|
+-------------------------------------------------------------------------+
|
|
| http://www.cacti.net/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
require(__DIR__ . '/../include/cli_check.php');
|
|
require_once($config['base_path'] . '/lib/api_automation_tools.php');
|
|
require_once($config['base_path'] . '/lib/api_data_source.php');
|
|
require_once($config['base_path'] . '/lib/api_graph.php');
|
|
require_once($config['base_path'] . '/lib/data_query.php');
|
|
require_once($config['base_path'] . '/lib/poller.php');
|
|
require_once($config['base_path'] . '/lib/utility.php');
|
|
|
|
ini_set('max_execution_time', '0');
|
|
ini_set('memory_limit', '-1');
|
|
|
|
/* switch to main database for cli's */
|
|
if ($config['poller_id'] > 1) {
|
|
db_switch_remote_to_main();
|
|
}
|
|
|
|
/* process calling arguments */
|
|
$parms = $_SERVER['argv'];
|
|
array_shift($parms);
|
|
|
|
if (cacti_sizeof($parms)) {
|
|
$host_template_ids = array();
|
|
$host_ids = array();
|
|
$graph_template_ids = array();
|
|
$regex = array();
|
|
|
|
$graphTemplates = getGraphTemplates();
|
|
$hostTemplates = getHostTemplates();
|
|
$all = false;
|
|
$force = false;
|
|
$list = false;
|
|
$preserve = false;
|
|
|
|
$listHosts = false;
|
|
$listGraphTemplates = false;
|
|
$listHostTemplates = false;
|
|
|
|
$quietMode = false;
|
|
|
|
$shortopts = 'VvHh';
|
|
|
|
$longopts = array(
|
|
'host-id::',
|
|
'graph-type::',
|
|
'graph-template-id::',
|
|
'host-template-id::',
|
|
'graph-regex::',
|
|
'all',
|
|
'preserve',
|
|
'quiet',
|
|
|
|
'list',
|
|
'list-hosts',
|
|
'list-host-templates',
|
|
'list-graph-templates',
|
|
'force',
|
|
'version',
|
|
'help'
|
|
);
|
|
|
|
$options = getopt($shortopts, $longopts);
|
|
|
|
foreach($options as $arg => $value) {
|
|
switch($arg) {
|
|
case 'graph-regex':
|
|
if (!is_array($value)) {
|
|
$value = array($value);
|
|
}
|
|
|
|
$regex = $value;
|
|
|
|
foreach($value as $item) {
|
|
if (!validate_is_regex($item)) {
|
|
print "ERROR: Regex specified '$item', is not a valid Regex!" . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
break;
|
|
case 'graph-template-id':
|
|
if (!is_array($value)) {
|
|
$value = array($value);
|
|
}
|
|
|
|
$graph_template_ids = $value;
|
|
|
|
break;
|
|
case 'host-template-id':
|
|
if (!is_array($value)) {
|
|
$value = array($value);
|
|
}
|
|
|
|
$host_template_ids = $value;
|
|
|
|
break;
|
|
case 'host-id':
|
|
if (!is_array($value)) {
|
|
$value = array($value);
|
|
}
|
|
|
|
$host_ids = $value;
|
|
|
|
break;
|
|
case 'all':
|
|
$all = true;
|
|
|
|
break;
|
|
case 'list':
|
|
$list = true;
|
|
|
|
break;
|
|
case 'list-hosts':
|
|
$listHosts = true;
|
|
|
|
break;
|
|
case 'list-graph-templates':
|
|
$listGraphTemplates = true;
|
|
|
|
break;
|
|
case 'list-host-templates':
|
|
$listHostTemplates = true;
|
|
|
|
break;
|
|
case 'force':
|
|
$force = true;
|
|
|
|
break;
|
|
case 'version':
|
|
case 'V':
|
|
case 'v':
|
|
display_version();
|
|
exit(0);
|
|
case 'help':
|
|
case 'H':
|
|
case 'h':
|
|
display_help();
|
|
exit(0);
|
|
default:
|
|
print "ERROR: Invalid Argument: ($arg)" . PHP_EOL . PHP_EOL;
|
|
}
|
|
}
|
|
} else {
|
|
display_help();
|
|
exit(0);
|
|
}
|
|
|
|
if ($list && $force) {
|
|
print "The --list and --force options are mutually exclusive. Pick on or the other." . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
if (cacti_sizeof($host_template_ids)) {
|
|
foreach($host_template_ids as $id) {
|
|
if (!is_numeric($id) || $id <= 0) {
|
|
print "FATAL: Host Template ID $id is invalid" . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (cacti_sizeof($graph_template_ids)) {
|
|
foreach($graph_template_ids as $id) {
|
|
if (!is_numeric($id) || $id <= 0) {
|
|
print "FATAL: Graph Template ID $id is invalid" . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (cacti_sizeof($host_ids)) {
|
|
foreach($host_ids as $id) {
|
|
if (!is_numeric($id) || $id <= 0) {
|
|
print "FATAL: Host ID $id is invalid" . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($listHosts) {
|
|
$hosts = getHosts($host_template_ids);
|
|
|
|
displayHosts($hosts, $quietMode);
|
|
|
|
exit(0);
|
|
} elseif ($listHostTemplates) {
|
|
$hostTemplates = getHostTemplates();
|
|
|
|
displayHostTemplates($hostTemplates, $quietMode);
|
|
|
|
exit(0);
|
|
} elseif ($listGraphTemplates) {
|
|
$graphTemplates = getGraphTemplatesByHostTemplate($host_template_ids);
|
|
|
|
displayGraphTemplates($graphTemplates, $quietMode);
|
|
|
|
exit(0);
|
|
} else {
|
|
$sql_where = 'WHERE gl.id > 0';
|
|
$all_option = true;
|
|
|
|
if (cacti_sizeof($host_ids) && $all === false) {
|
|
$sql_where .= ' AND gl.host_id IN (' . implode(',', $host_ids). ')';
|
|
$all_option = false;
|
|
}
|
|
|
|
if (cacti_sizeof($host_template_ids) && $all === false) {
|
|
$sql_where .= ' AND h.host_template_id IN (' . implode(',', $host_template_ids). ')';
|
|
$all_option = false;
|
|
}
|
|
|
|
if (cacti_sizeof($graph_template_ids) && $all === false) {
|
|
$sql_where .= ' AND gl.graph_template_id IN (' . implode(',', $graph_template_ids). ')';
|
|
$all_option = false;
|
|
}
|
|
|
|
if (cacti_sizeof($regex) && $all === false) {
|
|
$sql_where .= ' AND (';
|
|
$sql_cwhere = '';
|
|
|
|
foreach($regex as $r) {
|
|
$sql_cwhere .= ($sql_cwhere == '' ? '':' OR ') . 'title_cache RLIKE "' . $r . '"';
|
|
}
|
|
|
|
$sql_where .= $sql_cwhere . ')';
|
|
$all_option = false;
|
|
}
|
|
|
|
if ($all_option && $all === false && $list === false) {
|
|
print 'ERROR: The options specified will remove all graphs. To do this you must use the --all option. Exiting' . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
$graphs = db_fetch_assoc("SELECT gl.id, gtg.title_cache
|
|
FROM graph_local AS gl
|
|
INNER JOIN graph_templates_graph AS gtg
|
|
ON gl.id=gtg.local_graph_id
|
|
INNER JOIN host AS h
|
|
ON h.id = gl.host_id
|
|
$sql_where");
|
|
|
|
if ($graphs != false && cacti_sizeof($graphs)) {
|
|
print 'There are ' . cacti_sizeof($graphs) . ' Graphs to Remove.' . (!$force ? ' Use the --force option to remove these Graphs.':'');
|
|
|
|
if ($list) {
|
|
print PHP_EOL . "ID\tGraphName" . PHP_EOL;
|
|
|
|
foreach($graphs as $graph) {
|
|
print $graph['id'] . "\t" . $graph['title_cache'] . PHP_EOL;
|
|
}
|
|
} elseif ($force) {
|
|
$local_graph_ids = array_rekey($graphs, 'id', 'id');
|
|
|
|
if ($preserve) {
|
|
print ' Data Sources will be preserved.' . PHP_EOL;
|
|
$delete_type = 1;
|
|
} else {
|
|
print ' Data Sources will be removed if possible.' . PHP_EOL;
|
|
$delete_type = 2;
|
|
}
|
|
|
|
api_delete_graphs($local_graph_ids, $delete_type);
|
|
|
|
print 'Delete Operation Completed' . PHP_EOL;
|
|
} else {
|
|
print PHP_EOL . ' Use the --list option to view the list of Graphs' . PHP_EOL;;
|
|
}
|
|
} else {
|
|
print 'No matching Graphs found.' . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
exit(0);
|
|
|
|
/* display_version - displays version information */
|
|
function display_version() {
|
|
$version = get_cacti_cli_version();
|
|
print "Cacti Remove Graphs Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL;
|
|
}
|
|
|
|
function display_help() {
|
|
display_version();
|
|
|
|
print PHP_EOL . "usage: remove_graphs.php --graph-template-id=ID [--host-template-id=ID" . PHP_EOL;
|
|
print " [--host-id=ID] [--graph-regex=R]" . PHP_EOL;
|
|
print " [--force] [--preserve]" . PHP_EOL . PHP_EOL;
|
|
|
|
print "Cacti utility for removing Graphs through the command line." . PHP_EOL . PHP_EOL;
|
|
|
|
print "Options:" . PHP_EOL;
|
|
print " --graph-template-id=ID Mandatory list of Graph Templates." . PHP_EOL;
|
|
print " --host-template-id=ID Optional list of Device Templates." . PHP_EOL;
|
|
print " --host-id=ID Optional list of Device IDs." . PHP_EOL;
|
|
print " --graph-regex=R Optional Graph name regular expression." . PHP_EOL;
|
|
print " --all Remove all Graphs. Ignore other settings." . PHP_EOL;
|
|
print " --force Actually remove the Graphs, dont just list." . PHP_EOL;
|
|
print " --preserve Preserve the Data Sources. Default is to remove." . PHP_EOL . PHP_EOL;
|
|
|
|
print "By default, you must provide from one to many graph-template-id. Device Template IDs" . PHP_EOL;
|
|
print "Device IDs and the regular expression are optional. If you wish to specify multiple" . PHP_EOL;
|
|
print "IDs, just repeat the parameter ex: --host-template-id=X --host-template-id=Y" . PHP_EOL . PHP_EOL;
|
|
|
|
print "By default, this utility will only report on the number of Graphs that will be removed. If you" . PHP_EOL;
|
|
print "provide the --force option, the Graphs will actually be removed. If you use the --list option" . PHP_EOL;
|
|
print "each of the Graphs to be removed, will be listed. Options --list and --force are" . PHP_EOL;
|
|
print "mutually exclusive." . PHP_EOL . PHP_EOL;
|
|
|
|
print "List Options:" . PHP_EOL;
|
|
print " --list" . PHP_EOL;
|
|
print " --list-hosts [--host-template-id=ID]" . PHP_EOL;
|
|
print " --list-graph-templates [--host-template-id=ID]" . PHP_EOL;
|
|
print " --list-host-templates" . PHP_EOL . PHP_EOL;
|
|
}
|
|
|