SNMP - Timeticks: Berechnen von Timestamps

  • PHP

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Umbekannt.

    SNMP - Timeticks: Berechnen von Timestamps

    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:

    PHP-Quellcode

    1. /**
    2. * show interfaces
    3. * Zeigt alle Interfaces an mit den Informationen:
    4. * Slot/Port, Operational Status, Last Time Link Changed, BandWidth (Megabits), Duplex, Bytes Received, CRC Error Frames, Bytes Xmitted, Lost Frames (TX)
    5. **/
    6. public function getAllInterfaces(){
    7. $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");
    8. $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");
    9. $status = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.8");
    10. $lastchange = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.9");
    11. $rbytes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.10");
    12. $bandwidth = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.5");
    13. $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");
    14. $sbytes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.17");
    15. $lostframes = snmp2_walk($this->ipaddress, $this->community, "1.3.6.1.2.1.2.2.1.19");
    16. $return = array();
    17. for($i=0; $i<count($slots); $i++){
    18. // Slot / Port
    19. $return[$i]["port"] = str_replace("INTEGER: ", "",$slots[$i])."/".str_replace("INTEGER: ", "",$ports[$i]);
    20. //Status
    21. if($status[$i] == "INTEGER: up(1)"){
    22. $return[$i]["status"] = "up";
    23. }else{
    24. $return[$i]["status"] = "down";
    25. }
    26. //Ticks in Zeit konvertieren (Last Change)
    27. $array = explode(" ", preg_replace("/Timeticks: \((.+)\)/", "$1", $lastchange[$i]));
    28. $ticks = (int)$array[0];
    29. $time = $this->ticks_to_time($ticks);
    30. $date = date("d.m.Y H:i:s", $time);
    31. $return[$i]["lastchange"] = $date;
    32. //Received Bytes
    33. $return[$i]["rbytes"] = (int)trim(str_replace("Counter32: ", "", $rbytes[$i]));
    34. }
    35. return $return;
    36. }
    37. /**
    38. * Konvertieren von Ticks in einen Unixtimestamp
    39. **/
    40. private function ticks_to_time($ticks){
    41. $time = ($ticks - 621355968000000000) / 10000000;
    42. return $time;
    43. }


    Liefert:

    Quellcode

    1. Array
    2. (
    3. [0] => Array
    4. (
    5. [port] => 1/1
    6. [status] => down
    7. [lastchange] => 01.01.0001 01:00:01
    8. [rbytes] => 0
    9. )
    10. )


    Beispiel Timeticks:

    Quellcode

    1. IF-MIB::ifLastChange.1001 = Timeticks: (8700) 0:01:27.00
    2. IF-MIB::ifLastChange.1002 = Timeticks: (342222600) 39 days, 14:37:06.00
    3. IF-MIB::ifLastChange.1003 = Timeticks: (519800) 1:26:38.00
    4. IF-MIB::ifLastChange.1004 = Timeticks: (322236500) 37 days, 7:06:05.00
    5. IF-MIB::ifLastChange.1005 = Timeticks: (152611800) 17 days, 15:55:18.00
    6. IF-MIB::ifLastChange.1006 = Timeticks: (340785200) 39 days, 10:37:32.00
    7. IF-MIB::ifLastChange.1007 = Timeticks: (13300) 0:02:13.00
    8. IF-MIB::ifLastChange.1008 = Timeticks: (8700) 0:01:27.00
    9. IF-MIB::ifLastChange.1009 = Timeticks: (13300) 0:02:13.00
    10. IF-MIB::ifLastChange.1010 = Timeticks: (13300) 0:02:13.00
    11. IF-MIB::ifLastChange.1011 = Timeticks: (8700) 0:01:27.00
    12. IF-MIB::ifLastChange.1012 = Timeticks: (258192800) 29 days, 21:12:08.00
    13. IF-MIB::ifLastChange.1013 = Timeticks: (13300) 0:02:13.00
    14. IF-MIB::ifLastChange.1014 = Timeticks: (13400) 0:02:14.00
    15. IF-MIB::ifLastChange.1015 = Timeticks: (8700) 0:01:27.00
    16. IF-MIB::ifLastChange.1016 = Timeticks: (179861900) 20 days, 19:36:59.00
    17. IF-MIB::ifLastChange.1017 = Timeticks: (8700) 0:01:27.00
    18. IF-MIB::ifLastChange.1018 = Timeticks: (512400) 1:25:24.00
    19. IF-MIB::ifLastChange.1019 = Timeticks: (13400) 0:02:14.00
    20. IF-MIB::ifLastChange.1020 = Timeticks: (8700) 0:01:27.00
    21. IF-MIB::ifLastChange.1021 = Timeticks: (514600) 1:25:46.00
    22. IF-MIB::ifLastChange.1022 = Timeticks: (524400) 1:27:24.00
    23. IF-MIB::ifLastChange.1023 = Timeticks: (330861400) 38 days, 7:03:34.00
    24. IF-MIB::ifLastChange.1024 = Timeticks: (11200) 0:01:52.00
    25. IF-MIB::ifLastChange.1025 = Timeticks: (9800) 0:01:38.00
    26. IF-MIB::ifLastChange.1026 = Timeticks: (9800) 0:01:38.00
    27. IF-MIB::ifLastChange.1027 = Timeticks: (4000) 0:00:40.00
    28. IF-MIB::ifLastChange.1028 = Timeticks: (4000) 0:00:40.00
    29. IF-MIB::ifLastChange.13600003 = Timeticks: (11300) 0:01:53.00
    30. IF-MIB::ifLastChange.13604098 = Timeticks: (400) 0:00:04.00


    Hierbei sei übrigens gesagt das ich einen Alcatel OmniSwitch 6850E via SNMP auslese.
    Moin,
    leider hilft der Ansatz absolut nicht. Etwas abgewandelt habe ich das bereits versucht zu implementieren und erhalte keine korrekten Daten.
    Wobei noch gesagt sei, das im obigen Script noch ein kleiner Fehler ist, den timestamp berechne ich mit der Ausgabe von meiner privaten Methode ticks_to_time und ziehe den Wert vom aktuellen Timestamp ab (time())
    um auf das Datum zu kommen an dem die letzte Änderung am Portstatus durchgeführt wurde.

    Des weiteren musste ich feststellen das sich die Anzahl der Timeticks beim Auslesen der OID via SNMP nicht zeitlich verändert, was man ja eigentlich annehmen würde.