本文整理汇总了PHP中snmpget函数的典型用法代码示例。如果您正苦于以下问题:PHP snmpget函数的具体用法?PHP snmpget怎么用?PHP snmpget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmpget函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: menu
function menu()
{
echo "<div>\r\n <form method=\"get\" action=\"\">";
if (empty($GLOBALS[enumint])) {
echo "Router IP: <input type=\"text\" name=\"ip\" id=\"ip\" value=\"{$GLOBALS['ip']}\"/>\r\n Community: <input type=\"text\" name=\"community\" id=\"community\" value=\"{$GLOBALS['community']}\"/>";
} else {
// Disable form entry for IP and Community once Interfaces have been enumerated
echo "Router IP: <input type=\"text\" name=\"ip\" id=\"ip\" value=\"{$GLOBALS['ip']}\" readonly=\"readonly\"/>\r\n Community: <input type=\"text\" name=\"community\" id=\"community\" value=\"{$GLOBALS['community']}\" readonly=\"readonly\"/>";
}
if (!empty($GLOBALS[enumint])) {
// Generate Dropdown list of Interfaces if the Interface Enumeration has happened
echo " Interface: <select name=\"interface\">";
for ($i = 1; $i < $GLOBALS[enumint] + 2; $i++) {
$valint = snmpget($GLOBALS[ip], $GLOBALS[community], "1.3.6.1.2.1.2.2.1.2.{$i}");
$valintnm = snmpget($GLOBALS[ip], $GLOBALS[community], "1.3.6.1.2.1.31.1.1.1.18.{$i}");
if (!empty($valint)) {
if ("{$GLOBALS['interface']}" == $i) {
echo "<option value=\"{$i}\" selected>{$valint} {$valintnm}</option>";
} else {
echo "<option value=\"{$i}\">{$valint} {$valintnm}</option>";
}
}
}
echo "</select>\r\n Refresh (Secs): <input type=\"text\" name=\"refresh\" id=\"refresh\" value=\"{$GLOBALS['refresh']}\"/>\r\n <input type=\"submit\" id=\"submit\" value=\"Submit\"/>\r\n <input type=\"reset\" id=\"reset\" onclick=\"window.location='?';\" value=\"Reset\"/>\r\n </form>\r\n </div>";
} else {
echo "\r\n <input type=\"submit\" id=\"submit\" value=\"List Interfaces\"/>\r\n </form>\r\n </div>";
}
}
示例2: cacti_snmp_get
function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 500, $retries = 0, $environ = SNMP_POLLER)
{
global $config;
/* 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 || $community == "" && $version != 3) {
return "U";
}
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 ($version == "1") {
$snmp_value = @snmpget("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
} elseif ($version == "2") {
$snmp_value = @snmp2_get("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
} else {
$snmp_value = @snmp3_get("{$hostname}:{$port}", $username, "authNoPriv", "MD5", $password, "", "", $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 authNoPriv -a MD5 -A {$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);
} else {
exec(read_config_option("path_snmpget") . " -O fntev {$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;
}
示例3: Get
function Get($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 \">snmpget -v3 -c{$cm} " . $comms[$cm]['aprot'] . "/" . $comms[$cm]['pprot'] . " {$ip} {$oid} ({$t} usec * {$r})</div>";
}
return snmp3_get($ip, $cm, 'authPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], $comms[$cm]['pprot'], $comms[$cm]['ppass'], ".{$oid}", $t, $r);
} elseif ($ver == 3 and $comms[$cm]['aprot']) {
if ($debug) {
echo "<div class=\"textpad noti \">snmpget -v3 -c{$cm} " . $comms[$cm]['aprot'] . " {$ip} {$oid} ({$t} usec * {$r})</div>";
}
return snmp3_get($ip, $cm, 'authNoPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], 'DES', '', ".{$oid}", $t, $r);
} elseif ($ver == 2) {
if ($debug) {
echo "<div class=\"textpad noti \">snmpget -v2c -c{$cm} {$ip} {$oid} ({$t} usec * {$r})</div>";
}
return snmp2_get($ip, $cm, ".{$oid}", $t, $r);
} else {
if ($debug) {
echo "<div class=\"textpad noti \">snmpget -v1 -c{$cm} {$ip} {$oid} ({$t} usec * {$r})</div>";
}
return snmpget($ip, $cm, ".{$oid}", $t, $r);
}
}
示例4: getSNMPValue
function getSNMPValue($Device, $ReadCommunity, $OID)
{
$SNMPAnswer = @snmpget($Device, $ReadCommunity, $OID);
if (preg_match("/\\b = \\b/i", $SNMPAnswer) != 1) {
$SNMPValue = $SNMPAnswer;
} else {
$tmp = strtok($SNMPAnswer, "=");
$tmp = strtok("=");
$SNMPValue = $tmp;
}
if (stristr($SNMPValue, "counter") || stristr($SNMPValue, "gauge") || stristr($SNMPValue, "string") || stristr($SNMPValue, "integer") || stristr($SNMPValue, "OID")) {
$tmp = strtok($SNMPValue, ":");
$tmp = ltrim(strtok(":"));
while ($tmp2 = strtok(":")) {
$tmp .= $tmp2;
}
$SNMPValue = $tmp;
}
if (stristr($SNMPValue, "timeticks")) {
$tmp = strtok($SNMPValue, "\\)");
$tmp = ltrim(strtok("\\)"));
$SNMPValue = $tmp;
}
return ltrim($SNMPValue);
}
示例5: index
public function index()
{
print snmpget("192.168.1.36", "public", "sysDescr.0") . "<BR>";
print snmpget("192.168.1.36", "public", "ifPhysAddress.14") . "<BR>";
print "—корость интерфейса: " . snmpget("192.168.1.36", "public", "ifSpeed.14") . "<BR>";
print "ќперативна¤ пам¤ть: " . snmpget("192.168.1.36", "public", "hrMemorySize.0") . "<BR>";
print "ќбъЄм диска: " . snmpget("192.168.1.36", "public", "hrDiskStorageCapacity.31") . "<BR>";
}
示例6: SNMPget_Render
function SNMPget_Render(&$parser, $snmphost = '127.0.0.1', $com = 'public', $snmpoid = 'SNMPv2-SMI::mib-2.1.6.0', $prefix = '')
{
$result = snmpget($snmphost, $com, $snmpoid, 50000);
if (!$result) {
return false;
}
return "{$prefix} " . clean_Result($result);
}
示例7: _getSNMP
private function _getSNMP($snmpID)
{
if ($this->ip == null) {
throw new Exception('ip adresi bos');
}
$snmpcikti = @snmpget($this->ip, 'public', $snmpID);
return $this->_filtrele($snmpcikti) != '' ? $this->_filtrele($snmpcikti) : self::bos_deger;
}
示例8: get
function get($oid)
{
if ($this->version == "1") {
$snmp_result = snmpget($this->ip, $this->community, $oid);
} else {
if ($this->version == "2c") {
$snmp_result = snmp2_get($this->ip, $this->community, $oid);
}
}
$result = $this->clear_snmp_string($snmp_result);
return $result;
}
示例9: all_aruba_controllers
function all_aruba_controllers($community = "public")
{
for ($i = 1; $i < 11; $i++) {
$ipController = "10.253.0.{$i}";
$sysName = @snmpget($ipController, $community, ".1.3.6.1.2.1.1.5.0");
if ($sysName == NULL) {
continue;
}
$cli[$ipController] = ap_clients_aruba_wlan_controller($ipController, $community);
}
var_dump($cli);
}
示例10: cacti_snmp_get
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;
}
}
示例11: get
static function get($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 = @snmpget($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
break;
case "2":
case "2c":
$result = @snmp2_get($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
break;
case "3":
$result = @snmp3_get($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 ($result) {
// retira 'STRING: ' do inicio do texto
$result = trim(preg_replace('/^[^:]+: ?/', '', $result));
if ($cache_var && $cache_ttl) {
$cache->save($cache_var, $result, $cache_ttl);
}
return $result;
} else {
//throw new Exception("Sem resposta SNMP");
return null;
}
}
示例12: ReadData
public function ReadData($targetString, &$map, &$mapItem)
{
$data[IN] = null;
$data[OUT] = null;
$data_time = 0;
$timeout = intval($this->owner->get_hint("snmp_timeout", 1000000));
$abort_count = intval($this->owner->get_hint("snmp_abort_count"), 0);
$retries = intval($this->owner->get_hint("snmp_retries"), 2);
if (preg_match($this->regexpsHandled[0], $targetString, $matches)) {
$community = $matches[1];
$host = $matches[2];
$oids = array();
$oids[IN] = $matches[3];
$oids[OUT] = $matches[4];
if ($abort_count == 0 || $abort_count > 0 && (!isset($this->down_cache[$host]) || intval($this->down_cache[$host]) < $abort_count)) {
$this->changeSNMPSettings();
$channels = array("in" => IN, "out" => OUT);
foreach ($channels as $channelName => $channel) {
if ($oids[$channel] != '-') {
$result = snmpget($host, $community, $oids[$channel], $timeout, $retries);
if ($result !== false) {
$data[$channel] = floatval($result);
$mapItem->add_hint("snmp_" . $channelName . "_raw", $result);
} else {
$this->down_cache[$host]++;
}
}
wm_debug("SNMP ReadData: Got {$result} for {$channelName}\n");
}
$data_time = time();
$this->restoreSNMPSettings();
} else {
wm_warn("SNMP for {$host} has reached {$abort_count} failures. Skipping. [WMSNMP01]");
}
}
wm_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);
}
示例13: index
public function index()
{
$this->toView['title'] = 'Pings';
$this->loadModel('modelLog', 'modelLog');
$this->loadModel('modelLink', 'modelLink');
$relatorioUsuarios = array();
$this->loadLib('Ping');
$this->loadModel('modelLink');
$ping = array();
$filiais = array();
$links = $this->modelLink->getLinks();
foreach ($links as $link) {
for ($i = 0; $i <= 3; $i++) {
$ping[$i] = $this->Ping->pingTime($link['ip_router']);
}
$pingMedio = number_format(array_sum($ping) / count($ping) * 1000, 2);
array_push($filiais, array('titulo' => $link['titulo'], 'ip' => $link['ip_router'], 'ping' => $pingMedio));
}
$syscontact = snmpget("172.12.10.56", "public", '.1');
var_dump($syscontact);
$this->toView['relatorioUsuarios'] = $relatorioUsuarios;
//$this->loadView('viewPingometro', get_defined_vars());
}
示例14: flush
?>
</td></tr>
<?php
if ($ver and $rrdstep) {
echo "<tr><th bgcolor=#{$bg2}>System</th><th bgcolor=#{$bgb}>";
echo "<a href=Devices-Graph.php?dv={$ud}&cpu=on><img src=inc/drawrrd.php?dv={$ud}&t=cpu&s=s border=0 title=\"CPU load\">";
echo "<a href=Devices-Graph.php?dv={$ud}&mem=on><img src=inc/drawrrd.php?dv={$ud}&t=mem&s=s border=0 title=\"Available Memory\">";
echo "<a href=Devices-Graph.php?dv={$ud}&tmp=on><img src=inc/drawrrd.php?dv={$ud}&t=tmp&s=s border=0 title=\"Temperature\">";
echo "</th></tr>";
}
flush();
if ($ver) {
echo "<tr><th bgcolor=#{$bg2}>Uptime</th><td bgcolor=#{$bgb}>";
error_reporting(1);
snmp_set_quick_print(1);
$uptime = snmpget("{$ip}", "{$comm}", ".1.3.6.1.2.1.1.3.0", $timeout * 100000);
if ($uptime) {
sscanf($uptime, "%d:%d:%d:%d.%d", $upd, $uph, $upm, $ups, $ticks);
$upmin = $upm + 60 * $uph + 1440 * $upd;
if ($upd < 1) {
echo "<img src=img/16/impt.png hspace=10> ";
} else {
echo "<img src=img/16/bchk.png hspace=10> ";
}
echo sprintf("%d D %d:%02d:%02d", $upd, $uph, $upm, $ups) . "</td></tr>\n";
} else {
echo $toumsg;
echo "</td></tr>\n";
}
}
flush();
示例15: cacti_snmp_get
function cacti_snmp_get($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;
/* 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($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == '' && $version != 3) {
return 'U';
}
if (snmp_get_method($version) == SNMP_METHOD_PHP && (!strlen($context) || $version != 3)) {
/* make sure snmp* is verbose so we can see what types of data
we are getting back */
snmp_set_quick_print(0);
/* set the output format to numeric */
snmp_set_valueretrieval($method);
if ($version == '1') {
$snmp_value = @snmpget("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
} elseif ($version == '2') {
$snmp_value = @snmp2_get("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
} else {
if ($priv_proto == '[None]') {
$proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
}
$snmp_value = @snmp3_get("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
}
if ($snmp_value === false) {
cacti_log("WARNING: SNMP Get Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
}
} 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 = '-X ' . 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 */
}
/* no valid snmp version has been set, get out */
if (empty($snmp_auth)) {
return;
}
exec(cacti_escapeshellcmd(read_config_option('path_snmpget')) . ' -O fntev ' . $snmp_auth . " -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid), $snmp_value);
/* fix for multi-line snmp output */
if (is_array($snmp_value)) {
$snmp_value = implode(' ', $snmp_value);
}
}
/* fix for multi-line snmp output */
if (isset($snmp_value)) {
if (is_array($snmp_value)) {
$snmp_value = implode(' ', $snmp_value);
}
}
if (substr_count($snmp_value, 'Timeout:')) {
cacti_log("WARNING: SNMP Get Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
}
/* strip out non-snmp data */
$snmp_value = format_snmp_string($snmp_value, false);
return $snmp_value;
}