SNMP-MIB
Napsal: 11 Mar 2010 21:10
od hawkfree
Nacitam nejake info v php z MT pres snmp, ale nejak nevim jak funguje OID. Kdyz si ho vypisu treba > /system resource print oid , zjistim treba pro cpu ".1.3.6.1.2.1.25.3.3.1.2.1", ale to nejde, dude vypise seznam vseho co se da vypsat, ale jediny na co skript reaguje je ".1.3.6.1.4.1.14988.1.1.1.2.1.3",coz je signal wifi, prefix ".1.3.6.1.4.1.14988.. ma kazda hodnota z MIB i podle dokumentace. Jaka OID se daji pouzit pro jednotlive hodnoty?
<?php
$ip="x.x.x.x";
$community = 'public';
$object_id = '.1.3.6.1.4.1.14988.1.1.1.2.1.3';
$a = snmpwalk($ip, $community, $object_id);
foreach ($a as $val)
{echo "$val <br>";}
?>
Re: SNMP-MIB
Napsal: 11 Mar 2010 21:30
od hawkfree
Tak uz jsem na to asi prisel. Nevim proc, ale nemuze se tam psat to posledni cislo OID.
Re: SNMP-MIB
Napsal: 12 Mar 2010 01:38
od sub_zero
hawkfree píše:Tak uz jsem na to asi prisel. Nevim proc, ale nemuze se tam psat to posledni cislo OID.
taky jsme to resili, od nejake trojkove verze to prestalo chodit.. a ve verzi 4.6 uz to zase jde
Re: SNMP-MIB
Napsal: 12 Mar 2010 01:53
od berkoff
$host predavej jako IP: napr 10.10.10.10
Muj skript jako napoveda

chodi na nekterych 3 verzich, snad ti to nejak pomuze. Nepsal sem to vsechno ja, neco je okopirovany, ale dohromady to fakci.

Kód: Vybrat vše
<?
$community = "public";
function fsnmpget($host, $community, $mib) {
$str = snmpget($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("\"", "", $str);
$str = str_replace("Timeticks: ", "", $str);
return $str;
}
function fsnmpwalk($host, $community, $mib) {
$str = snmpwalk($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("\"", "", $str);
return $str;
}
function fsnmpwalkoid($host, $community, $mib) {
$str = snmpwalkoid($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("\"", "", $str);
return $str;
}
$host = $GLOBALS["host"];
$community = $GLOBALS["community"];
$time = date("U");
#
# Get Description, Location and Name from AP
$systemDescription = fsnmpget($host, $community, "system.sysDescr.0");
$systemLocation = fsnmpget($host, $community, "system.sysLocation.0");
$systemName = fsnmpget($host, $community, "system.sysName.0");
$strength = fsnmpwalkoid($host, $community, ".1.3.6.1.4.1.14988.1.1.1.2.1.3");
$interfaces = fsnmpwalkoid($host, $community, ".1.3.6.1.2.1.2.2.1.2");
$procload=fsnmpget($host, $community, ".1.3.6.1.2.1.25.3.3.1.2.1");
$uptime=fsnmpget($host, $community, ".1.3.6.1.2.1.1.3.0");
$teplota=fsnmpget($host, $community, ".1.3.6.1.4.1.14988.1.1.3.10.0");
$teplota=fsnmpget($host, $community, ".1.3.6.1.4.1.14988.1.1.3.10.0");
$napeti=fsnmpget($host, $community, ".1.3.6.1.4.1.14988.1.1.3.8.0");
echo 'Připojená zařízení:';
echo '<br>';
echo '<br>';
array_walk($strength, 'signal_strength');
function dec2hex($value) {
return str_replace(" ", "0", sprintf("%2X", $value));
}
function format_mac($key, $num = 3) {
$mac_parse = str_replace("SNMPv2-SMI::enterprises.14988.1.1.1.2.1.$num.", "", $key);
$mac_decimal = substr($mac_parse, 0, strlen($mac_parse)-2);
list($first, $second, $third, $fourth, $fifth, $sixth) = split("[:.-]", $mac_decimal);
return dec2hex($first).":".dec2hex($second).":".dec2hex($third).":".dec2hex($fourth).":".dec2hex($fifth).":".dec2hex($sixth);
}
function get_interface($key, $num = 3) {
$mac_parse = str_replace("SNMPv2-SMI::enterprises.14988.1.1.1.2.1.$num.", "", $key);
$mac_decimal = substr($mac_parse, 0, strlen($mac_parse));
list($first, $second, $third, $fourth, $fifth, $sixth, $int) = split("[:.-]", $mac_decimal);
return "$int";
}
function flipmac($mac) {
return hexdec(substr($mac, 0, 2)).".".hexdec(substr($mac, 2, 2)).".".hexdec(substr($mac, 4, 2)).".".hexdec(substr($mac, 6, 2)).".".hexdec(substr($mac, 8, 2)).".".hexdec(substr($mac, 10, 2));
}
echo '<br>';
echo '<br>';
echo 'Vytížení procesoru: '.$procload.'<br>';
echo 'Mikrotik: '.$systemName.'<br>';
echo 'Uptime: '.$uptime.'<br>';
echo 'Teplota: '.$teplota.'<br>';
echo 'Napetí: '.$napeti.'<br>';
echo '<br>';
function signal_strength($value, $key) {
global $host, $community, $time, $interfaces;
$mac = format_mac($key);
$interfacenum = get_interface($key);
$interfacename = $interfaces["IF-MIB::ifDescr.".$interfacenum];
echo $interfaces[0];
$signal = $value." dBm";
$macfind = str_replace(":", "", $mac);
?>
<?
echo ''.$mac.' | '.$signal.' | '.$interfacename.'<br>';
?>
<?
}
?>