Example #1
0
function Walk($ip, $ver, $cm, $oid, $t = 1000000, $r = 2)
{
    global $debug, $comms;
    if ($ver == 3 and $comms[$cm]['pprot']) {
        if ($debug) {
            echo "<div class=\"textpad noti \">snmpwalk -v3 -c{$cm} " . $comms[$cm]['aprot'] . "/" . $comms[$cm]['pprot'] . " {$ip} {$oid} ({$t} usec * {$r})</div>";
        }
        return snmp3_real_walk($ip, $cm, 'authPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], $comms[$cm]['pprot'], $comms[$cm]['ppass'], ".{$oid}", $t);
    } elseif ($ver == 3 and $comms[$cm]['aprot']) {
        if ($debug) {
            echo "<div class=\"textpad noti \">snmpwalk -v3 -c{$cm} " . $comms[$cm]['aprot'] . " {$ip} {$oid} ({$t} usec * {$r})</div>";
        }
        return snmp3_real_walk($ip, $cm, 'authNoPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], 'DES', '', ".{$oid}", $t);
    } elseif ($ver == 2) {
        if ($debug) {
            echo "<div class=\"textpad noti \">snmpwalk -v2c -c{$cm} {$ip} {$oid} ({$t} usec * {$r})</div>";
        }
        return snmp2_real_walk($ip, $cm, ".{$oid}", $t);
    } else {
        if ($debug) {
            echo "<div class=\"textpad noti \">snmpwalk -v1 -c{$cm} {$ip} {$oid} ({$t} usec * {$r})</div>";
        }
        return snmprealwalk($ip, $cm, ".{$oid}", $t);
    }
}
Example #2
0
 function walk($oid)
 {
     // We're using realwalk so that we can build iterators with map_oids(), see:
     // walk     [0] => eth0
     // realwalk [IF-MIB::ifDescr.2] => eth0
     if ($this->version == "1") {
         $snmp_result = snmprealwalk($this->ip, $this->community, $oid);
     } else {
         if ($this->version == "2c") {
             $snmp_result = snmp2_real_walk($this->ip, $this->community, $oid);
         }
     }
     $result = $this->clear_snmp_string($snmp_result);
     return $result;
 }
Example #3
0
function readmac6248($switchf, $macarrayf)
{
    $a = snmp2_real_walk("{$switchf}", "public", "SNMPv2-SMI::mib-2.17.7.1.2.2.1.3.1");
    foreach (array_keys($a) as $val) {
        $pattern = '/([0-9]*)\\.([0-9]*)\\.([0-9]*)\\.([0-9]*)\\.([0-9]*)\\.([0-9]*)$/';
        preg_match($pattern, $val, &$mac);
        $rmac = sprintf("%02X:%02X:%02X:%02X:%02X:%02X", $mac[1], $mac[2], $mac[3], $mac[4], $mac[5], $mac[6]);
        $ip_ = $switchf;
        $npattern = '/([0-9]*)\\.([0-9]*)\\.([0-9]*)\\.([0-9]*)$/';
        preg_match($npattern, $ip_, &$ip);
        $network = $ip[2] . "." . $ip[3];
        if ($network == "43.128") {
            $network = "43.28";
        }
        if ($network == "43.126") {
            $network = "43.26";
        }
        $macarrayf[] = "" . $rmac . ";" . $network . "";
    }
    return $macarrayf;
}
Example #4
0
 static function walk($host, $object_id, $cache_ttl = null)
 {
     if ($cache_ttl) {
         $cache_var = str_replace('.', '_', $host->ip . $object_id);
         $cache = new CacheAPC();
         $resultCache = $cache->load($cache_var);
         if ($resultCache !== null) {
             return $resultCache;
         }
     }
     snmp_set_oid_output_format(self::$oid_format);
     $snmp = $host->snmpTemplate;
     if ($snmp instanceof SnmpTemplate) {
         switch ($snmp->version) {
             case "1":
                 $result = @snmprealwalk($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             case "2":
             case "2c":
                 $result = @snmp2_real_walk($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             case "3":
                 $result = @snmp3_real_walk($host->ip, $snmp->security_name, $snmp->security_level, $snmp->auth_protocol, $snmp->auth_passphrase, $snmp->priv_protocol, $snmp->priv_passphrase, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             default:
                 throw new Exception('SNMP Template not implemented yet');
         }
     }
     if (is_array($result)) {
         if ($cache_var && $cache_ttl) {
             $cache->save($cache_var, $result, $cache_ttl);
         }
         return $result;
     } else {
         //throw new Exception("Sem resposta SNMP");
         return array();
     }
 }
Example #5
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;
}
Example #6
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;
}
Example #7
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;
}
Example #8
0
<?php

/* Datapump - Devices from NMS to GTS (SNMP Version) */
error_reporting(E_ALL ^ E_NOTICE);
// Read in mib
snmp_read_mib("/usr/share/snmp/mibs/IDIRECT-REMOTE-MIB.txt");
// SNMP Query NMS Server
$a = snmp2_real_walk("204.9.216.250", "dcsatnetwork", "1.3.6.1.4.1.13732");
// Convert returned data to usable array
foreach ($a as $idx => $val) {
    list($branch, $snmpid) = explode(".", $idx);
    list($tree, $node) = explode("::", $branch);
    list($type, $value) = explode(":", $val, 2);
    switch ($node) {
        case 'nmstate':
            $netmodem[$snmpid][$node] = substr($value, strpos($value, "(") + 1, 1);
            break;
        default:
            $netmodem[$snmpid][$node] = trim($value);
    }
}
//print_r($netmodem);
foreach ($netmodem as $nm) {
    if ($nm[typeid] == "remote(3)") {
        echo "Target[" . $nm[nmid] . "]: downstreamtotalKiloBytes." . $nm[nmdid] . "&upstreamtotalKiloBytes." . $nm[nmdid] . ":dcsatnetwork@204.9.216.250:::::2 * 1000\n";
        echo "MaxBytes[" . $nm[nmid] . "]: 100000\n";
        echo "RouterName[" . $nm[nmid] . "]: nmname." . $nm[nmdid] . "\n";
        echo "Title[" . $nm[nmid] . "]: " . $nm[nmname] . " Traffic\n";
        echo "YLegend[" . $nm[nmid] . "]: Bits per Second\n";
        echo "LegendI[" . $nm[nmid] . "]: Downstream:\n";
        echo "LegendO[" . $nm[nmid] . "]: Upstream:\n";
Example #9
0
 function my_snmp_real_walk($ip, $credentials, $oid)
 {
     $timeout = '30000000';
     $retries = '0';
     switch ($credentials->credentials->version) {
         case '1':
             $array = @snmprealwalk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '2':
             $array = @snmp2_real_walk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '3':
             $sec_name = $credentials->credentials->security_name ?: '';
             $sec_level = $credentials->credentials->security_level ?: '';
             $auth_protocol = $credentials->credentials->authentication_protocol ?: '';
             $auth_passphrase = $credentials->credentials->authentication_passphrase ?: '';
             $priv_protocol = $credentials->credentials->privacy_protocol ?: '';
             $priv_passphrase = $credentials->credentials->privacy_passphrase ?: '';
             $array = @snmp3_real_walk($ip, $sec_name, $sec_level, $auth_protocol, $auth_passphrase, $priv_protocol, $priv_passphrase, $oid, $timeout, $retries);
             break;
         default:
             return false;
             break;
     }
     if (!is_array($array)) {
         return false;
     }
     foreach ($array as $i => $value) {
         $array[$i] = trim($array[$i]);
         if ($array[$i] == '""') {
             $array[$i] = '';
         }
         if (strpos($array[$i], '.') === 0) {
             $array[$i] = substr($array[$i], 1);
         }
         // remove the first and last characters if they are "
         if (substr($array[$i], 0, 1) == "\"") {
             $array[$i] = substr($array[$i], 1, strlen($array[$i]));
         }
         if (substr($array[$i], -1, 1) == "\"") {
             $array[$i] = substr($array[$i], 0, strlen($array[$i]) - 1);
         }
         // remove some return strings
         if (strpos(strtolower($array[$i]), '/etc/snmp') !== false or strpos(strtolower($array[$i]), 'no such instance') !== false or strpos(strtolower($array[$i]), 'no such object') !== false or strpos(strtolower($array[$i]), 'not set') !== false or strpos(strtolower($array[$i]), 'unknown value type') !== false) {
             $array[$i] = '';
         }
         // remove any quotation marks
         $array[$i] = str_replace('"', ' ', $array[$i]);
         // replace any line breaks with spaces
         $array[$i] = str_replace(array("\r", "\n"), " ", $array[$i]);
     }
     return $array;
 }
Example #10
0
 protected function snmpget($oid, $version = null, $community = null)
 {
     if (!$version) {
         $version = $this->getAgentVersion();
     }
     if (!$community) {
         $community = $this->getAgentReadCommunity();
     }
     switch ($version) {
         case 1:
             return @snmprealwalk($this->host, $community, $oid, $this->timeout * 1000000, $this->retries);
         case 2:
             return @snmp2_real_walk($this->host, $community, $oid, $this->timeout * 1000000, $this->retries);
         case 3:
             extract($this->version3);
             return @snmp3_real_walk($this->host, $secName, $secLevel, $authProtocol, $authPassphrase, $privProtocol, $privPassphrase, $oid, $this->timeout * 1000000, $this->retries);
         default:
             return false;
     }
 }
Example #11
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;
}
 function walk($oid, $suffix_as_key = FALSE)
 {
     switch ($this->version) {
         case self::VERSION_1:
             if ($suffix_as_key) {
                 $this->result = snmpwalk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmprealwalk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_2C:
         case self::VERSION_2c:
             if ($suffix_as_key) {
                 $this->result = snmp2_walk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmp2_real_walk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_3:
             if ($suffix_as_key) {
                 $this->result = snmp3_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             } else {
                 $this->result = snmp3_real_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             }
             break;
     }
     return $this->result;
 }
Example #13
0
 /**
  * Proxy to the snmp2_real_walk command
  *
  * @param string $oid The OID to walk
  * @return array The results of the walk
  */
 public function realWalk($oid)
 {
     switch ($this->getVersion()) {
         case 1:
             return $this->_lastResult = @snmprealwalk($this->getHost(), $this->getCommunity(), $oid, $this->getTimeout(), $this->getRetry());
             break;
         case '2c':
             return $this->_lastResult = @snmp2_real_walk($this->getHost(), $this->getCommunity(), $oid, $this->getTimeout(), $this->getRetry());
             break;
         case '3':
             return $this->_lastResult = @snmp3_real_walk($this->getHost(), $this->getSecName(), $this->getSecLevel(), $this->getAuthProtocol(), $this->getAuthPassphrase(), $this->getPrivProtocol(), $this->getPrivPassphrase(), $oid, $this->getTimeout(), $this->getRetry());
             break;
         default:
             throw new Exception('Invalid SNMP version: ' . $this->getVersion());
     }
 }
Example #14
0
         $cpuCount++;
     }
 }
 $users = @snmp2_real_walk($host, "public", '.1.3.6.1.2.1.25.1.5', TIMEOUT, RETRIES);
 if (array_key_exists("HOST-RESOURCES-MIB::hrSystemNumUsers.0", $users)) {
     $userCount = $users["HOST-RESOURCES-MIB::hrSystemNumUsers.0"];
 } elseif (array_key_exists("iso.3.6.1.2.1.25.1.5.0", $users)) {
     $userCount = $users["iso.3.6.1.2.1.25.1.5.0"];
 } else {
     $userCount = array();
 }
 if (!empty($userCount)) {
     preg_match('/Gauge[0-9]*\\: (.*)/', $userCount, $matches);
     $hostInfo[$host]['User Count'] = $matches[1];
 }
 $procs = @snmp2_real_walk($host, "public", '.1.3.6.1.2.1.25.1.6', TIMEOUT, RETRIES);
 if (array_key_exists("HOST-RESOURCES-MIB::hrSystemProcesses.0", $procs)) {
     $procCount = $procs["HOST-RESOURCES-MIB::hrSystemProcesses.0"];
 } elseif (array_key_exists("iso.3.6.1.2.1.25.1.6.0", $procs)) {
     $procCount = $procs["iso.3.6.1.2.1.25.1.6.0"];
 } else {
     $procCount = array();
 }
 if (!empty($procCount)) {
     preg_match('/Gauge[0-9]*\\: (.*)/', $procCount, $matches);
     $hostInfo[$host]['Process Count'] = $matches[1];
 }
 foreach ($oid_simple as $name => $value) {
     $curResult = @snmp2_get($host, "public", $value, TIMEOUT, RETRIES);
     if (!empty($curResult)) {
         if (strpos($curResult, "STRING") !== false) {
Example #15
0
 /**
  * 
  * @return type
  */
 public function WriteVlanMacData()
 {
     $count = 0;
     if (!empty($this->allTerminators) and !empty($this->allVlanHosts)) {
         foreach ($this->allTerminators as $eachTerminator) {
             $ip = $eachTerminator["ip"];
             $vlanPoolId = $eachTerminator['vlanpoolid'];
             $data = snmp2_real_walk($ip, 'Magistral', '.1.3.6.1.4.1.9.9.380.1.4.1.1.3');
             foreach ($data as $each => $value) {
                 $decmac = str_replace('.1.3.6.1.4.1.9.9.380.1.4.1.1.3.', '', $each);
                 $vlanPlusMac = explode(".", $decmac, 2);
                 $vlan = $vlanPlusMac[0];
                 $mac = $this->dec2mac($vlanPlusMac[1]);
                 foreach ($this->allVlanHosts as $eachHost) {
                     if ($eachHost['vlanpoolid'] == $vlanPoolId and $eachHost['vlan'] == $vlan) {
                         $login = $eachHost['login'];
                     }
                 }
                 if (!empty($this->allHistory)) {
                     if ($this->allHistory[$login]['mac'] != $mac) {
                         $this->WriteHistory($login, $vlan, $mac);
                     }
                 } else {
                     $this->WriteHistory($login, $vlan, $mac);
                 }
                 $count++;
             }
         }
     }
     file_put_contents(self::FLAGPREFIX, $count);
 }
//EXPECTF format is quickprint OFF
snmp_set_quick_print(false);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "Checking error handling\n";
var_dump(snmp2_real_walk($hostname, $community, '.1.3.6.1.2.1.1', ''));
var_dump(snmp2_real_walk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, ''));
echo "Checking working\n";
echo "Single OID\n";
$return = snmp2_real_walk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($return));
var_dump(sizeof($return));
var_dump(key($return));
var_dump(array_shift($return));
echo "Single OID in array\n";
$return = snmp2_real_walk($hostname, $community, array('.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump(gettype($return));
var_dump(sizeof($return));
var_dump(key($return));
var_dump(array_shift($return));
echo "More error handling\n";
echo "Multiple correct OID\n";
$return = snmp2_real_walk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6'), $timeout, $retries);
var_dump($return);
echo "Multiple OID with wrong OID\n";
$return = snmp2_real_walk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6...1'), $timeout, $retries);
var_dump($return);
$return = snmp2_real_walk($hostname, $community, array('.1.3.6...1', '.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump($return);
echo "Single nonexisting OID\n";
$return = snmp2_real_walk($hostname, $community, array('.1.3.6.99999.0.99999.111'), $timeout, $retries);
var_dump($return);
Example #17
0
 /**
  * Changes onu pvid by snmp query and if needed creates vlan
  * 
  * @param string $login
  * @param int $vlan
  * 
  * @return string
  */
 public function ChangeOnuPvid($login, $vlan, $onu_port = '1')
 {
     $OnuData = $this->GetOnuMac($login);
     if (!empty($OnuData)) {
         $OnuMac = $OnuData[0];
         $oltId = $OnuData[1];
         $oltData = $this->GetOltData($oltId);
         if (!empty($oltData)) {
             $oltIp = $oltData[0];
             $oltCommunity = $oltData[1];
             $template = $this->GetOltModelTemplate($oltData[2]);
             if (!empty($template)) {
                 if (file_exists('config/snmptemplates/' . $template)) {
                     $iniData = rcms_parse_ini_file('config/snmptemplates/' . $template, true);
                     if ($iniData['signal']['SIGNALMODE'] == 'BDCOM') {
                         $vlanCreateOid = $iniData['vlan']['CREATE'];
                         $ChangeOnuPvidOid = $iniData['vlan']['PVID'];
                         $SaveConfigOid = $iniData['vlan']['SAVE'];
                         $CheckVlanOid = $iniData['vlan']['CHECK'];
                         $IfIndexOid = $iniData['vlan']['IFINDEX'];
                         $IfIndex = $this->GetClientIface($OnuMac, $oltIp, $oltCommunity, $IfIndexOid);
                         if ($IfIndex) {
                             $VlanCheck = $this->CheckOltVlan($vlan, $oltIp, $oltCommunity, $CheckVlanOid);
                             $data = array();
                             if ($VlanCheck) {
                                 //create vlan on OLT
                                 $data[] = array('oid' => $vlanCreateOid . "." . $vlan, 'type' => 'i', 'value' => '4');
                             }
                             //Change pvid on onu port by default port 1
                             $data[] = array('oid' => $ChangeOnuPvidOid . "." . $IfIndex . "." . $onu_port, 'type' => 'i', 'value' => "{$vlan}");
                             $data[] = array('oid' => $SaveConfigOid, 'type' => 'i', 'value' => '1');
                             $result = $this->snmp->set($oltIp, $oltCommunity, $data);
                             $result .= $this->AutoConfig->CreateVlanLooped($oltId, $vlan, false);
                             return $result;
                         } else {
                             show_error(__('Cant find onu'));
                         }
                     }
                     if ($iniData['signal']['SIGNALMODE'] == 'ZTE') {
                         $UniIndex = '';
                         $allCards = array();
                         $allCardsRange = array();
                         $OnuUniRange = array();
                         $FoundCardData = '';
                         $ChangeOnuPvidOid = $iniData['vlan']['PVID'];
                         $ChangeOnuPvidAddOid = $iniData['vlan']['ADDUNI'];
                         $GetAllOnuOid = $iniData['vlan']['ALLONU'];
                         $AllCardsOid = $iniData['vlan']['ALLCARDS'];
                         $ApplyOnuPvidOid = $iniData['vlan']['PVID'];
                         $ChangeOnuTrunkOid = $iniData['vlan']['TRUNK'];
                         $ChangeOnuTrunkAddOid = $iniData['vlan']['ADDPON'];
                         $AllOnu = @snmp2_real_walk($oltIp, $oltCommunity, $GetAllOnuOid);
                         $zteFormat = explode(":", $OnuMac);
                         $zteFormatMac = $zteFormat[0] . $zteFormat[1] . '.' . $zteFormat[2] . $zteFormat[3] . '.' . $zteFormat[4] . $zteFormat[5];
                         foreach ($AllOnu as $index => $eachOnu) {
                             $eachOnu = trim(str_replace('Hex-STRING:', '', $eachOnu));
                             if ($eachOnu == $zteFormatMac) {
                                 $UniIndex = str_replace($GetAllOnuOid, '', $index);
                             }
                         }
                         if (empty($UniIndex)) {
                             show_error(__('Cant find onu'));
                             die;
                         }
                         if (!empty($UniIndex)) {
                             //Need to find out what cards installed into OLT.
                             //Then need expand array of all possible UNI IDs.
                             //Then need expand array of all possible PON port IDs.
                             //Maybe make some advanced search by found out slot and port and expand array for onu pon ports
                             //only for founded slot and port. It could be usefull if many slots and ports are used.
                             $allCards = @snmp2_real_walk($oltIp, $oltCommunity, $AllCardsOid);
                             if (!empty($allCards)) {
                                 foreach ($allCards as $cardIndex => $eachCard) {
                                     $startId = 805830912;
                                     $searchIndex[] = $AllCardsOid . '.0.0.';
                                     $searchIndex[] = $AllCardsOid . '.1.1.';
                                     $cardIndex = str_replace($searchIndex, '', $cardIndex);
                                     $searchCard4[] = '/EPFC/';
                                     $searchCard4[] = '/EPFCB/';
                                     $searchCard8[] = '/ETGO/';
                                     if (preg_match($searchCard4, $eachCard)) {
                                         $counter = $startId + 524288 * ($cardIndex - 1);
                                         for ($i = 1; $i <= 4; $i++) {
                                             $allCardsRange[$cardIndex][$i][]['start'] = $counter;
                                             $allCardsRange[$cardIndex][$i][]['end'] = $counter + 64 * 256;
                                             $counter += 65536;
                                         }
                                     }
                                     if (preg_match($searchCard8, $eachCard)) {
                                         $counter = $startId + 524288 * ($cardIndex - 1);
                                         for ($i = 1; $i <= 8; $i++) {
                                             $allCardsRange[$cardIndex][$i][]['start'] = $counter;
                                             $allCardsRange[$cardIndex][$i][]['end'] = $counter + 64 * 256;
                                             $counter += 65536;
                                         }
                                     }
                                 }
                             } else {
                                 show_error(__('No cards found on OLT'));
                                 die;
                             }
                             if (!empty($allCardsRange)) {
                                 foreach ($allCardsRange as $CardNumber) {
                                     foreach ($CardNumber as $PortNumber => $range) {
                                         if ($UniIndex > $range['start'] and $UniIndex < $range['end']) {
                                             $FoundCardData['card'] = $CardNumber;
                                             $FoundCardData['port'] = $PortNumber;
                                         }
                                     }
                                 }
                             } else {
                                 show_error(__('No suitable cards found on OLT. Supported: EPFC, EPFCB, ETGO.'));
                                 die;
                             }
                             if (!empty($FoundCardData)) {
                                 //Make array of all available onu number for onu and find it out
                                 $UniIdStart = 805830912;
                                 $UniIdCard = $UniIdStart + 524288 * ($FoundCardData['card'] - 1);
                                 $UniIdPort = $UniIdCard + 65536 * ($FoundCardData['port'] - 1);
                                 for ($i = 1; $i <= 64; $i++) {
                                     $OnuUniRange[$UniIdCard] = $i;
                                     $UniIdCard += 256;
                                 }
                                 $onuNumber = $OnuUniRange[$UniIndex];
                                 //ONU PON PORT FIND PART
                                 $OnuPonStartId = 1073741824;
                                 $OnuPonPortOltCardId = $OnuPonStartId + 524288 * ($FoundCardData['card'] - 1);
                                 $OnuPonPortOltPortId = $OnuPonPortOltCardId + 65536 * ($FoundCardData['port'] - 1);
                                 $OnuPonPortId = $OnuPonPortOltPortId + 256 * ($onuNumber - 1);
                                 $snmpSet = $this->altCfg['SNMPSET_PATH'];
                                 $result = '';
                                 $result .= shell_exec($snmpSet . ' -c ' . $oltCommunity . ' ' . $oltIp . ' ' . $ChangeOnuPvidAddOid . $UniIndex . '.1' . ' i 2 ' . $ChangeOnuPvidOid . $UniIndex . '.1' . ' i ' . $vlan);
                                 $result .= shell_exec($snmpSet . ' -c ' . $oltCommunity . ' ' . $oltIp . ' ' . $ApplyOnuPvidOid . $UniIndex . '.1' . ' i 2');
                                 $result .= shell_exec($snmpSet . ' -c ' . $oltCommunity . ' ' . $oltIp . ' ' . $ChangeOnuTrunkAddOid . $OnuPonPortId . ' i 1 ' . $ChangeOnuTrunkOid . ' i ' . $vlan);
                                 $result .= $this->AutoConfig->CreateVlanLooped($oltId, $vlan, false);
                                 return $result;
                             } else {
                                 show_error(__('Onu is out of range of supported cards.'));
                                 die;
                             }
                         }
                     }
                 } else {
                     show_error(__('SNMP template for OTL file not exists for modelid' . ' ' . $oltData[2]));
                 }
             } else {
                 show_error(__('No snmp template for OLT found') . ' modelid ' . $oltData[2]);
             }
         } else {
             show_error(__('No olt data found for oltid' . ' ' . $oltId));
         }
     } else {
         show_error(__('No pair onu->login found in PONizer'));
     }
 }
Example #18
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;
}
Example #19
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;
}
Example #20
0
 function snmpwalkoid($oid)
 {
     return snmp2_real_walk($this->hostname, $this->snmpsetup['community'], $oid);
 }
Example #21
0
function getRadioCounters($radioTable)
{
    global $ip, $community;
    $table = array();
    $counters = array(1 => "TransmittedFragmentCount", 10 => "MulticastReceivedFrameCount", 11 => "FCSErrorCount", 12 => "TransmittedFrameCount", 2 => "MulticastTransmittedFrameCount", 3 => "RetryCount", 33 => "FailedCount", 4 => "MultipleRetryCount", 5 => "FrameDuplicateCount", 6 => "RTSSuccessCount", 7 => "RTSFailureCount", 8 => "ACKFailureCount", 9 => "ReceivedFragmentCount");
    foreach ($counters as $index => $counter_field) {
        $temp = snmp2_real_walk($ip, $community, ".1.3.6.1.4.1.14179.2.2.6.1.{$index}");
        foreach ($temp as $key => $value) {
            $tmp = explode(".", $key);
            $id = array();
            for ($i = count($tmp) - 7; $i < count($tmp); $i++) {
                $id[] = $tmp[$i];
            }
            $id = implode(".", $id);
            $table[$radioTable[$id]][$counter_field] = sanatize_snmp("Counter32", $value);
        }
    }
    return $table;
}
Example #22
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;
}
function net_dev_show($type, $name, $port, $vg_id)
{
    $row = $GLOBALS['monkdb']->query('select * from net_devs where type="' . $type . '" and name="' . $name . '"')->fetch_assoc();
    $iprow = $GLOBALS['billdb']->query('select segment from staff where vg_id=' . $vg_id)->fetch_assoc();
    if ($row['type'] == 'switch') {
        if ($row['snmp_version'] == '2c') {
            snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
            $ifOperStatus = snmp2_get($row['mgmt_ip'], 'public', 'RFC1213-MIB::ifOperStatus.' . $port);
            switch ($ifOperStatus) {
                case '1':
                    echo 'port - <b>up</b><br/>';
                    break;
                case '2':
                    echo 'port - <b>down</b><br/>';
                    break;
            }
            $ip_mac_vlan = ip_mac_vlan(long2ip($iprow['segment']));
            if ($ip_mac_vlan) {
                echo 'vlan - <b>' . $ip_mac_vlan['vlan'] . '</b><br/>';
                echo 'ip - <b>' . $ip_mac_vlan['ip'] . '</b><br/>';
                echo 'mac - <b>' . $ip_mac_vlan['mac'] . '</b><br/>';
            }
            $snmp_mac_table = snmp2_real_walk($row['mgmt_ip'], 'public', '1.3.6.1.2.1.17.7.1.2.2.1.2');
            foreach ($snmp_mac_table as $key => $row1) {
                $arr = explode('2.17.7.1.2.2.1.2.', $key);
                $arr = explode('.', $arr[1]);
                if ($row1 == $port) {
                    echo 'SNMP data - <b>' . dechex($arr[1]) . ':' . dechex($arr[2]) . ':' . dechex($arr[3]) . ':' . dechex($arr[4]) . ':' . dechex($arr[5]) . ':' . dechex($arr[6]) . ' , vlan=' . $arr[0] . ' , port=' . $row1 . "</b><br/>\n";
                }
            }
        }
        if ($row['snmp_version'] == '1') {
            snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
            $ifOperStatus = snmpget($row['mgmt_ip'], 'public', 'IF-MIB::ifOperStatus.' . $port);
            switch ($ifOperStatus) {
                case '1':
                    echo 'port - <b>up</b><br/>';
                    break;
                case '2':
                    echo 'port - <b>down</b><br/>';
                    break;
            }
            $ip_mac_vlan = ip_mac_vlan(long2ip($iprow['segment']));
            if ($ip_mac_vlan) {
                echo 'vlan - <b>' . $ip_mac_vlan['vlan'] . '</b><br/>';
                echo 'ip - <b>' . $ip_mac_vlan['ip'] . '</b><br/>';
                echo 'mac - <b>' . $ip_mac_vlan['mac'] . '</b><br/>';
            }
        }
    }
    if ($row['type'] == 'dslam') {
        if ($row['snmp_version'] == '2c') {
            snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
            $port = $port + $row['if_index_shift'];
            $ifOperStatus = snmp2_get($row['mgmt_ip'], 'public', 'IF-MIB::ifOperStatus.' . $port);
            switch ($ifOperStatus) {
                case '1':
                    echo 'port - <b>up</b><br/>';
                    break;
                case '2':
                    echo 'port - <b>down</b><br/>';
                    break;
            }
            if ($ifOperStatus == '1') {
                $ip_mac_vlan = ip_mac_vlan(long2ip($iprow['segment']));
                if ($ip_mac_vlan) {
                    echo 'vlan - <b>' . $ip_mac_vlan['vlan'] . '</b><br/>';
                    echo 'ip - <b>' . $ip_mac_vlan['ip'] . '</b><br/>';
                    echo 'mac - <b>' . $ip_mac_vlan['mac'] . '</b><br/>';
                    $snmp_mac_table = snmprealwalk($row['mgmt_ip'], 'public', '1.3.6.1.2.1.17.7.1.2.2.1.2');
                    foreach ($snmp_mac_table as $key => $row1) {
                        $arr = explode('2.17.7.1.2.2.1.2.', $key);
                        $arr = explode('.', $arr[1]);
                        if ($row1 == $port - $row['if_index_shift']) {
                            echo 'SNMP data - <b>' . dechex($arr[1]) . ':' . dechex($arr[2]) . ':' . dechex($arr[3]) . ':' . dechex($arr[4]) . ':' . dechex($arr[5]) . ':' . dechex($arr[6]) . ' , vlan=' . $arr[0] . ' , port=' . $row1 . "</b><br/>\n";
                        }
                    }
                    echo '<hr/>';
                }
                echo '<br/>';
                echo 'ATU-C: Current SNR Margin - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.2.1.4.' . $port) . '</b> db/10<br/>';
                echo 'ATU-C: Current attentuation - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.2.1.5.' . $port) . '</b> db/10<br/>';
                echo 'ATU-C: Current output power - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.2.1.7.' . $port) . '</b> db/10<br/>';
                echo 'ATU-C: Speed - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.2.1.8.' . $port) . '</b> bps<br/>';
                echo '<br/>';
                echo 'ATU-R: Current SNR Margin - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.3.1.4.' . $port) . '</b> db/10<br/>';
                echo 'ATU-R: Current attentuation - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.3.1.5.' . $port) . '</b> db/10<br/>';
                echo 'ATU-R: Current output power - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.3.1.7.' . $port) . '</b> db/10<br/>';
                echo 'ATU-R: Speed - <b>' . snmp2_get($row['mgmt_ip'], 'public', 'SNMPv2-SMI::transmission.94.1.1.3.1.8.' . $port) . '</b> bps<br/>';
            }
            if ($_SESSION['username'] == 'nalcheg' or $_SESSION['username'] == 'den' or $_SESSION['username'] == 'andrey') {
                echo '<hr/><b><a href="#" onclick="dslam_port_restart(\'' . $row['mgmt_ip'] . '\',' . $port . ',' . $row['if_index_shift'] . ')">RESTART PORT</a></b>';
            }
        }
    }
}
Example #24
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;
}
Example #25
0
define("TIMEOUT", 200000);
define("RETRIES", 5);
if (!isset($_GET["host"])) {
    exit;
} else {
    $host = $_GET["host"];
}
$result = false;
$process_list = '.1.3.6.1.2.1.25.4.2.1.2';
$process_time = '.1.3.6.1.2.1.25.5.1.1.1';
$process_mem = '.1.3.6.1.2.1.25.5.1.1.2';
$process_param = '.1.3.6.1.2.1.25.4.2.1.5';
$curResultPL = @snmp2_real_walk($host, "public", $process_list, TIMEOUT, RETRIES);
$curResultPT = @snmp2_real_walk($host, "public", $process_time, TIMEOUT, RETRIES);
$curResultPM = @snmp2_real_walk($host, "public", $process_mem, TIMEOUT, RETRIES);
$curResultPA = @snmp2_real_walk($host, "public", $process_param, TIMEOUT, RETRIES);
$process = array();
if (!empty($curResultPL)) {
    # PL: iso.3.6.1.2.1.25.4.2.1.2.PID
    foreach ($curResultPL as $key => $processInfo) {
        if (strpos($key, "HOST-RESOURCES-MIB::hrSWRunName") !== false) {
            preg_match('/HOST\\-RESOURCES\\-MIB\\:\\:hrSWRunName\\.(.*)/', $key, $name);
            preg_match('/STRING: (.*)/', $processInfo, $matches);
        } elseif (strpos($key, "iso.3.6.1.2.1.25.4.2.1.2") !== false) {
            preg_match('/iso.3.6.1.2.1.25.4.2.1.2.(\\d*)/', $key, $name);
            preg_match('/STRING: "(.*)"/', $processInfo, $matches);
        }
        $process[$name[1]]['name'] = $matches[1];
    }
    $result = true;
}