Example #1
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "")
{
    $host = db_fetch_row("select\n\t\thost.id,\n\t\thost.hostname,\n\t\thost.snmp_community,\n\t\thost.snmp_version,\n\t\thost.snmp_username,\n\t\thost.snmp_password,\n\t\thost.snmp_port,\n\t\thost.snmp_timeout,\n\t\thost.disabled\n\t\tfrom host\n\t\twhere host.id={$host_id}");
    /* the $host_field_override array can be used to override certain host fields in the poller cache */
    if (isset($host)) {
        $host = array_merge($host, $host_field_override);
    }
    if (isset($host["id"]) || isset($host_id)) {
        if (isset($host)) {
            if ($host["disabled"] == "on") {
                return true;
            }
        } else {
            if ($poller_action_id == 0) {
                return true;
            }
            $host["id"] = 0;
            $host["snmp_community"] = "";
            $host["snmp_timeout"] = "";
            $host["snmp_username"] = "";
            $host["snmp_password"] = "";
            $host["snmp_version"] = "";
            $host["snmp_port"] = "";
            $host["hostname"] = "None";
        }
        if ($poller_action_id == 0) {
            if ($host["snmp_version"] < 1 || $host["snmp_version"] > 3 || $host["snmp_community"] == "" && $host["snmp_version"] != 3) {
                return true;
            }
        }
        return db_execute("insert into poller_item (local_data_id,host_id,action,hostname,\n\t\t\tsnmp_community,snmp_version,snmp_timeout,snmp_username,snmp_password,snmp_port,rrd_name,rrd_path,\n\t\t\trrd_num,arg1,arg2,arg3) values ({$local_data_id}," . $host["id"] . ",{$poller_action_id},'" . $host["hostname"] . "',\n\t\t\t'" . $host["snmp_community"] . "','" . $host["snmp_version"] . "','" . $host["snmp_timeout"] . "',\n\t\t\t'" . $host["snmp_username"] . "','" . $host["snmp_password"] . "','" . $host["snmp_port"] . "',\n\t\t\t'{$data_source_item_name}','" . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',\n\t\t\t'{$num_rrd_items}','{$arg1}','{$arg2}','{$arg3}')");
    }
}
Example #2
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = '', $arg2 = '', $arg3 = '')
{
    static $hosts = array();
    if (!isset($hosts[$host_id])) {
        $host = db_fetch_row_prepared('SELECT
		host.id,
		host.hostname,
		host.snmp_community,
		host.snmp_version,
		host.snmp_username,
		host.snmp_password,
		host.snmp_auth_protocol,
		host.snmp_priv_passphrase,
		host.snmp_priv_protocol,
		host.snmp_context,
		host.snmp_port,
		host.snmp_timeout,
		host.disabled
		FROM host
		WHERE host.id = ?', array($host_id));
        $hosts[$host_id] = $host;
    } else {
        $host = $hosts[$host_id];
    }
    /* the $host_field_override array can be used to override certain host fields in the poller cache */
    if (isset($host)) {
        $host = array_merge($host, $host_field_override);
    }
    if (isset($host['id']) || isset($host_id)) {
        if (isset($host)) {
            if ($host['disabled'] == 'on') {
                return;
            }
        } else {
            if ($poller_action_id == 0) {
                return;
            }
            $host['id'] = 0;
            $host['snmp_community'] = '';
            $host['snmp_timeout'] = '';
            $host['snmp_username'] = '';
            $host['snmp_password'] = '';
            $host['snmp_auth_protocol'] = '';
            $host['snmp_priv_passphrase'] = '';
            $host['snmp_priv_protocol'] = '';
            $host['snmp_context'] = '';
            $host['snmp_version'] = '';
            $host['snmp_port'] = '';
            $host['hostname'] = 'None';
        }
        if ($poller_action_id == 0) {
            if ($host['snmp_version'] < 1 || $host['snmp_version'] > 3 || $host['snmp_community'] == '' && $host['snmp_version'] != 3) {
                return;
            }
        }
        $rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);
        return "({$local_data_id}, " . '0, ' . $host['id'] . ", {$poller_action_id}," . db_qstr($host['hostname']) . ",\n\t\t\t" . db_qstr($host['snmp_community']) . ', ' . db_qstr($host['snmp_version']) . ', ' . db_qstr($host['snmp_timeout']) . ",\n\t\t\t" . db_qstr($host['snmp_username']) . ', ' . db_qstr($host['snmp_password']) . ', ' . db_qstr($host['snmp_auth_protocol']) . ",\n\t\t\t" . db_qstr($host['snmp_priv_passphrase']) . ', ' . db_qstr($host['snmp_priv_protocol']) . ', ' . db_qstr($host['snmp_context']) . ",\n\t\t\t" . db_qstr($host['snmp_port']) . ', ' . db_qstr($data_source_item_name) . ', ' . db_qstr(clean_up_path(get_data_source_path($local_data_id, true))) . ",\n\t\t\t" . db_qstr($num_rrd_items) . ', ' . db_qstr($rrd_step) . ', ' . db_qstr($rrd_next_step) . ', ' . db_qstr($arg1) . ', ' . db_qstr($arg2) . ', ' . db_qstr($arg3) . ", '1')";
    }
}
Example #3
0
function substitute_path_variables($path) {
	require_once(CACTI_BASE_PATH . "/lib/sys/string.php");

	/* script query */
	$path = clean_up_path(str_replace("|path_cacti|", CACTI_BASE_PATH, $path));
	$path = clean_up_path(str_replace("|path_php_binary|", read_config_option("path_php_binary"), $path));

	/* data source */
	$path = clean_up_path(str_replace("<path_rra>", CACTI_BASE_PATH . "/rra", $path));

	/* script */
	$path = clean_up_path(str_replace("<path_cacti>", CACTI_BASE_PATH, $path));
	$path = clean_up_path(str_replace("<path_snmpget>", read_config_option("path_snmpget"), $path));
	$path = clean_up_path(str_replace("<path_php_binary>", read_config_option("path_php_binary"), $path));

	return $path;
}
Example #4
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "")
{
    global $cnn_id;
    static $hosts = array();
    if (!isset($hosts[$host_id])) {
        $host = db_fetch_row("select\n\t\thost.id,\n\t\thost.hostname,\n\t\thost.snmp_community,\n\t\thost.snmp_version,\n\t\thost.snmp_username,\n\t\thost.snmp_password,\n\t\thost.snmp_auth_protocol,\n\t\thost.snmp_priv_passphrase,\n\t\thost.snmp_priv_protocol,\n\t\thost.snmp_context,\n\t\thost.snmp_port,\n\t\thost.snmp_timeout,\n\t\thost.disabled\n\t\tfrom host\n\t\twhere host.id={$host_id}");
        $hosts[$host_id] = $host;
    } else {
        $host = $hosts[$host_id];
    }
    /* the $host_field_override array can be used to override certain host fields in the poller cache */
    if (isset($host)) {
        $host = array_merge($host, $host_field_override);
    }
    if (isset($host["id"]) || isset($host_id)) {
        if (isset($host)) {
            if ($host["disabled"] == "on") {
                return;
            }
        } else {
            if ($poller_action_id == 0) {
                return;
            }
            $host["id"] = 0;
            $host["snmp_community"] = "";
            $host["snmp_timeout"] = "";
            $host["snmp_username"] = "";
            $host["snmp_password"] = "";
            $host["snmp_auth_protocol"] = "";
            $host["snmp_priv_passphrase"] = "";
            $host["snmp_priv_protocol"] = "";
            $host["snmp_context"] = "";
            $host["snmp_version"] = "";
            $host["snmp_port"] = "";
            $host["hostname"] = "None";
        }
        if ($poller_action_id == 0) {
            if ($host["snmp_version"] < 1 || $host["snmp_version"] > 3 || $host["snmp_community"] == "" && $host["snmp_version"] != 3) {
                return;
            }
        }
        $rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);
        return "({$local_data_id}, " . "0, " . $host["id"] . ", {$poller_action_id}," . $cnn_id->qstr($host["hostname"]) . ",\n\t\t\t" . $cnn_id->qstr($host["snmp_community"]) . ", " . $cnn_id->qstr($host["snmp_version"]) . ", " . $cnn_id->qstr($host["snmp_timeout"]) . ",\n\t\t\t" . $cnn_id->qstr($host["snmp_username"]) . ", " . $cnn_id->qstr($host["snmp_password"]) . ", " . $cnn_id->qstr($host["snmp_auth_protocol"]) . ",\n\t\t\t" . $cnn_id->qstr($host["snmp_priv_passphrase"]) . ", " . $cnn_id->qstr($host["snmp_priv_protocol"]) . ", " . $cnn_id->qstr($host["snmp_context"]) . ",\n\t\t\t" . $cnn_id->qstr($host["snmp_port"]) . ", " . $cnn_id->qstr($data_source_item_name) . ", " . $cnn_id->qstr(clean_up_path(get_data_source_path($local_data_id, true))) . ",\n\t\t\t" . $cnn_id->qstr($num_rrd_items) . ", " . $cnn_id->qstr($rrd_step) . ", " . $cnn_id->qstr($rrd_next_step) . ", " . $cnn_id->qstr($arg1) . ", " . $cnn_id->qstr($arg2) . ", " . $cnn_id->qstr($arg3) . ", '1')";
    }
}
Example #5
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
	$host = db_fetch_row("select
		host.id,
		host.hostname,
		host.snmp_community,
		host.snmp_version,
		host.snmp_username,
		host.snmp_password,
		host.snmp_port,
		host.snmp_timeout,
		host.disabled
		from host
		where host.id=$host_id");

	/* the $host_field_override array can be used to override certain host fields in the poller cache */
	if (isset($host)) {
		$host = array_merge($host, $host_field_override);
	}

	if (isset($host["id"]) || (isset($host_id))) {
		if (isset($host)) {
			if ($host["disabled"] == "on") {
				return true;
			}
		} else {
			$host["id"] = 0;
			$host["snmp_community"] = "";
			$host["snmp_timeout"] = "";
			$host["snmp_username"] = "";
			$host["snmp_password"] = "";
			$host["snmp_version"] = "";
			$host["snmp_port"] = "";
			$host["hostname"] = "None";
		}

		return db_execute("insert into poller_item (local_data_id,host_id,action,hostname,
			snmp_community,snmp_version,snmp_timeout,snmp_username,snmp_password,snmp_port,rrd_name,rrd_path,
			rrd_num,arg1,arg2,arg3) values ($local_data_id," . $host["id"] . ",$poller_action_id,'" . $host["hostname"] . "',
			'" . $host["snmp_community"] . "','" . $host["snmp_version"] . "','" . $host["snmp_timeout"] . "',
			'" . $host["snmp_username"] . "','" . $host["snmp_password"] . "','" . $host["snmp_port"] . "',
			'$data_source_item_name','" . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
			'$num_rrd_items','$arg1','$arg2','$arg3')");
	}
}
Example #6
0
function substitute_script_query_path($path) {
	global $config;

	$path = clean_up_path(str_replace("|path_cacti|", $config["base_path"], $path));
	$path = clean_up_path(str_replace("|path_php_binary|", read_config_option("path_php_binary"), $path));

	return $path;
}
Example #7
0
function substitute_script_query_path($path)
{
    global $config;
    $path = clean_up_path(str_replace('|path_cacti|', $config['base_path'], $path));
    $path = clean_up_path(str_replace('|path_php_binary|', read_config_option('path_php_binary'), $path));
    return $path;
}
Example #8
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
	$host = db_fetch_row("select
		host.id,
		host.hostname,
		host.snmp_community,
		host.snmp_version,
		host.snmp_username,
		host.snmp_password,
		host.snmp_auth_protocol,
		host.snmp_priv_passphrase,
		host.snmp_priv_protocol,
		host.snmp_context,
		host.snmp_port,
		host.snmp_timeout,
		host.disabled
		from host
		where host.id=$host_id");

	/* the $host_field_override array can be used to override certain host fields in the poller cache */
	if (isset($host)) {
		$host = array_merge($host, $host_field_override);
	}

	if (isset($host["id"]) || (isset($host_id))) {
		if (isset($host)) {
			if ($host["disabled"] == "on") {
				return true;
			}
		} else {
			if ($poller_action_id == 0) {
				return true;
			}

			$host["id"] = 0;
			$host["snmp_community"] = "";
			$host["snmp_timeout"] = 0;
			$host["snmp_username"] = "";
			$host["snmp_password"] = "";
			$host["snmp_auth_protocol"] = "";
			$host["snmp_priv_passphrase"] = "";
			$host["snmp_priv_protocol"] = "";
			$host["snmp_context"] = "";
			$host["snmp_version"] = 0;
			$host["snmp_port"] = 161;
			$host["hostname"] = "None";
		}

		if ($poller_action_id == 0) {
			if (($host["snmp_version"] < 1) || ($host["snmp_version"] > 3) ||
				($host["snmp_community"] == "" && $host["snmp_version"] != 3)) {
				return true;
			}
		}

		$rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);

		return db_execute("INSERT INTO poller_item (local_data_id, host_id, action,hostname,
			snmp_community, snmp_version, snmp_timeout, snmp_username, snmp_password,
			snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, rrd_name, rrd_path,
			rrd_num, rrd_step, rrd_next_step, arg1, arg2, arg3)
			VALUES
			($local_data_id, " . $host["id"] . ", $poller_action_id,'" . $host["hostname"] . "',
			'" . $host["snmp_community"]       . "', '" . $host["snmp_version"]       . "', '" . $host["snmp_timeout"] . "',
			'" . $host["snmp_username"]        . "', '" . $host["snmp_password"]      . "', '" . $host["snmp_auth_protocol"] . "',
			'" . $host["snmp_priv_passphrase"] . "', '" . $host["snmp_priv_protocol"] . "', '" . $host["snmp_context"] . "',
			'" . $host["snmp_port"]            . "', '$data_source_item_name', '"     . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
			'$num_rrd_items', '$rrd_step', '$rrd_next_step', '$arg1', '$arg2', '$arg3')");
	}
}
Example #9
0
function api_poller_cache_item_add($host_id, $data_source_id, $polling_interval, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
	global $cnn_id;

	require_once(CACTI_BASE_PATH . "/lib/sys/string.php");
	require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php");

	if (empty($data_source_id)) {
		return;
	}

	if (!empty($host_id)) {
		$host = db_fetch_row("select
			host.id,
			host.poller_id,
			host.hostname,
			host.snmp_community,
			host.snmp_version,
			host.snmpv3_auth_username,
			host.snmpv3_auth_password,
			host.snmpv3_auth_protocol,
			host.snmpv3_priv_passphrase,
			host.snmpv3_priv_protocol,
			host.snmp_port,
			host.snmp_timeout,
			host.availability_method,
			host.ping_method,
			host.disabled
			from host
			where host.id = $host_id");
	}

	/* return if the device is marked as disabled */
	if ((isset($host)) && ($host["disabled"] == "on")) {
		return;
	}

	$save["local_data_id"] = $data_source_id;
	$save["host_id"] = $host_id;
	$save["action"] = $poller_action_id;
	$save["poller_id"] = (isset($host) ? $host["poller_id"] : "");
	$save["hostname"] = (isset($host) ? $host["hostname"] : "");
	$save["snmp_community"] = (isset($host) ? $host["snmp_community"] : "");
	$save["snmp_version"] = (isset($host) ? $host["snmp_version"] : "");
	$save["snmpv3_auth_username"] = (isset($host) ? $host["snmpv3_auth_username"] : "");
	$save["snmpv3_auth_password"] = (isset($host) ? $host["snmpv3_auth_password"] : "");
	$save["snmpv3_auth_protocol"] = (isset($host) ? $host["snmpv3_auth_protocol"] : "");
	$save["snmpv3_priv_passphrase"] = (isset($host) ? $host["snmpv3_priv_passphrase"] : "");
	$save["snmpv3_priv_protocol"] = (isset($host) ? $host["snmpv3_priv_protocol"] : "");
	$save["snmp_timeout"] = (isset($host) ? $host["snmp_timeout"] : "");
	$save["snmp_port"] = (isset($host) ? $host["snmp_port"] : "");
	$save["availability_method"] = (isset($host) ? $host["availability_method"] : "");
	$save["ping_method"] = (isset($host) ? $host["ping_method"] : "");
	$save["rrd_name"] = $data_source_item_name;
	$save["rrd_path"] = addslashes(clean_up_path(api_data_source_path_get($data_source_id, true)));
	$save["rrd_num"] = $num_rrd_items;
	$save["rrd_step"] = $polling_interval;
	$save["rrd_next_step"] = api_poller_get_rrd_next_step($polling_interval, $num_rrd_items); // FIX ME
	$save["arg1"] = $arg1;
	$save["arg2"] = $arg2;
	$save["arg3"] = $arg3;

	/* for pass by reference */
	$table_name = "poller_item";

	db_execute($cnn_id->GetInsertSQL($table_name, $save));
}
Example #10
0
/**
 * This function is a callback function that is used while extracting a zipfile
 * http://www.phpconcept.net/pclzip/man/en/index.php?options-pclzip_cb_pre_extract
 *
 * @param $p_event
 * @param $p_header
 * @return 1 (If the function returns 1, then the extraction is resumed)
 */
function clean_up_files_in_zip($p_event, &$p_header)
{
    $res = clean_up_path($p_header['filename']);
    return $res;
}
Example #11
0
/** api_poller_cache_item_add - add an item to the poller cache
 *
 * @param int $device_id
 * @param string $device_field_override
 * @param int $local_data_id
 * @param int $rrd_step
 * @param int $poller_action_id
 * @param string $data_source_item_name
 * @param int $num_rrd_items
 * @param string $arg1
 * @param string $arg2
 * @param string $arg3
 * @return unknown_type
 */
function api_poller_cache_item_add($device_id, $device_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
	static $devices = array();

	if (!isset($devices[$device_id])) {
		$device = db_fetch_row("select
			device.id,
			device.poller_id,
			device.hostname,
			device.snmp_community,
			device.snmp_version,
			device.snmp_username,
			device.snmp_password,
			device.snmp_auth_protocol,
			device.snmp_priv_passphrase,
			device.snmp_priv_protocol,
			device.snmp_context,
			device.snmp_port,
			device.snmp_timeout,
			device.disabled
			from device
			where device.id=$device_id");

		$devices[$device_id] = $device;
	} else {
		$device = $devices[$device_id];
	}

	/* the $device_field_override array can be used to override certain device fields in the poller cache */
	if (isset($device)) {
		$device = array_merge($device, $device_field_override);
	}

	if (isset($device["id"]) || (isset($device_id))) {
		if (isset($device)) {
			if ($device["disabled"] == CHECKED) {
				return;
			}
		} else {
			if ($poller_action_id == 0) {
				return;
			}

			$device["id"] = 0;
			$device["poller_id"] = 0;
			$device["snmp_community"] = "";
			$device["snmp_timeout"] = "";
			$device["snmp_username"] = "";
			$device["snmp_password"] = "";
			$device["snmp_auth_protocol"] = "";
			$device["snmp_priv_passphrase"] = "";
			$device["snmp_priv_protocol"] = "";
			$device["snmp_context"] = "";
			$device["snmp_version"] = "";
			$device["snmp_port"] = "";
			$device["hostname"] = "None";
		}

		if ($poller_action_id == 0) {
			if (($device["snmp_version"] < 1) || ($device["snmp_version"] > 3) ||
				($device["snmp_community"] == "" && $device["snmp_version"] != 3)) {
				return;
			}
		}

		$rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);

		return "($local_data_id, " . $device["poller_id"] . ", " . $device["id"] . ", $poller_action_id,'" . $device["hostname"] . "',
			'" . $device["snmp_community"]       . "', '" . $device["snmp_version"]       . "', '" . $device["snmp_timeout"] . "',
			'" . $device["snmp_username"]        . "', '" . $device["snmp_password"]      . "', '" . $device["snmp_auth_protocol"] . "',
			'" . $device["snmp_priv_passphrase"] . "', '" . $device["snmp_priv_protocol"] . "', '" . $device["snmp_context"] . "',
			'" . $device["snmp_port"]            . "', '$data_source_item_name', '"     . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
			'$num_rrd_items', '$rrd_step', '$rrd_next_step', '$arg1', '$arg2', '$arg3', '1')";
	}
}