Пример #1
0
function GetRoutingTable($host, $community, $rtrtype)
{
    global $w, $p;
    $OID = array("generic" => ".1.3.6.1.2.1.4.21.1.11", "riverstone" => ".1.3.6.1.2.1.4.24.4", "juniper" => ".1.3.6.1.2.1.4.24.4.1");
    if (!extension_loaded("snmp")) {
        myError($w, $p, "no snmp!!! - compile php with --with-snmp --enable-ucd-snmp-hack");
        exit;
    }
    if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
        // Windows snmp different
    } else {
        // Unix snmp different - need to set quickprint to be compatible
        // with Windows format. Windows does not have long print format
        // must test for os version as undefined function generates error
        // even with @
        snmp_set_quick_print(1);
    }
    // protect against bad users!
    if (!array_key_exists($rtrtype, $OID)) {
        $rtrtype = "generic";
    }
    $routes = @snmpwalkoid($host, $community, $OID[$rtrtype]);
    if (!$routes) {
        return 0;
    }
    for (reset($routes); $network = key($routes); next($routes)) {
        //here is the way to do it with RFC 2096 using ipCidrRouteMask
        //this is what we get back from the riverstone
        //meaning:  subnet IP, subnet mask, destination = ip destination ip
        if ($rtrtype == "riverstone") {
            //kill the destination
            list($oc1, $oc2, $oc3, $oc4, $oc5, $rest) = explode(".", strrev($network), 6);
            //take the subnetmask
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", $rest, 5);
            $mask = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
            //take the subnet addr
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", $rest, 5);
            $netaddr = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
        } else {
            // The Old way to do it with RFC 1213 MIBv2 (which is deprecated)
            // do some magic to obtain a unique, sortable array index to force the results
            // into ip address order. index will be x0000000000 where the digits are the
            // integer representation of the ip address padded with zeros.
            $mask = $routes[$network];
            // strip out last 4 octets from mib value - lots of .'s
            // complicate matters
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", strrev($network), 5);
            $netaddr = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
        }
        // $ind='x'.str_pad(inet_aton(substr($netaddr, strpos($netaddr, '.')+1)), 10, "0", STR_PAD_LEFT);
        $ind = 'x' . str_pad(inet_aton($netaddr), 10, "0", STR_PAD_LEFT);
        $result["{$ind}"] = array("rtrbase" => $netaddr, "rtrmask" => $mask);
    }
    //"rtrmask"=>substr($mask, strpos($mask, ' ')+1));
    return $result;
}
Пример #2
0
function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 500, $environ = SNMP_POLLER) {
	global $config;

	$retries = read_config_option("snmp_retries");
	if ($retries == "") $retries = 3;

	/* always use SNMP version 1 for UI stuff */
	if ($environ == SNMP_WEBUI) {
		$version = "1";
	}

	if (($config["php_snmp_support"] == true) && ($version == "1")) {
		/* make sure snmp* is verbose so we can see what types of data
		we are getting back */
		snmp_set_quick_print(0);

		$snmp_value = @snmpget("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			$snmp_auth = "-u $username -l authPriv -a MD5 -A $password -x DES -X $password"; /* v3 - username/password */
		}

		/* no valid snmp version has been set, get out */
		if (empty($snmp_auth)) { return; }

		if (read_config_option("snmp_version") == "ucd-snmp") {
			exec(read_config_option("path_snmpget") . " -O vt -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid", $snmp_value);
		}elseif (read_config_option("snmp_version") == "net-snmp") {
			exec(read_config_option("path_snmpget") . " -O vt $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid", $snmp_value);
		}
	}

	if (isset($snmp_value)) {
		/* fix for multi-line snmp output */
		if (is_array($snmp_value)) {
			$snmp_value = implode(" ", $snmp_value);
		}

		/* strip out non-snmp data */
		$snmp_value = format_snmp_string($snmp_value);

		return $snmp_value;
	}
}
 private function changeSNMPSettings()
 {
     if (function_exists("snmp_get_quick_print")) {
         $this->snmpSavedQuickPrint = snmp_get_quick_print();
         snmp_set_quick_print(1);
     }
     if (function_exists("snmp_get_valueretrieval")) {
         $this->snmpSavedValueRetrieval = snmp_get_valueretrieval();
     }
     if (function_exists('snmp_set_oid_output_format')) {
         snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
     }
     if (function_exists('snmp_set_valueretrieval')) {
         snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
     }
 }
Пример #4
0
 function __construct($cfg)
 {
     snmp_set_quick_print(TRUE);
     if ((string) $cfg->host !== '') {
         $this->host = (string) $cfg->host;
     }
     if ((string) $cfg->port !== '') {
         $this->port = intval((string) $cfg->port);
     }
     if ((string) $cfg->community !== '') {
         $this->community = (string) $cfg->community;
     }
     foreach ($cfg->mib as $mib) {
         snmp_read_mib((string) $mib);
     }
 }
Пример #5
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 500, $environ = SNMP_POLLER) {
	global $config;

	$snmp_array = array();
	$temp_array = array();
	/* determine default retries */
	$retries = read_config_option("snmp_retries");
	if ($retries == "") $retries = 3;

	if (snmp_get_method($version) == SNMP_METHOD_PHP) {
		/* make sure snmp* is verbose so we can see what types of data
		we are getting back */
		snmp_set_quick_print(0);

		if (function_exists("snmp_set_valueretrieval")) {
			snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
		}

		if ($version == "1") {
			$temp_array = @snmprealwalk("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
		} else {
			$temp_array = @snmp2_real_walk("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
		}

		$o = 0;
		for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
			$snmp_array[$o]["oid"] = ereg_replace("^\.", "", $i);
			$snmp_array[$o]["value"] = format_snmp_string($temp_array[$i]);
			$o++;
		}
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			$snmp_auth = "-u $username -l authPriv -a MD5 -A $password -x DES -X $password"; /* v3 - username/password */
		}

		if (read_config_option("snmp_version") == "ucd-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid");
		}else {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -O QfntUe $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid");
		}

		if ((sizeof($temp_array) == 0) || (substr_count($temp_array[0], "No Such Object"))) {
			return array();
		}

		for ($i=0; $i < count($temp_array); $i++) {
			$snmp_array[$i]["oid"] = trim(ereg_replace("(.*) =.*", "\\1", $temp_array[$i]));
			$snmp_array[$i]["value"] = format_snmp_string($temp_array[$i]);
		}
	}

	return $snmp_array;
}
Пример #6
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $environ = SNMP_POLLER) {
	global $config, $banned_snmp_strings;

	$snmp_oid_included = false;
	$snmp_auth	       = '';
	$snmp_array        = array();
	$temp_array        = array();

	/* determine default retries */
	if (($retries == 0) || (!is_numeric($retries))) {
		$retries = read_config_option("snmp_retries");
		if ($retries == "") $retries = 3;
	}

	$path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");

	if ((snmp_get_method($version) == SNMP_METHOD_PHP) &&
		(!strlen($context) || ($version != 3)) &&
		(($version == 1) ||
		(version_compare(phpversion(), "5.1") >= 0) ||
		(!file_exists($path_snmpbulkwalk)))) {
		/* make sure snmp* is verbose so we can see what types of data
		we are getting back */

		/* force php to return numeric oid's */
		if (function_exists("snmp_set_oid_numeric_print")) {
			snmp_set_oid_numeric_print(TRUE);
			$snmp_oid_included = true;
		}

		snmp_set_quick_print(0);

		if ($version == "1") {
			$temp_array = @snmprealwalk("$hostname:$port", "$community", "$oid", ($timeout * 1000), $retries);
		}elseif ($version == "2") {
			$temp_array = @snmp2_real_walk("$hostname:$port", "$community", "$oid", ($timeout * 1000), $retries);
		}else{
			if ($priv_proto == "[None]") {
				$proto = "authNoPriv";
				$priv_proto = "";
			}else{
				$proto = "authPriv";
			}

			$temp_array = @snmp3_real_walk("$hostname:$port", "$username", $proto, $auth_proto, "$password", $priv_proto, "$priv_pass", "$oid", ($timeout * 1000), $retries);
		}

		/* check for bad entries */
		if (is_array($temp_array) && sizeof($temp_array)) {
		foreach($temp_array as $key => $value) {
			foreach($banned_snmp_strings as $item) {
				if(strstr($value, $item) != "") {
					unset($temp_array[$key]);
					continue 2;
				}
			}
		}
		}

		$o = 0;
		for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
			if ($temp_array[$i] != "NULL") {
				$snmp_array[$o]["oid"] = preg_replace("/^\./", "", $i);
				$snmp_array[$o]["value"] = format_snmp_string($temp_array[$i], $snmp_oid_included);
			}
			$o++;
		}
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? cacti_escapeshellarg($community): "-c " . cacti_escapeshellarg($community); /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? cacti_escapeshellarg($community): "-c " . cacti_escapeshellarg($community); /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			if ($priv_proto == "[None]") {
				$proto = "authNoPriv";
				$priv_proto = "";
			}else{
				$proto = "authPriv";
			}

			if (strlen($priv_pass)) {
				$priv_pass = "******" . cacti_escapeshellarg($priv_pass) . " -x " . cacti_escapeshellarg($priv_proto);
			}else{
				$priv_pass = "";
			}

			if (strlen($context)) {
				$context = "-n " . cacti_escapeshellarg($context);
			}else{
				$context = "";
			}

			$snmp_auth = trim("-u " . cacti_escapeshellarg($username) .
				" -l " . cacti_escapeshellarg($proto) .
				" -a " . cacti_escapeshellarg($auth_proto) .
				" -A " . cacti_escapeshellarg($password) .
				" "    . $priv_pass .
				" "    . $context); /* v3 - username/password */
		}

		if (read_config_option("snmp_version") == "ucd-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid");
		}else {
			if (file_exists($path_snmpbulkwalk) && ($version > 1) && ($max_oids > 1)) {
				$temp_array = exec_into_array($path_snmpbulkwalk . " -O Qn $snmp_auth -v $version -t $timeout -r $retries -Cr$max_oids $hostname:$port $oid");
			}else{
				$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -O Qn $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid");
			}
		}

		/* check for bad entries */
		if (is_array($temp_array) && sizeof($temp_array)) {
		foreach($temp_array as $key => $value) {
			foreach($banned_snmp_strings as $item) {
				if(strstr($value, $item) != "") {
					unset($temp_array[$key]);
					continue 2;
				}
			}
		}
		}

		for ($i=0; $i < count($temp_array); $i++) {
			if ($temp_array[$i] != "NULL") {
				$snmp_array[$i]["oid"]   = trim(preg_replace("/(.*) =.*/", "\\1", $temp_array[$i]));
				$snmp_array[$i]["value"] = format_snmp_string($temp_array[$i], true);
			}
		}
	}

	return $snmp_array;
}
Пример #7
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $v3username, $v3password, $v3authproto = "", $v3privpassphrase = "", $v3privproto = "", $port = 161, $timeout = 500, $environ = SNMP_POLLER) {
	require_once(CACTI_BASE_PATH . "/lib/sys/exec.php");

	$snmp_array = array();
	$temp_array = array();

	/* determine default retries */
	$retries = read_config_option("snmp_retries");
	if ($retries == "") $retries = 3;

	/* get rid of quotes in privacy passphrase */
	$v3privpassphrase = str_replace("#space#", " ", $v3privpassphrase);

	if ($v3privproto == "[None]") {
		$v3privproto = "";
	}

	$path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");

	if ((snmp_get_method($version) == SNMP_METHOD_PHP) &&
		(($version == 1) ||
		(version_compare(phpversion(), "5.1") >= 0) ||
		(!file_exists($path_snmpbulkwalk)))) {
		/* make sure snmp* is verbose so we can see what types of data
		we are getting back */
		snmp_set_quick_print(0);

		/* force php to return numeric oid's */
		if (function_exists("snmp_set_oid_numeric_print")) {
			snmp_set_oid_numeric_print(1);
		}

		if ($version == "1") {
			$temp_array = @snmprealwalk("$hostname:$port", $community, trim($oid), ($timeout * 1000), $retries);
		}elseif ($version == "2") {
			$temp_array = @snmp2_real_walk("$hostname:$port", $community, trim($oid), ($timeout * 1000), $retries);
		}else{
			$temp_array = @snmp3_real_walk("$hostname:$port", $v3username, snmp_get_v3authpriv($v3privproto), $v3authproto,
				$v3password, $v3privproto, $v3privpassphrase, trim($oid), ($timeout * 1000), $retries);
		}

		$o = 0;
		for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
			$snmp_array[$o]["oid"] = ereg_replace("^\.", "", $i);
			$snmp_array[$o]["value"] = format_snmp_string($temp_array[$i]);
			$o++;
		}
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			$snmp_auth = "-u $v3username -A $v3password -a $v3authproto -X $v3privpassphrase -x $v3privproto -l " . snmp_get_v3authpriv($v3privproto); /* v3 - username/password/etc... */
		}

		if (read_config_option("snmp_version") == "ucd-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid");
		}else {
			if (strlen(trim($path_snmpbulkwalk)) && ($version > 1)) {
				$temp_array = exec_into_array(read_config_option("path_snmpbulkwalk") . " -O QfntUe $snmp_auth -v $version -t $timeout -r $retries -Cr50 $hostname:$port $oid");
			}else{
				$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -O QfntUe $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid");
			}
		}

		if ((sizeof($temp_array) == 0) ||
			(substr_count($temp_array[0], "No Such Object")) ||
			(substr_count($temp_array[0], "No more variables"))) {
			return array();
		}

		for ($i=0; $i < count($temp_array); $i++) {
			$snmp_array[$i]["oid"] = trim(ereg_replace("(.*) =.*", "\\1", $temp_array[$i]));
			$snmp_array[$i]["value"] = format_snmp_string($temp_array[$i]);
		}
	}

	return $snmp_array;
}
Пример #8
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 500, $retries = 0, $environ = SNMP_POLLER) {
	global $config;

	$snmp_array = array();
	$temp_array = array();

	/* determine default retries */
	if (($retries == 0) || (!is_numeric($retries))) {
		$retries = read_config_option("snmp_retries");
		if ($retries == "") $retries = 3;
	}

	$path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");

	if ((snmp_get_method($version) == SNMP_METHOD_PHP) &&
		(($version == 1) ||
		(version_compare(phpversion(), "5.1") >= 0) ||
		(!file_exists($path_snmpbulkwalk)))) {
		/* make sure snmp* is verbose so we can see what types of data
		we are getting back */

		/* force php to return numeric oid's */
		if (function_exists("snmp_set_oid_numeric_print")) {
			snmp_set_oid_numeric_print(TRUE);
		}

		snmp_set_quick_print(0);

		if ($version == "1") {
			$temp_array = @snmprealwalk("$hostname:$port", "$community", "$oid", ($timeout * 1000), $retries);
		}elseif ($version == "2") {
			$temp_array = @snmp2_real_walk("$hostname:$port", "$community", "$oid", ($timeout * 1000), $retries);
		}else{
			$temp_array = @snmp3_real_walk("$hostname:$port", $username, "authNoPriv", "MD5", $password, "", "", $oid, ($timeout * 1000), $retries);
		}

		$o = 0;
		for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
			$snmp_array[$o]["oid"] = ereg_replace("^\.", "", $i);
			$snmp_array[$o]["value"] = format_snmp_string($temp_array[$i]);
			$o++;
		}
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			$snmp_auth = "-u $username -l authNoPriv -a MD5 -A $password"; /* v3 - username/password */
		}

		if (read_config_option("snmp_version") == "ucd-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid");
		}else {
			if (file_exists($path_snmpbulkwalk) && ($version > 1)) {
				$temp_array = exec_into_array($path_snmpbulkwalk . " -O n $snmp_auth -v $version -t $timeout -r $retries -Cr50 $hostname:$port $oid");
			}else{
				$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -O n $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid");
			}
		}

		if ((sizeof($temp_array) == 0) ||
			(substr_count($temp_array[0], "No Such Object")) ||
			(substr_count($temp_array[0], "No more variables"))) {
			return array();
		}

		for ($i=0; $i < count($temp_array); $i++) {
			$snmp_array[$i]["oid"] = trim(ereg_replace("(.*) =.*", "\\1", $temp_array[$i]));
			$snmp_array[$i]["value"] = format_snmp_string($temp_array[$i]);
		}
	}

	return $snmp_array;
}
Пример #9
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $port = 161, $timeout = 500, $retries = 0, $environ = SNMP_POLLER)
{
    global $config;
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option("snmp_retries");
        if ($retries == "") {
            $retries = 3;
        }
    }
    $path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");
    if (snmp_get_method($version) == SNMP_METHOD_PHP && ($version == 1 || version_compare(phpversion(), "5.1") >= 0 || !file_exists($path_snmpbulkwalk))) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        /* force php to return numeric oid's */
        if (function_exists("snmp_set_oid_numeric_print")) {
            snmp_set_oid_numeric_print(TRUE);
        }
        snmp_set_quick_print(0);
        if ($version == "1") {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == "2") {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($auth_proto == "[None]") {
                $proto = "authNoPriv";
            } else {
                $proto = "authPriv";
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", $username, $proto, $auth_proto, "{$password}", "{$priv_pass}", $priv_proto, "{$oid}", $timeout * 1000, $retries);
        }
        $o = 0;
        for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
            $snmp_array[$o]["oid"] = ereg_replace("^\\.", "", $i);
            $snmp_array[$o]["value"] = format_snmp_string($temp_array[$i]);
            $o++;
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == "1") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER;
            /* v1/v2 - community string */
        } elseif ($version == "2") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER;
            /* v1/v2 - community string */
            $version = "2c";
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == "3") {
            if ($auth_proto == "[None]") {
                $proto = "authNoPriv";
            } else {
                $proto = "authPriv";
            }
            if (strlen($priv_pass)) {
                $priv_pass = "******"{$priv_pass}\" -x {$priv_proto}";
            } else {
                $priv_pass = "";
            }
            $snmp_auth = "-u {$username} -l {$proto} -a {$auth_proto} -A {$password} {$priv_pass}";
            /* v3 - username/password */
        }
        if (read_config_option("snmp_version") == "ucd-snmp") {
            $temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v{$version} -t {$timeout} -r {$retries} {$hostname}:{$port} {$snmp_auth} {$oid}");
        } else {
            if (file_exists($path_snmpbulkwalk) && $version > 1) {
                $temp_array = exec_into_array($path_snmpbulkwalk . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr50 {$hostname}:{$port} {$oid}");
            } else {
                $temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} {$hostname}:{$port} {$oid}");
            }
        }
        if (sizeof($temp_array) == 0 || substr_count($temp_array[0], "No Such Object") || substr_count($temp_array[0], "No more variables") || substr_count($temp_array[0], "End of MIB") || substr_count($temp_array[0], "Wrong Type")) {
            return array();
        }
        for ($i = 0; $i < count($temp_array); $i++) {
            $snmp_array[$i]["oid"] = trim(ereg_replace("(.*) =.*", "\\1", $temp_array[$i]));
            $snmp_array[$i]["value"] = format_snmp_string($temp_array[$i]);
        }
    }
    return $snmp_array;
}
Пример #10
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $method = SNMP_VALUE_LIBRARY, $environ = SNMP_POLLER)
{
    global $config, $banned_snmp_strings;
    $snmp_oid_included = true;
    $snmp_auth = '';
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option('snmp_retries');
        if ($retries == '') {
            $retries = 3;
        }
    }
    /* do not attempt to poll invalid combinations */
    if ($version == 0 || !is_numeric($version) || !is_numeric($max_oids) || !is_numeric($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == '' && $version != 3) {
        return array();
    }
    $path_snmpbulkwalk = read_config_option('path_snmpbulkwalk');
    if (snmp_get_method($version) == SNMP_METHOD_PHP && (!strlen($context) || $version != 3) && ($version == 1 || version_compare(phpversion(), '5.1') >= 0 || !file_exists($path_snmpbulkwalk))) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        /* force php to return numeric oid's */
        cacti_oid_numeric_format();
        snmp_set_quick_print(0);
        /* set the output format to numeric */
        snmp_set_valueretrieval($method);
        if ($version == '1') {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == '2') {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
        }
        if ($temp_array === false) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
            $o = 0;
            for (reset($temp_array); $i = key($temp_array); next($temp_array)) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$o]['oid'] = preg_replace('/^\\./', '', $i);
                    $snmp_array[$o]['value'] = format_snmp_string($temp_array[$i], $snmp_oid_included);
                }
                $o++;
            }
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == '1') {
            $snmp_auth = '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
        } elseif ($version == '2') {
            $snmp_auth = '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
            $version = '2c';
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == '3') {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            if (strlen($priv_pass)) {
                $priv_pass = '******' . snmp_escape_string($priv_pass) . ' -x ' . snmp_escape_string($priv_proto);
            } else {
                $priv_pass = '';
            }
            if (strlen($context)) {
                $context = '-n ' . snmp_escape_string($context);
            } else {
                $context = '';
            }
            $snmp_auth = trim('-u ' . snmp_escape_string($username) . ' -l ' . snmp_escape_string($proto) . ' -a ' . snmp_escape_string($auth_proto) . ' -A ' . snmp_escape_string($password) . ' ' . $priv_pass . ' ' . $context);
            /* v3 - username/password */
        }
        if (file_exists($path_snmpbulkwalk) && $version > 1 && $max_oids > 1) {
            $temp_array = exec_into_array(cacti_escapeshellcmd($path_snmpbulkwalk) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr{$max_oids} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
        } else {
            $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option('path_snmpwalk')) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
        }
        if (substr_count(implode(' ', $temp_array), 'Timeout:')) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
            for ($i = 0; $i < count($temp_array); $i++) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$i]['oid'] = trim(preg_replace('/(.*) =.*/', "\\1", $temp_array[$i]));
                    $snmp_array[$i]['value'] = format_snmp_string($temp_array[$i], true);
                }
            }
        }
    }
    return $snmp_array;
}
Пример #11
0
 function __set($name, $value)
 {
     switch ($name) {
         case 'quick_print':
             snmp_set_quick_print($value);
             break;
         case 'oid_output_format':
             /* needs php >= 5.2.0 */
             snmp_set_oid_output_format($value);
             break;
         case 'enum_print':
             snmp_set_enum_print($value);
             break;
         case 'valueretrieval':
             snmp_set_valueretrieval($value);
             break;
         default:
             $trace = debug_backtrace();
             trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
             return null;
     }
 }
Пример #12
0
if (empty($community)) {
    $community = "tceo";
}
if (empty($refresh)) {
    $refresh = "10";
}
// Change seconds to Milliseconds for setInterval loop
$chartloop = $refresh * 1000;
// Set Bandwidth OID's by Numerical Interface Choice
if (!empty($interface)) {
    $oid0 = "1.3.6.1.2.1.2.2.1.10.{$interface}";
    $oid1 = "1.3.6.1.2.1.2.2.1.16.{$interface}";
}
// Set PHP-SNMP Default Variables
snmp_set_oid_numeric_print(1);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
// Get OID Data if Requested
if (!empty($oid0)) {
    $output0 = snmpget($ip, $community, $oid0);
}
if (!empty($oid1)) {
    $output1 = snmpget($ip, $community, $oid1);
}
// Generate HTML Head Function
function head()
{
    echo "<!DOCTYPE html>\r\n    <html>\r\n    <head>\r\n      <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\r\n      <title>Jordan's Live Bandwidth Grapher</title>\r\n      <style>\r\n      body {\r\n        background-color: #F5F5F5;\r\n        font-family: Monaco, Menlo, Consolas, \"Courier New\", monospace;\r\n      }\r\n      </style>\r\n    </head>";
}
// Generate Menu Function
Пример #13
0
 /**
  * Function gets a count of printed papers,
  * or returns false if call failed
  *
  * @return int|boolean
  */
 public function getNumberOfPrintedPapers()
 {
     snmp_set_quick_print(true);
     $numberOfPrintedPapers = $this->get(self::SNMP_NUMBER_OF_PRINTED_PAPERS);
     snmp_set_quick_print(false);
     return $numberOfPrintedPapers !== false ? (int) $numberOfPrintedPapers : false;
 }
 function ReadData($targetstring, &$map, &$item)
 {
     $data[IN] = NULL;
     $data[OUT] = NULL;
     $data_time = 0;
     $timeout = 1000000;
     $retries = 2;
     $abort_count = 0;
     $in_result = NULL;
     $out_result = NULL;
     if ($map->get_hint("snmp_timeout") != '') {
         $timeout = intval($map->get_hint("snmp_timeout"));
         debug("Timeout changed to " . $timeout . " microseconds.\n");
     }
     if ($map->get_hint("snmp_abort_count") != '') {
         $abort_count = intval($map->get_hint("snmp_abort_count"));
         debug("Will abort after {$abort_count} failures for a given host.\n");
     }
     if ($map->get_hint("snmp_retries") != '') {
         $retries = intval($map->get_hint("snmp_retries"));
         debug("Number of retries changed to " . $retries . ".\n");
     }
     if (preg_match("/^snmp:([^:]+):([^:]+):([^:]+):([^:]+)\$/", $targetstring, $matches)) {
         $community = $matches[1];
         $host = $matches[2];
         $in_oid = $matches[3];
         $out_oid = $matches[4];
         if ($abort_count == 0 || $abort_count > 0 && (!isset($this->down_cache[$host]) || intval($this->down_cache[$host]) < $abort_count)) {
             if (function_exists("snmp_get_quick_print")) {
                 $was = snmp_get_quick_print();
                 snmp_set_quick_print(1);
             }
             if (function_exists("snmp_get_valueretrieval")) {
                 $was2 = snmp_get_valueretrieval();
             }
             if (function_exists('snmp_set_oid_output_format')) {
                 snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             }
             if (function_exists('snmp_set_valueretrieval')) {
                 snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
             }
             if ($in_oid != '-') {
                 $in_result = snmpget($host, $community, $in_oid, $timeout, $retries);
                 if ($in_result) {
                     $data[IN] = floatval($in_result);
                     $item->add_hint("snmp_in_raw", $in_result);
                 } else {
                     $this->down_cache[$host]++;
                 }
             }
             if ($out_oid != '-') {
                 $out_result = snmpget($host, $community, $out_oid, $timeout, $retries);
                 if ($out_result) {
                     // use floatval() here to force the output to be *some* kind of number
                     // just in case the stupid formatting stuff doesn't stop net-snmp returning 'down' instead of 2
                     $data[OUT] = floatval($out_result);
                     $item->add_hint("snmp_out_raw", $out_result);
                 } else {
                     $this->down_cache[$host]++;
                 }
             }
             debug("SNMP ReadData: Got {$in_result} and {$out_result}\n");
             $data_time = time();
             if (function_exists("snmp_set_quick_print")) {
                 snmp_set_quick_print($was);
             }
         } else {
             warn("SNMP for {$host} has reached {$abort_count} failures. Skipping. [WMSNMP01]");
         }
     }
     debug("SNMP ReadData: Returning (" . ($data[IN] === NULL ? 'NULL' : $data[IN]) . "," . ($data[OUT] === NULL ? 'NULL' : $data[OUT]) . ",{$data_time})\n");
     return array($data[IN], $data[OUT], $data_time);
 }
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
echo "Checking error handling\n";
var_dump(snmp_get_quick_print('noarg'));
var_dump(snmp_set_quick_print('noarg'));
var_dump(snmp_set_quick_print());
echo "Checking working\n";
var_dump(snmp_get_quick_print());
snmp_set_quick_print(false);
var_dump(snmp_get_quick_print());
snmp_set_quick_print(true);
var_dump(snmp_get_quick_print());
Пример #16
0
 /**
  * get available mibs for a device
  *
  * @param args json params converted into an array
  *             id contains an array of ids
  *             community snmp community string
  * @throws none
  * @return array containing result and possible error messages
  */
 public function ajax_getMIBS($args)
 {
     try {
         $data = array();
         $dev = $this->getDevice($args['id']);
         snmp_set_quick_print(true);
         $oids = snmprealwalk($dev->address, $args['community'], null);
         if ($oids === false) {
             return array('result' => 'failure', 'error' => 'SNMP Failure');
         } else {
             // load returned mibs
             foreach ($oids as $k => $v) {
                 $mib_txt = sprintf("%s%s (%s%s)", substr($k, 0, 25), strlen($k) > 25 ? "..." : "", substr($v, 0, 15), strlen($v) > 15 ? "..." : "");
                 $data[] = array('mib' => $k, 'mib_txt' => $mib_txt, 'value' => $v);
             }
         }
     } catch (Exception $e) {
         return array('result' => 'failure', 'error' => $e->getMessage());
     }
     return array('result' => 'success', 'data' => $data);
 }
Пример #17
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $environ = SNMP_POLLER)
{
    global $config, $banned_snmp_strings;
    $snmp_oid_included = true;
    $snmp_auth = '';
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option("snmp_retries");
        if ($retries == "") {
            $retries = 3;
        }
    }
    /* determine default max_oids */
    if ($max_oids == 0 || !is_numeric($max_oids)) {
        $max_oids = read_config_option("max_get_size");
        if ($max_oids == "") {
            $max_oids = 10;
        }
    }
    /* do not attempt to poll invalid combinations */
    if ($version == 0 || !is_numeric($version) || !is_numeric($max_oids) || !is_numeric($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == "" && $version != 3) {
        return array();
    }
    $path_snmpbulkwalk = read_config_option("path_snmpbulkwalk");
    if (snmp_get_method($version) == SNMP_METHOD_PHP && (!strlen($context) || $version != 3) && ($version == 1 || version_compare(phpversion(), "5.1") >= 0 || !file_exists($path_snmpbulkwalk))) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        /* force php to return numeric oid's */
        if (function_exists("snmp_set_oid_numeric_print")) {
            snmp_set_oid_numeric_print(TRUE);
        }
        if (function_exists("snmprealwalk")) {
            $snmp_oid_included = false;
        }
        snmp_set_quick_print(0);
        if ($version == "1") {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == "2") {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($priv_proto == "[None]" || $priv_pass == '') {
                $proto = "authNoPriv";
                $priv_proto = "";
            } else {
                $proto = "authPriv";
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
        }
        if ($temp_array === false) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != "") {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        $o = 0;
        for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
            if ($temp_array[$i] != "NULL") {
                $snmp_array[$o]["oid"] = preg_replace("/^\\./", "", $i);
                $snmp_array[$o]["value"] = format_snmp_string($temp_array[$i], $snmp_oid_included);
            }
            $o++;
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == "1") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? snmp_escape_string($community) : "-c " . snmp_escape_string($community);
            /* v1/v2 - community string */
        } elseif ($version == "2") {
            $snmp_auth = read_config_option("snmp_version") == "ucd-snmp" ? snmp_escape_string($community) : "-c " . snmp_escape_string($community);
            /* v1/v2 - community string */
            $version = "2c";
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == "3") {
            if ($priv_proto == "[None]" || $priv_pass == '') {
                $proto = "authNoPriv";
                $priv_proto = "";
            } else {
                $proto = "authPriv";
            }
            if (strlen($priv_pass)) {
                $priv_pass = "******" . snmp_escape_string($priv_pass) . " -x " . snmp_escape_string($priv_proto);
            } else {
                $priv_pass = "";
            }
            if (strlen($context)) {
                $context = "-n " . snmp_escape_string($context);
            } else {
                $context = "";
            }
            $snmp_auth = trim("-u " . snmp_escape_string($username) . " -l " . snmp_escape_string($proto) . " -a " . snmp_escape_string($auth_proto) . " -A " . snmp_escape_string($password) . " " . $priv_pass . " " . $context);
            /* v3 - username/password */
        }
        if (read_config_option("snmp_version") == "ucd-snmp") {
            /* escape the command to be executed and vulnerable parameters
             * numeric parameters are not subject to command injection
             * snmp_auth is treated seperately, see above */
            $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option("path_snmpwalk")) . " -v{$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} {$snmp_auth} " . cacti_escapeshellarg($oid));
        } else {
            if (file_exists($path_snmpbulkwalk) && $version > 1 && $max_oids > 1) {
                $temp_array = exec_into_array(cacti_escapeshellcmd($path_snmpbulkwalk) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr{$max_oids} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            } else {
                $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option("path_snmpwalk")) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            }
        }
        if (substr_count(implode(" ", $temp_array), "Timeout:")) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != "") {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        for ($i = 0; $i < count($temp_array); $i++) {
            if ($temp_array[$i] != "NULL") {
                $snmp_array[$i]["oid"] = trim(preg_replace("/(.*) =.*/", "\\1", $temp_array[$i]));
                $snmp_array[$i]["value"] = format_snmp_string($temp_array[$i], true);
            }
        }
    }
    return $snmp_array;
}
Пример #18
0
 function WIFI_GetSignal($ip, $mac_node, $community)
 {
     $devices = array('mac' => $mac_node, 'rssi' => NULL, 'tx' => NULL, 'rx' => NULL);
     $mac = explode(':', $mac_node);
     $oid_rssi = '.1.3.6.1.4.1.14988.1.1.1.2.1.3';
     $oid_tx = '.1.3.6.1.4.1.14988.1.1.1.2.1.8';
     $oid_rx = '.1.3.6.1.4.1.14988.1.1.1.2.1.9';
     for ($x = 0; $x < 6; $x++) {
         $oid_rssi .= '.' . hexdec($mac[$x]);
         $oid_tx .= '.' . hexdec($mac[$x]);
         $oid_rx .= '.' . hexdec($mac[$x]);
     }
     @snmp_set_oid_numeric_print(TRUE);
     @snmp_set_quick_print(TRUE);
     @snmp_set_enum_print(TRUE);
     if ($sn = @snmpwalk($ip, $community, $oid_rssi)) {
         foreach ($sn as $a => $x) {
             $devices['rssi'] = $x;
         }
         $sntx = @snmpwalk($ip, $community, $oid_tx);
         foreach ($sntx as $a => $x) {
             $devices['tx'] = $x / 1000000;
         }
         $snrx = @snmpwalk($ip, $community, $oid_rx);
         foreach ($snrx as $a => $x) {
             $devices['rx'] = $x / 1000000;
         }
     }
     return $devices;
 }
Пример #19
0
                 $last_status = $sub_row[2];
             }
             // If the alarm threshold was breached, generate a ticket
             if ($down_count == $alarm_threshold && $last_status == 1 && $alert_status == 1) {
                 $timestamp = mktime();
                 $timestamp_human = date("d-M-Y H:i:s", $timestamp);
                 echo $message = "ALERT {$hostname} - Disk Utilization Threshold breached at {$timestamp_human}";
                 $subject = $message;
                 ticket_post($smtp_email, $smtp_email, "28", "{$subject}", "{$message}", '1');
             }
         }
     }
 } else {
     if ("Memory Utilization" == $param_name) {
         //end of else if dsk utilization
         snmp_set_quick_print(1);
         $snmp_result = '';
         $memInfo = "hrStorageDescr";
         if (strtolower($snmp_version) == 'v3') {
             //SNMP V3 is used
             $snmp_result = @snmp3_real_walk($hostname, $v3_user, "authNoPriv", "MD5", $v3_pwd, "DES", "", $memInfo, $timeout, $count);
         } else {
             $snmp_result = @snmprealwalk($hostname, $community_string, $memInfo, $timeout, $count);
         }
         if (count($snmp_result) < 1) {
             echo "Unable to query server {$hostname} for Memory Utilization";
         }
         $mem_pct_used = 0;
         foreach ($snmp_result as $oid => $val) {
             if ("/" == substr($val, 0, 1)) {
                 //ignore
Пример #20
0
function DevRoutes($ip, $c)
{
    global $toumsg;
    #error_reporting(1);
    snmp_set_quick_print(1);
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.2") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['ifx'] = $val;
    }
    if (!$oid) {
        echo $toumsg;
        die;
    }
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.3") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['me1'] = $val;
    }
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.7") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['nho'] = $val;
    }
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.9") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['pro'] = $val;
    }
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.10") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['age'] = $val;
    }
    foreach (snmprealwalk($ip, $c, ".1.3.6.1.2.1.4.21.1.11") as $oid => $val) {
        $i = explode('.', $oid);
        $route["{$i['1']}.{$i['2']}.{$i['3']}.{$i['4']}"]['msk'] = $val;
    }
    return $route;
}
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
//EXPECTF format is quickprint OFF
snmp_set_quick_print(false);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "Single OID\n";
var_dump(snmp2_getnext($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
echo "Single OID in array\n";
var_dump(snmp2_getnext($hostname, $community, array('.1.3.6.1.2.1.1.1.0'), $timeout, $retries));
echo "Multiple OID\n";
var_dump(snmp2_getnext($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.6.0'), $timeout, $retries));
Пример #22
0
function snmptable($host, $community, $oid)
{
    # This handy function was bought to you by scot at indievisible dot org
    # Found on the PHP.net documentation page for snmprealwalk.
    # The important thing about this function is that it fills in the blanks.
    # Regular SNMP walks leave out items so you can't blindly prod things into arrays any more.
    snmp_set_oid_numeric_print(TRUE);
    snmp_set_quick_print(TRUE);
    snmp_set_enum_print(TRUE);
    $retval = array();
    if (!($raw = snmp2_real_walk($host, $community, $oid))) {
        return false;
    }
    if (count($raw) == 0) {
        return false;
    }
    // no data
    $prefix_length = 0;
    $largest = 0;
    foreach ($raw as $key => $value) {
        if ($prefix_length == 0) {
            // don't just use $oid's length since it may be non-numeric
            $prefix_elements = count(explode('.', $oid));
            $tmp = '.' . strtok($key, '.');
            while ($prefix_elements > 1) {
                $tmp .= '.' . strtok('.');
                $prefix_elements--;
            }
            $tmp .= '.';
            $prefix_length = strlen($tmp);
        }
        $key = substr($key, $prefix_length);
        $index = explode('.', $key, 2);
        isset($retval[$index[1]]) or $retval[$index[1]] = array();
        if ($largest < $index[0]) {
            $largest = $index[0];
        }
        $retval[$index[1]][$index[0]] = $value;
    }
    if (count($retval) == 0) {
        return false;
    }
    // no data
    // fill in holes and blanks the agent may "give" you
    foreach ($retval as $k => $x) {
        for ($i = 1; $i <= $largest; $i++) {
            if (!isset($retval[$k][$i])) {
                $retval[$k][$i] = '';
            }
        }
        ksort($retval[$k]);
    }
    return $retval;
}