#!/usr/bin/env python
###############################################################################
#
# NO WARRANTY
#
# BECAUSE THE PROGRAM IS PROVIDED FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
#
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.
#
###############################################################################
"""
Example script to continuously print the value of specified system diagnostics value.
"""
import sys
import time
import packetlogic2
#
# "parse" arguments.
#
try:
[host, user, pwd, zonename, valuename] = sys.argv[1:]
except ValueError:
print "Usage: sysdiag_tail.py plhost pluser plpass zonename valuename"
print "Example: realtime_display_netobject_data.py 192.168.1.25 admin pldemo00 connections 'current count'"
sys.exit(1)
#
# Connect to PacketLogic system
#
try:
pl = packetlogic2.connect(host, user, pwd)
except:
t, v, tb = sys.exc_info()
print "Error: Couldn't connect: %s" % v
sys.exit(1)
#
# Get System Diagnostics resource
#
sd = pl.SysDiag()
#
# Function to print value every 5s
#
def repeatadly_print_value(z, v):
while True:
if v.type == z.TYPE_MOMENT:
print "%8d/s %8d" % (v.value.rate, v.value.value)
elif v.type == z.TYPE_SPEED:
print "%8dbps %8d" % (v.value.rate*8, v.value.value)
else:
print "%8d" % v.value.value
time.sleep(5)
z.refresh()
#
# Find requested sysdiag value
#
zones = sd.zone_list()
for baseoid,zone in zones.iteritems():
if zone.name == zonename:
zone.refresh()
for _,val in zone.valuedefs.iteritems():
if val.name == valuename:
repeatadly_print_value(zone, val)
break
else:
print "Value named '%s' in '%s' not found, available values:" % (valuename, zonename)
for k,v in zone.valuedefs.iteritems():
print " * '%s' (%d.%s %s)" % (v.name, k, baseoid, v.oid)
pass
break
else:
print "Zone named %s not found, available zones:" % zonename
for baseoid, z in zones.iteritems():
print " * '%s' (%s)" % (z.name, baseoid)