Skip to content

Commit

Permalink
Fixed and added:
Browse files Browse the repository at this point in the history
1) Realtime integration complete
2) Added option to update sys OID's in spine and cmd.php
3) Updated poller as well
4) Made cmd.php argument processing sane
5) Remove one more 'rrdtool_graph' variant (aka Realtime)
6) Moved Realtime settings under Visual
7) Added some core Javascript utility functions
8) Added minimum width to dropdowns to make more appealing
9) Cleanup some redundant syntax in headers
10) Typos in format files


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/cacti/branches/0.8.8@7678 860744bd-22fc-0310-8c96-e9fe5004b5ca
  • Loading branch information
ronytomen committed Jan 12, 2015
1 parent b62cc0e commit 902ac97
Show file tree
Hide file tree
Showing 38 changed files with 2,700 additions and 1,450 deletions.
5 changes: 3 additions & 2 deletions cacti.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2225,8 +2225,9 @@ CREATE TABLE IF NOT EXISTS poller_output_realtime (
rrd_name varchar(19) NOT NULL default '',
`time` datetime NOT NULL default '0000-00-00 00:00:00',
output text NOT NULL,
poller_id int(11) NOT NULL,
PRIMARY KEY (local_data_id,rrd_name,`time`)
poller_id varchar(30) NOT NULL default '',
PRIMARY KEY (local_data_id,rrd_name,`time`),
KEY poller_id(poller_id)
) ENGINE=MyISAM;

--
Expand Down
222 changes: 151 additions & 71 deletions cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function sig_handler($signo) {
switch ($signo) {
case SIGTERM:
case SIGINT:
cacti_log('WARNING: Cacti Poller process terminated by user', TRUE);
cacti_log('WARNING: Cacti Poller process terminated by user', true);

/* record the process as having completed */
record_cmdphp_done();
Expand All @@ -41,6 +41,13 @@ function sig_handler($signo) {
}
}

include(dirname(__FILE__) . '/include/global.php');
include_once($config['base_path'] . '/lib/snmp.php');
include_once($config['base_path'] . '/lib/poller.php');
include_once($config['base_path'] . '/lib/rrd.php');
include_once($config['base_path'] . '/lib/ping.php');
include_once($config['library_path'] . '/variables.php');

/* let the poller server know about cmd.php being finished */
function record_cmdphp_done($pid = '') {
if ($pid == '') $pid = getmypid();
Expand All @@ -53,6 +60,27 @@ function record_cmdphp_started() {
db_execute('INSERT INTO poller_time (poller_id, pid, start_time, end_time) VALUES (0, ' . getmypid() . ", NOW(), '0000-00-00 00:00:00')");
}

/* display_help - displays the usage of the function */
function display_help () {
$version = db_fetch_cell('SELECT cacti FROM version');
echo "Cacti Legacy Host Data Collector, Version $version, " . COPYRIGHT_YEARS . "\n\n";
echo "usage: cmd.php [ --first=ID --last=ID ] [-d | --debug] [-h | --help | -v | --version]\n\n";
echo "-f | --first - First host id in the range to collect from\n";
echo "-l | --last - Last host id in the range to collect from\n";
echo "-m | --mibs - Refresh all system mibs from hosts supporting snmp\n";
echo "-d | --debug - Display verbose output during execution\n";
echo "-v --version - Display this help message\n";
echo "-h --help - Display this help message\n";
}

function debug($message) {
global $debug;

if ($debug) {
print("DEBUG: " . $message . "\n");
}
}

/* do NOT run this script through a web browser */
if (!isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die('<br><strong>This script is only meant to run at the command line.</strong>');
Expand All @@ -65,12 +93,71 @@ function record_cmdphp_started() {

$no_http_headers = true;

include(dirname(__FILE__) . '/include/global.php');
include_once($config['base_path'] . '/lib/snmp.php');
include_once($config['base_path'] . '/lib/poller.php');
include_once($config['base_path'] . '/lib/rrd.php');
include_once($config['base_path'] . '/lib/ping.php');
include_once($config['library_path'] . '/variables.php');
/* process calling arguments */
$parms = $_SERVER["argv"];
array_shift($parms);

$first = NULL;
$last = NULL;
$allhost = true;
$refresh = false;
$debug = false;
$mibs = false;

if (sizeof($parms)) {
foreach($parms as $parameter) {
@list($arg, $value) = @explode("=", $parameter);

switch ($arg) {
case "--refresh":
$refresh = true;

break;
case "--version":
case "-V":
case "-H":
case "--help":
display_help();
exit(0);
case "--first":
case "-f":
$first = $value;
$allhost = false;
break;
case "--last":
case "-l":
$last = $value;
$allhost = false;
break;
case "--mibs":
case "-m":
$mibs = true;
break;
case "--debug":
case "-d":
$debug = true;
break;
default:
echo "ERROR: Invalid Argument: ($arg)\n\n";
display_help();
exit(1);
}
}
}

if ($first == NULL || $last == NULL ) {
cacti_log("FATAL: You must either a host range, or no range at all using --first=N --last=N syntax!", true, "POLLER");
exit(-1);
}elseif (!is_numeric($first) || $first <0) {
cacti_log("FATAL: The first host in the host range is invalid!=", true, "POLLER");
exit(-1);
}elseif (!is_numeric($last) || $last <0) {
cacti_log("FATAL: The last host in the host range is invalid!=", true, "POLLER");
exit(-1);
}elseif ($last < $first) {
cacti_log("FATAL: The first host must always be less or equal to the last host!=", true, "POLLER");
exit(-1);
}

/* notify cacti processes that a poller is running */
record_cmdphp_started();
Expand Down Expand Up @@ -108,18 +195,19 @@ function record_cmdphp_started() {
$polling_interval = read_config_option('poller_interval');

/* check arguments */
if ( $_SERVER['argc'] == 1 ) {
if ($allhost) {
if (isset($polling_interval)) {
$polling_items = db_fetch_assoc('SELECT * FROM poller_item WHERE rrd_next_step<=0 ORDER BY host_id');
$script_server_calls = db_fetch_cell('SELECT count(*) FROM poller_item WHERE (action = 2 AND rrd_next_step <= 0)');
$script_server_calls = db_fetch_cell('SELECT count(*) FROM poller_item WHERE (action=2 AND rrd_next_step<=0)');
}else{
$polling_items = db_fetch_assoc('SELECT * FROM poller_item ORDER by host_id');
$script_server_calls = db_fetch_cell('SELECT count(*) from poller_item WHERE (action = 2)');
$script_server_calls = db_fetch_cell('SELECT count(*) from poller_item WHERE (action=2)');
}

$print_data_to_stdout = true;

/* get the number of polling items from the database */
$hosts = db_fetch_assoc("SELECT * FROM host WHERE disabled = '' ORDER BY id");
$hosts = db_fetch_assoc("SELECT * FROM host WHERE disabled='' ORDER BY id");

/* rework the hosts array to be searchable */
$hosts = array_rekey($hosts, 'id', $host_struc);
Expand All @@ -134,60 +222,52 @@ function record_cmdphp_started() {
}
}else{
$print_data_to_stdout = false;
if ($_SERVER['argc'] == '3') {
if ($_SERVER['argv'][1] <= $_SERVER['argv'][2]) {
/* address potential exploits */
input_validate_input_number($_SERVER['argv'][1]);
input_validate_input_number($_SERVER['argv'][2]);

$hosts = db_fetch_assoc_prepared("SELECT *
FROM host
WHERE (disabled = '' AND id >= ? AND id <= ?)
ORDER by id", array($_SERVER['argv'][1], $_SERVER['argv'][2]));
$hosts = array_rekey($hosts,'id',$host_struc);
$host_count = sizeof($hosts);

if (isset($polling_interval)) {
$polling_items = db_fetch_assoc_prepared('SELECT *
FROM poller_item
WHERE (host_id >= ? AND host_id <= ? AND rrd_next_step <= 0)
ORDER by host_id', array($_SERVER['argv'][1], $_SERVER['argv'][2]));

$script_server_calls = db_fetch_cell_prepared('SELECT count(*)
FROM poller_item
WHERE (action = 2 AND host_id >= ? AND host_id <= ? AND rrd_next_step <= 0)',
array($_SERVER['argv'][1], $_SERVER['argv'][2]));

/* setup next polling interval */
db_execute_prepared('UPDATE poller_item
SET rrd_next_step = rrd_next_step - ' . $polling_interval . '
WHERE (host_id >= ? AND host_id <= ?)',
array($_SERVER['argv'][1], $_SERVER['argv'][2]));

db_execute_prepared('UPDATE poller_item
SET rrd_next_step = rrd_step - ' . $polling_interval . '
WHERE (rrd_next_step < 0 AND host_id >= ? AND host_id <= ?)',
array($_SERVER['argv'][1], $_SERVER['argv'][2]));
}else{
$polling_items = db_fetch_assoc_prepared('SELECT * FROM poller_item
WHERE (host_id >= ? and host_id <= ?)
ORDER by host_id', array($_SERVER['argv'][1], $_SERVER['argv'][2]));

$script_server_calls = db_fetch_cell_prepared('SELECT count(*) FROM poller_item
WHERE (action IN (' . POLLER_ACTION_SCRIPT_PHP . ',' . POLLER_ACTION_SCRIPT_PHP_COUNT . ') AND (host_id >= ? AND host_id <= ?))',
array($_SERVER['argv'][1], $_SERVER['argv'][2]));
}
if ($first <= $last) {
/* address potential exploits */
input_validate_input_number($first);
input_validate_input_number($last);

$hosts = db_fetch_assoc_prepared("SELECT *
FROM host
WHERE (disabled = '' AND id >= ? AND id <= ?)
ORDER by id", array($first, $last));
$hosts = array_rekey($hosts,'id',$host_struc);
$host_count = sizeof($hosts);

if (isset($polling_interval)) {
$polling_items = db_fetch_assoc_prepared('SELECT *
FROM poller_item
WHERE (host_id >= ? AND host_id <= ? AND rrd_next_step <= 0)
ORDER by host_id', array($first, $last));

$script_server_calls = db_fetch_cell_prepared('SELECT count(*)
FROM poller_item
WHERE (action = 2 AND host_id >= ? AND host_id <= ? AND rrd_next_step <= 0)',
array($first, $last));

/* setup next polling interval */
db_execute_prepared('UPDATE poller_item
SET rrd_next_step = rrd_next_step - ' . $polling_interval . '
WHERE (host_id >= ? AND host_id <= ?)',
array($first, $last));

db_execute_prepared('UPDATE poller_item
SET rrd_next_step = rrd_step - ' . $polling_interval . '
WHERE (rrd_next_step < 0 AND host_id >= ? AND host_id <= ?)',
array($first, $last));
}else{
print "ERROR: Invalid Arguments. The first argument must be less than or equal to the first.\n";
print "USAGE: CMD.PHP [[first_host] [second_host]]\n";
cacti_log("ERROR: Invalid Arguments. This rist argument must be less than or equal to the first.");
$polling_items = db_fetch_assoc_prepared('SELECT * FROM poller_item
WHERE (host_id >= ? and host_id <= ?)
ORDER by host_id', array($first, $last));

/* record the process as having completed */
record_cmdphp_done();
exit('-1');
$script_server_calls = db_fetch_cell_prepared('SELECT count(*) FROM poller_item
WHERE (action IN (' . POLLER_ACTION_SCRIPT_PHP . ',' . POLLER_ACTION_SCRIPT_PHP_COUNT . ') AND (host_id >= ? AND host_id <= ?))',
array($first, $last));
}
}else{
cacti_log('ERROR: Invalid Number of Arguments. You must specify 0 or 2 arguments.', $print_data_to_stdout);
print "ERROR: Invalid Arguments. The first argument must be less than or equal to the first.\n";
print "USAGE: CMD.PHP [[first_host] [second_host]]\n";
cacti_log("ERROR: Invalid Arguments. This rist argument must be less than or equal to the first.");

/* record the process as having completed */
record_cmdphp_done();
Expand Down Expand Up @@ -229,7 +309,7 @@ function record_cmdphp_started() {
}
}
}else{
$using_proc_function = FALSE;
$using_proc_function = false;
}

foreach ($polling_items as $item) {
Expand Down Expand Up @@ -259,21 +339,21 @@ function record_cmdphp_started() {
$hosts[$host_id]['ping_timeout'], $hosts[$host_id]['ping_retries'])) {
$host_down = false;
update_host_status(HOST_UP, $host_id, $hosts, $ping, $hosts[$host_id]['availability_method'], $print_data_to_stdout);

if ($mibs && $hosts[$host_id]['availability_method'] != 0 && $hosts[$host_id]['availability_method'] != 3) {
update_system_mibs($host_id);
}
}else{
$host_down = true;
update_host_status(HOST_DOWN, $host_id, $hosts, $ping, $hosts[$host_id]['availability_method'], $print_data_to_stdout);
}

if (!$host_down) {
/* do the reindex check for this host */
$reindex = db_fetch_assoc_prepared('SELECT
poller_reindex.data_query_id,
poller_reindex.action,
poller_reindex.op,
poller_reindex.assert_value,
poller_reindex.arg1
from poller_reindex
WHERE poller_reindex.host_id = ?', array($item['host_id']));
$reindex = db_fetch_assoc_prepared('SELECT pr.data_query_id, pr.action,
pr.op, pr.assert_value, pr.arg1
FROM poller_reindex AS pr
WHERE pr.host_id=?', array($item['host_id']));

if ((sizeof($reindex) > 0) && (!$host_down)) {
if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) {
Expand Down Expand Up @@ -597,7 +677,7 @@ function record_cmdphp_started() {
$host_count),$print_data_to_stdout);
}
}else if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM) {
cacti_log('NOTE: There are no items in your poller for this polling cycle!', TRUE, 'POLLER');
cacti_log('NOTE: There are no items in your poller for this polling cycle!', true, 'POLLER');
}

/* record the process as having completed */
Expand Down
17 changes: 7 additions & 10 deletions cmd_realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@
exit(-1);
}

$poller_id = (int)$_SERVER['argv'][1];
$poller_id = $_SERVER['argv'][1];
$graph_id = (int)$_SERVER['argv'][2];
$interval = (int)$_SERVER['argv'][3];

if ($poller_id <= 0) {
echo "Invalid poller_id specified.\n\n";
exit(-1);
}

if ($graph_id <= 0)
{
if ($graph_id <= 0) {
echo "Invalid graph_id specified.\n\n";
exit(-1);
}
Expand Down Expand Up @@ -203,8 +197,11 @@
}

if (isset($output)) {
/* insert a U in place of the actual value if the snmp agent restarts */
db_execute("insert into poller_output_realtime (local_data_id, rrd_name, time, poller_id, output) values (" . $item["local_data_id"] . ", '" . $item["rrd_name"] . "', '$host_update_time', '".$poller_id."', '" . addslashes($output) . "')");
db_execute_prepared("INSERT INTO poller_output_realtime
(local_data_id, rrd_name, time, poller_id, output)
VALUES
(?, ?, ?, ?, ?)",
array($item["local_data_id"], $item["rrd_name"], $host_update_time, $poller_id, $output));
}
}

Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Cacti CHANGELOG
-feature: Merge Watermark Plugin
-feature: Merge UGroup Plugin
-feature: Merge DSStats Plugin
-feature: Merge Settings Pluign
-feature: Merge Settings Plugin
-feature: Merge Realtime Plugin
-feature: Merge Reporting (Nectar) Plugin
-feature: Make all page refresh Ajax based
-feature: Make Suggest Naming more consistent
-feature: Add State Filter for Pugins Page
Expand Down
5 changes: 5 additions & 0 deletions docs/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location:../index.php");

?>
2 changes: 1 addition & 1 deletion formats/cacti_group.format
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</style>
<!-- header -->
<table class="header_table">
<tr class="header_row" ><td class="header">Nectar Report</td></tr>
<tr class="header_row" ><td class="header">Cacti Reporting Report</td></tr>
<!-- main report -->
<tr><td>
<REPORT>
Expand Down
2 changes: 1 addition & 1 deletion formats/lotus_notes.format
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</style>
<!-- header -->
<table class="header_table">
<tr class="header_row" ><td class="header">Nectar Report for Lotus Notes</td></tr>
<tr class="header_row" ><td class="header">Cacti Reporting Report for Lotus Notes</td></tr>
<!-- main report -->
<tr><td>
<REPORT>
Expand Down
Loading

0 comments on commit 902ac97

Please sign in to comment.