function ss_mikrotik_qusers_getvalue($hostid, $index, $column)
{
    global $config;
    switch ($column) {
        case "curBytesIn":
        case "curBytesOut":
        case "curPacketsIn":
        case "curPacketsOut":
        case "connectTime":
            $value = db_fetch_cell("SELECT\n\t\t\t{$column} AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
        case "avgBytesIn":
        case "avgBytesOut":
        case "avgPacketsIn":
        case "avgPacketsOut":
            $column = str_replace("avgB", "b", $column);
            $column = str_replace("avgP", "p", $column);
            $value = db_fetch_cell("SELECT\n\t\t\tIF(connectTime>0,({$column}/connectTime),0) AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
        case "bytesIn":
        case "bytesOut":
        case "packetsIn":
        case "packetsOut":
            $value = db_fetch_cell("SELECT\n\t\t\t{$column} AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
    }
    if (!empty($value)) {
        return $value;
    } else {
        return "0";
    }
}
Example #2
0
/**
 * Saves auth control data for a certain control id
 *
 * Saves auth control data for a certain control id
 *
 * @return 1 on success, 0 on error
 */
function auth_control_data_save($data, $category = "SYSTEM", $enable_user_edit = 0, $plugin_id = 0, $control_id = 0) {

	/* Validate input */
	if (!is_array($data)) {
		return 0;
	}
	if (!is_numeric($enable_user_edit)) {
		return 0;
	}
	if (($enable_user_edit < 0) || ($enable_user_edit > 1)) {
		$enable_user_edit = 0;
	}
	if (!is_numeric($plugin_id)) {
		return 0;
	}
	if (!is_numeric($control_id)) {
		return 0;
	}
	if (empty($control_id)) {
		$control_id = $_SESSION["sess_user_id"];
	}

	/* Create SQL Query */
	$username = db_fetch_cell("SELECT username FROM user_auth WHERE id = " . $control_id, "username");
	$sql = "REPLACE INTO `auth_data` (`control_id`,`plugin_id`,`category`,`name`,`value`,`enable_user_edit`,`updated_when`,`updated_by`) VALUES ";
	foreach ($data as $name => $value) {
		$sql .= "(" . $control_id . "," . $plugin_id . ",'" . $category . "','" . $name . "','" . $value . "'," . $enable_user_edit . ",NOW(),'" . $username . "'),";
	}
	$sql = substr($sql,0,strlen($sql) - 1);

	/* Execute query and return */
	return db_execute($sql);

}
Example #3
0
function upgrade_to_0_8_6i() {
	/* once again, larger fields for OID's and the like */
	db_install_execute("0.8.6i", "ALTER TABLE `poller_item` MODIFY COLUMN `arg1` TEXT;");
	db_install_execute("0.8.6i", "ALTER TABLE `poller_reindex` MODIFY COLUMN `arg1` VARCHAR(255) NOT NULL;");
	db_install_execute("0.8.6i", "ALTER TABLE `host_snmp_cache` MODIFY COLUMN `oid` TEXT NOT NULL;");

	/* let's add more graph tree items for those larger installations */
	db_install_execute("0.8.6i", "ALTER TABLE `graph_tree_items` MODIFY COLUMN `id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT;");

	/* let's keep track of an important statistical value */
	db_install_execute("0.8.6i", "ALTER TABLE `poller_time` ADD COLUMN `pid` INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER `id`;");

	/* add some missing information from default/system data input methods */
	/* first we must see if the user was smart enough to add it themselves */
	$snmp_get = db_fetch_cell("SELECT id FROM data_input_fields WHERE data_name='snmp_port' AND data_input_id='1'");
	$snmp_index = db_fetch_cell("SELECT id FROM data_input_fields WHERE data_name='snmp_port' AND data_input_id='2'");

	if ($snmp_index > 0) {
		db_install_execute("0.8.6i", "REPLACE INTO `data_input_fields` VALUES ($snmp_index, 'c1f36ee60c3dc98945556d57f26e475b',2,'SNMP Port','snmp_port','in','',0,'snmp_port','','');");
	}else{
		db_install_execute("0.8.6i", "REPLACE INTO `data_input_fields` VALUES (0, 'c1f36ee60c3dc98945556d57f26e475b',2,'SNMP Port','snmp_port','in','',0,'snmp_port','','');");
	}

	if ($snmp_get > 0) {
		db_install_execute("0.8.6i", "REPLACE INTO `data_input_fields` VALUES ($snmp_get, 'fc64b99742ec417cc424dbf8c7692d36',1,'SNMP Port','snmp_port','in','',0,'snmp_port','','');");
	}else{
		db_install_execute("0.8.6i", "REPLACE INTO `data_input_fields` VALUES (0, 'fc64b99742ec417cc424dbf8c7692d36',1,'SNMP Port','snmp_port','in','',0,'snmp_port','','');");
	}
}
Example #4
0
function rrdclean_check_upgrade()
{
    global $config;
    $files = array('index.php', 'plugins.php', 'rrdcleaner.php');
    if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) {
        return;
    }
    $current = plugin_rrdclean_version();
    $current = $current['version'];
    $old = db_fetch_row("SELECT * FROM plugin_config WHERE directory='rrdclean'");
    if (sizeof($old) && $current != $old["version"]) {
        /* if the plugin is installed and/or active */
        if ($old["status"] == 1 || $old["status"] == 4) {
            /* re-register the hooks */
            plugin_rrdclean_install();
            /* perform a database upgrade */
            rrdclean_database_upgrade();
        }
        # stub for updating tables
        #$_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM <table>"), "Field", "Field");
        #if (!in_array("<new column>", $_columns)) {
        #	db_execute("ALTER TABLE <table> ADD COLUMN <new column> VARCHAR(40) NOT NULL DEFAULT '' AFTER <old column>");
        #}
        # new hooks
        #api_plugin_register_hook('rrdclean', 'config_settings',       'rrdclean_config_settings', 'setup.php');
        #if (api_plugin_is_enabled('rrdclean')) {
        # may sound ridiculous, but enables new hooks
        #	api_plugin_enable_hooks('rrdclean');
        #}
        # register new version
        $info = plugin_rrdclean_version();
        $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='rrdclean'");
        db_execute("UPDATE plugin_config\r\n\t\t\tSET name='" . $info["longname"] . "',\r\n\t\t\tauthor='" . $info["author"] . "',\r\n\t\t\twebpage='" . $info["homepage"] . "',\r\n\t\t\tversion='" . $info["version"] . "'\r\n\t\t\tWHERE id='{$id}'");
    }
}
Example #5
0
function form_save()
{
    global $export_types, $export_errors;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post('export_item_id'));
    /* ==================================================== */
    if (isset($_POST['save_component_export'])) {
        $export_errors = 0;
        $xml_data = get_item_xml($_POST['export_type'], $_POST['export_item_id'], (isset($_POST['include_deps']) ? $_POST['include_deps'] : '') == '' ? false : true);
        if ($_POST['output_format'] == '1') {
            top_header();
            print "<table width='100%' align='center'><tr><td><pre>" . htmlspecialchars($xml_data) . '</pre></td></tr></table>';
            bottom_footer();
        } elseif ($_POST['output_format'] == '2') {
            header('Content-type: application/xml');
            if ($export_errors) {
                echo "WARNING: Export Errors Encountered.  Refresh Browser Window for Details!\n";
            }
            print $xml_data;
        } elseif ($_POST['output_format'] == '3') {
            if ($export_errors) {
                header('Location: templates_export.php');
            } else {
                header('Content-type: application/xml');
                header('Content-Disposition: attachment; filename=cacti_' . $_POST['export_type'] . '_' . strtolower(clean_up_file_name(db_fetch_cell(str_replace('|id|', $_POST['export_item_id'], $export_types[$_POST['export_type']]['title_sql'])))) . '.xml');
                print $xml_data;
            }
        }
    }
}
function ss_mikrotik_queue_simple_getvalue($host_id, $index, $column)
{
    $return_arr = array();
    switch ($column) {
        case 'qsInOctets':
            $column = 'curBytesIn';
            break;
        case 'qsOutOctets':
            $column = 'curBytesOut';
            break;
        case 'qsInPackets':
            $column = 'curPacketsIn';
            break;
        case 'qsOutPackets':
            $column = 'curPacketsOut';
            break;
        case 'qsInQueues':
            $column = 'curQueuesIn';
            break;
        case 'qsOutQueues':
            $column = 'curQueuesOut';
            break;
        case 'qsInDropped':
            $column = 'curDroppedIn';
            break;
        case 'qsOutDropped':
            $column = 'curDroppedOut';
            break;
    }
    $index2 = str_replace('_', ' ', $index);
    $value = db_fetch_cell("SELECT\n\t\t{$column} AS value\n\t\tFROM plugin_mikrotik_queues\n\t\tWHERE name IN ('{$index}', '{$index2}')\n\t\tAND host_id='{$host_id}'");
    return $value;
}
Example #7
0
function get_full_script_path($data_source_id) {
	require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");
	require_once(CACTI_BASE_PATH . "/include/data_source/data_source_constants.php");

	$data_input_type = db_fetch_cell("select data_input_type from data_source where id = $data_source_id");

	/* snmp-actions don't have paths */
	if ($data_input_type != DATA_INPUT_TYPE_SCRIPT) {
		return false;
	}

	$data_source_fields = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = $data_source_id"), "name", "value");

	if (isset($data_source_fields["script_id"])) {
		$script_path = db_fetch_cell("select input_string from data_input where id = " . $data_source_fields["script_id"]);

		/* exclude the manditory script_id field */
		unset($data_source_fields["script_id"]);

		/* substitute user variables */
		while (list($name, $value) = each($data_source_fields)) {
			$script_path = str_replace("<" . $name . ">", $value, $script_path);
		}

		/* substitute path variables */
		$script_path = substitute_path_variables($script_path);

		/* remove all remaining variables */
		$script_path = preg_replace("/(<[A-Za-z0-9_]+>)+/", "", $script_path);

		return $script_path;
	}
}
Example #8
0
function form_save()
{
    global $export_types, $export_errors;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post("export_item_id"));
    /* ==================================================== */
    if (isset($_POST["save_component_export"])) {
        $export_errors = 0;
        $xml_data = get_item_xml($_POST["export_type"], $_POST["export_item_id"], (isset($_POST["include_deps"]) ? $_POST["include_deps"] : "") == "" ? false : true);
        if ($_POST["output_format"] == "1") {
            include_once "./include/top_header.php";
            print "<table width='100%' align='center'><tr><td><pre>" . htmlspecialchars($xml_data) . "</pre></td></tr></table>";
            include_once "./include/bottom_footer.php";
        } elseif ($_POST["output_format"] == "2") {
            header("Content-type: application/xml");
            if ($export_errors) {
                echo "WARNING: Export Errors Encountered.  Refresh Browser Window for Details!\n";
            }
            print $xml_data;
        } elseif ($_POST["output_format"] == "3") {
            if ($export_errors) {
                header("Location: templates_export.php");
            } else {
                header("Content-type: application/xml");
                header("Content-Disposition: attachment; filename=cacti_" . $_POST["export_type"] . "_" . strtolower(clean_up_file_name(db_fetch_cell(str_replace("|id|", $_POST["export_item_id"], $export_types[$_POST["export_type"]]["title_sql"])))) . ".xml");
                print $xml_data;
            }
        }
    }
}
function ss_mikrotik_qusers_getvalue($hostid, $index, $column)
{
    global $config;
    switch ($column) {
        case 'curBytesIn':
        case 'curBytesOut':
        case 'curPacketsIn':
        case 'curPacketsOut':
        case 'connectTime':
            $value = db_fetch_cell("SELECT\n\t\t\t{$column} AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
        case 'avgBytesIn':
        case 'avgBytesOut':
        case 'avgPacketsIn':
        case 'avgPacketsOut':
            $column = str_replace('avgB', 'b', $column);
            $column = str_replace('avgP', 'p', $column);
            $value = db_fetch_cell("SELECT\n\t\t\tIF(connectTime>0,({$column}/connectTime),0) AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
        case 'bytesIn':
        case 'bytesOut':
        case 'packetsIn':
        case 'packetsOut':
            $value = db_fetch_cell("SELECT\n\t\t\t{$column} AS value\n\t\t\tFROM plugin_mikrotik_users\n\t\t\tWHERE (name='{$index}'\n\t\t\tAND host_id='{$hostid}')");
            break;
    }
    if (!empty($value)) {
        return $value;
    } else {
        return '0';
    }
}
Example #10
0
function upgrade_to_0_8_7c() {
	/* speed up the UI, missed in 0.8.7b upgrade, avoid failures if index already exists */
	$result = db_fetch_assoc("SHOW INDEX FROM `data_local`") or die (mysql_error());
	$indices = array();
	foreach($result as $index => $arr) {
		$indices[] = $arr["Key_name"];
	}
	if (!in_array('host_id', $indices)) {
		db_install_execute("0.8.7c", "ALTER TABLE `data_local` ADD INDEX `host_id`(`host_id`)");
	}

	$result = db_fetch_assoc("SHOW INDEX FROM `host_snmp_cache`") or die (mysql_error());
	$indices = array();
	foreach($result as $index => $arr) {
		$indices[] = $arr["Key_name"];
	}
	if (!in_array('field_name', $indices)) {
		db_install_execute("0.8.7c", "ALTER TABLE `host_snmp_cache` ADD INDEX `field_name`(`field_name`)");
	}
	if (!in_array('field_value', $indices)) {
		db_install_execute("0.8.7c", "ALTER TABLE `host_snmp_cache` ADD INDEX `field_value`(`field_value`)");
	}

	/* speed up graph automations some more */
	db_install_execute("0.8.7c", "ALTER TABLE `data_input_fields` ADD INDEX `input_output`(`input_output`)");

	/* increase the width of the settings field, but only if MySQL is >= 5 */
	if (substr(db_fetch_cell("SELECT @@version"), 0, 1) >= 5) {
		db_install_execute("0.8.7c", "ALTER TABLE `settings` MODIFY COLUMN `name` VARCHAR(512) NOT NULL DEFAULT ''");
	}

	/* add a default for NOT NULL columns */
	db_install_execute("0.8.7c", "ALTER TABLE `data_local` MODIFY COLUMN `snmp_index` VARCHAR(255) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `graph_local` MODIFY COLUMN `snmp_index` VARCHAR(255) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `graph_templates_graph` MODIFY COLUMN `upper_limit` VARCHAR(20) NOT NULL DEFAULT '0';");
	db_install_execute("0.8.7c", "ALTER TABLE `graph_templates_graph` MODIFY COLUMN `lower_limit` VARCHAR(20) NOT NULL DEFAULT '0';");
	db_install_execute("0.8.7c", "ALTER TABLE `graph_templates_graph` MODIFY COLUMN `scale_log_units` CHAR(2) DEFAULT NULL;");
	db_install_execute("0.8.7c", "ALTER TABLE `host` MODIFY COLUMN `availability` DECIMAL(8,5) NOT NULL DEFAULT '100.00000';");
	db_install_execute("0.8.7c", "ALTER TABLE `host_snmp_cache` MODIFY COLUMN `snmp_index` VARCHAR(255) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `host_snmp_cache` MODIFY COLUMN `oid` TEXT NOT NULL;");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `snmp_auth_protocol` VARCHAR(5) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `snmp_priv_passphrase` VARCHAR(200) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `snmp_priv_protocol` VARCHAR(6) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `rrd_next_step` MEDIUMINT(8) NOT NULL DEFAULT '0';");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `arg1` TEXT DEFAULT NULL;");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_reindex` MODIFY COLUMN `arg1` VARCHAR(255) NOT NULL DEFAULT '';");
	db_install_execute("0.8.7c", "ALTER TABLE `user_auth` MODIFY COLUMN `enabled` CHAR(2) NOT NULL DEFAULT 'on';");
	db_install_execute("0.8.7c", "ALTER TABLE `user_log` MODIFY COLUMN `ip` VARCHAR(40) NOT NULL DEFAULT '';");

	/* change size of columns to match current cacti.sql file */
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `rrd_step` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '300';");
	db_install_execute("0.8.7c", "ALTER TABLE `poller_time` MODIFY COLUMN `pid` INT(11) UNSIGNED NOT NULL DEFAULT '0';");

	/* Update deletion verification setting */
	db_install_execute("0.8.7c", "UPDATE settings SET name = 'deletion_verification' WHERE name = 'remove_verification'");

	/* Correct issue where rrd_next_step goes large in a positive way instead of the way it should go */
	db_install_execute("0.8.7c", "ALTER TABLE `poller_item` MODIFY COLUMN `rrd_step` MEDIUMINT(8) NOT NULL DEFAULT 300");
}
function ss_mikrotik_procs($hostid = "")
{
    $procs = db_fetch_cell("SELECT processes\n\t\tFROM plugin_mikrotik_system\n\t\tWHERE host_id={$hostid}");
    if ($procs == '') {
        $procs = 'U';
    }
    return $procs;
}
Example #12
0
function display_help()
{
    $version = db_fetch_cell('SELECT cacti FROM version');
    echo "Empty Poller Output Table Utility, Version {$version}, " . COPYRIGHT_YEARS . "\n\n";
    print "usage: poller_output_empty.php [-h] [--help] [-v] [--version]\n\n";
    print "-v --version  - Display this help message\n";
    print "-h --help     - Display this help message\n";
}
function ss_mikrotik_users($hostid = "")
{
    $users = db_fetch_cell("SELECT users\n\t\tFROM plugin_mikrotik_system\n\t\tWHERE host_id={$hostid}");
    if ($users == '') {
        $users = 'U';
    }
    return $users;
}
function ss_mikrotik_health($hostid = "", $column = "no")
{
    $value = db_fetch_cell("SELECT {$column}\n\t\tFROM plugin_mikrotik_system_health\n\t\tWHERE host_id={$hostid}");
    if ($value == '') {
        $value = 'U';
    }
    return $value;
}
function ss_mikrotik_trees($hostid = "")
{
    $trees = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_mikrotik_trees\n\t\tWHERE host_id={$hostid}");
    if ($trees == '') {
        $trees = 'U';
    }
    return $trees;
}
function ss_mikrotik_wapcount($hostid = "")
{
    $waps = db_fetch_cell("SELECT count(*)\n\t\tFROM plugin_mikrotik_wireless_aps\n\t\tWHERE host_id={$hostid} \n\t\tAND unix_timestamp(last_seen)>unix_timestamp()-1200");
    if ($waps == '') {
        $waps = 'U';
    }
    return $waps;
}
Example #17
0
function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "")
{
    $snmp = explode(":", $snmp_auth);
    $snmp_version = $snmp[0];
    $snmp_port = $snmp[1];
    $snmp_timeout = $snmp[2];
    $ping_retries = $snmp[3];
    $max_oids = $snmp[4];
    $snmp_auth_username = "";
    $snmp_auth_password = "";
    $snmp_auth_protocol = "";
    $snmp_priv_passphrase = "";
    $snmp_priv_protocol = "";
    $snmp_context = "";
    $snmp_community = "";
    if ($snmp_version == 3) {
        $snmp_auth_username = $snmp[6];
        $snmp_auth_password = $snmp[7];
        $snmp_auth_protocol = $snmp[8];
        $snmp_priv_passphrase = $snmp[9];
        $snmp_priv_protocol = $snmp[10];
        $snmp_context = $snmp[11];
    } else {
        $snmp_community = $snmp[5];
    }
    $oids = array("total" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4");
    if ($cmd == "index") {
        $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
        for ($i = 0; $i < sizeof($return_arr); $i++) {
            print $return_arr[$i] . "\n";
        }
    } elseif ($cmd == "num_indexes") {
        $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
        print sizeof($return_arr);
    } elseif ($cmd == "query") {
        $arg = $arg1;
        $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
        $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
        for ($i = 0; $i < sizeof($arr_index); $i++) {
            print $arr_index[$i] . "!" . $arr[$i] . "\n";
        }
    } elseif ($cmd == "get") {
        $arg = $arg1;
        $index = $arg2;
        if ($arg == "total" || $arg == "used") {
            $sau = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from host_snmp_cache where host_id={$host_id} and field_name='hrStorageAllocationUnits' and snmp_index='{$index}'"));
            $snmp_data = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
            if ($snmp_data < 0) {
                return ($snmp_data + 4294967296) * $sau;
            } else {
                return $snmp_data * $sau;
            }
        } else {
            return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
        }
    }
}
 /**
  * Check if given hash credentials are ok
  * @param string $hash
  * @return boolean
  */
 public function verifyLogin($hash)
 {
     $hash = preg_replace("/[^a-zA-Z0-9]/", "", $hash);
     $id = db_fetch_cell("SELECT id FROM user_auth WHERE MD5(CONCAT(username,password)) = '" . $hash . "' LIMIT 1");
     if (!$id) {
         return false;
     }
     return true;
 }
Example #19
0
function display_help()
{
    $version = db_fetch_cell('SELECT cacti FROM version');
    echo "Cacti Database Analyze Utility, Version {$version}, " . COPYRIGHT_YEARS . "\n\n";
    echo "usage: analyze_database.php [-d|--debug] [-h|--help|-v|-V|--version]\n\n";
    echo "-d | --debug     - Display verbose output during execution\n";
    echo "-v -V --version  - Display this help message\n";
    echo "-h --help        - display this help message\n";
}
Example #20
0
function ss_hmib_htypes_getvalue($index, $column)
{
    $return_arr = array();
    switch ($column) {
        case "up":
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=3\n\t\t\t\tAND host_type={$index}");
            break;
        case "down":
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=1\n\t\t\t\tAND host_type={$index}");
            break;
        case "recovering":
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=2\n\t\t\t\tAND host_type={$index}");
            break;
        case "disabled":
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.disabled='on' OR host.status=0\n\t\t\t\tAND host_type={$index}");
            break;
        default:
            switch ($column) {
                case "users":
                    $query = "SUM(users)";
                    break;
                case "num_cpus":
                    $query = "SUM(numCpus)";
                    break;
                case "avgCpu":
                    $query = "AVG(cpuPercent)";
                    break;
                case "maxCpu":
                    $query = "MAX(cpuPercent)";
                    break;
                case "avgMem":
                    $query = "AVG(memUsed)";
                    break;
                case "maxMem":
                    $query = "MAX(memUsed)";
                    break;
                case "avgSwap":
                    $query = "AVG(swapUsed)";
                    break;
                case "maxSwap":
                    $query = "MAX(swapUsed)";
                    break;
                case "avgProc":
                    $query = "AVG(processes)";
                    break;
                case "maxProc":
                    $query = "MAX(processes)";
                    break;
            }
            $value = db_fetch_cell("SELECT {$query} \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tWHERE host_type={$index}");
    }
    if ($value == '') {
        $value = "0";
    }
    return $value;
}
Example #21
0
function ss_hmib_htypes_getvalue($index, $column)
{
    $return_arr = array();
    switch ($column) {
        case 'up':
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=3\n\t\t\t\tAND host_type={$index}");
            break;
        case 'down':
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=1\n\t\t\t\tAND host_type={$index}");
            break;
        case 'recovering':
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.status=2\n\t\t\t\tAND host_type={$index}");
            break;
        case 'disabled':
            $value = db_fetch_cell("SELECT COUNT(*) \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tINNER JOIN host\n\t\t\t\tON host.id=hrs.host_id\n\t\t\t\tWHERE host.disabled='on' OR host.status=0\n\t\t\t\tAND host_type={$index}");
            break;
        default:
            switch ($column) {
                case 'users':
                    $query = 'SUM(users)';
                    break;
                case 'num_cpus':
                    $query = 'SUM(numCpus)';
                    break;
                case 'avgCpu':
                    $query = 'AVG(cpuPercent)';
                    break;
                case 'maxCpu':
                    $query = 'MAX(cpuPercent)';
                    break;
                case 'avgMem':
                    $query = 'AVG(memUsed)';
                    break;
                case 'maxMem':
                    $query = 'MAX(memUsed)';
                    break;
                case 'avgSwap':
                    $query = 'AVG(swapUsed)';
                    break;
                case 'maxSwap':
                    $query = 'MAX(swapUsed)';
                    break;
                case 'avgProc':
                    $query = 'AVG(processes)';
                    break;
                case 'maxProc':
                    $query = 'MAX(processes)';
                    break;
            }
            $value = db_fetch_cell("SELECT {$query} \n\t\t\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\t\t\tWHERE host_type={$index}");
    }
    if ($value == '') {
        $value = '0';
    }
    return $value;
}
Example #22
0
function input_edit()
{
    global $colors, $graph_item_types, $consolidation_functions, $fields_graph_template_input_edit;
    $header_label = "[" . _("Graph Template: ") . db_fetch_cell("select template_name from graph_template where id=" . $_GET["graph_template_id"]) . "]";
    if (!empty($_GET["id"])) {
        $graph_template_input = db_fetch_row("select * from graph_template_item_input where id=" . $_GET["id"]);
    }
    $graph_template_items = db_fetch_assoc("select\n\t\tgraph_template_item.id as graph_template_item_id,\n\t\tgraph_template_item.graph_item_type,\n\t\tgraph_template_item.consolidation_function,\n\t\tgraph_template_item_input_item.graph_template_item_input_id\n\t\tfrom graph_template_item\n\t\tleft join graph_template_item_input_item on (graph_template_item_input_item.graph_template_item_id=graph_template_item.id and graph_template_item_input_item.graph_template_item_input_id = " . (empty($_GET["id"]) ? "NULL" : $_GET["id"]) . ")\n\t\t" . (empty($_GET["id"]) ? "where" : "where") . " graph_template_item.graph_template_id = " . $_GET["graph_template_id"] . "\n\t\torder by graph_template_item.sequence");
    /* ==================== Box: Graph Item Input ==================== */
    html_start_box("<strong>" . _("Graph Item Input") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_graph_template_input_edit, isset($graph_template_input) ? $graph_template_input : array())));
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle"><?php 
    echo _("Associated Graph Items");
    ?>
</font><br>
			<?php 
    echo _("Select the graph items to be non-templated for the field above.");
    ?>
		</td>
		<td>
		<?php 
    $i = 0;
    if (sizeof($graph_template_items) > 0) {
        foreach ($graph_template_items as $item) {
            if ($item["graph_template_item_input_id"] == "") {
                $old_value = "";
            } else {
                $old_value = "on";
            }
            if ($item["graph_item_type"] == GRAPH_ITEM_TYPE_GPRINT) {
                $start_bold = "";
                $end_bold = "";
            } else {
                $start_bold = "<strong>";
                $end_bold = "</strong>";
            }
            form_checkbox("i_" . $item["graph_template_item_id"], $old_value, "{$start_bold} Item #" . ($i + 1) . ": " . $graph_item_types[$item["graph_item_type"]] . " (" . $consolidation_functions[$item["consolidation_function"]] . "){$end_bold}", "", $_GET["graph_template_id"], true);
            print "<br>";
            $i++;
        }
    } else {
        print "<em>" . _("No Items") . "</em>";
    }
    ?>
		</td>
	</tr>

	<?php 
    html_end_box();
    form_hidden_box("id", isset($_GET["id"]) ? $_GET["id"] : "0", "0");
    form_hidden_box("graph_template_id", $_GET["graph_template_id"], "0");
    form_save_button("graph_templates.php?action=edit&id=" . $_GET["graph_template_id"]);
}
Example #23
0
/** display_help - generic help screen for utilities
 * @return		 - null */
function display_help()
{
    $version = db_fetch_cell("SELECT cacti FROM version");
    print "Reporting Poller Version " . $version . ", " . COPYRIGHT_YEARS . "\n\n";
    print "usage: poller_reports.php [-d | --debug] [-h | -H | --help] [-v | -V | --version]\n\n";
    print "-f | --force     - Force all Reports to be sent\n";
    print "-d | --debug     - Display verbose output during execution\n";
    print "-v -V --version  - Display this help message\n";
    print "-h -H --help     - display this help message\n";
}
Example #24
0
function display_help()
{
    $version = db_fetch_cell("SELECT cacti FROM version LIMIT 1");
    print "Cacti Graph Export Tool Version {$version}, Copyright 2004-2015 - The Cacti Group\n\n";
    print "usage: poller_export.php [-f|--force] [-d|--debug] [-h|--help|-v|-V|--version]\n\n";
    print "-f | --force     - Force export to run now running now\n";
    print "-d | --debug     - Display verbose output during execution\n";
    print "-v -V --version  - Display this help message\n";
    print "-h --help        - display this help message\n";
}
Example #25
0
function display_help()
{
    $version = db_fetch_cell('SELECT cacti FROM version LIMIT 1');
    print "Cacti Graph Export Tool Version {$version}, " . COPYRIGHT_YEARS . "\n\n";
    print "usage: poller_export.php [-f|--force] [-d|--debug] [-h|--help|-v|-V|--version]\n\n";
    print "-f | --force     - Force export to run now running now\n";
    print "-d | --debug     - Display verbose output during execution\n";
    print "-v -V --version  - Display this help message\n";
    print "-h --help        - display this help message\n";
}
Example #26
0
function display_help()
{
    $version = db_fetch_cell('SELECT cacti FROM version');
    print 'Data Sources Statistics Poller, Version ' . $version . ', ' . COPYRIGHT_YEARS . "\n\n";
    print "usage: poller_dsstats.php [-f | --force] [-d | --debug] [-h | -H | --help] [-v | -V | --version]\n\n";
    print "-f | --force     - Force the execution of a update process\n";
    print "-d | --debug     - Display verbose output during execution\n";
    print "-v -V --version  - Display this help message\n";
    print "-h -H --help     - display this help message\n";
}
function ss_mikrotik_cpu($hostid = "", $summary = "no")
{
    if ($hostid == "" || $summary == "yes") {
        $cpu = db_fetch_row("SELECT AVG(cpuPercent) AS avgCpu, \n\t\t\tMAX(cpuPercent) AS maxCpu\n\t\t\tFROM plugin_mikrotik_system");
        return 'avg:' . $cpu['avgCpu'] . ' max:' . $cpu['maxCpu'];
    } else {
        $cpu = db_fetch_cell("SELECT cpuPercent\n\t\t\tFROM plugin_mikrotik_system\n\t\t\tWHERE host_id={$hostid}");
        return $cpu;
    }
}
Example #28
0
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled)
{
    /* fetch some cache variables */
    if (empty($id)) {
        $_host_template_id = 0;
    } else {
        $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}");
    }
    $save["id"] = $id;
    $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3);
    $save["description"] = form_input_validate($description, "description", "", false, 3);
    $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
    $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3);
    $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3);
    $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3);
    $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3);
    $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3);
    $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3);
    $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);
    $host_id = 0;
    if (!is_error_message()) {
        $host_id = sql_save($save, "host");
        if ($host_id) {
            raise_message(1);
            /* push out relavant fields to data sources using this host */
            push_out_host($host_id, 0);
            /* the host substitution cache is now stale; purge it */
            kill_session_var("sess_host_cache_array");
            /* update title cache for graph and data source */
            update_data_source_title_cache_from_host($host_id);
            update_graph_title_cache_from_host($host_id);
        } else {
            raise_message(2);
        }
        /* if the user changes the host template, add each snmp query associated with it */
        if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
            $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}");
            if (sizeof($snmp_queries) > 0) {
                foreach ($snmp_queries as $snmp_query) {
                    db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")");
                    /* recache snmp data */
                    run_data_query($host_id, $snmp_query["snmp_query_id"]);
                }
            }
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}");
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")");
                }
            }
        }
    }
    return $host_id;
}
Example #29
0
File: cmd.php Project: MrWnn/cacti
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 ss_mikrotik_users($hostid = "", $summary = "no")
{
    if ($hostid == "" || $summary == "yes") {
        $users = db_fetch_cell("SELECT SUM(users)\n\t\t\tFROM plugin_mikrotik_system");
    } else {
        $users = db_fetch_cell("SELECT users\n\t\t\tFROM plugin_mikrotik_system\n\t\t\tWHERE host_id={$hostid}");
    }
    if ($users == '') {
        $users = 'U';
    }
    return $users;
}