Description

This JunOS script overcomes the 497-day limitation of the standard sysUpTime MIB.

Symptoms

The standard sysUpTime MIB has a 32-bit value and its unit is 0.01 seconds. Because of this, it can only express up to 497 days, 3 hours, 27 minutes, and 52.95 seconds. However, in many cases, system uptime is longer than this limitation. With the Junos utility MIB described in this article, system uptime can be longer than 497 days.

Solution

The standard sysUpTime MIB has a 32-bit value.

Background information:

  • Standalone system and virtual-chassis system need different scripts.
  • You can distinguish which script is necessary for your system by using the show system uptime | display xml command.

 

JUNOScript for Utility MIB for Standalone System

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns ext = "http://xmlsoft.org/XSLT/namespace";

match / {
  <op-script-results> {
    var $cmd = <command> "show system uptime";
    var $out = jcs:invoke($cmd);
    var $showuptime = ($out/uptime-information/up-time/@junos:seconds);
    var $mibset-fd = <request-snmp-utility-mib-set> {
      <object-type> "counter64";
      <instance> "systemUptime";
      <object-value> $showuptime;
    }
    var $stdout=jcs:invoke($mibset-fd);
  }
}

 

Virtual Chassis System

Content of SLAX script: 

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns ext = "http://xmlsoft.org/XSLT/namespace";

match / {
  <op-script-results> {
    var $cmd = <command> "show system uptime";
    var $out = jcs:invoke($cmd);
    var $showuptime = ($out /multi-routing-engine-item[re-name=="fpc0"]/system-uptime-information /uptime-information/up-time/@junos:seconds);
    var $mibset-fd = <request-snmp-utility-mib-set> {
      <object-type> "counter64";
      <instance> "systemUptime";
      <object-value> $showuptime;
    }
    var $stdout=jcs:invoke($mibset-fd);
  }
}
 
=================================================================

jun@EX_VC> show system uptime | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.3R9/junos">
    <multi-routing-engine-results>

        <multi-routing-engine-item>

            <re-name> fpc0        >>>>>>>>>>>>>>> here!

            <system-uptime-information xmlns="http://xml.juniper.net/junos/12.3R9/junos">
                <current-time>
                    <date-time junos:seconds="1426851938"> 2015-03-20 20:45:38 KST
               
                <system-booted-time>
                    <date-time junos:seconds="1426241161"> 2015-03-13 19:06:01 KST
                    <time-length junos:seconds="610777"> 1w0d 01:39
               
                <protocols-started-time>
                    <date-time junos:seconds="1426241283"> 2015-03-13 19:08:03 KST
                    <time-length junos:seconds="610655"> 1w0d 01:37
               
                <last-configured-time>
                    <date-time junos:seconds="1426851827"> 2015-03-20 20:43:47 KST
                    <time-length junos:seconds="111"> 00:01:51
                    <user> jun
               
                <uptime-information>
                    <date-time junos:seconds="1426851938"> 8:45PM
                    <up-time junos:seconds="610807"> 7 days, 1:40
                    <active-user-count junos:format="4 users"> 4
                    <load-average-1> 0.12
                    <load-average-5> 0.07
                    <load-average-15> 0.05

    <cli>
    <banner> {master:0}
    

 

For localre - standalone systems

Content of SLAX script: 

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns ext = "http://xmlsoft.org/XSLT/namespace";

match / {
  <op-script-results> {
    var $cmd = <command> "show system uptime";
    var $out = jcs:invoke($cmd);
    var $showuptime = ($out/multi-routing-engine-item[re-name=="localre"]/system-uptime-information/uptime-information/up-time/@junos:seconds);
    var $mibset-fd = <request-snmp-utility-mib-set> {
      <object-type> "counter64";
      <instance> "systemUptime";
      <object-value> $showuptime;
    }
    var $stdout=jcs:invoke($mibset-fd);
  }
}

=================================================================
{master:0}[edit]
root@QFX# run show system uptime | display xml 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/22.4R0/junos">
    <multi-routing-engine-results>
        
        <multi-routing-engine-item>
            
            <re-name>localre</re-name>        >>>>>>>>>>> here! 
            
            <system-uptime-information xmlns="http://xml.juniper.net/junos/22.4R0/junos">
                <current-time>
                    <date-time junos:seconds="1740086247">2025-02-20 13:17:27 PST</date-time>
                </current-time>
                <time-source> NTP CLOCK </time-source>
                <system-booted-time>
                    <date-time junos:seconds="1740082249">2025-02-20 12:10:49 PST</date-time>
                    <time-length junos:seconds="3998">01:06:38</time-length>
                </system-booted-time>
                <protocols-started-time>
                    <date-time junos:seconds="1740082325">2025-02-20 12:12:05 PST</date-time>
                    <time-length junos:seconds="3922">01:05:22</time-length>
                </protocols-started-time>
                <last-configured-time>
                    <date-time junos:seconds="1740085845">2025-02-20 13:10:45 PST</date-time>
                    <time-length junos:seconds="402">00:06:42</time-length>
                    <user>root</user>
                </last-configured-time>
                <uptime-information>
                    <date-time junos:seconds="1740086247">1:17PM</date-time>
                    <up-time junos:seconds="4020">1:07</up-time>
                    <active-user-count junos:format="1 users">1</active-user-count>
                    <load-average-1>0.21</load-average-1>
                    <load-average-5>0.27</load-average-5>
                    <load-average-15>0.25</load-average-15>
                    <user-table></user-table>
                </uptime-information>
            </system-uptime-information>
        </multi-routing-engine-item>
        
    </multi-routing-engine-results>
    <cli>
        <banner>{master:0}[edit]</banner>
    </cli>                              
</rpc-reply>

{master:0}[edit]
root@QFX# 


 
CLI configuration

set event-options generate-event 1MIN time-interval 60
set event-options policy sysuptime events 1MIN
set event-options policy sysuptime then event-script sysuptime.slax
set event-options event-script file sysuptime.slax 
Verification

Note: jnxUtilCounter64Value Time will be displayed in seconds

{master:0}
jun@EX_VC> show snmp mib walk jnxUtil
jnxUtilCounter64Value.115.121.11510..116.101.109.85.112.116.105.109.101 = 610721
jnxUtilCounter64Time.115.121.115.116.101.109.85.112.116.105.109.101 = 07 df 03 14 14 2c 0f 00 2b 09 00

{master:0}
jun@EX_VC> show snmp mib walk jnxUtil ascii
jnxUtilCounter64Value."systemUptime" = 610721
jnxUtilCounter64Time."systemUptime" = 07 df 03 14 14 2c 0f 00 2b 09 00

Please refer the below to get show snmp mib get OID value from show snmp mib walk output 
{master:0}

Step 1: Run SNMP MIB Walk

First, execute the show snmp mib walk command to identify the full OID along with its index:

show snmp mib walk 1.3.6.1.4.1.2636.3.47.1.1.2.1.2  

mwUkillCounter64Value.115.121.115.116.101.109.85.112.116.105.109.101 = 77137680  

In this output, the index 115.121.115.116.101.109.85.112.116.105.109.101 represents the ASCII-encoded string systemUptime (e.g., 115 = 's', 121 = 'y', etc.).

Step 2: Retrieve the OID Value using SNMP MIB Get

To obtain the show snmp mib get output, use the full OID (base OID + ASCII index) in the following format:

jun@EX_VC>show snmp mib get  1.3.6.1.4.1.2636.3.47.1.1.2.1.2.115.121.115.116.101.109.85.112.116.105.109.101 
jnxUtilCounter64Value.115.121.115.116.101.109.85.112.116.105.109.101 = 46369320

=================================================

From SNMP server 

MIB jnxUtilCounter64Value = OID 1.3.6.1.4.1.2636.3.47.1.1.2.1.2 
MIB jnxUtilCounter64Time = OID 1.3.6.1.4.1.2636.3.47.1.1.2.1.3

root@Ubuntu:~# snmpwalk -v2c -c qfx5120 10.10.10.1 1.3.6.1.4.1.2636.3.47.1.1.2.1.2
iso.3.6.1.4.1.2636.3.47.1.1.2.1.2.115.121.115.116.101.109.85.112.116.105.109.101 = Counter64: 9540

root@Ubuntu:~# snmpwalk -v2c -c qfx5120 10.10.10.1 1.3.6.1.4.1.2636.3.47.1.1.2.1.3
iso.3.6.1.4.1.2636.3.47.1.1.2.1.3.115.121.115.116.101.109.85.112.116.105.109.101 = Hex-STRING: 07 E9 02 14 0E 31 1A 00 2D 08 00 

root@Ubuntu:~# 

9000 seconds = 2.5 hours

{master:0}[edit]
root@QFX# run show system uptime             
localre:
--------------------------------------------------------------------------
Current time: 2025-02-20 14:49:45 PST
Time Source:  NTP CLOCK 
System booted: 2025-02-20 12:10:49 PST (02:38:56 ago)
Protocols started: 2025-02-20 12:12:05 PST (02:37:40 ago)
Last configured: 2025-02-20 13:10:45 PST (01:39:00 ago) by root
 2:49PM  up 2:39, 1 users, load averages: 0.20, 0.20, 0.22

{master:0}[edit]
root@QFX# 

Modification History

2/20/25 - Added new examples and correcting fonts