Apply fixes from StyleCI (#12124)

This commit is contained in:
Jellyfrog
2020-09-21 15:59:34 +02:00
committed by GitHub
parent 0d56bbd946
commit 29f45ca352
816 changed files with 5038 additions and 5038 deletions

View File

@@ -29,16 +29,16 @@ if (isset($options['v'])) {
Config::set('auth_ldap_debug', 1);
}
echo "Authentication Method: " . Config::get('auth_mechanism') . PHP_EOL;
echo 'Authentication Method: ' . Config::get('auth_mechanism') . PHP_EOL;
// if ldap like, check selinux
if (Config::get('auth_mechanism') == 'ldap' || Config::get('auth_mechanism') == "active_directory") {
if (Config::get('auth_mechanism') == 'ldap' || Config::get('auth_mechanism') == 'active_directory') {
$enforce = shell_exec('getenforce 2>/dev/null');
if (Str::contains($enforce, 'Enforcing')) {
// has selinux
$output = shell_exec('getsebool httpd_can_connect_ldap');
if ($output != "httpd_can_connect_ldap --> on\n") {
print_error("You need to run: setsebool -P httpd_can_connect_ldap=1");
print_error('You need to run: setsebool -P httpd_can_connect_ldap=1');
exit;
}
}
@@ -76,14 +76,14 @@ try {
$bind_success = $adbind_rm->invoke($authorizer, true, true);
if (! $bind_success) {
echo ldap_error($lc_rp->getValue($authorizer)) . PHP_EOL;
print_message("Could not anonymous bind to AD");
print_message('Could not anonymous bind to AD');
} else {
print_message('AD bind anonymous successful');
}
}
if (! $bind_success) {
print_error("Could not bind to AD, you will not be able to use the API or alert AD users");
print_error('Could not bind to AD, you will not be able to use the API or alert AD users');
}
}
@@ -93,8 +93,8 @@ try {
return "{$user['username']} ({$user['user_id']})";
}, $users);
echo "Users: " . implode(', ', $output) . PHP_EOL;
echo "Total users: " . count($users) . PHP_EOL;
echo 'Users: ' . implode(', ', $output) . PHP_EOL;
echo 'Total users: ' . count($users) . PHP_EOL;
exit;
}
@@ -139,6 +139,6 @@ try {
}
}
} catch (Exception $e) {
echo "Error: " . get_class($e) . " thrown!\n";
echo 'Error: ' . get_class($e) . " thrown!\n";
echo $e->getMessage() . PHP_EOL;
}

View File

@@ -9,7 +9,7 @@ chdir($install_dir);
$init_modules = [];
require $install_dir . '/includes/init.php';
$options = getopt('dh:e:', ["help"]);
$options = getopt('dh:e:', ['help']);
Config::set('rrd.enable', false);
Config::set('influxdb.enable', false);
@@ -35,7 +35,7 @@ $where = '';
$params = [];
if (isset($options['h'])) {
if (is_numeric($options['h'])) {
$where = "AND `device_id` = ?";
$where = 'AND `device_id` = ?';
$params = [$options['h']];
} elseif (Str::contains($options['h'], ',')) {
$device_ids = array_map('trim', explode(',', $options['h']));
@@ -43,7 +43,7 @@ if (isset($options['h'])) {
$where = 'AND `device_id` in ' . dbGenPlaceholders(count($device_ids));
$params = $device_ids;
} else {
$where = "AND `hostname` LIKE ?";
$where = 'AND `hostname` LIKE ?';
$params = [str_replace('*', '%', mres($options['h']))];
}
}
@@ -57,7 +57,7 @@ if (isset($options['e'])) {
$enable_sel_value = $options['e'];
}
echo "Full Polling: ";
echo 'Full Polling: ';
Config::set('polling.selected_ports', false);
foreach ($devices as $index => $device) {
echo $device['device_id'] . ' ';
@@ -73,7 +73,7 @@ foreach ($devices as $index => $device) {
echo PHP_EOL;
Config::set('polling.selected_ports', true);
echo "Selective Polling: ";
echo 'Selective Polling: ';
foreach ($devices as $index => $device) {
echo $device['device_id'] . ' ';
if (! $debug) {
@@ -104,15 +104,15 @@ foreach ($devices as &$device) {
// $enable_sel_value is negative and we want to enable it for all devices with an even lower value.
// It also has to save more than 1 s, or we might enable it for devices with i.e. 100ms vs 50ms, which isn't needed.
$device['set'] = "none";
$device['set'] = 'none';
if (isset($enable_sel_value) && $device['diff_perc'] < ($enable_sel_value * -1) && $device['diff_sec'] < -1) {
set_dev_attrib($device, 'selected_ports', "true");
$device['set'] = "true";
set_dev_attrib($device, 'selected_ports', 'true');
$device['set'] = 'true';
$set_count++;
}
if (isset($enable_sel_value) && $device['diff_perc'] > $enable_sel_value && $device['diff_sec'] > 1) {
set_dev_attrib($device, 'selected_ports', "false");
$device['set'] = "false";
set_dev_attrib($device, 'selected_ports', 'false');
$device['set'] = 'false';
$set_count++;
}
}

View File

@@ -60,7 +60,7 @@ if (isset($hostname)) {
}
if (isset($options['help']) || empty($target_os)) {
echo "Script to collect snmp data from devices to be used for testing.
echo 'Script to collect snmp data from devices to be used for testing.
Snmp data is saved in tests/snmpsim.
Usage:
@@ -75,7 +75,7 @@ Optional:
-f, --file Save data to file instead of the standard location
-d, --debug Enable debug output
--snmpsim Run snmpsimd.py using the collected data for manual testing.
";
';
exit;
}
@@ -121,7 +121,7 @@ try {
$prefer_new_snmprec = isset($options['n']) || isset($options['prefer-new']);
echo "Capturing Data: ";
echo 'Capturing Data: ';
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
$capture->captureFromDevice($device['device_id'], true, $prefer_new_snmprec);
} catch (InvalidModuleException $e) {

View File

@@ -32,9 +32,9 @@ if (! is_writable(getenv('HOME'))) {
$use_https = true;
// Set up proxy if needed, check git config for proxies too
if ($proxy = getenv("HTTPS_PROXY") ?: getenv("https_proxy")) {
if ($proxy = getenv('HTTPS_PROXY') ?: getenv('https_proxy')) {
$use_https = true;
} elseif ($proxy = getenv("HTTP_PROXY") ?: getenv("http_proxy")) {
} elseif ($proxy = getenv('HTTP_PROXY') ?: getenv('http_proxy')) {
$use_https = false;
} elseif ($proxy = trim(shell_exec('git config --global --get https.proxy'))) {
putenv("HTTPS_PROXY=$proxy");
@@ -86,7 +86,7 @@ if (is_file($install_dir . '/composer.phar')) {
// if nothing else, use system supplied composer
if (! $exec) {
$path_exec = trim(shell_exec("which composer 2> /dev/null"));
$path_exec = trim(shell_exec('which composer 2> /dev/null'));
if ($path_exec) {
$exec = $path_exec;
}

View File

@@ -52,11 +52,11 @@ $rancid_map['ciscowlc'] = 'cisco-wlc8';
foreach (dbFetchRows("SELECT `hostname`,`os`,`disabled`,`status` FROM `devices` WHERE `ignore` = 0 AND `type` != '' GROUP BY `hostname`") as $devices) {
if (isset($rancid_map[$devices['os']])) {
$status = "up";
$status = 'up';
if ($devices['disabled']) {
$status = "down";
$status = 'down';
}
echo $devices['hostname'] . ';' . $rancid_map[$devices['os']] . ';' . $status . PHP_EOL;
}
}
echo "# EOF " . PHP_EOL;
echo '# EOF ' . PHP_EOL;

View File

@@ -39,7 +39,7 @@ $options = getopt($short_opts);
// print the help
if (isset($options['h'])) {
echo "LibreNMS JSON App tool
echo 'LibreNMS JSON App tool
-j The file containing the JSON to use for the test.
-s Print the SNMPrec data.
-t Print the JSON test data file.
@@ -61,7 +61,7 @@ if (isset($options['h'])) {
and how they data is flattned as well for when writing alert rules. -k
prints it in a slightly neater manner and in a manner and in tested
order.
";
';
exit();
}
@@ -112,7 +112,7 @@ if ((isset($options['l'])) || (
$data = $json['data'];
$metrics = data_flatten($data);
$metrics_keys = array_keys($metrics);
usort($metrics_keys, "strcasecmp"); //orders them in the manner in which the test script compares them
usort($metrics_keys, 'strcasecmp'); //orders them in the manner in which the test script compares them
//print metrics if needed
if (isset($options['m'])) {
if (isset($options['k'])) {
@@ -121,7 +121,7 @@ if (isset($options['m'])) {
}
} else {
foreach ($metrics_keys as $key) {
echo $key . "=" . $metrics[$key] . "\n";
echo $key . '=' . $metrics[$key] . "\n";
}
}
exit(0);
@@ -149,8 +149,8 @@ if (isset($options['s'])) {
"1.3.6.1.2.1.1.6.0|4|<private>\n" .
"1.3.6.1.2.1.25.1.1.0|67|77552962\n" .
"1.3.6.1.4.1.8072.1.3.2.2.1.21.6.100.105.115.116.114.111|2|1\n" .
"1.3.6.1.4.1.8072.1.3.2.2.1.21." . $oid . "|2|1\n" .
"1.3.6.1.4.1.8072.1.3.2.3.1.2." . $oid . "|4x|" . bin2hex($raw_json) . "\n";
'1.3.6.1.4.1.8072.1.3.2.2.1.21.' . $oid . "|2|1\n" .
'1.3.6.1.4.1.8072.1.3.2.3.1.2.' . $oid . '|4x|' . bin2hex($raw_json) . "\n";
exit(0);
}
@@ -158,36 +158,36 @@ if (isset($options['s'])) {
if (isset($options['t'])) {
$test_data = [
'applications' => [
"discovery" => [
"applications" => [
"app_type" => $options['a'],
"app_state" => "UNKNOWN",
"discovered" => "1",
"app_state_prev" => null,
"app_status" => "",
"app_instance" => "",
'discovery' => [
'applications' => [
'app_type' => $options['a'],
'app_state' => 'UNKNOWN',
'discovered' => '1',
'app_state_prev' => null,
'app_status' => '',
'app_instance' => '',
],
"application_metrics" => [],
'application_metrics' => [],
],
"poller" => [
"applications" => [
"app_type" => $options['a'],
"app_state" => "OK",
"discovered" => "1",
"app_state_prev" => "UNKNOWN",
"app_status" => "",
"app_instance" => "",
'poller' => [
'applications' => [
'app_type' => $options['a'],
'app_state' => 'OK',
'discovered' => '1',
'app_state_prev' => 'UNKNOWN',
'app_status' => '',
'app_instance' => '',
],
"application_metrics" => [],
'application_metrics' => [],
],
],
];
foreach ($metrics_keys as $key) {
$test_data['applications']['poller']['application_metrics'][] = [
"metric" => $key,
"value" => $metrics[$key],
"value_prev" => null,
"app_type" => $options['a'],
'metric' => $key,
'value' => $metrics[$key],
'value_prev' => null,
'app_type' => $options['a'],
];
}
echo json_encode($test_data, JSON_PRETTY_PRINT) . "\n";

View File

@@ -16,10 +16,10 @@ require realpath(__DIR__ . '/..') . '/includes/init.php';
// Find the correct bill, exit if we get anything other than 1 result.
function list_bills($bill_name)
{
$bill = dbFetchRows("SELECT `bill_id`,`bill_name` FROM `bills` WHERE `bill_name` LIKE ?", ["$bill_name"]);
$bill = dbFetchRows('SELECT `bill_id`,`bill_name` FROM `bills` WHERE `bill_name` LIKE ?', ["$bill_name"]);
if (count($bill) != 1) {
echo "Did not find exactly 1 bill, exiting\n";
echo "Query:" . $bill . "\n";
echo 'Query:' . $bill . "\n";
exit(1);
} else {
echo "Found bill {$bill[0]['bill_name']} ({$bill[0]['bill_id']})\n";
@@ -38,7 +38,7 @@ function create_bill($bill_name, $bill_type, $bill_cdr, $bill_day)
* - bill_cdr: if bill_type is cdr, then this is in bits, if bill_type is quota, then it's in bytes (!!)
* - bill_day: day of month billing starts.
**/
echo "Creating bill with name : " . $bill_name . " (Type: " . $bill_type . ", Quota: " . $bill_cdr . ")\n";
echo 'Creating bill with name : ' . $bill_name . ' (Type: ' . $bill_type . ', Quota: ' . $bill_cdr . ")\n";
$insert = [
'bill_name' => $bill_name,
'bill_type' => $bill_type,
@@ -46,7 +46,7 @@ function create_bill($bill_name, $bill_type, $bill_cdr, $bill_day)
'bill_day' => '1',
];
$create_bill = dbInsert($insert, 'bills');
echo "Created bill ID " . $create_bill . "\n";
echo 'Created bill ID ' . $create_bill . "\n";
return $create_bill;
}
@@ -54,7 +54,7 @@ function create_bill($bill_name, $bill_type, $bill_cdr, $bill_day)
// This will get an array of devices we are interested in from the CLI glob
function get_devices($host_glob, $nameType)
{
return dbFetchRows("SELECT `device_id`,`hostname`,`sysName` FROM `devices` WHERE `" . $nameType . "` LIKE ?", ["%$host_glob%"]);
return dbFetchRows('SELECT `device_id`,`hostname`,`sysName` FROM `devices` WHERE `' . $nameType . '` LIKE ?', ["%$host_glob%"]);
}
// This will flush bill ports if -r is set on cli
@@ -75,8 +75,8 @@ function add_ports_to_bill($devs, $intf_glob, $id)
// Expected interface glob:
echo "Interface glob: $intf_glob\n";
$device_ids = array_column($devs, "device_id");
$ids = implode(",", $device_ids);
$device_ids = array_column($devs, 'device_id');
$ids = implode(',', $device_ids);
// Find the devices which match the list of IDS and also the interface glob
$query = "SELECT ports.port_id,ports.ifName,ports.ifAlias FROM ports INNER JOIN devices ON ports.device_id = devices.device_id WHERE ifType = 'ethernetCsmacd' AND ports.ifAlias LIKE '%$intf_glob%' AND ports.device_id in ($ids)";
@@ -129,11 +129,11 @@ $options = getopt('b:s:h:i:f:np:t:q:');
if (! empty($options['s'])) {
$host_glob = str_replace('*', '%', mres($options['s']));
$nameType = "sysName";
$nameType = 'sysName';
}
if (! empty($options['h'])) {
$host_glob = str_replace('*', '%', mres($options['h']));
$nameType = "hostname";
$nameType = 'hostname';
}
if (array_key_exists('n', $options)) {
$create_bill = true;

View File

@@ -79,11 +79,11 @@ discovery:
}
if ($os === 'generic') {
c_echo("Base discovery file created,");
c_echo('Base discovery file created,');
}
}
$mib_name = get_user_input("ctrl+c to exit now otherwise please enter the MIB name including path (url is also fine) for us to check for sensors:");
$mib_name = get_user_input('ctrl+c to exit now otherwise please enter the MIB name including path (url is also fine) for us to check for sensors:');
if (filter_var($mib_name, FILTER_VALIDATE_URL)) {
$mib_data = file_get_contents($mib_name);
@@ -163,7 +163,7 @@ modules:
c_echo($discovery_data);
}
} else {
c_echo("
c_echo('
Info:
You can use to build the yaml files for a new OS.
Usage:
@@ -175,14 +175,14 @@ Usage:
Example:
./scripts/new-os.php -h 44 -o new-eos
");
');
exit(1);
}
function get_user_input($msg)
{
c_echo($msg . ' ');
$handle = fopen("php://stdin", "r");
$handle = fopen('php://stdin', 'r');
$line = fgets($handle);
return trim($line);

View File

@@ -68,9 +68,9 @@ if ($port_id_file) {
if ($port_id_file == '-') {
$fh = STDIN;
} else {
$fh = fopen($port_id_file, "r");
$fh = fopen($port_id_file, 'r');
if (! $fh) {
echo "Failed to open port-id list \"" . $port_id_file . "\": \n";
echo 'Failed to open port-id list "' . $port_id_file . "\": \n";
exit(1);
}
}

View File

@@ -25,8 +25,8 @@
*/
/* do NOT run this script through a web browser */
if (! isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
exit("<br><strong>This script is only meant to run at the command line.</strong>");
if (! isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
exit('<br><strong>This script is only meant to run at the command line.</strong>');
}
/* We are not talking to the browser */
@@ -45,17 +45,17 @@ $using_cacti = false;
$debug = false;
$dryrun = false;
$avgnan = 'avg';
$rrdfile = "";
$rrdfile = '';
$std_kills = true;
$var_kills = true;
$html = false;
if ($using_cacti) {
$method = read_config_option("spikekill_method");
$numspike = read_config_option("spikekill_number");
$stddev = read_config_option("spikekill_deviations");
$percent = read_config_option("spikekill_percent");
$outliers = read_config_option("spikekill_outliers");
$method = read_config_option('spikekill_method');
$numspike = read_config_option('spikekill_number');
$stddev = read_config_option('spikekill_deviations');
$percent = read_config_option('spikekill_percent');
$outliers = read_config_option('spikekill_outliers');
} else {
$method = 1; // Standard Deviation
$numspike = 10;
@@ -65,18 +65,18 @@ if ($using_cacti) {
}
/* process calling arguments */
$parms = $_SERVER["argv"];
$parms = $_SERVER['argv'];
array_shift($parms);
foreach ($parms as $parameter) {
@[$arg, $value] = @explode("=", $parameter);
@[$arg, $value] = @explode('=', $parameter);
switch ($arg) {
case "--method":
case "-M":
if ($value == "variance") {
case '--method':
case '-M':
if ($value == 'variance') {
$method = 2;
} elseif ($value == "stddev") {
} elseif ($value == 'stddev') {
$method = 1;
} else {
echo "FATAL: You must specify either 'stddev' or 'variance' as methods.\n\n";
@@ -85,12 +85,12 @@ foreach ($parms as $parameter) {
}
break;
case "--avgnan":
case "-A":
if ($value == "avg") {
$avgnan = "avg";
} elseif ($value == "nan") {
$avgnan = "nan";
case '--avgnan':
case '-A':
if ($value == 'avg') {
$avgnan = 'avg';
} elseif ($value == 'nan') {
$avgnan = 'nan';
} else {
echo "FATAL: You must specify either 'avg' or 'nan' as replacement methods.\n\n";
display_help();
@@ -98,8 +98,8 @@ foreach ($parms as $parameter) {
}
break;
case "--rrdfile":
case "-R":
case '--rrdfile':
case '-R':
$rrdfile = $value;
if (! file_exists($rrdfile)) {
@@ -113,8 +113,8 @@ foreach ($parms as $parameter) {
}
break;
case "--stddev":
case "-S":
case '--stddev':
case '-S':
$stddev = $value;
if (! is_numeric($stddev) || ($stddev < 1)) {
@@ -124,8 +124,8 @@ foreach ($parms as $parameter) {
}
break;
case "--outliers":
case "-O":
case '--outliers':
case '-O':
$outliers = $value;
if (! is_numeric($outliers) || ($outliers < 1)) {
@@ -135,8 +135,8 @@ foreach ($parms as $parameter) {
}
break;
case "--percent":
case "-P":
case '--percent':
case '-P':
$percent = $value / 100;
if (! is_numeric($percent) || ($percent <= 0)) {
@@ -146,22 +146,22 @@ foreach ($parms as $parameter) {
}
break;
case "--html":
case '--html':
$html = true;
break;
case "-d":
case "--debug":
case '-d':
case '--debug':
$debug = true;
break;
case "-D":
case "--dryrun":
case '-D':
case '--dryrun':
$dryrun = true;
break;
case "--number":
case "-n":
case '--number':
case '-n':
$numspike = $value;
if (! is_numeric($numspike) || ($numspike < 1)) {
@@ -171,22 +171,22 @@ foreach ($parms as $parameter) {
}
break;
case "-h":
case "-v":
case "-V":
case "--version":
case "--help":
case '-h':
case '-v':
case '-V':
case '--version':
case '--help':
display_help();
exit;
default:
print "ERROR: Invalid Parameter " . $parameter . "\n\n";
print 'ERROR: Invalid Parameter ' . $parameter . "\n\n";
display_help();
exit;
}
}
/* additional error check */
if ($rrdfile == "") {
if ($rrdfile == '') {
echo "FATAL: You must specify an RRDfile!\n\n";
display_help();
exit;
@@ -194,12 +194,12 @@ if ($rrdfile == "") {
/* determine the temporary file name */
$seed = mt_rand();
if ($config["cacti_server_os"] == "win32") {
$tempdir = getenv("TEMP");
$xmlfile = $tempdir . "/" . str_replace(".rrd", "", basename($rrdfile)) . ".dump." . $seed;
if ($config['cacti_server_os'] == 'win32') {
$tempdir = getenv('TEMP');
$xmlfile = $tempdir . '/' . str_replace('.rrd', '', basename($rrdfile)) . '.dump.' . $seed;
} else {
$tempdir = "/tmp";
$xmlfile = "/tmp/" . str_replace(".rrd", "", basename($rrdfile)) . ".dump." . $seed;
$tempdir = '/tmp';
$xmlfile = '/tmp/' . str_replace('.rrd', '', basename($rrdfile)) . '.dump.' . $seed;
}
if ($html) {
@@ -207,14 +207,14 @@ if ($html) {
}
if ($using_cacti) {
cacti_log("NOTE: Removing Spikes for '$rrdfile', Method:'$method'", false, "WEBUI");
cacti_log("NOTE: Removing Spikes for '$rrdfile', Method:'$method'", false, 'WEBUI');
}
/* execute the dump command */
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Creating XML file '$xmlfile' from '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: Creating XML file '$xmlfile' from '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
if ($using_cacti) {
shell_exec(read_config_option("path_rrdtool") . " dump $rrdfile > $xmlfile");
shell_exec(read_config_option('path_rrdtool') . " dump $rrdfile > $xmlfile");
} else {
shell_exec("rrdtool dump $rrdfile > $xmlfile");
}
@@ -227,9 +227,9 @@ if (file_exists($xmlfile)) {
unlink($xmlfile);
} else {
if ($using_cacti) {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "FATAL: RRDtool Command Failed. Please verify that the RRDtool path is valid in Settings->Paths!" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . 'FATAL: RRDtool Command Failed. Please verify that the RRDtool path is valid in Settings->Paths!' . ($html ? "</td></tr>\n" : "\n");
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "FATAL: RRDtool Command Failed. Please insure RRDtool is in your path!" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . 'FATAL: RRDtool Command Failed. Please insure RRDtool is in your path!' . ($html ? "</td></tr>\n" : "\n");
}
exit;
}
@@ -291,68 +291,68 @@ $ds_name = [];
*/
if (sizeof($output)) {
foreach ($output as $line) {
if (substr_count($line, "<v>")) {
$linearray = explode("<v>", $line);
if (substr_count($line, '<v>')) {
$linearray = explode('<v>', $line);
/* discard the row */
array_shift($linearray);
$ds_num = 0;
foreach ($linearray as $dsvalue) {
/* peel off garbage */
$dsvalue = trim(str_replace("</row>", "", str_replace("</v>", "", $dsvalue)));
if (strtolower($dsvalue) != "nan") {
if (! isset($rra[$rra_num][$ds_num]["numsamples"])) {
$rra[$rra_num][$ds_num]["numsamples"] = 1;
$dsvalue = trim(str_replace('</row>', '', str_replace('</v>', '', $dsvalue)));
if (strtolower($dsvalue) != 'nan') {
if (! isset($rra[$rra_num][$ds_num]['numsamples'])) {
$rra[$rra_num][$ds_num]['numsamples'] = 1;
} else {
$rra[$rra_num][$ds_num]["numsamples"]++;
$rra[$rra_num][$ds_num]['numsamples']++;
}
if (! isset($rra[$rra_num][$ds_num]["sumofsamples"])) {
$rra[$rra_num][$ds_num]["sumofsamples"] = $dsvalue;
if (! isset($rra[$rra_num][$ds_num]['sumofsamples'])) {
$rra[$rra_num][$ds_num]['sumofsamples'] = $dsvalue;
} else {
$rra[$rra_num][$ds_num]["sumofsamples"] += $dsvalue;
$rra[$rra_num][$ds_num]['sumofsamples'] += $dsvalue;
}
if (! isset($rra[$rra_num][$ds_num]["max_value"])) {
$rra[$rra_num][$ds_num]["max_value"] = $dsvalue;
} elseif ($dsvalue > $rra[$rra_num][$ds_num]["max_value"]) {
$rra[$rra_num][$ds_num]["max_value"] = $dsvalue;
if (! isset($rra[$rra_num][$ds_num]['max_value'])) {
$rra[$rra_num][$ds_num]['max_value'] = $dsvalue;
} elseif ($dsvalue > $rra[$rra_num][$ds_num]['max_value']) {
$rra[$rra_num][$ds_num]['max_value'] = $dsvalue;
}
if (! isset($rra[$rra_num][$ds_num]["min_value"])) {
$rra[$rra_num][$ds_num]["min_value"] = $dsvalue;
} elseif ($dsvalue < $rra[$rra_num][$ds_num]["min_value"]) {
$rra[$rra_num][$ds_num]["min_value"] = $dsvalue;
if (! isset($rra[$rra_num][$ds_num]['min_value'])) {
$rra[$rra_num][$ds_num]['min_value'] = $dsvalue;
} elseif ($dsvalue < $rra[$rra_num][$ds_num]['min_value']) {
$rra[$rra_num][$ds_num]['min_value'] = $dsvalue;
}
/* store the sample for standard deviation calculation */
$samples[$rra_num][$ds_num][] = $dsvalue;
}
if (! isset($rra[$rra_num][$ds_num]["totalsamples"])) {
$rra[$rra_num][$ds_num]["totalsamples"] = 1;
if (! isset($rra[$rra_num][$ds_num]['totalsamples'])) {
$rra[$rra_num][$ds_num]['totalsamples'] = 1;
} else {
$rra[$rra_num][$ds_num]["totalsamples"]++;
$rra[$rra_num][$ds_num]['totalsamples']++;
}
$ds_num++;
}
} elseif (substr_count($line, "<rra>")) {
} elseif (substr_count($line, '<rra>')) {
$in_rra = true;
} elseif (substr_count($line, "<min>")) {
$ds_min[] = trim(str_replace("<min>", "", str_replace("</min>", "", trim($line))));
} elseif (substr_count($line, "<max>")) {
$ds_max[] = trim(str_replace("<max>", "", str_replace("</max>", "", trim($line))));
} elseif (substr_count($line, "<name>")) {
$ds_name[] = trim(str_replace("<name>", "", str_replace("</name>", "", trim($line))));
} elseif (substr_count($line, "<cf>")) {
$rra_cf[] = trim(str_replace("<cf>", "", str_replace("</cf>", "", trim($line))));
} elseif (substr_count($line, "<pdp_per_row>")) {
$rra_pdp[] = trim(str_replace("<pdp_per_row>", "", str_replace("</pdp_per_row>", "", trim($line))));
} elseif (substr_count($line, "</rra>")) {
} elseif (substr_count($line, '<min>')) {
$ds_min[] = trim(str_replace('<min>', '', str_replace('</min>', '', trim($line))));
} elseif (substr_count($line, '<max>')) {
$ds_max[] = trim(str_replace('<max>', '', str_replace('</max>', '', trim($line))));
} elseif (substr_count($line, '<name>')) {
$ds_name[] = trim(str_replace('<name>', '', str_replace('</name>', '', trim($line))));
} elseif (substr_count($line, '<cf>')) {
$rra_cf[] = trim(str_replace('<cf>', '', str_replace('</cf>', '', trim($line))));
} elseif (substr_count($line, '<pdp_per_row>')) {
$rra_pdp[] = trim(str_replace('<pdp_per_row>', '', str_replace('</pdp_per_row>', '', trim($line))));
} elseif (substr_count($line, '</rra>')) {
$in_rra = false;
$rra_num++;
} elseif (substr_count($line, "<step>")) {
$step = trim(str_replace("<step>", "", str_replace("</step>", "", trim($line))));
} elseif (substr_count($line, '<step>')) {
$step = trim(str_replace('<step>', '', str_replace('</step>', '', trim($line))));
}
}
}
@@ -366,7 +366,7 @@ calculateVarianceAverages($rra, $samples);
3) The max and min cutoffs of all samples
4) The number of kills in each ds based upon the thresholds
*/
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Searching for Spikes in XML file '$xmlfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: Searching for Spikes in XML file '$xmlfile'" . ($html ? "</td></tr>\n" : "\n");
calculateOverallStatistics($rra, $samples);
/* debugging and/or status report */
@@ -382,7 +382,7 @@ if ($method == 1) {
$new_output = updateXML($output, $rra);
}
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: NO Standard Deviation Spikes found in '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: NO Standard Deviation Spikes found in '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
}
} else {
/* variance subroutine */
@@ -391,7 +391,7 @@ if ($method == 1) {
$new_output = updateXML($output, $rra);
}
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: NO Variance Spikes found in '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: NO Variance Spikes found in '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
}
}
@@ -402,18 +402,18 @@ if (! $dryrun) {
if (backupRRDFile($rrdfile)) {
createRRDFileFromXML($xmlfile, $rrdfile);
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "FATAL: Unable to backup '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "FATAL: Unable to backup '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
}
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "FATAL: Unable to write XML file '$xmlfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "FATAL: Unable to write XML file '$xmlfile'" . ($html ? "</td></tr>\n" : "\n");
}
}
} else {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Dryrun requested. No updates performed" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . 'NOTE: Dryrun requested. No updates performed' . ($html ? "</td></tr>\n" : "\n");
}
if ($html) {
echo "</table>";
echo '</table>';
}
/* All Functions */
@@ -422,14 +422,14 @@ function createRRDFileFromXML($xmlfile, $rrdfile)
global $using_cacti, $html;
/* execute the dump command */
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Re-Importing '$xmlfile' to '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: Re-Importing '$xmlfile' to '$rrdfile'" . ($html ? "</td></tr>\n" : "\n");
if ($using_cacti) {
$response = shell_exec(read_config_option("path_rrdtool") . " restore -f -r $xmlfile $rrdfile");
$response = shell_exec(read_config_option('path_rrdtool') . " restore -f -r $xmlfile $rrdfile");
} else {
$response = shell_exec("rrdtool restore -f -r $xmlfile $rrdfile");
}
if (strlen($response)) {
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . $response . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . $response . ($html ? "</td></tr>\n" : "\n");
}
}
@@ -443,24 +443,24 @@ function backupRRDFile($rrdfile)
global $using_cacti, $tempdir, $seed, $html;
if ($using_cacti) {
$backupdir = read_config_option("spikekill_backupdir");
$backupdir = read_config_option('spikekill_backupdir');
if ($backupdir == "") {
if ($backupdir == '') {
$backupdir = $tempdir;
}
} else {
$backupdir = $tempdir;
}
if (file_exists($backupdir . "/" . basename($rrdfile))) {
$newfile = basename($rrdfile) . "." . $seed;
if (file_exists($backupdir . '/' . basename($rrdfile))) {
$newfile = basename($rrdfile) . '.' . $seed;
} else {
$newfile = basename($rrdfile);
}
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : "") . "NOTE: Backing Up '$rrdfile' to '" . $backupdir . "/" . $newfile . "'" . ($html ? "</td></tr>\n" : "\n");
echo($html ? "<tr><td colspan='20' class='spikekill_note'>" : '') . "NOTE: Backing Up '$rrdfile' to '" . $backupdir . '/' . $newfile . "'" . ($html ? "</td></tr>\n" : "\n");
return copy($rrdfile, $backupdir . "/" . $newfile);
return copy($rrdfile, $backupdir . '/' . $newfile);
}
function calculateVarianceAverages(&$rra, &$samples)
@@ -472,7 +472,7 @@ function calculateVarianceAverages(&$rra, &$samples)
if (sizeof($dses)) {
foreach ($dses as $ds_num => $ds) {
if (sizeof($ds) < $outliers * 3) {
$rra[$rra_num][$ds_num]["variance_avg"] = "NAN";
$rra[$rra_num][$ds_num]['variance_avg'] = 'NAN';
} else {
rsort($ds, SORT_NUMERIC);
$ds = array_slice($ds, $outliers);
@@ -480,7 +480,7 @@ function calculateVarianceAverages(&$rra, &$samples)
sort($ds, SORT_NUMERIC);
$ds = array_slice($ds, $outliers);
$rra[$rra_num][$ds_num]["variance_avg"] = array_sum($ds) / sizeof($ds);
$rra[$rra_num][$ds_num]['variance_avg'] = array_sum($ds) / sizeof($ds);
}
}
}
@@ -500,71 +500,71 @@ function calculateOverallStatistics(&$rra, &$samples)
if (sizeof($dses)) {
foreach ($dses as $ds) {
if (isset($samples[$rra_num][$ds_num])) {
$rra[$rra_num][$ds_num]["standard_deviation"] = standard_deviation($samples[$rra_num][$ds_num]);
if ($rra[$rra_num][$ds_num]["standard_deviation"] == "NAN") {
$rra[$rra_num][$ds_num]["standard_deviation"] = 0;
$rra[$rra_num][$ds_num]['standard_deviation'] = standard_deviation($samples[$rra_num][$ds_num]);
if ($rra[$rra_num][$ds_num]['standard_deviation'] == 'NAN') {
$rra[$rra_num][$ds_num]['standard_deviation'] = 0;
}
$rra[$rra_num][$ds_num]["average"] = $rra[$rra_num][$ds_num]["sumofsamples"] / $rra[$rra_num][$ds_num]["numsamples"];
$rra[$rra_num][$ds_num]['average'] = $rra[$rra_num][$ds_num]['sumofsamples'] / $rra[$rra_num][$ds_num]['numsamples'];
$rra[$rra_num][$ds_num]["min_cutoff"] = $rra[$rra_num][$ds_num]["average"] - ($stddev * $rra[$rra_num][$ds_num]["standard_deviation"]);
if ($rra[$rra_num][$ds_num]["min_cutoff"] < $ds_min[$ds_num]) {
$rra[$rra_num][$ds_num]["min_cutoff"] = $ds_min[$ds_num];
$rra[$rra_num][$ds_num]['min_cutoff'] = $rra[$rra_num][$ds_num]['average'] - ($stddev * $rra[$rra_num][$ds_num]['standard_deviation']);
if ($rra[$rra_num][$ds_num]['min_cutoff'] < $ds_min[$ds_num]) {
$rra[$rra_num][$ds_num]['min_cutoff'] = $ds_min[$ds_num];
}
$rra[$rra_num][$ds_num]["max_cutoff"] = $rra[$rra_num][$ds_num]["average"] + ($stddev * $rra[$rra_num][$ds_num]["standard_deviation"]);
if ($rra[$rra_num][$ds_num]["max_cutoff"] > $ds_max[$ds_num]) {
$rra[$rra_num][$ds_num]["max_cutoff"] = $ds_max[$ds_num];
$rra[$rra_num][$ds_num]['max_cutoff'] = $rra[$rra_num][$ds_num]['average'] + ($stddev * $rra[$rra_num][$ds_num]['standard_deviation']);
if ($rra[$rra_num][$ds_num]['max_cutoff'] > $ds_max[$ds_num]) {
$rra[$rra_num][$ds_num]['max_cutoff'] = $ds_max[$ds_num];
}
$rra[$rra_num][$ds_num]["numnksamples"] = 0;
$rra[$rra_num][$ds_num]["sumnksamples"] = 0;
$rra[$rra_num][$ds_num]["avgnksamples"] = 0;
$rra[$rra_num][$ds_num]['numnksamples'] = 0;
$rra[$rra_num][$ds_num]['sumnksamples'] = 0;
$rra[$rra_num][$ds_num]['avgnksamples'] = 0;
/* go through values and find cutoffs */
$rra[$rra_num][$ds_num]["stddev_killed"] = 0;
$rra[$rra_num][$ds_num]["variance_killed"] = 0;
$rra[$rra_num][$ds_num]['stddev_killed'] = 0;
$rra[$rra_num][$ds_num]['variance_killed'] = 0;
if (sizeof($samples[$rra_num][$ds_num])) {
foreach ($samples[$rra_num][$ds_num] as $sample) {
if (($sample > $rra[$rra_num][$ds_num]["max_cutoff"]) ||
($sample < $rra[$rra_num][$ds_num]["min_cutoff"])) {
debug(sprintf("Std Kill: Value '%.4e', StandardDev '%.4e', StdDevLimit '%.4e'", $sample, $rra[$rra_num][$ds_num]["standard_deviation"], ($rra[$rra_num][$ds_num]["max_cutoff"] * (1 + $percent))));
$rra[$rra_num][$ds_num]["stddev_killed"]++;
if (($sample > $rra[$rra_num][$ds_num]['max_cutoff']) ||
($sample < $rra[$rra_num][$ds_num]['min_cutoff'])) {
debug(sprintf("Std Kill: Value '%.4e', StandardDev '%.4e', StdDevLimit '%.4e'", $sample, $rra[$rra_num][$ds_num]['standard_deviation'], ($rra[$rra_num][$ds_num]['max_cutoff'] * (1 + $percent))));
$rra[$rra_num][$ds_num]['stddev_killed']++;
$std_kills = true;
} else {
$rra[$rra_num][$ds_num]["numnksamples"]++;
$rra[$rra_num][$ds_num]["sumnksamples"] += $sample;
$rra[$rra_num][$ds_num]['numnksamples']++;
$rra[$rra_num][$ds_num]['sumnksamples'] += $sample;
}
if ($rra[$rra_num][$ds_num]["variance_avg"] == "NAN") {
if ($rra[$rra_num][$ds_num]['variance_avg'] == 'NAN') {
/* not enought samples to calculate */
} elseif ($sample > ($rra[$rra_num][$ds_num]["variance_avg"] * (1 + $percent))) {
} elseif ($sample > ($rra[$rra_num][$ds_num]['variance_avg'] * (1 + $percent))) {
/* kill based upon variance */
debug(sprintf("Var Kill: Value '%.4e', VarianceDev '%.4e', VarianceLimit '%.4e'", $sample, $rra[$rra_num][$ds_num]["variance_avg"], ($rra[$rra_num][$ds_num]["variance_avg"] * (1 + $percent))));
$rra[$rra_num][$ds_num]["variance_killed"]++;
debug(sprintf("Var Kill: Value '%.4e', VarianceDev '%.4e', VarianceLimit '%.4e'", $sample, $rra[$rra_num][$ds_num]['variance_avg'], ($rra[$rra_num][$ds_num]['variance_avg'] * (1 + $percent))));
$rra[$rra_num][$ds_num]['variance_killed']++;
$var_kills = true;
}
}
}
if ($rra[$rra_num][$ds_num]["numnksamples"] > 0) {
$rra[$rra_num][$ds_num]["avgnksamples"] = $rra[$rra_num][$ds_num]["sumnksamples"] / $rra[$rra_num][$ds_num]["numnksamples"];
if ($rra[$rra_num][$ds_num]['numnksamples'] > 0) {
$rra[$rra_num][$ds_num]['avgnksamples'] = $rra[$rra_num][$ds_num]['sumnksamples'] / $rra[$rra_num][$ds_num]['numnksamples'];
}
} else {
$rra[$rra_num][$ds_num]["standard_deviation"] = "N/A";
$rra[$rra_num][$ds_num]["average"] = "N/A";
$rra[$rra_num][$ds_num]["min_cutoff"] = "N/A";
$rra[$rra_num][$ds_num]["max_cutoff"] = "N/A";
$rra[$rra_num][$ds_num]["numnksamples"] = "N/A";
$rra[$rra_num][$ds_num]["sumnksamples"] = "N/A";
$rra[$rra_num][$ds_num]["avgnksamples"] = "N/A";
$rra[$rra_num][$ds_num]["stddev_killed"] = "N/A";
$rra[$rra_num][$ds_num]["variance_killed"] = "N/A";
$rra[$rra_num][$ds_num]["stddev_killed"] = "N/A";
$rra[$rra_num][$ds_num]["numnksamples"] = "N/A";
$rra[$rra_num][$ds_num]["sumnksamples"] = "N/A";
$rra[$rra_num][$ds_num]["variance_killed"] = "N/A";
$rra[$rra_num][$ds_num]["avgnksamples"] = "N/A";
$rra[$rra_num][$ds_num]['standard_deviation'] = 'N/A';
$rra[$rra_num][$ds_num]['average'] = 'N/A';
$rra[$rra_num][$ds_num]['min_cutoff'] = 'N/A';
$rra[$rra_num][$ds_num]['max_cutoff'] = 'N/A';
$rra[$rra_num][$ds_num]['numnksamples'] = 'N/A';
$rra[$rra_num][$ds_num]['sumnksamples'] = 'N/A';
$rra[$rra_num][$ds_num]['avgnksamples'] = 'N/A';
$rra[$rra_num][$ds_num]['stddev_killed'] = 'N/A';
$rra[$rra_num][$ds_num]['variance_killed'] = 'N/A';
$rra[$rra_num][$ds_num]['stddev_killed'] = 'N/A';
$rra[$rra_num][$ds_num]['numnksamples'] = 'N/A';
$rra[$rra_num][$ds_num]['sumnksamples'] = 'N/A';
$rra[$rra_num][$ds_num]['variance_killed'] = 'N/A';
$rra[$rra_num][$ds_num]['avgnksamples'] = 'N/A';
}
$ds_num++;
@@ -585,69 +585,69 @@ function outputStatistics($rra)
echo "\n";
printf(
"%10s %16s %10s %7s %7s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s\n",
"Size",
"DataSource",
"CF",
"Samples",
"NonNan",
"Avg",
"StdDev",
"MaxValue",
"MinValue",
"MaxStdDev",
"MinStdDev",
"StdKilled",
"VarKilled",
"StdDevAvg",
"VarAvg"
'Size',
'DataSource',
'CF',
'Samples',
'NonNan',
'Avg',
'StdDev',
'MaxValue',
'MinValue',
'MaxStdDev',
'MinStdDev',
'StdKilled',
'VarKilled',
'StdDevAvg',
'VarAvg'
);
printf(
"%10s %16s %10s %7s %7s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s\n",
"----------",
"---------------",
"----------",
"-------",
"-------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------",
"----------"
'----------',
'---------------',
'----------',
'-------',
'-------',
'----------',
'----------',
'----------',
'----------',
'----------',
'----------',
'----------',
'----------',
'----------',
'----------'
);
foreach ($rra as $rra_key => $dses) {
if (sizeof($dses)) {
foreach ($dses as $dskey => $ds) {
printf(
"%10s %16s %10s %7s %7s " .
($ds["average"] < 1E6 ? "%10s " : "%10.4e ") .
($ds["standard_deviation"] < 1E6 ? "%10s " : "%10.4e ") .
(isset($ds["max_value"]) ? ($ds["max_value"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") .
(isset($ds["min_value"]) ? ($ds["min_value"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") .
(isset($ds["max_cutoff"]) ? ($ds["max_cutoff"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") .
(isset($ds["min_cutoff"]) ? ($ds["min_cutoff"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") .
"%10s %10s " .
(isset($ds["avgnksampled"]) ? ($ds["avgnksamples"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") .
(isset($ds["variance_avg"]) ? ($ds["variance_avg"] < 1E6 ? "%10s " : "%10.4e ") : "%10s ") . "\n",
'%10s %16s %10s %7s %7s ' .
($ds['average'] < 1E6 ? '%10s ' : '%10.4e ') .
($ds['standard_deviation'] < 1E6 ? '%10s ' : '%10.4e ') .
(isset($ds['max_value']) ? ($ds['max_value'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') .
(isset($ds['min_value']) ? ($ds['min_value'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') .
(isset($ds['max_cutoff']) ? ($ds['max_cutoff'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') .
(isset($ds['min_cutoff']) ? ($ds['min_cutoff'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') .
'%10s %10s ' .
(isset($ds['avgnksampled']) ? ($ds['avgnksamples'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') .
(isset($ds['variance_avg']) ? ($ds['variance_avg'] < 1E6 ? '%10s ' : '%10.4e ') : '%10s ') . "\n",
displayTime($rra_pdp[$rra_key]),
$ds_name[$dskey],
$rra_cf[$rra_key],
$ds["totalsamples"],
(isset($ds["numsamples"]) ? $ds["numsamples"] : "0"),
($ds["average"] != "N/A" ? round($ds["average"], 2) : $ds["average"]),
($ds["standard_deviation"] != "N/A" ? round($ds["standard_deviation"], 2) : $ds["standard_deviation"]),
(isset($ds["max_value"]) ? round($ds["max_value"], 2) : "N/A"),
(isset($ds["min_value"]) ? round($ds["min_value"], 2) : "N/A"),
($ds["max_cutoff"] != "N/A" ? round($ds["max_cutoff"], 2) : $ds["max_cutoff"]),
($ds["min_cutoff"] != "N/A" ? round($ds["min_cutoff"], 2) : $ds["min_cutoff"]),
$ds["stddev_killed"],
$ds["variance_killed"],
($ds["avgnksamples"] != "N/A" ? round($ds["avgnksamples"], 2) : $ds["avgnksamples"]),
(isset($ds["variance_avg"]) ? round($ds["variance_avg"], 2) : "N/A")
$ds['totalsamples'],
(isset($ds['numsamples']) ? $ds['numsamples'] : '0'),
($ds['average'] != 'N/A' ? round($ds['average'], 2) : $ds['average']),
($ds['standard_deviation'] != 'N/A' ? round($ds['standard_deviation'], 2) : $ds['standard_deviation']),
(isset($ds['max_value']) ? round($ds['max_value'], 2) : 'N/A'),
(isset($ds['min_value']) ? round($ds['min_value'], 2) : 'N/A'),
($ds['max_cutoff'] != 'N/A' ? round($ds['max_cutoff'], 2) : $ds['max_cutoff']),
($ds['min_cutoff'] != 'N/A' ? round($ds['min_cutoff'], 2) : $ds['min_cutoff']),
$ds['stddev_killed'],
$ds['variance_killed'],
($ds['avgnksamples'] != 'N/A' ? round($ds['avgnksamples'], 2) : $ds['avgnksamples']),
(isset($ds['variance_avg']) ? round($ds['variance_avg'], 2) : 'N/A')
);
}
}
@@ -657,51 +657,51 @@ function outputStatistics($rra)
} else {
printf(
"<tr><th style='width:10%%;'>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
"Size",
"DataSource",
"CF",
"Samples",
"NonNan",
"Avg",
"StdDev",
"MaxValue",
"MinValue",
"MaxStdDev",
"MinStdDev",
"StdKilled",
"VarKilled",
"StdDevAvg",
"VarAvg"
'Size',
'DataSource',
'CF',
'Samples',
'NonNan',
'Avg',
'StdDev',
'MaxValue',
'MinValue',
'MaxStdDev',
'MinStdDev',
'StdKilled',
'VarKilled',
'StdDevAvg',
'VarAvg'
);
foreach ($rra as $rra_key => $dses) {
if (sizeof($dses)) {
foreach ($dses as $dskey => $ds) {
printf(
"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>" .
($ds["average"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") .
($ds["standard_deviation"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") .
(isset($ds["max_value"]) ? ($ds["max_value"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") : "%s</td><td>") .
(isset($ds["min_value"]) ? ($ds["min_value"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") : "%s</td><td>") .
(isset($ds["max_cutoff"]) ? ($ds["max_cutoff"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") : "%s</td><td>") .
(isset($ds["min_cutoff"]) ? ($ds["min_cutoff"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") : "%s</td><td>") .
"%s</td><td>%s</td><td>" .
(isset($ds["avgnksampled"]) ? ($ds["avgnksamples"] < 1E6 ? "%s</td><td>" : "%.4e</td><td>") : "%s</td><td>") .
(isset($ds["variance_avg"]) ? ($ds["variance_avg"] < 1E6 ? "%s</td></tr>\n" : "%.4e</td></tr>\n") : "%s</td></tr>\n") . "\n",
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>' .
($ds['average'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') .
($ds['standard_deviation'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') .
(isset($ds['max_value']) ? ($ds['max_value'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') : '%s</td><td>') .
(isset($ds['min_value']) ? ($ds['min_value'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') : '%s</td><td>') .
(isset($ds['max_cutoff']) ? ($ds['max_cutoff'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') : '%s</td><td>') .
(isset($ds['min_cutoff']) ? ($ds['min_cutoff'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') : '%s</td><td>') .
'%s</td><td>%s</td><td>' .
(isset($ds['avgnksampled']) ? ($ds['avgnksamples'] < 1E6 ? '%s</td><td>' : '%.4e</td><td>') : '%s</td><td>') .
(isset($ds['variance_avg']) ? ($ds['variance_avg'] < 1E6 ? "%s</td></tr>\n" : "%.4e</td></tr>\n") : "%s</td></tr>\n") . "\n",
displayTime($rra_pdp[$rra_key]),
$ds_name[$dskey],
$rra_cf[$rra_key],
$ds["totalsamples"],
(isset($ds["numsamples"]) ? $ds["numsamples"] : "0"),
($ds["average"] != "N/A" ? round($ds["average"], 2) : $ds["average"]),
($ds["standard_deviation"] != "N/A" ? round($ds["standard_deviation"], 2) : $ds["standard_deviation"]),
(isset($ds["max_value"]) ? round($ds["max_value"], 2) : "N/A"),
(isset($ds["min_value"]) ? round($ds["min_value"], 2) : "N/A"),
($ds["max_cutoff"] != "N/A" ? round($ds["max_cutoff"], 2) : $ds["max_cutoff"]),
($ds["min_cutoff"] != "N/A" ? round($ds["min_cutoff"], 2) : $ds["min_cutoff"]),
$ds["stddev_killed"],
$ds["variance_killed"],
($ds["avgnksamples"] != "N/A" ? round($ds["avgnksamples"], 2) : $ds["avgnksamples"]),
(isset($ds["variance_avg"]) ? round($ds["variance_avg"], 2) : "N/A")
$ds['totalsamples'],
(isset($ds['numsamples']) ? $ds['numsamples'] : '0'),
($ds['average'] != 'N/A' ? round($ds['average'], 2) : $ds['average']),
($ds['standard_deviation'] != 'N/A' ? round($ds['standard_deviation'], 2) : $ds['standard_deviation']),
(isset($ds['max_value']) ? round($ds['max_value'], 2) : 'N/A'),
(isset($ds['min_value']) ? round($ds['min_value'], 2) : 'N/A'),
($ds['max_cutoff'] != 'N/A' ? round($ds['max_cutoff'], 2) : $ds['max_cutoff']),
($ds['min_cutoff'] != 'N/A' ? round($ds['min_cutoff'], 2) : $ds['min_cutoff']),
$ds['stddev_killed'],
$ds['variance_killed'],
($ds['avgnksamples'] != 'N/A' ? round($ds['avgnksamples'], 2) : $ds['avgnksamples']),
(isset($ds['variance_avg']) ? round($ds['variance_avg'], 2) : 'N/A')
);
}
}
@@ -722,40 +722,40 @@ function updateXML(&$output, &$rra)
if (sizeof($output)) {
foreach ($output as $line) {
if (substr_count($line, "<v>")) {
$linearray = explode("<v>", $line);
if (substr_count($line, '<v>')) {
$linearray = explode('<v>', $line);
/* discard the row */
array_shift($linearray);
/* initialize variables */
$ds_num = 0;
$out_row = "<row>";
$out_row = '<row>';
foreach ($linearray as $dsvalue) {
/* peel off garbage */
$dsvalue = trim(str_replace("</row>", "", str_replace("</v>", "", $dsvalue)));
if (strtolower($dsvalue) == "nan") {
$dsvalue = trim(str_replace('</row>', '', str_replace('</v>', '', $dsvalue)));
if (strtolower($dsvalue) == 'nan') {
/* do nothing, it's a NaN */
} else {
if ($method == 2) {
if ($dsvalue > (1 + $percent) * $rra[$rra_num][$ds_num]["variance_avg"]) {
if ($dsvalue > (1 + $percent) * $rra[$rra_num][$ds_num]['variance_avg']) {
if ($kills < $numspike) {
if ($avgnan == "avg") {
$dsvalue = $rra[$rra_num][$ds_num]["variance_avg"];
if ($avgnan == 'avg') {
$dsvalue = $rra[$rra_num][$ds_num]['variance_avg'];
} else {
$dsvalue = "NaN";
$dsvalue = 'NaN';
}
$kills++;
$total_kills++;
}
}
} else {
if (($dsvalue > $rra[$rra_num][$ds_num]["max_cutoff"]) ||
($dsvalue < $rra[$rra_num][$ds_num]["min_cutoff"])) {
if (($dsvalue > $rra[$rra_num][$ds_num]['max_cutoff']) ||
($dsvalue < $rra[$rra_num][$ds_num]['min_cutoff'])) {
if ($kills < $numspike) {
if ($avgnan == "avg") {
$dsvalue = $rra[$rra_num][$ds_num]["average"];
if ($avgnan == 'avg') {
$dsvalue = $rra[$rra_num][$ds_num]['average'];
} else {
$dsvalue = "NaN";
$dsvalue = 'NaN';
}
$kills++;
$total_kills++;
@@ -764,19 +764,19 @@ function updateXML(&$output, &$rra)
}
}
$out_row .= "<v> " . $dsvalue . "</v>";
$out_row .= '<v> ' . $dsvalue . '</v>';
$ds_num++;
}
$out_row .= "</row>";
$out_row .= '</row>';
$new_array[] = $out_row;
} else {
if (substr_count($line, "</rra>")) {
if (substr_count($line, '</rra>')) {
$ds_minmax = [];
$rra_num++;
$kills = 0;
} elseif (substr_count($line, "</database>")) {
} elseif (substr_count($line, '</database>')) {
$ds_num++;
$kills = 0;
}
@@ -795,15 +795,15 @@ function removeComments(&$output)
if (sizeof($output)) {
foreach ($output as $line) {
$line = trim($line);
if ($line == "") {
if ($line == '') {
continue;
} else {
/* is there a comment, remove it */
$comment_start = strpos($line, "<!--");
$comment_start = strpos($line, '<!--');
if ($comment_start === false) {
/* do nothing no line */
} else {
$comment_end = strpos($line, "-->");
$comment_end = strpos($line, '-->');
if ($comment_start == 0) {
$line = trim(substr($line, $comment_end + 3));
} else {
@@ -811,7 +811,7 @@ function removeComments(&$output)
}
}
if ($line != "") {
if ($line != '') {
$new_array[] = $line;
}
}
@@ -828,21 +828,21 @@ function displayTime($pdp)
$total_time = $pdp * $step; // seconds
if ($total_time < 60) {
return $total_time . " secs";
return $total_time . ' secs';
} else {
$total_time = $total_time / 60;
if ($total_time < 60) {
return $total_time . " mins";
return $total_time . ' mins';
} else {
$total_time = $total_time / 60;
if ($total_time < 24) {
return $total_time . " hours";
return $total_time . ' hours';
} else {
$total_time = $total_time / 24;
return $total_time . " days";
return $total_time . ' days';
}
}
}
@@ -853,7 +853,7 @@ function debug($string)
global $debug;
if ($debug) {
echo "DEBUG: " . $string . "\n";
echo 'DEBUG: ' . $string . "\n";
}
}
@@ -877,10 +877,10 @@ function display_help()
if ($using_cacti) {
$version = spikekill_version();
} else {
$version = "v1.0";
$version = 'v1.0';
}
echo "Cacti Spike Remover " . ($using_cacti ? "v" . $version["version"] : $version) . ", Copyright 2009, The Cacti Group, Inc.\n\n";
echo 'Cacti Spike Remover ' . ($using_cacti ? 'v' . $version['version'] : $version) . ", Copyright 2009, The Cacti Group, Inc.\n\n";
echo "Usage:\n";
echo "removespikes.php -R|--rrdfile=rrdfile [-M|--method=stddev] [-A|--avgnan] [-S|--stddev=N]\n";
echo " [-P|--percent=N] [-N|--number=N] [-D|--dryrun] [-d|--debug] [-h|--help|-v|-V|--version]\n\n";

View File

@@ -67,7 +67,7 @@ function rename_mib_file($file)
function extract_mib_name($file)
{
// extract the mib name (tried regex, but was too complex and I had to read the whole file)
if ($handle = fopen($file, "r")) {
if ($handle = fopen($file, 'r')) {
$header = '';
while (($line = fgets($handle)) !== false) {
$trimmed = trim($line);

View File

@@ -95,7 +95,7 @@ if ($os_name) {
if (isset($options['f'])) {
if (count($os_list) != 1) {
echo "Failed to create test data, -f/--file option can be used with one os/variant combination.\n";
echo "Multiple combinations (" . count($os_list) . ") found.\n";
echo 'Multiple combinations (' . count($os_list) . ") found.\n";
exit(1);
}
$output_file = $options['f'];

View File

@@ -17,7 +17,7 @@ if (isset($options['r']) && isset($options['h'])) {
$where = "alerts.device_id = $device_id && alerts.rule_id = $rule_id";
$alerts = $runAlerts->loadAlerts($where);
if (empty($alerts)) {
echo "No active alert found, please check that you have the correct ids";
echo 'No active alert found, please check that you have the correct ids';
exit(2);
}
$alert = $alerts[0];
@@ -26,7 +26,7 @@ if (isset($options['r']) && isset($options['h'])) {
$alert['note'] = 'Testing';
$runAlerts->issueAlert($alert);
} else {
c_echo("
c_echo('
Info:
Use this to send an actual alert via transports that is currently active.
Usage:
@@ -37,6 +37,6 @@ Usage:
Example:
./scripts/test-alert.php -r 4 -d -h localhost
");
');
exit(1);
}

View File

@@ -41,7 +41,7 @@ if (isset($options['t']) && isset($options['h']) && isset($options['r'])) {
unset($obj['alert']);
print_r($obj);
} else {
c_echo("
c_echo('
Usage:
-t Is the template ID.
-h Is the device ID or hostname
@@ -54,6 +54,6 @@ Usage:
Example:
./scripts/test-template.php -t 10 -d -h localhost -r 2 -p mail
");
');
exit(1);
}

View File

@@ -23,10 +23,10 @@ if ($ports == 'all') {
$ports = '';
}
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` WHERE `hostname` LIKE ?", ['%' . $hosts . '%']) as $device) {
echo "Found hostname " . $device['hostname'] . ".......\n";
foreach (dbFetchRows("SELECT `port_id`,`ifIndex`,`ifName`,`ifSpeed` FROM `ports` WHERE `ifName` LIKE ? AND `device_id` = ?", ['%' . $ports . '%', $device['device_id']]) as $port) {
echo "Tuning port " . $port['ifName'] . ".......\n";
foreach (dbFetchRows('SELECT `device_id`,`hostname` FROM `devices` WHERE `hostname` LIKE ?', ['%' . $hosts . '%']) as $device) {
echo 'Found hostname ' . $device['hostname'] . ".......\n";
foreach (dbFetchRows('SELECT `port_id`,`ifIndex`,`ifName`,`ifSpeed` FROM `ports` WHERE `ifName` LIKE ? AND `device_id` = ?', ['%' . $ports . '%', $device['device_id']]) as $port) {
echo 'Tuning port ' . $port['ifName'] . ".......\n";
$rrdfile = get_port_rrdfile_path($device['hostname'], $port['port_id']);
Rrd::tune('port', $rrdfile, $port['ifSpeed']);
}