本文整理汇总了PHP中snmp_set_valueretrieval函数的典型用法代码示例。如果您正苦于以下问题:PHP snmp_set_valueretrieval函数的具体用法?PHP snmp_set_valueretrieval怎么用?PHP snmp_set_valueretrieval使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_set_valueretrieval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($Host, $Community)
{
//check snmp module
if (!@extension_loaded('snmp')) {
if (!@dl('snmp.so')) {
die('Unable to Load SNMP Module');
}
}
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
$this->Host = $Host;
$this->Community = $Community;
$this->RandomNumber = rand(1, 65535);
//$this->RandomNumber = rand();
}
示例2: connect
/**
* Define connection target
*
* @param string $host
* @param int $port
* @param string $community
*/
public function connect($host, $port = 161, $community = "public", $timeout = 2, $retries = 2, $SNMP_VALUE_PLAIN = false)
{
if (is_null($port)) {
$port = self::DEFAULT_PORT;
}
$this->community = $community;
$this->host = $host;
$this->port = $port;
$this->timeout = !$timeout ? self::DEFAULT_TIMEOUT : $timeout;
$this->timeout = $this->timeout * 100000;
$this->retries = $retries ? $retries : self::DEFAULT_RETRIES;
$this->snmpValuePlain = $SNMP_VALUE_PLAIN;
if ($SNMP_VALUE_PLAIN == true) {
@snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
} else {
@snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
}
}
示例3: _getpeersfromrouter
function _getpeersfromrouter($config)
{
if ($config['snmp_community'] == '') {
die('no community value set');
}
if (!$config['hostname']) {
die('no hostname value set');
}
snmp_set_oid_numeric_print(1);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
if ($raw_snmp = snmpwalkoid($config['hostname'] . ':' . $config['port'], $config['snmp_community'], $this->base_oid)) {
if ($rawfile = fopen($this->cachefile, 'w')) {
fputs($rawfile, serialize($raw_snmp));
} else {
die('could not write to cache file! ' . $this->cachefile);
}
} else {
die('connection to router failed!');
}
}
示例4: error_reporting
<?php
# Program: Topology-Spanningtree.php
# Programmer: Remo Rickli
$printable = 1;
error_reporting(1);
snmp_set_quick_print(1);
snmp_set_oid_numeric_print(1);
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
include_once ("inc/header.php");
include_once ("inc/libdev.php");
include_once ("inc/libsnmp.php");
$_GET = sanitize($_GET);
$dev = isset($_GET['dev']) ? $_GET['dev'] : "";
$shg = isset($_GET['shg']) ? "checked" : "";
$vln = isset($_GET['vln']) ? $_GET['vln'] : "";
?>
<h1>Spanningtree Tool</h1>
<form method="get" action="<?= $self ?>.php" name="stree">
<table class="content"><tr class="<?= $modgroup[$self] ?>1">
<th width="50"><a href="<?= $self ?>.php"><img src="img/32/<?= $selfi ?>.png"></a></th>
<th>
Device
<select size="1" name="dev" onchange="document.stree.vln.value=''">
<option value=""><?= $sellbl ?> ->
<?php
$link = DbConnect($dbhost,$dbuser,$dbpass,$dbname);
$query = GenQuery('devices','s','device,devip,services,snmpversion,readcomm,location,contact,cliport,icon','device','',array('services & 2','snmpversion'),array('=','!='),array('2','0'),array('AND') );
示例5: ini_set
$writetimeout = $writetimeout * 1000000;
// Для модели DGS-3100-24TG увеличиваем время ожидания вдвое
if ($ModelType == 'DGS-3100-24TG') {
$timeout = $timeout * 2;
$max_exec_time = $max_exec_time * 2;
}
// Устанавливаем максимальное время исполнения скрипта
ini_set('max_execution_time', $max_exec_time);
// Устанавливаем сокращенный вывод для snmp-запросов
snmp_set_quick_print(1);
// Устанавливаем числовой вывод для snmp-запросов если версия PHP старше 5.2
if (substr(phpversion(), 0, 3) > 5.2) {
@snmp_set_enum_print(1);
}
// Устанавливаем тип вывода для snmp-запросов
snmp_set_valueretrieval(0);
// По умолчанию ошибок не обнаружено, о чем сообщаем в значении переменной
$noerrors = "true";
// Определяем значение версии модуля на случай, если оно не определено в самом модуле
$modulever = '0.00';
// Текущая версия скрипта
$current_version = '0.99b';
// Подключаем блок c информацией о коммутаторе
include 'infosw.php';
// Подключаем основной модуль
@(include './modules/' . $module . '_mod.php');
//<--Начало блока:'Формирование верхнего меню со вкладками'--
// Говорим, что по дефолту у нас как минимум 1 колонка (модуль)
$col_count = 1;
// Считаем, сколько модулей определено всего
while (isset(${'menu_item' . $col_count})) {
示例6: snmp_audit
function snmp_audit($ip, $credentials, $display)
{
error_reporting(E_ALL);
$CI =& get_instance();
$log = new stdClass();
$log->file = 'system';
$log->severity = 7;
if ($display == 'y') {
$log->display = 'y';
} else {
$log->display = 'n';
}
if (!extension_loaded('snmp')) {
$log->message = 'SNMP PHP function not loaded hence not attempting to run snmp_helper::snmp_audit function';
$log->severity = 5;
stdlog($log);
unset($log);
return false;
} else {
$log->message = 'SNMP PHP function loaded and attempting to run snmp_helper::snmp_audit function';
stdlog($log);
}
# we need an ip address
if (empty($ip)) {
$log->message = 'SNMP command received no ip address';
$log->severity = 5;
stdlog($log);
unset($log);
return false;
} elseif (!filter_var($ip, FILTER_VALIDATE_IP)) {
$log->message = 'SNMP command received invalid ip address';
$log->severity = 5;
stdlog($log);
unset($log);
return false;
} else {
$log->message = 'snmp_helper::snmp_audit function received ip ' . $ip;
stdlog($log);
}
if (empty($credentials) or !is_object($credentials)) {
$log->message = 'SNMP snmp_helper::snmp_audit received no credentials for ' . $ip;
$log->severity = 5;
stdlog($log);
unset($log);
return false;
} else {
$log->message = 'snmp_helper::snmp_audit function received credentials for ip ' . $ip;
stdlog($log);
}
# new in 1.5 - remove the type from the returned SNMP query.
# this affects the snmp_clean function in this file
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
$details = new stdClass();
$module = new stdclass();
$return_ips = new stdClass();
$return_ips->item = array();
$details->ip = (string) $ip;
$details->manufacturer = '';
$details->serial = '';
$details->model = '';
$details->type = '';
$details->sysDescr = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.1.0");
$details->description = $details->sysDescr;
$details->sysContact = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.4.0");
$details->contact = $details->sysContact;
$details->sysName = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.5.0");
$details->hostname = $details->sysName;
$details->name = $details->sysName;
$details->sysLocation = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.6.0");
$details->location = $details->sysLocation;
// uptime
$details->sysUpTime = intval(my_snmp_get($ip, $credentials, "1.3.6.1.6.3.10.2.1.3.0")) * 100;
if (empty($details->sysUpTime)) {
$details->sysUpTime = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
}
if (empty($details->sysUpTime)) {
$i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
if ($i > '' and strpos($i, ")") !== false) {
$j = explode(")", $i);
$details->uptime = intval(trim($j[1]) * 24 * 60 * 60);
} else {
$details->uptime = '';
}
}
// OID
$details->sysObjectID = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.2.0");
$details->snmp_oid = $details->sysObjectID;
if ($details->snmp_oid > '') {
$details->manufacturer = get_oid($details->snmp_oid);
if ($details->manufacturer == 'net-snmp') {
$details->manufacturer = (string) '';
}
}
# sometimes we get an OID, but not enough to specify a manufacturer
$explode = explode(".", $details->snmp_oid);
if (!isset($explode[6])) {
$vendor_oid = 0;
if (strpos($details->sysDescr, "ZyXEL") !== false) {
# we have a Zyxel device
//.........这里部分代码省略.........
示例7: Connect
/**
* Define connection target
*
* @param string $host
* @param int $port
* @param string $community
*/
public function Connect($host, $port=161, $community="public", $timeout = false, $retries = false, $SNMP_VALUE_PLAIN = false)
{
if (is_null($port))
$port = self::DEFAULT_PORT ;
//$this->Connection = "{$host}:{$port}";
$this->Connection = "{$host}";
$this->Community = $community;
if (!$timeout)
$this->Timeout = (!defined("SNMP_TIMEOUT")) ? self::DEFAULT_TIMEOUT : SNMP_TIMEOUT;
else
$this->Timeout = $timeout;
$this->Timeout = $this->Timeout*100000;
$this->Retries = $retries ? $retries : self::DEFAULT_RETRIES;
if ($SNMP_VALUE_PLAIN == true)
@snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
else
@snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
}
示例8: net_dev_show
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>';
}
}
}
}
示例9: cacti_snmp_walk
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 = '-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 */
}
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);
//.........这里部分代码省略.........
示例10: __construct
/**
* read the data into an internal array and also call the parent constructor
*
* @param String $enc encoding
*/
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_SNMPPINFO_ACCESS)) {
case 'command':
if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
$printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
} else {
$printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
}
foreach ($printers as $printer) {
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
if (strlen(trim($buffer)) > 0) {
$this->_filecontent[$printer] = $buffer;
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
if (strlen(trim($buffer2)) > 0) {
$this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer2;
}
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
if (strlen(trim($buffer3)) > 0) {
$this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer3;
}
}
}
}
break;
case 'php-snmp':
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
$printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
} else {
$printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
}
foreach ($printers as $printer) {
if (!PSI_DEBUG) {
restore_error_handler();
/* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
/* fatal errors only */
}
$bufferarr = snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000, 1);
if (!PSI_DEBUG) {
error_reporting($old_err_rep);
/* restore error level */
set_error_handler('errorHandlerPsi');
/* restore error handler */
}
if (!empty($bufferarr)) {
$buffer = "";
foreach ($bufferarr as $id => $string) {
$buffer = $buffer . $id . " = " . $string . "\n";
}
if (!PSI_DEBUG) {
restore_error_handler();
/* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
/* fatal errors only */
}
$bufferarr2 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1);
if (!PSI_DEBUG) {
error_reporting($old_err_rep);
/* restore error level */
set_error_handler('errorHandlerPsi');
/* restore error handler */
}
if (!empty($bufferarr2)) {
foreach ($bufferarr2 as $id => $string) {
$buffer = $buffer . $id . " = " . $string . "\n";
}
}
if (!PSI_DEBUG) {
restore_error_handler();
/* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
/* fatal errors only */
}
$bufferarr3 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1);
if (!PSI_DEBUG) {
error_reporting($old_err_rep);
/* restore error level */
set_error_handler('errorHandlerPsi');
/* restore error handler */
}
if (!empty($bufferarr3)) {
foreach ($bufferarr3 as $id => $string) {
$buffer = $buffer . $id . " = " . $string . "\n";
}
}
if (strlen(trim($buffer)) > 0) {
//.........这里部分代码省略.........
示例11: __construct
function __construct($version, $host, $community)
{
parent::__construct($version, $host, $community);
//snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
/* Return values without SNMP type hint */
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
/* needs php >= 5.2.0 */
// snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
// snmp_set_quick_print(1);
}
示例12: cacti_snmp_walk
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 = 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;
}
}
/* 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(SNMP_OID_OUTPUT_NUMERIC);
$snmp_oid_included = true;
}
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"] = ereg_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]") {
$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 */
}
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 */
//.........这里部分代码省略.........
示例13: dirname
<?php
require_once dirname(__FILE__) . '/snmp_include.inc';
echo "Checking error handling\n";
var_dump(snmp_get_valueretrieval('noarg'));
var_dump(snmp_set_valueretrieval());
var_dump(snmp_set_valueretrieval('noarg'));
var_dump(snmp_set_valueretrieval(67));
echo "Checking working\n";
var_dump(snmp_get_valueretrieval());
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
var_dump(snmp_get_valueretrieval() === SNMP_VALUE_LIBRARY);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
var_dump(snmp_get_valueretrieval() === SNMP_VALUE_PLAIN);
snmp_set_valueretrieval(SNMP_VALUE_OBJECT);
var_dump(snmp_get_valueretrieval() === SNMP_VALUE_OBJECT);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN | SNMP_VALUE_OBJECT);
var_dump(snmp_get_valueretrieval() === (SNMP_VALUE_PLAIN | SNMP_VALUE_OBJECT));
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY | SNMP_VALUE_OBJECT);
var_dump(snmp_get_valueretrieval() === (SNMP_VALUE_LIBRARY | SNMP_VALUE_OBJECT));
示例14: __construct
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
case 'command':
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] = $buffer;
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n" . $buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n" . $buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n" . $buffer;
}
}
}
}
break;
case 'php-snmp':
if (!extension_loaded("snmp")) {
$this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly");
break;
}
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
if (!PSI_DEBUG) {
restore_error_handler();
/* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
/* fatal errors only */
}
$bufferarr = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000, 1);
if (!PSI_DEBUG) {
error_reporting($old_err_rep);
/* restore error level */
set_error_handler('errorHandlerPsi');
/* restore error handler */
}
if (!empty($bufferarr)) {
$buffer = "";
foreach ($bufferarr as $id => $string) {
$buffer .= $id . " = " . $string . "\n";
}
if (!PSI_DEBUG) {
restore_error_handler();
/* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
/* fatal errors only */
}
$bufferarr2 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000, 1);
$bufferarr3 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000, 1);
$bufferarr4 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000, 1);
if (!PSI_DEBUG) {
error_reporting($old_err_rep);
/* restore error level */
set_error_handler('errorHandlerPsi');
/* restore error handler */
}
if (!empty($bufferarr2)) {
foreach ($bufferarr2 as $id => $string) {
$buffer .= $id . " = " . $string . "\n";
}
if (!empty($bufferarr3)) {
foreach ($bufferarr3 as $id => $string) {
$buffer .= $id . " = " . $string . "\n";
}
}
}
if (!empty($bufferarr4)) {
foreach ($bufferarr4 as $id => $string) {
$buffer .= $id . " = " . $string . "\n";
}
//.........这里部分代码省略.........
示例15: Connect
/**
* Define connection target
*
* @param string $host
* @param int $port
* @param string $community
*/
public function Connect($host, $port = 161, $community = "public", $timeout = false, $retries = false, $SNMP_VALUE_PLAIN = false)
{
if (is_null($port)) {
$port = self::DEFAULT_PORT;
}
//$this->Connection = "{$host}:{$port}";
$this->Connection = "{$host}";
$this->Community = $community;
if (!$timeout) {
$this->Timeout = !defined("SNMP_TIMEOUT") ? self::DEFAULT_TIMEOUT : SNMP_TIMEOUT;
} else {
$this->Timeout = $timeout;
}
$this->Timeout = $this->Timeout * 100000;
$this->Retries = $retries ? $retries : self::DEFAULT_RETRIES;
if ($SNMP_VALUE_PLAIN == true) {
@snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
} else {
@snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
}
$this->Shell = ShellFactory::GetShellInstance();
}