Moin moin,
ich habe da einmal eine generelle Frage an euch und erhoffe mir das jemand ggf. eine Antwort auf meine nachfolgende Frage findet.
Erst einmal ich schreibe derzeit an einem Webinterface zum Auslesen von Informationen / Setzen von neuen Einstellungen auf Alcatel-Switches via SNMP. Alles soweit funktioniert momentan ganz gut, die Grundfunktionen sind implementiert für Sachen wie Portresets und etc. Allerdings möchte ich nun auslesen wann an welchem Port der Portstatus geändert wurde.
Alles bis hier hin noch wunderbar. Das Problem was ich jetzt habe ist, die OID über die ich einen SNMP-Walk laufen lasse liefert mir timeticks zurück als Zeitangabe für die letzte Änderung des Status.
Meine Frage ist jetzt wie ich anhand des Timeticks einen UNIX-Timestamp berechnen kann. Welche Faktoren benötige ich zum umrechnen des Timeticks auf einen UNIX-Timestamp?
Ich habe schon so einiges ausprobiert, aber lande leider mit meinen Timestamps nur in der Zukunft bzw. weit in der Vergangenheit sprich ich erhalte keine korrekten Timestamps.
Aktueller Sourcecode den ich habe sieht wie folgt aus:
Liefert:
Beispiel Timeticks:
Hierbei sei übrigens gesagt das ich einen Alcatel OmniSwitch 6850E via SNMP auslese.
ich habe da einmal eine generelle Frage an euch und erhoffe mir das jemand ggf. eine Antwort auf meine nachfolgende Frage findet.
Erst einmal ich schreibe derzeit an einem Webinterface zum Auslesen von Informationen / Setzen von neuen Einstellungen auf Alcatel-Switches via SNMP. Alles soweit funktioniert momentan ganz gut, die Grundfunktionen sind implementiert für Sachen wie Portresets und etc. Allerdings möchte ich nun auslesen wann an welchem Port der Portstatus geändert wurde.
Alles bis hier hin noch wunderbar. Das Problem was ich jetzt habe ist, die OID über die ich einen SNMP-Walk laufen lasse liefert mir timeticks zurück als Zeitangabe für die letzte Änderung des Status.
Meine Frage ist jetzt wie ich anhand des Timeticks einen UNIX-Timestamp berechnen kann. Welche Faktoren benötige ich zum umrechnen des Timeticks auf einen UNIX-Timestamp?
Ich habe schon so einiges ausprobiert, aber lande leider mit meinen Timestamps nur in der Zukunft bzw. weit in der Vergangenheit sprich ich erhalte keine korrekten Timestamps.
Aktueller Sourcecode den ich habe sieht wie folgt aus:
PHP-Quellcode
- /**
- * show interfaces
- * Zeigt alle Interfaces an mit den Informationen:
- * Slot/Port, Operational Status, Last Time Link Changed, BandWidth (Megabits), Duplex, Bytes Received, CRC Error Frames, Bytes Xmitted, Lost Frames (TX)
- **/
- public function getAllInterfaces(){
- $slots = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.4.1.6486.800.1.2.1.5.1.1.2.1.1.1");
- $ports = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.4.1.6486.800.1.2.1.5.1.1.2.1.1.2");
- $status = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.8");
- $lastchange = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.9");
- $rbytes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.10");
- $bandwidth = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.5");
- $crcframes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.4.1.6486.800.1.2.1.5.1.1.2.2.1.3");
- $sbytes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.17");
- $lostframes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.19");
- $return = array();
- for($i=0; $i<count($slots); $i++){
- // Slot / Port
- $return[$i]["port"] = str_replace("INTEGER: ", "",$slots[$i])."/".str_replace("INTEGER: ", "",$ports[$i]);
- //Status
- if($status[$i] == "INTEGER: up(1)"){
- $return[$i]["status"] = "up";
- }else{
- $return[$i]["status"] = "down";
- }
- //Ticks in Zeit konvertieren (Last Change)
- $array = explode(" ", preg_replace("/Timeticks: \((.+)\)/", "$1", $lastchange[$i]));
- $ticks = (int)$array[0];
- $time = $this->ticks_to_time($ticks);
- $date = date("d.m.Y H:i:s", $time);
- $return[$i]["lastchange"] = $date;
- //Received Bytes
- $return[$i]["rbytes"] = (int)trim(str_replace("Counter32: ", "", $rbytes[$i]));
- }
- return $return;
- }
- /**
- * Konvertieren von Ticks in einen Unixtimestamp
- **/
- private function ticks_to_time($ticks){
- $time = ($ticks - 621355968000000000) / 10000000;
- return $time;
- }
Liefert:
Beispiel Timeticks:
Quellcode
- IF-MIB::ifLastChange.1001 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1002 = Timeticks: (342222600) 39 days, 14:37:06.00
- IF-MIB::ifLastChange.1003 = Timeticks: (519800) 1:26:38.00
- IF-MIB::ifLastChange.1004 = Timeticks: (322236500) 37 days, 7:06:05.00
- IF-MIB::ifLastChange.1005 = Timeticks: (152611800) 17 days, 15:55:18.00
- IF-MIB::ifLastChange.1006 = Timeticks: (340785200) 39 days, 10:37:32.00
- IF-MIB::ifLastChange.1007 = Timeticks: (13300) 0:02:13.00
- IF-MIB::ifLastChange.1008 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1009 = Timeticks: (13300) 0:02:13.00
- IF-MIB::ifLastChange.1010 = Timeticks: (13300) 0:02:13.00
- IF-MIB::ifLastChange.1011 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1012 = Timeticks: (258192800) 29 days, 21:12:08.00
- IF-MIB::ifLastChange.1013 = Timeticks: (13300) 0:02:13.00
- IF-MIB::ifLastChange.1014 = Timeticks: (13400) 0:02:14.00
- IF-MIB::ifLastChange.1015 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1016 = Timeticks: (179861900) 20 days, 19:36:59.00
- IF-MIB::ifLastChange.1017 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1018 = Timeticks: (512400) 1:25:24.00
- IF-MIB::ifLastChange.1019 = Timeticks: (13400) 0:02:14.00
- IF-MIB::ifLastChange.1020 = Timeticks: (8700) 0:01:27.00
- IF-MIB::ifLastChange.1021 = Timeticks: (514600) 1:25:46.00
- IF-MIB::ifLastChange.1022 = Timeticks: (524400) 1:27:24.00
- IF-MIB::ifLastChange.1023 = Timeticks: (330861400) 38 days, 7:03:34.00
- IF-MIB::ifLastChange.1024 = Timeticks: (11200) 0:01:52.00
- IF-MIB::ifLastChange.1025 = Timeticks: (9800) 0:01:38.00
- IF-MIB::ifLastChange.1026 = Timeticks: (9800) 0:01:38.00
- IF-MIB::ifLastChange.1027 = Timeticks: (4000) 0:00:40.00
- IF-MIB::ifLastChange.1028 = Timeticks: (4000) 0:00:40.00
- IF-MIB::ifLastChange.13600003 = Timeticks: (11300) 0:01:53.00
- IF-MIB::ifLastChange.13604098 = Timeticks: (400) 0:00:04.00
Hierbei sei übrigens gesagt das ich einen Alcatel OmniSwitch 6850E via SNMP auslese.