OID hrSystemUptime -1.3.6.1.2.1.25.1.1 correct format

Can someone tell me how to get the OID hrSystemUptime to show in the format of days hours, minutes and seconds?

Parents
  • Well, that depends on the system reporting it. The reference for the OID says it returns TICKS. On some systems a TICK=SECONDS/100 it is different on others. The OID that Cisco uses is hundredths of a second. So, a PYTHON conversion might look like:

    >>> # Timedelta function demonstration
    >>> from datetime import datetime, timedelta
    >>> ticks = 99439400
    >>> seconds = ticks/100
    >>>
    >>> # Using current time
    >>> ini_time_for_now = datetime.now()
    >>>
    >>> # printing initial_date
    >>> print ("initial_date", str(ini_time_for_now))
    initial_date 2023-05-24 10:51:21.238179
    >>>
    >>> # Some another datetime
    >>> new_final_time = ini_time_for_now + \
    ... timedelta(seconds=seconds)
    >>>
    >>> # printing new final_date
    >>> print ("new_final_time", str(new_final_time))
    new_final_time 2023-06-04 23:04:35.238179
    >>>
    >>>
    >>> # printing calculated past_dates
    >>> print('Time difference:', str(new_final_time - \
    ... ini_time_for_now))
    Time difference: 11 days, 12:13:14

    In other environments is can be different for example on my MS Windows PC using PowerShell you get:

    PS> $TS = New-Timespan -Seconds 994394
    PS> $TS

    Days : 11
    Hours : 12
    Minutes : 13
    Seconds : 14
    Milliseconds : 0
    Ticks : 9943940000000
    TotalDays : 11.5091898148148
    TotalHours : 276.220555555556
    TotalMinutes : 16573.2333333333
    TotalSeconds : 994394
    TotalMilliseconds : 994394000

    Showing TICKS at 12,340,000,000 is SECONDS*10,000,000 or put another way SECONDS=TICKS/10,000,000.

    Really need to know where you want the conversation to occur. 

  • Thanks for your response, the system that is reporting the system uptime is a Palo Alto Firewall

  • I checked and the Palo Alto firewall is using the standard seconds = ticks/100. Our firewall responded with 321780053. Using PowerShell [because it is easy


    $TS = New-Timespan -Seconds (321780053/100)

    $TS

    Days : 37
    Hours : 5
    Minutes : 50
    Seconds : 1
    Milliseconds : 0
    Ticks : 32178010000000
    TotalDays : 37.2430671296296
    TotalHours : 893.833611111111
    TotalMinutes : 53630.0166666667
    TotalSeconds : 3217801
    TotalMilliseconds : 3217801000

    This corresponds to the Uptime reported in the GUI.

Reply
  • I checked and the Palo Alto firewall is using the standard seconds = ticks/100. Our firewall responded with 321780053. Using PowerShell [because it is easy


    $TS = New-Timespan -Seconds (321780053/100)

    $TS

    Days : 37
    Hours : 5
    Minutes : 50
    Seconds : 1
    Milliseconds : 0
    Ticks : 32178010000000
    TotalDays : 37.2430671296296
    TotalHours : 893.833611111111
    TotalMinutes : 53630.0166666667
    TotalSeconds : 3217801
    TotalMilliseconds : 3217801000

    This corresponds to the Uptime reported in the GUI.

Children