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>"; } }
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; }
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); } }
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); }
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>"; }
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); }
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; }
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; }
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); }
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; } }
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; } }
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); }
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()); }
?> </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();
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 = '******' . 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; }
} $mem_pct_used = 0; foreach ($snmp_result as $oid => $val) { if ("/" == substr($val, 0, 1)) { //ignore } else { $index = substr($oid, strrpos($oid, ".") + 1); $used = ''; $total = ''; if (strtolower($snmp_version) == 'v3') { //SNMP V3 is used $used = @snmp3_get($hostname, $v3_user, "authNoPriv", "MD5", $v3_pwd, "DES", "", "hrStorageUsed.{$index}", $timeout, $count); $total = @snmp3_get($hostname, $v3_user, "authNoPriv", "MD5", $v3_pwd, "DES", "", "hrStorageSize.{$index}", $timeout, $count); } else { $used = @snmpget($hostname, $community_string, "hrStorageUsed.{$index}", $timeout, $count); $total = @snmpget($hostname, $community_string, "hrStorageSize.{$index}", $timeout, $count); } echo "Used: {$used};;;;;Total: {$total}\n"; if (!ereg("^[0-9]+\$", $used)) { echo "Unable to determine used space due to failed snmp query"; } if (!ereg("^[0-9]+\$", $total)) { echo "Unable to determine size due to failed snmp query"; } $mem_pct_used = 0; if ($total > 0) { $mem_pct_used = round($used / $total * 100, 0); } } } if ($mem_pct_used < $param_threshold) {
function get_snmp($details) { $CI =& get_instance(); if (!isset($details->system_id) or $details->system_id == '') { $details->snmp_community = 'public'; $details->snmp_version = '2c'; $details->snmp_port = '161'; } else { $encrypted_access_details = $CI->m_system->get_access_details($details->system_id); if ($encrypted_access_details == '') { } $decoded_access_details = $CI->encrypt->decode($encrypted_access_details); $decoded_access_details = json_decode($decoded_access_details); $details->snmp_community = @$decoded_access_details->snmp_community; $details->snmp_version = @$decoded_access_details->snmp_version; $details->snmp_port = @$decoded_access_details->snmp_port; $details->man_ip_address = @$decoded_access_details->ip_address; } if (!isset($details->snmp_community) or $details->snmp_community == '') { $details->snmp_community = 'public'; } if (!isset($details->snmp_version) or $details->snmp_version == '') { $details->snmp_version = ''; } if (!isset($details->snmp_port) or $details->snmp_port == '') { $details->snmp_port = '161'; } # we may only have been given a system_id # but if the access_details were completed, that may be enough # if they weren't, we would at least need a hostname ot ip address if (!isset($details->man_ip_address) and !isset($details->hostname)) { return; } $module = new stdclass(); if ((!isset($details->hostname) or $details->hostname == '') and (isset($details->man_ip_address) and $details->man_ip_address != '' and $details->man_ip_address != '000.000.000.000' and $details->man_ip_address != '0.0.0.0')) { $details->hostname = gethostbyaddr(ip_address_from_db($details->man_ip_address)); } if ((!isset($details->man_ip_address) or $details->man_ip_address == '' or $details->man_ip_address == '0.0.0.0' or $details->man_ip_address == '000.000.000.000') and (isset($details->hostname) and $details->hostname != '')) { $details->man_ip_address = gethostbyname($details->hostname); } if (filter_var($details->hostname, FILTER_VALIDATE_IP)) { # we did not get a valid hostname back :-( } else { # we have a name of some sort if (strpos($details->hostname, ".") !== FALSE) { # fqdn - explode it if (!isset($details->fqdn) or $details->fqdn == '') { $details->fqdn = $details->hostname; } $i = explode(".", $details->hostname); $details->hostname = $i[0]; if (!isset($details->domain) or $details->domain == '') { unset($i[0]); $details->domain = implode(".", $i); } } else { # it's just a name } } $timeout = '300000'; $retries = '2'; if (!extension_loaded('snmp')) { return $details; } # test for SNMP version # to do - test for v3 if ($details->snmp_version == '') { if ($test_v1 = @snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout)) { # ok, we have v1 $details->snmp_version = '1'; } if ($test_v2 = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout)) { # ok, we have v2 $details->snmp_version = '2c'; } } if ($details->snmp_version == '2c') { snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC); // test for connectivity $test_connect = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout, $retries); if ($test_connect) { // printer duplex $details->printer_duplex = ''; $i = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.13.4.1.10.1"); if (count($i) > 0) { $details->printer_duplex = 'False'; for ($k = 0; $k < count($i); $k++) { if (mb_strpos($i[$k], "Duplex") !== FALSE) { $details->printer_duplex = 'True'; } } } // sysObjectID #$i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0" )); $details->snmp_oid = str_replace("OID: .", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.2.0")); if (strtolower($details->snmp_oid) == 'no such object available on this agent at this oid') { $details->snmp_oid = ''; } if ($details->snmp_oid > '') { $oid = get_oid($details->snmp_oid); $details->manufacturer = $oid->manufacturer; $details->man_manufacturer = $oid->manufacturer; $details->model = $oid->model; $details->man_model = $oid->model; $details->type = $oid->type; $details->device_type = $oid->type; $details->man_type = $oid->type; $details->os_group = $oid->os_group; $details->man_os_group = $oid->os_group; } if ($details->snmp_oid == '1.3.6.1.4.1.8072.3.2.255') { # a generic OID - take some guesses... $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0")); if (strpos($i, "Darwin Kernel Version 12") !== FALSE) { # looks like an OSX device $details->manufacturer = "Apple Inc"; } } if ($details->snmp_oid == '1.3.6.1.4.1.6876.4.1') { # grab some specific details for VMware ESX $model = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.1.0")); $version = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.2.0")); $details->model = $model . " (" . $version . ")"; $details->model = str_replace("\"", "", $details->model); $details->man_model = $details->model; $details->os_group = "VMware"; $details->man_os_group = "VMware"; $details->os_family = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.1.0")); $details->os_family = str_replace("\"", "", $details->os_family); $details->man_os_family = $details->os_family; $details->os_name = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0")); $details->os_name = str_replace("\"", "", $details->os_name); $details->man_os_name = $details->os_name; $details->type = 'computer'; $details->man_type = 'computer'; $details->device_type = 'computer'; $details->man_class = 'hypervisor'; } if (substr($details->snmp_oid, 0, 13) == '1.3.6.1.4.1.9') { # grab some Cisco specific details $i = explode("\$", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.9.25.1.1.1.2.5")); $details->os_version = trim($i[1]); $i = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.9.25.1.1.1.2.7"); if (strpos($i, "IOS") !== FALSE) { $details->os_group = 'Cisco'; $details->man_os_group = 'Cisco'; $details->os_family = 'Cisco IOS'; $details->man_os_family = 'Cisco IOS'; $details->os_name = "Cisco IOS version " . $details->os_version; $details->man_os_name = "Cisco IOS version " . $details->os_version; } if (strpos($i, "Catalyst Operating") !== FALSE) { $details->os_group = 'Cisco'; $details->man_os_group = 'Cisco'; $details->os_family = 'Cisco Catalyst OS'; $details->man_os_family = 'Cisco Catalyst OS'; $detail->os_name = "Cisco Catalyst OS version " . $details->os_version; $detail->man_os_name = "Cisco Catalyst OS version " . $details->os_version; } } // manufacturer if (!isset($details->manufacturer) or $details->manufacturer == '') { $hex = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.8.2.1.14.1"); if (count($hex) > 0) { if (isset($hex[1])) { if (mb_strpos($hex[1], "Hex-STRING: ") !== FALSE) { $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]); for ($i = 0; $i < strlen($hex[1]); $i++) { $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2))); } } else { $details->manufacturer = str_replace("STRING: ", "", $hex[1]); $details->manufacturer = str_replace('"', '', $details->manufacturer); } } } if ($details->manufacturer == '' or $details->manufacturer == 'No Such Object available on this agent at this OID') { $details->manufacturer = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.12.1"))); } } if ($details->manufacturer == 'No Such Instance currently exists at this OID') { $details->manufacturer = ''; } if ($details->manufacturer == 'No Such Object available on this agent at this OID') { $details->manufacturer = ''; } // serial if (!isset($details->serial) or $details->serial == '') { # generic snmp $details->serial = str_replace('"', '', str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.5.1.1.17.1"))); if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Object available on this agent at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } # Generic Cisco if ($details->serial == '') { $details->serial = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.11.1"))); if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Object available on this agent at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } } # Cisco 37xx stack if ($details->serial == '') { $details->serial = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.5.1.2.19.0"))); if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Object available on this agent at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } } # remove false if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Object available on this agent at this OID') { $details->serial = ''; } if ($details->serial == 'No Such Instance currently exists at this OID') { $details->serial = ''; } } $details->man_serial = $details->serial; // mac address if (!isset($details->mac_address) or $details->mac_address == '') { $interface_number = @str_replace("INTEGER: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.2." . $details->man_ip_address)); $details->mac_address = @str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.2.2.1.6." . $interface_number)); $details->mac_address = @trim(str_replace("Hex-", "", $details->mac_address)); $details->mac_address = @str_replace(" ", ":", $details->mac_address); # need to split and join because of the dropped 0's $i = explode(":", $details->mac_address); for ($k = 0; $k < count($i); $k++) { if (strlen($i[$k]) == 1) { $i[$k] = '0' . $i[$k]; } if (strlen($i[$k]) == 0) { $i[$k] = '00'; } } $details->mac_address = strtoupper(implode(":", $i)); if ($details->mac_address == '00') { $details->mac_address = ''; } } // type if (!isset($details->type) or $details->type == '') { $h = str_replace("OID: HOST-RESOURCES-TYPES::hrDevice", "", str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.25.3.2.1.2.1"))); if (strtolower($h) == 'no such object available on this agent at this oid' or $h == '') { # If the device is a Switch, the OID 1.3.6.1.2.1.17.1.2.0 and OID 1.3.6.1.2.1.4.1.0 should have a value of 2 $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.17.1.2.0")); $j = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.1.0")); if ($i == '2' and $j == '2') { $details->type = 'switch'; } # If the device is a Router, the OID 1.3.6.1.2.1.4.1.0 should have a value of 1 if (!isset($details->type) or $details->type == '') { $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.1.0")); if ($i == '1') { $device->type = 'router'; } } # If the device is a Printer, the OID 1.3.6.1.2.1.43.5.1.1.1.1 should have a value if (!isset($details->type) or $details->type == '') { $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.5.1.1.1.1")); if ($i == '1') { $device->type = 'printer'; } } } } if (isset($details->type) and $details->type != '' and (!isset($details->man_type) or $details->man_type == '')) { $details->man_type = $details->type; } // model if (!isset($details->model) or $details->model == '') { $details->model = str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.25.3.2.1.3.1")); if ($details->model == '' or $details->model == 'No Such Object available on this agent at this OID') { if (strpos(strtolower($details->manufacturer), 'cisco') !== FALSE) { $details->model = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.13.1"))); } } } if (strtolower($details->model) == 'no such object available on this agent at this oid') { $details->model = ''; } // name if (!isset($details->sysname) or $details->sysname == '') { $details->sysname = strtolower(str_replace("\"", "", str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0")))); } if (strtolower($details->sysname) == 'no such object available on this agent at this oid') { $details->sysname = ''; } // description if (!isset($details->description) or $details->description == '') { $details->description = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0"))); $details->description = str_replace("\r\n", " ", $details->description); } if (strtolower($details->description) == 'no such object available on this agent at this oid') { $details->description = ''; } // uptime if (!isset($details->uptime) or $details->uptime == '') { $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.3.0")); if ($i > '' and strpos($i, ")") !== FALSE) { $j = explode(")", $i); $details->uptime = trim($j[1]); } else { $details->uptime = ''; } } // location if (!isset($details->location) or $details->location == '') { $details->location = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.6.0"))); } if ($details->location == 'Unknown (edit /etc/snmp/snmpd.conf)') { $details->location = ''; } if ($details->location == 'not set') { $details->location = ''; } if ($details->location == 'No Such Object available on this agent at this OID') { $details->location = ''; } if ($details->location > '') { $details->description = "Location: " . $details->location . ". " . $details->description; } // contact if (!isset($details->contact) or $details->contact == '') { $details->contact = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.4.0"))); } if ($details->contact == 'Root (configure /etc/snmp/snmpd.conf)') { $details->contact = ''; } if ($details->contact == 'not set') { $details->contact = ''; } if ($details->contact > '') { $details->description = "Contact: " . $details->contact . ". " . $details->description; } // subnet if (!isset($details->subnet) or $details->subnet == '') { $details->subnet = @str_replace("IpAddress: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.3." . $details->man_ip_address)); } if ($details->subnet == 'No Such Instance currently exists at this OID') { $details->subnet = ''; } if ($details->subnet == 'No Such Object available on this agent at this OID') { $details->subnet = ''; } /* // installed modules with serial numbers $i = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.11"); if (count($i) > 0) { if (($i[0] == 'No more variables left in this MIB View (It is past the end of the MIB tree)') or ($i[0] == '')){unset($i); $i = array();} if (count($i) > 0) { $count = 0; for ($j=0; $j<count($i); $j++) { if ((mb_strpos($i[$j], $details->serial) === FALSE) and ($i[$j] != "") and ($i[$j] != "\"\"")){ $k = $j + 1; $k = "1.3.6.1.2.1.47.1.1.1.1.3." . $k; $oid = snmp2_get($details->man_ip_address, $details->snmp_community, $k); $oid = str_replace("OID: .", "", $oid); $module->$count = get_oid($oid); $module->$count->serial = str_replace("STRING: ", "", $i[$j]); $module->$count->serial = str_replace('"', '', $module->$count->serial); $count++; } } $details->modules = $module; } } */ } } if ($details->snmp_version == '1') { $details->snmp_oid = ''; $details->snmp_oid = str_replace("OID: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.2.0")); if (strtolower($details->snmp_oid) == 'no such object available on this agent at this oid') { $details->snmp_oid = ''; } if ($details->snmp_oid > '') { $oid = get_oid($details->snmp_oid); $details->manufacturer = $oid->manufacturer; $details->man_manufacturer = $oid->manufacturer; $details->model = $oid->model; $details->man_model = $oid->model; $details->type = $oid->type; $details->device_type = $oid->type; $details->man_type = $oid->type; $details->os_group = $oid->os_group; $details->man_os_group = $oid->os_group; } if ($details->oid == '1.3.6.1.4.1.714.1.2.6') { # We have a Wyse thin client - some specifics. $details->serial = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.714.1.2.6.2.1.0")); $details->sysname = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0")); $details->description = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0")); $details->contact = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.4.0")); if ($details->contact > '') { $details->description = "Contact: " . $details->contact . ". " . $details->description; } $details->location = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.6.0")); if ($details->location > '') { $details->description = "Location: " . $details->location . ". " . $details->description; } } $interface_number = str_replace("INTEGER: ", "", @snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.2." . $details->man_ip_address)); $i = "1.3.6.1.2.1.2.2.1.6." . $interface_number; $details->mac_address = snmpget($details->man_ip_address, $details->snmp_community, $i); $details->mac_address = trim(str_replace("Hex-STRING: ", "", $details->mac_address)); $details->mac_address = str_replace(" ", ":", $details->mac_address); $details->subnet = str_replace("IpAddress: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.3." . $details->man_ip_address)); $details->hostname = trim(str_replace("\"", "", str_replace("STRING: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0")))); $details->next_hop = str_replace("IpAddress: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.21.1.7.0.0.0.0")); } // update the system #if ($details->snmp_version > '') { #$CI2->m_system->process_snmp($details); return $details; #} }
private function __snmpget($object_id) { $retval = FALSE; switch ($this->version) { case self::VERSION_1: $retval = snmpget($this->host, $this->community, $object_id); break; case self::VERSION_2C: case self::VERSION_2c: $retval = snmp2_get($this->host, $this->community, $object_id); break; case self::VERSION_3: $retval = snmp3_get($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $object_id); break; } return $retval; }
<h3> <?php $r415 = snmpwalk('10.41.160.1', 'public', '.1.3.6.1.2.1.4.20.1.1'); $c6 = count($r415); //echo $c1; //echo $f1[0]; for ($i = 0; $i < $c6; $i++) { echo $r415[$i]; echo '<br>'; } ?> </h3> <h4>detail</h4> <h5> <?php $system6 = snmpget("10.41.160.1", "public", ".1.3.6.1.2.1.1.1.0"); echo $system6; ?> </h5> <h4>Up time</h4> <h5> <?php $up6 = snmpget("10.41.160.1", "public", ".1.3.6.1.2.1.1.3.0"); echo $up6; ?> </h5> </div> </div> </body> </html>
function get($object_id, $timeout = 1000000, $retries = 5) { return snmpget("{$this->host}:{$this->port}", $this->community, $object_id, $timeout, $retries); }
function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $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 || !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); 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]" || $priv_pass == '') { $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 { $snmp_value = ''; /* 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 */ } /* no valid snmp version has been set, get out */ if (empty($snmp_auth)) { return; } 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 */ exec(cacti_escapeshellcmd(read_config_option("path_snmpget")) . " -O vt -v{$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} {$snmp_auth} " . cacti_escapeshellarg($oid), $snmp_value); } else { 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; }
$h = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.4.2')), 9); $i = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.5.1')), 9); $j = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.5.2')), 9); $k = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.6.1')), 9); $l = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.6.2')), 9); $m = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.7.1')), 9); $n = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.7.2')), 9); $o = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.8.1')), 9); $p = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.8.2')), 9); $q = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.9.1')), 9); $r = substr(trim(snmpget('192.168.99.18', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.9.2')), 9); $a1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.1.1')), 9); $b1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.1.2')), 9); $c1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.2.1')), 9); $d1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.2.2')), 9); $e1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.3.1')), 9); $f1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.3.2')), 9); $g1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.4.1')), 9); $h1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.4.2')), 9); $i1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.5.1')), 9); $j1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.5.2')), 9); $k1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.6.1')), 9); $l1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.6.2')), 9); $m1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.7.1')), 9); $n1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.7.2')), 9); $o1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.8.1')), 9); $p1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.8.2')), 9); $q1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.9.1')), 9); $r1 = substr(trim(snmpget('192.168.99.17', 'public', '.1.3.6.1.4.1.9586.100.5.3.4.1.15.9.2')), 9); $all = $a + $b + $c + $d + $e + $f + $g + $h + $i + $j + $k + $l + $m + $n + $o + $p + $q + $r + $a1 + $b1 + $c1 + $d1 + $e1 + $f1 + $g1 + $h1 + $i1 + $j1 + $k1 + $l1 + $m1 + $n1 + $o1 + $p1 + $q1 + $r1; echo $all;
/* Обновление значение в базе для включен */ if ($strstate == "up") { $sql = "UPDATE ports SET state_id=1 WHERE device_id={$rowsql['0']} AND port={$i}"; $setstate = mysql_query($sql); /* Обновление значение в базе для выключен */ } else { $sql = "UPDATE ports SET state_id=2 WHERE device_id={$rowsql['0']} AND port={$i}"; $setstate = mysql_query($sql); } } if ($getstate != NULL && ereg("OFFICE", $strname) or ereg("40L.", $strname) or ereg("AVT.", $strname) or ereg("GAV.", $strname) or ereg("NG.", $strname) or ereg("NOV.", $strname) or ereg("ST.", $strname) or ereg("TRUNK", $strname) or ereg("PODVAL", $strname)) { /* Если состояние транкового порта изменено то внести это в логи */ $sql = "SELECT trank FROM ports WHERE device_id={$rowsql['0']} AND port={$i}"; $check_trank = mysql_query($sql); $check_trank_row = mysql_fetch_row($check_trank); $prst = snmpget("{$rowsql['2']}", "public", "ifOperStatus.{$i}"); $strprst = substr($prst, 9, strlen($prst) - 12); if ($check_trank_row[0] == 2 && $strprst == "up") { $today = date("H:i d.m.y"); $sql = "INSERT INTO `statetrank` (device_id, port, date, state_id) VALUES ('{$rowsql['0']}','{$i}','{$today}','1')"; $change_trank = mysql_query($sql); } else { if ($state_trank[0] == 1 && $strprst == "lowerLayerDown") { $today = date("H:i d.m.y"); $sql = "INSERT INTO `statetrank` (device_id, port, date, state_id) VALUES ('{$rowsql['0']}','{$i}','{$today}','2')"; $change_trank = mysql_query($sql); } } /* Само состояние порта */ if ($strprst == "up") { $sql = "UPDATE ports SET trank=1 WHERE device_id={$rowsql['0']} AND port={$i}";
function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $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) && (!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); 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); } }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 */ } /* 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, false); return $snmp_value; }
/** * Get object with OID $OID * * @param string $OID * @return string Object value */ public function Get($OID) { try { $retval = @snmpget($this->Connection, $this->Community, $OID, $this->Timeout, $this->Retries); } catch (Exception $e) { $this->RaiseWarning("Cannot get SNMP property. " . $e->__toString()); } return $retval; }
function cacti_snmp_get($hostname, $community, $oid, $version, $v3username, $v3password, $v3authproto = "", $v3privpassphrase = "", $v3privproto = "", $port = 161, $timeout = 500, $environ = SNMP_POLLER) { /* determine default 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"; } /* get rid of quotes in privacy passphrase */ $v3privpassphrase = str_replace("#space#", " ", $v3privpassphrase); if ($v3privproto == "[None]") { $v3privproto = ""; } 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, trim($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", $v3username, snmp_get_v3authpriv($v3privproto), $v3authproto, $v3password, $v3privproto, $v3privpassphrase, trim($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 $v3username -A $v3password -a $v3authproto -X $v3privpassphrase -x $v3privproto -l " . snmp_get_v3authpriv($v3privproto); /* v3 - username/password/etc... */ } /* 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; }
</body> <h2>Управление портом №<?php echo $row[3]; ?> </h2> <a href=telnet://<?php echo $row[0]; ?> ><font color="blue"><b><?php echo $row[1]; ?> </font></b></a> <?php /* Показать статус порта */ $prst = snmpget("{$row['0']}", "private", "ifOperStatus.{$port}"); if (ereg("Down", $prst) || ereg("down", $prst)) { echo "<font color=\"red\"><h5>Не активен</h5></font>\n"; } else { echo "<font color=\"green\"><h5>Активен</h5></font>\n"; } ?> <?php /* Выключение и включение порта */ if ($row[2] == DOWN) { print "<a href=\"port.php?id={$id}&port={$port}&porton\"><b>[Включить порт]</b></a>"; } else { print "<a href=\"port.php?id={$id}&port={$port}&portoff\"><b>[Выключить порт]</b></a>"; } echo "<br /><br />";
/* Построение таблицы */ $table = "<{$tr}><td>{$port_row['0']}</td><td>{$td}</td><td align=\"center\"><a href=mac.php?id={$rowsql['0']}&port={$port_row['0']}>{$port_row['2']}</a></td><td align=\"center\">{$port_state}</td></tr>"; /* Преобразование из цикла в строку */ if (!end($table)) { $array_row_port .= $table . ' '; } } /* Получение времени жизни кольца */ if ($rowsql[5] == 10) { $mst = snmpget("{$rowsql['2']}", "public", "{$rowsql['7']}"); $strmst = substr($mst, 8); $sec = $strmst / 100; $time = date('H:i', $sec); $day = date('d', $sec) - 1; } else { $mst = snmpget("{$rowsql['2']}", "public", "{$rowsql['7']}"); $strmst = substr($mst, 12, strpos($mst, ')') - 12); $sec = $strmst / 100; $time = date('H:i', $sec); $day = date('d', $sec) - 1; } /* Построение точки на карте */ $ymap .= "\n\t var placemark = new YMaps.Placemark(new YMaps.GeoPoint({$rowsql['3']}), {hasHint: 1, style: up});\n\t placemark.name = '<span style=\"background-color: #b0b0ff; color: #000\"><a href=telnet://{$rowsql['2']}>{$rowsql['1']}</a> MST: {$day} d, {$time}</span>';\n\t map.addOverlay(placemark);\n\t placemark.description = '<table border=0 cellspacing=1 cellpadding=0 style=\"background: #fff\"><tr><td width=18px></td><td width=120px></td><td width=20px></td><td width=20px></td></tr>{$array_row_port}</table>';\n "; /* Очишаем переменную для следующего круга */ $array_row_port = ""; $ymap .= "\n\t var polyline = new YMaps.Polyline([\n new YMaps.GeoPoint({$rowsql['3']}),\n new YMaps.GeoPoint({$rowsql['6']})], {style: \"CustomLine\"});\n map.addOverlay(polyline);\n "; /* Если выклчючен то показывать точку красным */ } else { $ymap .= "\n var placemark = new YMaps.Placemark(new YMaps.GeoPoint({$rowsql['3']}), {style: down});\n placemark.name = '<a href=telnet://{$rowsql['2']}>{$rowsql['1']}</a>';\n map.addOverlay(placemark);\n placemark.description = '<h3>Свитч недоступен!</h3>';\n "; $ymap .= "\n\t var polyline = new YMaps.Polyline([\n new YMaps.GeoPoint({$rowsql['3']}),\n new YMaps.GeoPoint({$rowsql['6']})], {style: \"CustomLineOFF\"});\n map.addOverlay(polyline);\n "; }
public function doSNMPGet($id) { $this->d = snmpget($this->hostname, $this->community, $this->hrStorage . $this->Descr . '.' . $id); $this->a = snmpget($this->hostname, $this->community, $this->hrStorage . $this->AllocationUnits . '.' . $id); $this->s = snmpget($this->hostname, $this->community, $this->hrStorage . $this->Size . '.' . $id); $this->u = snmpget($this->hostname, $this->community, $this->hrStorage . $this->Used . '.' . $id); Check_SNMP_Disk::convertValue($this->d); Check_SNMP_Disk::convertValue($this->a); Check_SNMP_Disk::convertValue($this->s); Check_SNMP_Disk::convertValue($this->u); $this->d = explode(' ', $this->d); $this->d = $this->d[0]; $this->s = $this->s * $this->a; $this->u = $this->u * $this->a; if ($this->s > self::$terabyte) { $this->s = round($this->s / self::$terabyte, 2); $this->u = round($this->u / self::$terabyte, 2); $this->uom = 'TB'; } else { if ($this->s > self::$gigabyte) { $this->s = round($this->s / self::$gigabyte, 2); $this->u = round($this->u / self::$gigabyte, 2); $this->uom = 'GB'; } else { if ($this->s > self::$megabyte) { $this->s = round($this->s / self::$megabyte, 2); $this->u = round($this->u / self::$megabyte, 2); $this->uom = 'MB'; } else { if ($this->s > self::$kilobyte) { $this->s = round($this->s / self::$kilobyte, 2); $this->u = round($this->u / self::$kilobyte, 2); $this->uom = 'KB'; } else { $this->uom = 'B'; } } } } $this->f = $this->s - $this->u; $this->pu = round($this->u / $this->s * 100, 0); $this->pf = round($this->f / $this->s * 100, 0); }
function snmpget($oid) { return snmpget($this->hostname, $this->snmpsetup['community'], $oid); }